Tutorials
qcr:2606.16482.1

Electronic Structure Problems in Qiskit Nature

This tutorial is the entry point to Qiskit Nature's flagship application: computing the electronic structure of molecules on a quantum computer. The electronic-structure problem, finding the energies and properties of a molecule's electrons, is the central task of quantum chemistry and one of the most anticipated uses of quantum computing. The tutorial shows the full setup: defining a molecule's geometry, using a classical chemistry driver (such as PySCF) to compute the one- and two-body integrals that define the electronic Hamiltonian, and building an ElectronicStructureProblem in Qiskit Nature. It explains how the resulting fermionic Hamiltonian is represented, how the second-quantized operators are constructed, and how the problem object exposes the information needed by downstream solvers. While later tutorials cover actually solving for the ground and excited states, this one establishes how a chemistry problem is specified and translated into the language of operators that quantum algorithms consume. By grounding the workflow in a concrete molecule and a real classical driver, the tutorial gives newcomers the essential foundation for quantum chemistry in Qiskit Nature.
Chemistry
Qubit
Circuit-based
Uploaded 3 days ago
13
Views
GitHub
Citing this entry? Use this QCR ID
Uploaded by
QL
QCR Librarian

Overview

https://github.com/qiskit-community/qiskit-nature/blob/0.8/docs/tutorials/01_electronic_structure.ipynb
In [ ]:
# --- Setup cell added by QCR (not part of the original tutorial) ---
# Source: qiskit-community/qiskit-nature @ 0.8, Apache License 2.0.
# Installs the example's dependencies. If a later cell still reports a missing
# package, restart the runtime/kernel and run again from the top.
%pip install -q qiskit-nature==0.8.0 pyscf qiskit-algorithms

Electronic structure

Introduction

The molecular Hamiltonian is

Because the nuclei are much heavier than the electrons they do not move on the same time scale and therefore, the behavior of nuclei and electrons can be decoupled. This is the Born-Oppenheimer approximation.

Therefore, one can first tackle the electronic problem with the nuclear coordinates entering only as parameters. The energy levels of the electrons in the molecule can then be found by solving the non-relativistic time independent Schrödinger equation,

where

In particular the ground state energy is given by: where is the ground state of the system.

However, the dimensionality of this problem grows exponentially with the number of degrees of freedom. To tackle this issue we would like to prepare on a quantum computer and measure the Hamiltonian expectation value (or ) directly.

So how do we do that concretely?

Starting from the Hartree-Fock solution

A good starting point for solving this problem is the Hartree-Fock (HF) method. This method approximates the N-body problem by N one-body problems where each electron evolves in the mean-field of the others. Classically solving the HF equations is efficient and leads to the exact exchange energy but does not include any electron correlation. Therefore, it is usually a good starting point to which to add correlation.

The Hamiltonian can then be re-expressed in the basis of the solutions of the HF method, also called Molecular Orbitals (MOs):

with the 1-body integrals and 2-body integrals

The MOs () can be occupied or virtual (unoccupied). One MO can contain 2 electrons. However, in what follows we actually work with Spin Orbitals which are associated with a spin up () of spin down () electron. Thus Spin Orbitals can contain one electron or be unoccupied.

Note: when referring to the number of orbitals, we will be using the number of spatial orbitals. This refers to any orbital in Cartesian space (whether its a molecular orbital or in another basis does not matter here). Each spatial orbital is then generally split into two spin orbitals.

We now show how to concretely realise these steps with Qiskit.

Obtaining an initial Hartree-Fock solution

Qiskit is interfaced with different classical codes which are able to find the HF solutions. Interfacing between Qiskit and the following codes is already available:

  • Gaussian
  • Psi4
  • PySCF

In the following we set up a PySCF driver, for the hydrogen molecule at equilibrium bond length (0.735 angstrom) in the singlet state and with no charge.

In [1]:
from qiskit_nature.units import DistanceUnit
from qiskit_nature.second_q.drivers import PySCFDriver

driver = PySCFDriver(
    atom="H 0 0 0; H 0 0 0.735",
    basis="sto3g",
    charge=0,
    spin=0,
    unit=DistanceUnit.ANGSTROM,
)

Running this driver, will yield an ElectronicStructureProblem, Qiskit Nature's representation of the electronic structure problem which we are interested in solving. For further information about the drivers, see https://qiskit-community.github.io/qiskit-nature/apidocs/qiskit_nature.second_q.drivers.html

In [2]:
problem = driver.run()
print(problem)
<qiskit_nature.second_q.problems.electronic_structure_problem.ElectronicStructureProblem object at 0x7f3bc13406a0>

The ElectronicStructureProblem and its components

Let us spend some time to understand this problem instance and its components.

The ElectronicEnergy Hamiltonian

The most important aspect is the internal Hamiltonian; in this case an ElectronicEnergy hamiltonian. This class is able to generate the second-quantized operator from the 1- and 2-body integrals which the classical code has computed for us.

IMPORTANT: The container class for the integral coefficients (PolynomialTensor) requires the 2-body terms to be provided in physicist order!

In [3]:
hamiltonian = problem.hamiltonian

coefficients = hamiltonian.electronic_integrals
print(coefficients.alpha)
Polynomial Tensor
 "+-":
[[-1.25633907e+00 -6.21867875e-17]
 [-7.78036432e-17 -4.71896007e-01]]
 "++--":
[[[[6.75710155e-01 1.12401641e-16]
   [1.56722377e-16 1.80931200e-01]]

  [[1.92605510e-16 1.80931200e-01]
   [6.64581730e-01 2.59298923e-16]]]


 [[[8.68926823e-17 6.64581730e-01]
   [1.80931200e-01 1.82411770e-16]]

  [[1.80931200e-01 2.57172666e-16]
   [7.20426423e-17 6.98573723e-01]]]]
In [4]:
second_q_op = hamiltonian.second_q_op()
print(second_q_op)
Fermionic Operator
number spin orbitals=4, number terms=36
  -1.2563390730032498 * ( +_0 -_0 )
+ -0.47189600728114245 * ( +_1 -_1 )
+ -1.2563390730032498 * ( +_2 -_2 )
+ -0.47189600728114245 * ( +_3 -_3 )
+ 0.33785507740175813 * ( +_0 +_0 -_0 -_0 )
+ 0.09046559989211565 * ( +_0 +_0 -_1 -_1 )
+ 0.09046559989211556 * ( +_0 +_1 -_0 -_1 )
+ 0.33229086512764827 * ( +_0 +_1 -_1 -_0 )
+ 0.33785507740175813 * ( +_0 +_2 -_2 -_0 )
+ 0.09046559989211565 * ( +_0 +_2 -_3 -_1 )
+ 0.09046559989211556 * ( +_0 +_3 -_2 -_1 )
+ 0.33229086512764827 * ( +_0 +_3 -_3 -_0 )
+ 0.33229086512764816 * ( +_1 +_0 -_0 -_1 )
+ 0.09046559989211574 * ( +_1 +_0 -_1 -_0 )
+ 0.09046559989211564 * ( +_1 +_1 -_0 -_0 )
+ 0.34928686136600906 * ( +_1 +_1 -_1 -_1 )
+ 0.33229086512764816 * ( +_1 +_2 -_2 -_1 )
+ 0.09046559989211574 * ( +_1 +_2 -_3 -_0 )
+ 0.09046559989211564 * ( +_1 +_3 -_2 -_0 )
+ 0.34928686136600906 * ( +_1 +_3 -_3 -_1 )
+ 0.33785507740175813 * ( +_2 +_0 -_0 -_2 )
+ 0.09046559989211565 * ( +_2 +_0 -_1 -_3 )
+ 0.09046559989211556 * ( +_2 +_1 -_0 -_3 )
+ 0.33229086512764827 * ( +_2 +_1 -_1 -_2 )
+ 0.33785507740175813 * ( +_2 +_2 -_2 -_2 )
+ 0.09046559989211565 * ( +_2 +_2 -_3 -_3 )
+ 0.09046559989211556 * ( +_2 +_3 -_2 -_3 )
+ 0.33229086512764827 * ( +_2 +_3 -_3 -_2 )
+ 0.33229086512764816 * ( +_3 +_0 -_0 -_3 )
+ 0.09046559989211574 * ( +_3 +_0 -_1 -_2 )
+ 0.09046559989211564 * ( +_3 +_1 -_0 -_2 )
+ 0.34928686136600906 * ( +_3 +_1 -_1 -_3 )
+ 0.33229086512764816 * ( +_3 +_2 -_2 -_3 )
+ 0.09046559989211574 * ( +_3 +_2 -_3 -_2 )
+ 0.09046559989211564 * ( +_3 +_3 -_2 -_2 )
+ 0.34928686136600906 * ( +_3 +_3 -_3 -_3 )

Note, that this is purely the electronic Hamiltonian of the system. That means, that the nuclear repulsion energy is not included. Instead, Qiskit Nature will add this constant energy offset in a post-processing step, in order to compute the total energy of your system. To learn how to include the nuclear repulsion energy in this operator, please refer to the documentation of the ElectronicEnergy class here.

In [5]:
hamiltonian.nuclear_repulsion_energy  # NOT included in the second_q_op above
0.7199689944489797

More attributes of the ElectronicStructureProblem

Below we list some additional attributes of our problem instance:

In [6]:
problem.molecule
MoleculeInfo(symbols=['H', 'H'], coords=[(0.0, 0.0, 0.0), (0.0, 0.0, 1.3889487015553204)], multiplicity=1, charge=0, units=<DistanceUnit.BOHR: 'Bohr'>, masses=[1, 1])
In [7]:
problem.reference_energy
-1.1169989967540035
In [8]:
problem.num_particles
(1, 1)
In [9]:
problem.num_spatial_orbitals
2
In [10]:
problem.basis
<ElectronicBasis.MO: 'molecular'>

To learn more about the basis of your problem, please refer to the tutorial on the BasisTransformer.

Additional observables

The ElectronicStructureProblem also contains additional operator factories, which will generate observables to be evaluated at the ground- and excited-states at the end of your computation.

In [11]:
problem.properties
<qiskit_nature.second_q.problems.electronic_properties_container.ElectronicPropertiesContainer at 0x7f3bc1340790>
In [12]:
problem.properties.particle_number
<qiskit_nature.second_q.properties.particle_number.ParticleNumber at 0x7f3bc1340820>
In [13]:
problem.properties.angular_momentum
<qiskit_nature.second_q.properties.angular_momentum.AngularMomentum at 0x7f3bc1340700>
In [14]:
problem.properties.magnetization
<qiskit_nature.second_q.properties.magnetization.Magnetization at 0x7f3bc1340760>
In [15]:
problem.properties.electronic_dipole_moment
<qiskit_nature.second_q.properties.dipole_moment.ElectronicDipoleMoment at 0x7f3bc1340880>

For more information about these properties, please refer to their tutorial.

Solving the ElectronicStructureProblem

In the following, we will compute the ground-state of our problem instance. To learn more about the individual components that go into the GroundStateSolver, please refer to the ground state tutorial.

In [16]:
from qiskit_algorithms import NumPyMinimumEigensolver
from qiskit_nature.second_q.algorithms import GroundStateEigensolver
from qiskit_nature.second_q.mappers import JordanWignerMapper

solver = GroundStateEigensolver(
    JordanWignerMapper(),
    NumPyMinimumEigensolver(),
)
In [17]:
result = solver.solve(problem)
print(result)
=== GROUND STATE ENERGY ===
 
* Electronic ground state energy (Hartree): -1.857275030202
  - computed part:      -1.857275030202
~ Nuclear repulsion energy (Hartree): 0.719968994449
> Total ground state energy (Hartree): -1.137306035753
 
=== MEASURED OBSERVABLES ===
 
  0:  # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
 
=== DIPOLE MOMENTS ===
 
~ Nuclear dipole moment (a.u.): [0.0  0.0  1.3889487]
 
  0: 
  * Electronic dipole moment (a.u.): [0.0  0.0  1.3889487]
    - computed part:      [0.0  0.0  1.3889487]
  > Dipole moment (a.u.): [0.0  0.0  0.0]  Total: 0.0
                 (debye): [0.0  0.0  0.0]  Total: 0.0
 
In [18]:
import tutorial_magics

%qiskit_version_table
%qiskit_copyright

Version Information

Qiskit SoftwareVersion
qiskit-terra0.24.0.dev0+2b3686f
qiskit-aer0.11.2
qiskit-ibmq-provider0.19.2
qiskit-nature0.6.0
System information
Python version3.9.16
Python compilerGCC 12.2.1 20221121 (Red Hat 12.2.1-4)
Python buildmain, Dec 7 2022 00:00:00
OSLinux
CPUs8
Memory (Gb)62.50002670288086
Thu Apr 06 08:53:41 2023 CEST

This code is a part of Qiskit

© Copyright IBM 2017, 2023.

This code is licensed under the Apache License, Version 2.0. You may
obtain a copy of this license in the LICENSE.txt file in the root directory
of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.

Any modifications or derivative works of this code must retain this
copyright notice, and modified files need to carry a notice indicating
that they have been altered from the originals.

Join the Discussion

Comments (0)

No comments yet. Be the first to share your thoughts!

Indexed by QCR Librarian

This entry was created automatically from publicly available records. QCR links to public sources and only stores repository content where the license permits redistribution.

Versions

v1 Latest
Jun 16, 2026
qcr:2606.16482.1

Cite all versions? Use the base QCR ID to always reference the latest version of this entry.

Tools used

Qiskit

Keywords

electronic-structure
quantum-chemistry
qiskit
pyscf
hamiltonian

You may also like5