From 74bb91aeebccb0b069446bdf6ce98e46612b5246 Mon Sep 17 00:00:00 2001 From: Caleb Johnson Date: Tue, 18 Jul 2023 09:03:52 -0500 Subject: [PATCH] Update freezing orbitals documentation (#315) * Update freezing orbitals documentation --- ...ntanglement_forging_ground_state_solver.py | 2 +- .../explanation/index.rst | 22 -------- .../how-tos/freeze-orbitals.ipynb | 51 ++++++++++++++----- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/circuit_knitting/forging/entanglement_forging_ground_state_solver.py b/circuit_knitting/forging/entanglement_forging_ground_state_solver.py index c185adf63..872bf2728 100644 --- a/circuit_knitting/forging/entanglement_forging_ground_state_solver.py +++ b/circuit_knitting/forging/entanglement_forging_ground_state_solver.py @@ -139,7 +139,7 @@ def __init__( optimizer: Optimizer to use to optimize the ansatz circuit parameters initial_point: Initial values for ansatz parameters orbitals_to_reduce: List of orbital indices to remove from the problem before - decomposition. + decomposition. See :ref:`Freezing orbitals` for more information. backend_names: Backend name or list of backend names to use during parallel computation options: Options or list of options to be applied to the backends mo_coeff: Coefficients for converting an input problem to MO basis diff --git a/docs/entanglement_forging/explanation/index.rst b/docs/entanglement_forging/explanation/index.rst index a0978d663..a89773bc0 100644 --- a/docs/entanglement_forging/explanation/index.rst +++ b/docs/entanglement_forging/explanation/index.rst @@ -138,28 +138,6 @@ orbital). Furthermore, in the case of water, it turns out that orbital 3 symmetry to the other orbitals, so excitations to orbital 3 are suppressed. For water, we thus freeze orbitals 0 and 3. - -Example: Water molecule -^^^^^^^^^^^^^^^^^^^^^^^ - -The total number of orbitals (core + valence) = 7 orbitals - -Frozen orbital approximation = 2 orbitals - -Active space orbitals = total number of orbitals – frozen orbitals = 5 -orbitals (bitstring size is set to 5) - -Leading excitation analysis = 3 unique bitstrings - -.. code:: python - - >>> from circuit_knitting.utils import reduce_bitstrings - >>> orbitals_to_reduce = [0,3] - >>> bitstrings = [(1,1,1,1,1,0,0), (1,0,1,1,1,0,1), (1,0,1,1,1,1,0)] - >>> reduced_bitstrings = reduce_bitstrings(bitstrings, orbitals_to_reduce) - >>> print(f'Bitstrings after orbital reduction: {reduced_bitstrings}') - Bitstrings after orbital reduction: [[1, 1, 1, 0, 0], [0, 1, 1, 0, 1], [0, 1, 1, 1, 0]] - A complete example is provided in the `guide on freezing orbitals <../how-tos/freeze-orbitals.ipynb>`_. .. _Picking the bitstrings: diff --git a/docs/entanglement_forging/how-tos/freeze-orbitals.ipynb b/docs/entanglement_forging/how-tos/freeze-orbitals.ipynb index 05233531f..91643cea4 100644 --- a/docs/entanglement_forging/how-tos/freeze-orbitals.ipynb +++ b/docs/entanglement_forging/how-tos/freeze-orbitals.ipynb @@ -37,7 +37,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "First, we set up the $\\mathrm{H}_2\\mathrm{O}$ molecule, specify the driver and converter, and instantiate an `ElectronicStructureProblem`." + "First, we set up the $\\mathrm{H}_2\\mathrm{O}$ molecule, specify the driver and converter, and instantiate an `ElectronicStructureProblem`. The total number of orbitals (core + valence) is seven." ] }, { @@ -71,13 +71,43 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Create the ansatz with a reduced set of bitstrings." + "Since the execution time scales exponentially in the number of orbitals, it’s a good idea to simplify the problem (if possible) by eliminating some of the orbitals. Some knowledge of chemistry is useful when picking orbitals to freeze. One good rule of thumb is to freeze the core orbital. For $\\mathrm{H}_2\\mathrm{O}$, this is the core oxygen $1s$ orbital, which corresponds to qubit 0 in the ansatz. Furthermore, the out-of-phase $2p$ orbital correponds to qubit 3 in the ansatz, so we freeze it as well. For $\\mathrm{H}_2\\mathrm{O}$, we thus freeze orbitals 0 and 3, resulting in length-5 bitstrings." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[(1, 1, 1, 0, 0), (0, 1, 1, 0, 1), (0, 1, 1, 1, 0)]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "orbitals_to_reduce = [0, 3]\n", + "bitstrings_u = [(1, 1, 1, 1, 1, 0, 0), (1, 0, 1, 1, 1, 0, 1), (1, 0, 1, 1, 1, 1, 0)]\n", + "reduced_bitstrings = reduce_bitstrings(bitstrings_u, orbitals_to_reduce)\n", + "reduced_bitstrings" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create the ansatz circuit. Since we have frozen two orbitals, the size of our active space has been decreased from 7 to 5, so we create a 5-qubit ansatz circuit. Finally, we instantiate an ``EntanglementForgingAnsatz``, which contains the ansatz circuit and the reduced bitstrings." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, "outputs": [ { "data": { @@ -108,7 +138,7 @@ " └───────────────┘└──────────────┘└───────────────┘" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -139,11 +169,6 @@ "circuit_u.append(hop_gate.to_gate({theta: theta_3}), [0, 2])\n", "circuit_u.append(hop_gate.to_gate({theta: theta_4}), [3, 4])\n", "\n", - "# Set our bitstrings, and then reduce the chosen orbitals\n", - "orbitals_to_reduce = [0, 3]\n", - "bitstrings_u = [(1, 1, 1, 1, 1, 0, 0), (1, 0, 1, 1, 1, 0, 1), (1, 0, 1, 1, 1, 1, 0)]\n", - "reduced_bitstrings = reduce_bitstrings(bitstrings_u, orbitals_to_reduce)\n", - "\n", "ansatz = EntanglementForgingAnsatz(circuit_u=circuit_u, bitstrings_u=reduced_bitstrings)\n", "\n", "ansatz.circuit_u.draw()" @@ -158,7 +183,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -177,13 +202,13 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "

Version Information

Qiskit SoftwareVersion
qiskit-terra0.24.0
qiskit-aer0.12.0
qiskit-ibmq-provider0.20.2
qiskit-nature0.6.0
System information
Python version3.8.16
Python compilerClang 14.0.6
Python builddefault, Mar 1 2023 21:19:10
OSDarwin
CPUs8
Memory (Gb)32.0
Sun Jun 18 20:55:50 2023 CDT
" + "

Version Information

Qiskit SoftwareVersion
qiskit-terra0.24.1
qiskit-aer0.12.1
qiskit-ibmq-provider0.20.2
qiskit0.43.2
qiskit-nature0.6.0
System information
Python version3.8.16
Python compilerClang 14.0.6
Python builddefault, Mar 1 2023 21:19:10
OSDarwin
CPUs8
Memory (Gb)32.0
Tue Jul 11 12:13:03 2023 CDT
" ], "text/plain": [ "" @@ -219,7 +244,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -233,7 +258,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.16" + "version": "3.10.9" }, "vscode": { "interpreter": {