diff --git a/docs/notebooks/scaling/scaling.ipynb b/docs/notebooks/scaling/scaling.ipynb index 06a9b2e..67aaeac 100644 --- a/docs/notebooks/scaling/scaling.ipynb +++ b/docs/notebooks/scaling/scaling.ipynb @@ -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 .\")\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, @@ -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",