Skip to content

Commit e150259

Browse files
soranjhChiffafox
andauthored
Update PySCF demo to include initial states (#934)
**Title:** **Summary:** Adds a section to the PySCF demo explaining how to import initial states. **Relevant references:** **Possible Drawbacks:** **Related GitHub Issues:** --------- Co-authored-by: Stepan Fomichev <[email protected]>
1 parent bb4e726 commit e150259

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

demonstrations/tutorial_qchem_external.metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}
77
],
88
"dateOfPublication": "2023-01-03T00:00:00+00:00",
9-
"dateOfLastModification": "2023-01-04T00:00:00+00:00",
9+
"dateOfLastModification": "2023-09-21T00:00:00+00:00",
1010
"categories": [
1111
"Quantum Chemistry", "Devices and Performance"
1212
],

demonstrations/tutorial_qchem_external.py

+47-5
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
The quantum chemistry module in PennyLane, :mod:`qml.qchem <pennylane.qchem>`, provides built-in
2020
methods to compute molecular integrals, solve Hartree-Fock equations, and construct
2121
`fully-differentiable <https://pennylane.ai/qml/demos/tutorial_differentiable_HF.html>`_ molecular
22-
Hamiltonians. However, there are many other interesting and widely used quantum chemistry libraries out there. Instead of reinventing the wheel, PennyLane lets you to take advantage of various external resources and libraries to build upon existing research. In this demo we will show you how to integrate PennyLane with `PySCF <https://github.com/sunqm/pyscf>`_ and
23-
`OpenFermion <https://github.com/quantumlib/OpenFermion>`_ to compute molecular integrals and
24-
construct molecular Hamiltonians.
22+
Hamiltonians. However, there are many other interesting and widely used quantum chemistry libraries
23+
out there. Instead of reinventing the wheel, PennyLane lets you take advantage of various
24+
external resources and libraries to build upon existing research. In this demo we will show you how
25+
to integrate PennyLane with `PySCF <https://github.com/sunqm/pyscf>`_ and
26+
`OpenFermion <https://github.com/quantumlib/OpenFermion>`_ to compute molecular integrals,
27+
construct molecular Hamiltonians, and import initial states.
2528
2629
Building molecular Hamiltonians
2730
-------------------------------
@@ -131,6 +134,43 @@
131134
print(f'Estimated number of non-Clifford gates: {algo.gates:.2e}')
132135
print(f'Estimated number of logical qubits: {algo.qubits}')
133136

137+
##############################################################################
138+
# Importing initial states
139+
# ------------------------
140+
# Simulating molecules with quantum algorithms requires defining an initial state that should have
141+
# non-zero overlap with the molecular ground state. A trivial choice for the initial state is the
142+
# Hartree-Fock state which is obtained by putting the electrons in the lowest-energy molecular
143+
# orbitals. For molecules with a complicated electronic structure, the Hartree-Fock state has
144+
# only a small overlap with the ground state, which makes executing quantum algorithms
145+
# inefficient.
146+
#
147+
# Initial states obtained from affordable post-Hartree-Fock calculations can be used to make the
148+
# quantum workflow more performant. For instance, configuration interaction (CI) and coupled cluster
149+
# (CC) calculations with single and double (SD) excitations can be performed using PySCF and the
150+
# resulting wave function can be used as the initial state in the quantum algorithm. PennyLane
151+
# provides the :func:`~.pennylane.qchem.import_state` function that takes a PySCF solver object,
152+
# extracts the wave function and returns a state vector in the computational basis that can be used
153+
# in a quantum circuit. Let’s look at an example.
154+
#
155+
# First, we run CCSD calculations for the hydrogen molecule to obtain the solver object.
156+
157+
from pyscf import gto, scf, cc
158+
159+
mol = gto.M(atom=[['H', (0, 0, 0)], ['H', (0, 0, 0.7)]])
160+
myhf = scf.RHF(mol).run()
161+
mycc = cc.CCSD(myhf).run()
162+
163+
##############################################################################
164+
# Then, we use the :func:`~.pennylane.qchem.import_state` function to obtain the
165+
# state vector.
166+
167+
state = qml.qchem.import_state(mycc)
168+
print(state)
169+
170+
##############################################################################
171+
# You can verify that this state is a superposition of the Hartree-Fock state and a doubly-excited
172+
# state.
173+
134174
##############################################################################
135175
# Conclusions
136176
# -----------
@@ -144,9 +184,11 @@
144184
# the argument ``method=pyscf`` to the :func:`~.pennylane.qchem.molecular_hamiltonian` function.
145185
# 2. We can directly use one- and two-electron integrals from PySCF, but we need to convert the
146186
# tensor containing the two-electron integrals from chemists' notation to physicists' notation.
147-
# 3. Finally, we can easily convert OpenFermion operators to PennyLane operators using the
187+
# 3. We can easily convert OpenFermion operators to PennyLane operators using the
148188
# :func:`~.pennylane.import_operator` function.
189+
# 4. Finally, we can convert PySCF wave functions to PennyLane state vectors using the
190+
# :func:`~.pennylane.qchem.import_state` function.
149191
#
150192
# About the author
151193
# ----------------
152-
# .. include:: ../_static/authors/soran_jahangiri.txt
194+
# .. include:: ../_static/authors/soran_jahangiri.txt

0 commit comments

Comments
 (0)