From 95d04d1d0dc907ad6f0a4c522fcf6eaaf9b123f7 Mon Sep 17 00:00:00 2001 From: Adrian Mak Date: Wed, 17 Apr 2024 15:18:11 +0800 Subject: [PATCH 1/5] minor fix to ansatz documentation --- doc/source/api-reference/.ansatz.rst.swp | Bin 0 -> 12288 bytes doc/source/api-reference/ansatz.rst | 2 +- src/qibochem/ansatz/basis_rotation.py | 3 ++- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 doc/source/api-reference/.ansatz.rst.swp diff --git a/doc/source/api-reference/.ansatz.rst.swp b/doc/source/api-reference/.ansatz.rst.swp new file mode 100644 index 0000000000000000000000000000000000000000..9ddc48ab7fd3b4ec22ad1eee8c36545760710f65 GIT binary patch literal 12288 zcmeI2zi!k(5QisF2O=n-K`bDkvYq4*B9SOUL_`WCBna(kZ@tE=yLj(**B6okBq|Et z0GApttjZ=_GFkv;q8vs_r7&f@*e+hQeNB#s55rQzA^ z&Fd#epM4@q<+gNPBa7EV?#Nt>vZqRljiloH%)6 zYvv}TFaQHE00S@p126ysFaQJpvw_f`qsM%}BjZD!8IN-_<2c0t126ysFaQHE00S@p z126ysFaQHE@DCc0Dbc-oqK{1V|9|rR|NS`8H|8tzg?Yg|XPz=86PPPZi&l6lDNFdNKG<|=cUxx`fKf3Eg`fB_hQ0T_S*7=Qs7fB_hQ0T}oT z12Kn?Ww2RUs99-cwunnb1~Yf^@rL-Io2HPQ`k!^g%n;b@;aOtlc!1$DHiD7~PUC zIIW`%tGd58t#s**bh@px%qXLa5a)XT$wvpNmZ&SDrh>oAbC&FN{osVML+!i>xfW}8 nHbt{*ky$5((ivNNQMJ+=A6UltAY$ZO` Date: Wed, 17 Apr 2024 07:20:13 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/qibochem/ansatz/basis_rotation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/qibochem/ansatz/basis_rotation.py b/src/qibochem/ansatz/basis_rotation.py index 5926a50..a533d33 100644 --- a/src/qibochem/ansatz/basis_rotation.py +++ b/src/qibochem/ansatz/basis_rotation.py @@ -3,7 +3,6 @@ """ import numpy as np - from qibo import gates, models from scipy.linalg import expm From 4bd5da96b214ddf2c19348176b216e27481b25ca Mon Sep 17 00:00:00 2001 From: Adrian Mak Date: Wed, 17 Apr 2024 15:39:34 +0800 Subject: [PATCH 3/5] minor fix to ansatz documentation --- doc/source/api-reference/.ansatz.rst.swp | Bin 12288 -> 0 bytes doc/source/tutorials/ansatz.rst | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 doc/source/api-reference/.ansatz.rst.swp diff --git a/doc/source/api-reference/.ansatz.rst.swp b/doc/source/api-reference/.ansatz.rst.swp deleted file mode 100644 index 9ddc48ab7fd3b4ec22ad1eee8c36545760710f65..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2zi!k(5QisF2O=n-K`bDkvYq4*B9SOUL_`WCBna(kZ@tE=yLj(**B6okBq|Et z0GApttjZ=_GFkv;q8vs_r7&f@*e+hQeNB#s55rQzA^ z&Fd#epM4@q<+gNPBa7EV?#Nt>vZqRljiloH%)6 zYvv}TFaQHE00S@p126ysFaQJpvw_f`qsM%}BjZD!8IN-_<2c0t126ysFaQHE00S@p z126ysFaQHE@DCc0Dbc-oqK{1V|9|rR|NS`8H|8tzg?Yg|XPz=86PPPZi&l6lDNFdNKG<|=cUxx`fKf3Eg`fB_hQ0T_S*7=Qs7fB_hQ0T}oT z12Kn?Ww2RUs99-cwunnb1~Yf^@rL-Io2HPQ`k!^g%n;b@;aOtlc!1$DHiD7~PUC zIIW`%tGd58t#s**bh@px%qXLa5a)XT$wvpNmZ&SDrh>oAbC&FN{osVML+!i>xfW}8 nHbt{*ky$5((ivNNQMJ+=A6UltAY$ZO` Date: Fri, 19 Apr 2024 13:11:49 +0800 Subject: [PATCH 4/5] doc: ansatz basis_rotation tutorial --- doc/source/tutorials/ansatz.rst | 92 +++++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 5 deletions(-) diff --git a/doc/source/tutorials/ansatz.rst b/doc/source/tutorials/ansatz.rst index 271edf6..5bcc126 100644 --- a/doc/source/tutorials/ansatz.rst +++ b/doc/source/tutorials/ansatz.rst @@ -79,9 +79,6 @@ The following example demonstrates how the energy of the H2 molecule is affected | 0.2 | 0.673325849299 | ----------------------------- -.. - Placeholder for basis rotation ansatz documentation - .. _UCC Ansatz: @@ -141,14 +138,99 @@ An example of how to build a UCC doubles circuit ansatz for the :math:`H_2` mole q3: ... ─────o─RX─RX─o────────────o─RX─ +.. + _Basis rotation ansatz + +Basis rotation ansatz +--------------------- + +The starting points for contemporary quantum chemistry methods are often those based on the mean field approximation within a (finite) molecular orbital basis, i.e. the Hartree-Fock method. The electronic energy is calculated as the mean value of the electronic Hamiltonian :math:`\hat{H}_{\mathrm{elec}}` acting on a normalized single Slater determinant function :math:`\psi` [#f6]_ + +.. math:: + + \begin{align*} + E[\psi] &= \langle \psi | \hat{H}_{\mathrm{elec}} |\psi \rangle \\ + &= \sum_i^{N_f} \langle \phi_i |\hat{h}|\phi_i \rangle + \frac{1}{2} \sum_{i,j}^{N_f} + \langle \phi_i\phi_j||\phi_i\phi_j \rangle + \end{align*} + +The orthonormal molecular orbitals :math:`\phi` are optimized by a direct minimization of the energy functional with respect to parameters :math:`\kappa` that parameterize the unitary rotations of the orbital basis. Qibochem's implementation uses the QR decomposition of the unitary matrix as employed by Clements et al., [#f7]_ which results in a rectangular gate layout of `Givens rotation gates `_ that yield linear CNOT gate depth when decomposed. + + +.. code-block:: python + + import numpy as np + from qibochem.driver.molecule import Molecule + from qibochem.ansatz import basis_rotation, ucc + from qibo import Circuit, gates, models + + def basis_rotation_circuit(mol, parameters=0.0): + + nqubits = mol.nso + occ = range(0, mol.nelec) + vir = range(mol.nelec, mol.nso) + + U, kappa = basis_rotation.unitary(occ, vir, parameters=parameters) + gate_angles, final_U = basis_rotation.givens_qr_decompose(U) + gate_layout = basis_rotation.basis_rotation_layout(nqubits) + gate_list, ordered_angles = basis_rotation.basis_rotation_gates(gate_layout, gate_angles, kappa) + + circuit = Circuit(nqubits) + for _i in range(mol.nelec): + circuit.add(gates.X(_i)) + circuit.add(gate_list) + + return circuit, gate_angles + + h3p = Molecule([('H', (0.0000, 0.0000, 0.0000)), + ('H', (0.0000, 0.0000, 0.8000)), + ('H', (0.0000, 0.0000, 1.6000))], + charge=1, multiplicity=1) + h3p.run_pyscf(max_scf_cycles=1) + + e_init = h3p.e_hf + h3p_sym_ham = h3p.hamiltonian("sym", h3p.oei, h3p.tei, 0.0, "jw") + + hf_circuit, qubit_parameters = basis_rotation_circuit(h3p, parameters=0.1) + + print(hf_circuit.draw()) + + vqe = models.VQE(hf_circuit, h3p_sym_ham) + res = vqe.minimize(qubit_parameters) + + print('energy of initial guess: ', e_init) + print('energy after vqe : ', res[0]) + +.. code-block:: output + + q0: ─X─G─────────G─────────G───────── + q1: ─X─G─────G───G─────G───G─────G─── + q2: ─────G───G─────G───G─────G───G─── + q3: ─────G─────G───G─────G───G─────G─ + q4: ───────G───G─────G───G─────G───G─ + q5: ───────G─────────G─────────G───── + basis rotation: using uniform value of 0.1 for each parameter value + energy of initial guess: -1.1977713400022736 + energy after vqe : -1.2024564133305427 + + + + + + .. rubric:: References .. [#f1] Kutzelnigg, W. (1977). 'Pair Correlation Theories', in Schaefer, H.F. (eds) Methods of Electronic Structure Theory. Modern Theoretical Chemistry, vol 3. Springer, Boston, MA. -.. [#f2] Whitfield, J. D. et al., 'Simulation of electronic structure Hamiltonians using quantum computers', Mol. Phys. 109 (2011) 735. +.. [#f2] Whitfield, J. D. et al., 'Simulation of Electronic Structure Hamiltonians using Quantum Computers', Mol. Phys. 109 (2011) 735. -.. [#f3] Anand. A. et al., 'A quantum computing view on unitary coupled cluster theory', Chem. Soc. Rev. 51 (2022) 1659. +.. [#f3] Anand. A. et al., 'A Quantum Computing view on Unitary Coupled Cluster Theory', Chem. Soc. Rev. 51 (2022) 1659. .. [#f4] Crawford, T. D. et al., 'An Introduction to Coupled Cluster Theory for Computational Chemists', in Reviews in Computational Chemistry 14 (2007) 33. .. [#f5] Barkoutsos, P. K. et al., 'Quantum algorithms for electronic structure calculations: Particle-hole Hamiltonian and optimized wave-function expansions', Phys. Rev. A 98 (2018) 022322. + +.. [#f6] Piela, L. (2007). 'Ideas of Quantum Chemistry'. Elsevier B. V., the Netherlands. + +.. [#f7] Clements W. R. et al., 'Optimal Design for Universal Multiport Interferometers', Optica 3 (2016) 1460. + From b4912acf4e64ce5904361261d4c65fcdafa70818 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 19 Apr 2024 05:12:19 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/source/tutorials/ansatz.rst | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/doc/source/tutorials/ansatz.rst b/doc/source/tutorials/ansatz.rst index 5bcc126..86dac96 100644 --- a/doc/source/tutorials/ansatz.rst +++ b/doc/source/tutorials/ansatz.rst @@ -138,7 +138,7 @@ An example of how to build a UCC doubles circuit ansatz for the :math:`H_2` mole q3: ... ─────o─RX─RX─o────────────o─RX─ -.. +.. _Basis rotation ansatz Basis rotation ansatz @@ -150,11 +150,11 @@ The starting points for contemporary quantum chemistry methods are often those b \begin{align*} E[\psi] &= \langle \psi | \hat{H}_{\mathrm{elec}} |\psi \rangle \\ - &= \sum_i^{N_f} \langle \phi_i |\hat{h}|\phi_i \rangle + \frac{1}{2} \sum_{i,j}^{N_f} - \langle \phi_i\phi_j||\phi_i\phi_j \rangle + &= \sum_i^{N_f} \langle \phi_i |\hat{h}|\phi_i \rangle + \frac{1}{2} \sum_{i,j}^{N_f} + \langle \phi_i\phi_j||\phi_i\phi_j \rangle \end{align*} -The orthonormal molecular orbitals :math:`\phi` are optimized by a direct minimization of the energy functional with respect to parameters :math:`\kappa` that parameterize the unitary rotations of the orbital basis. Qibochem's implementation uses the QR decomposition of the unitary matrix as employed by Clements et al., [#f7]_ which results in a rectangular gate layout of `Givens rotation gates `_ that yield linear CNOT gate depth when decomposed. +The orthonormal molecular orbitals :math:`\phi` are optimized by a direct minimization of the energy functional with respect to parameters :math:`\kappa` that parameterize the unitary rotations of the orbital basis. Qibochem's implementation uses the QR decomposition of the unitary matrix as employed by Clements et al., [#f7]_ which results in a rectangular gate layout of `Givens rotation gates `_ that yield linear CNOT gate depth when decomposed. .. code-block:: python @@ -180,11 +180,11 @@ The orthonormal molecular orbitals :math:`\phi` are optimized by a direct minimi circuit.add(gates.X(_i)) circuit.add(gate_list) - return circuit, gate_angles + return circuit, gate_angles - h3p = Molecule([('H', (0.0000, 0.0000, 0.0000)), + h3p = Molecule([('H', (0.0000, 0.0000, 0.0000)), ('H', (0.0000, 0.0000, 0.8000)), - ('H', (0.0000, 0.0000, 1.6000))], + ('H', (0.0000, 0.0000, 1.6000))], charge=1, multiplicity=1) h3p.run_pyscf(max_scf_cycles=1) @@ -194,13 +194,13 @@ The orthonormal molecular orbitals :math:`\phi` are optimized by a direct minimi hf_circuit, qubit_parameters = basis_rotation_circuit(h3p, parameters=0.1) print(hf_circuit.draw()) - + vqe = models.VQE(hf_circuit, h3p_sym_ham) res = vqe.minimize(qubit_parameters) print('energy of initial guess: ', e_init) print('energy after vqe : ', res[0]) - + .. code-block:: output q0: ─X─G─────────G─────────G───────── @@ -233,4 +233,3 @@ The orthonormal molecular orbitals :math:`\phi` are optimized by a direct minimi .. [#f6] Piela, L. (2007). 'Ideas of Quantum Chemistry'. Elsevier B. V., the Netherlands. .. [#f7] Clements W. R. et al., 'Optimal Design for Universal Multiport Interferometers', Optica 3 (2016) 1460. -