Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Sep 22, 2023
2 parents 95a1af8 + e150259 commit dc5211c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion demonstrations/tutorial_qchem_external.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
],
"dateOfPublication": "2023-01-03T00:00:00+00:00",
"dateOfLastModification": "2023-01-04T00:00:00+00:00",
"dateOfLastModification": "2023-09-21T00:00:00+00:00",
"categories": [
"Quantum Chemistry", "Devices and Performance"
],
Expand Down
52 changes: 47 additions & 5 deletions demonstrations/tutorial_qchem_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
The quantum chemistry module in PennyLane, :mod:`qml.qchem <pennylane.qchem>`, provides built-in
methods to compute molecular integrals, solve Hartree-Fock equations, and construct
`fully-differentiable <https://pennylane.ai/qml/demos/tutorial_differentiable_HF.html>`_ molecular
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
`OpenFermion <https://github.com/quantumlib/OpenFermion>`_ to compute molecular integrals and
construct molecular Hamiltonians.
Hamiltonians. However, there are many other interesting and widely used quantum chemistry libraries
out there. Instead of reinventing the wheel, PennyLane lets you 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
`OpenFermion <https://github.com/quantumlib/OpenFermion>`_ to compute molecular integrals,
construct molecular Hamiltonians, and import initial states.
Building molecular Hamiltonians
-------------------------------
Expand Down Expand Up @@ -131,6 +134,43 @@
print(f'Estimated number of non-Clifford gates: {algo.gates:.2e}')
print(f'Estimated number of logical qubits: {algo.qubits}')

##############################################################################
# Importing initial states
# ------------------------
# Simulating molecules with quantum algorithms requires defining an initial state that should have
# non-zero overlap with the molecular ground state. A trivial choice for the initial state is the
# Hartree-Fock state which is obtained by putting the electrons in the lowest-energy molecular
# orbitals. For molecules with a complicated electronic structure, the Hartree-Fock state has
# only a small overlap with the ground state, which makes executing quantum algorithms
# inefficient.
#
# Initial states obtained from affordable post-Hartree-Fock calculations can be used to make the
# quantum workflow more performant. For instance, configuration interaction (CI) and coupled cluster
# (CC) calculations with single and double (SD) excitations can be performed using PySCF and the
# resulting wave function can be used as the initial state in the quantum algorithm. PennyLane
# provides the :func:`~.pennylane.qchem.import_state` function that takes a PySCF solver object,
# extracts the wave function and returns a state vector in the computational basis that can be used
# in a quantum circuit. Let’s look at an example.
#
# First, we run CCSD calculations for the hydrogen molecule to obtain the solver object.

from pyscf import gto, scf, cc

mol = gto.M(atom=[['H', (0, 0, 0)], ['H', (0, 0, 0.7)]])
myhf = scf.RHF(mol).run()
mycc = cc.CCSD(myhf).run()

##############################################################################
# Then, we use the :func:`~.pennylane.qchem.import_state` function to obtain the
# state vector.

state = qml.qchem.import_state(mycc)
print(state)

##############################################################################
# You can verify that this state is a superposition of the Hartree-Fock state and a doubly-excited
# state.

##############################################################################
# Conclusions
# -----------
Expand All @@ -144,9 +184,11 @@
# the argument ``method=pyscf`` to the :func:`~.pennylane.qchem.molecular_hamiltonian` function.
# 2. We can directly use one- and two-electron integrals from PySCF, but we need to convert the
# tensor containing the two-electron integrals from chemists' notation to physicists' notation.
# 3. Finally, we can easily convert OpenFermion operators to PennyLane operators using the
# 3. We can easily convert OpenFermion operators to PennyLane operators using the
# :func:`~.pennylane.import_operator` function.
# 4. Finally, we can convert PySCF wave functions to PennyLane state vectors using the
# :func:`~.pennylane.qchem.import_state` function.
#
# About the author
# ----------------
# .. include:: ../_static/authors/soran_jahangiri.txt
# .. include:: ../_static/authors/soran_jahangiri.txt

0 comments on commit dc5211c

Please sign in to comment.