Skip to content

Commit

Permalink
remove unnecessary compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMacCQ committed Dec 24, 2024
1 parent 1fa4d95 commit 89fc450
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,6 @@
"metadata": {},
"outputs": [],
"source": [
"from pytket import Circuit\n",
"\n",
"\n",
"def build_cost_layer(graph: nx.Graph, gamma_val: float) -> Circuit:\n",
" circ = Circuit(graph.number_of_nodes())\n",
"\n",
Expand Down Expand Up @@ -476,12 +473,12 @@
"\n",
"def eval_qaoa_energy(\n",
" backend: Backend,\n",
" compiler_pass: Callable[[Circuit], bool],\n",
" guess_mixer_angles: np.array,\n",
" guess_cost_angles: np.array,\n",
" graph: nx.Graph,\n",
" seed: int,\n",
" shots: int = 5000,\n",
" compiler_pass: Callable[[Circuit], bool] | None = None,\n",
") -> tuple[float, BackendResult]:\n",
"\n",
" # Build Circuit\n",
Expand All @@ -491,7 +488,8 @@
"\n",
" # Compile\n",
" RemoveBarriers().apply(qaoa_circuit)\n",
" compiler_pass(qaoa_circuit)\n",
" if compiler_pass:\n",
" compiler_pass(qaoa_circuit)\n",
"\n",
" # Execute\n",
" result: BackendResult = backend.run_circuit(qaoa_circuit, shots, seed=seed)\n",
Expand Down Expand Up @@ -524,12 +522,12 @@
"source": [
"def solve_maxcut_instance(\n",
" graph: nx.Graph,\n",
" compiler_pass: Callable[[Circuit], bool],\n",
" backend: Backend,\n",
" iterations: int = 100,\n",
" p_value: int = 3,\n",
" n_shots: int = 5000,\n",
" seed: int = 12345,\n",
" compiler_pass: Callable[[Circuit], bool]| None = None,\n",
") -> tuple[BackendResult, np.array, np.array]:\n",
"\n",
" highest_energy = 0\n",
Expand All @@ -543,12 +541,12 @@
" guess_cost_angles = rng.uniform(0, 1, p_value)\n",
" qaoa_energy, result = eval_qaoa_energy(\n",
" backend,\n",
" compiler_pass,\n",
" guess_mixer_angles,\n",
" guess_cost_angles,\n",
" seed=seed,\n",
" shots=n_shots,\n",
" graph=graph,\n",
" compiler_pass=None,\n",
" )\n",
"\n",
" if qaoa_energy > highest_energy:\n",
Expand Down Expand Up @@ -591,8 +589,7 @@
"source": [
"from pytket.extensions.qiskit import AerBackend\n",
"\n",
"backend = AerBackend()\n",
"comp = backend.get_compiled_circuit"
"backend = AerBackend()"
]
},
{
Expand All @@ -609,7 +606,7 @@
"%%time\n",
"qaoa_result, cost_angles, mixer_angles = solve_maxcut_instance(\n",
" backend=backend,\n",
" compiler_pass=backend.default_compilation_pass(2).apply,\n",
" compiler_pass=None,\n",
" n_shots=5000,\n",
" iterations=100,\n",
" graph=max_cut_graph,\n",
Expand Down

0 comments on commit 89fc450

Please sign in to comment.