Skip to content

Commit

Permalink
docs(notebooks): declare compute-uncompute function in notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrorrivero committed Mar 8, 2024
1 parent aa18018 commit 4d8b81c
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion docs/notebooks/scaling/scaling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,38 @@
"For execution, we also need to bind the circuit parameters to specific values and insert the desired measurements."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "20273cfe",
"metadata": {},
"outputs": [],
"source": [
"def compute_uncompute(\n",
" circuit: QuantumCircuit, *, barrier: bool = True, inplace: bool = False\n",
") -> QuantumCircuit:\n",
" \"\"\"Build compute-uncompute version of input quantum circuit.\n",
"\n",
" Args:\n",
" circuit: the original quantum circuit to build compute-uncompute version of.\n",
" barrier: whether to insert a barrier between the compute and uncompute\n",
" halves of the output circuit.\n",
" inplace: if True, modify the input circuit. Otherwise make a copy.\n",
"\n",
" Returns:\n",
" Compute-uncompute version of input quantum circuit with optional barrier.\n",
" \"\"\"\n",
" if not isinstance(circuit, QuantumCircuit):\n",
" raise TypeError(f\"Invalid circuit type {type(circuit)}, expected <QuantumCircuit>.\")\n",
" inverse = circuit.inverse()\n",
" if not inplace:\n",
" circuit = circuit.copy()\n",
" if barrier:\n",
" circuit.barrier()\n",
" circuit.compose(inverse, inplace=True)\n",
" return circuit"
]
},
{
"cell_type": "code",
"execution_count": 3,
Expand All @@ -253,7 +285,7 @@
}
],
"source": [
"from quantum_enablement.circuits import compute_uncompute, MBLChainCircuit\n",
"from quantum_enablement.circuits import MBLChainCircuit\n",
"\n",
"reference_circuit = compute_uncompute(MBLChainCircuit(num_qubits=4, depth=2), barrier=True)\n",
"reference_circuit.assign_parameters([0.1, 0.2, 0.3, 0.4, 0.5], inplace=True) # Note: dummy values\n",
Expand Down

0 comments on commit 4d8b81c

Please sign in to comment.