Code
qcr:2606.08897.1

Excited States Solvers in Qiskit Nature

This Qiskit Nature tutorial goes beyond the ground state to compute molecular excited states, the higher-energy electronic configurations whose energies determine absorption spectra, photochemistry, and reaction dynamics. Building on the ground-state workflow, it introduces the ExcitedStatesEigensolver and the methods Qiskit Nature provides for excited states, most notably the quantum Equation-of-Motion (qEOM) approach, which computes excitation energies as corrections on top of a ground state found by VQE. The tutorial shows how to set up an excited-states calculation: defining the electronic-structure problem, choosing a qubit mapper and a ground-state solver, wrapping them in an excited-states solver, and running it to obtain a spectrum of energy levels. It compares the quantum results against an exact classical excited-states calculation for validation and explains how the excitation operators are constructed and measured. By extending quantum chemistry from a single energy to a spectrum of states, the tutorial unlocks the molecular properties that depend on excitations, an important capability for realistic chemistry applications in Qiskit Nature.
Chemistry
Qubit
Circuit-based
Uploaded 2 days ago
11
Views
GitHub390
Citing this entry? Use this QCR ID
Uploaded by
QL
QCR Librarian

Overview

qiskit-community/qiskit-nature
390233
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

Excited states solvers

Introduction

In this tutorial we are going to discuss the excited states calculation interface of Qiskit Nature. The goal is to compute the excited states of a molecular Hamiltonian. This Hamiltonian can be electronic or vibrational. To know more about the preparation of the Hamiltonian, check out the Electronic structure and Vibrational structure tutorials.

The first step is to define the molecular system. In the following we ask for the electronic part of a hydrogen molecule.

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,
)

es_problem = driver.run()

We will also be sticking to the Jordan-Wigner mapping. To learn more about the various mappers available in Qiskit Nature, check out the Qubit Mappers tutorial.

In [2]:
from qiskit_nature.second_q.mappers import JordanWignerMapper

mapper = JordanWignerMapper()

The Solver

After these steps we need to define a solver. The solver is the algorithm through which the excited states are computed.

Let's first start with a purely classical example: the NumPyEigensolver. This algorithm exactly diagonalizes the Hamiltonian. Although it scales badly, it can be used on small systems to check the results of the quantum algorithms. Here, we are only interested to look at eigenstates with a given number of particles. To compute only those states a filter function can be passed to the NumPyEigensolver. A default filter function is already implemented in Qiskit Nature which you can use for this purpose.

We also need to specify the number of eigenvalues to be computed by the NumPyEigensolver. For this particular system, we are interested in the ground and first three excited states, so we will set k=4 (which defaults to 1 so be sure to set this, otherwise you will only obtain the ground state!).

In [3]:
from qiskit_algorithms import NumPyEigensolver

numpy_solver = NumPyEigensolver(k=4, filter_criterion=es_problem.get_default_filter_criterion())

The excitation energies can also be accessed with the qEOM algorithm. The EOM method finds the excitation energies (differences in energy between the ground state and all th excited states) by solving the following pseudo-eigenvalue problem.

with

Although the previous equation can be solved classically, each matrix element must be measured on the quantum computer with the corresponding ground state. To use the qEOM as a solver in Qiskit, we have to define a ground state calculation first, which will provide the required ground state information to the algorithm. With this the qEOM solver can be initialized like so:

In [4]:
from qiskit_algorithms import VQE
from qiskit_algorithms.optimizers import SLSQP
from qiskit.primitives import StatevectorEstimator
from qiskit_nature.second_q.algorithms import GroundStateEigensolver, QEOM, EvaluationRule
from qiskit_nature.second_q.circuit.library import HartreeFock, UCCSD

ansatz = UCCSD(
    es_problem.num_spatial_orbitals,
    es_problem.num_particles,
    mapper,
    initial_state=HartreeFock(
        es_problem.num_spatial_orbitals,
        es_problem.num_particles,
        mapper,
    ),
)

estimator = StatevectorEstimator()
# This first part sets the ground state solver
# see more about this part in the ground state calculation tutorial
solver = VQE(estimator, ansatz, SLSQP())
solver.initial_point = [0.0] * ansatz.num_parameters
gse = GroundStateEigensolver(mapper, solver)

# The qEOM algorithm is simply instantiated with the chosen ground state solver and Estimator primitive
qeom_excited_states_solver = QEOM(gse, estimator, "sd", EvaluationRule.ALL)

The calculation and results

We are now ready to compute the results. Below, we are comparing the results obtained by the exact NumPyEigensolver with the default filter criterion enabled with the results obtained by the qEOM algorithm.

In [5]:
from qiskit_nature.second_q.algorithms import ExcitedStatesEigensolver

numpy_excited_states_solver = ExcitedStatesEigensolver(mapper, numpy_solver)
numpy_results = numpy_excited_states_solver.solve(es_problem)

qeom_results = qeom_excited_states_solver.solve(es_problem)

print(numpy_results)
print("\n\n")
print(qeom_results)
=== 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
 
=== EXCITED STATE ENERGIES ===
 
  1: 
* Electronic excited state energy (Hartree): -0.882722150245
> Total excited state energy (Hartree): -0.162753155796
  2: 
* Electronic excited state energy (Hartree): -0.224911252831
> Total excited state energy (Hartree): 0.495057741618
 
=== MEASURED OBSERVABLES ===
 
  0:  # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
  1:  # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
  2:  # 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.388948701555]
    - computed part:      [0.0  0.0  1.388948701555]
  > Dipole moment (a.u.): [0.0  0.0  -0.000000001555]  Total: 0.000000001555
                 (debye): [0.0  0.0  -0.000000003953]  Total: 0.000000003953
 
  1: 
  * Electronic dipole moment (a.u.): [0.0  0.0  1.388948701555]
    - computed part:      [0.0  0.0  1.388948701555]
  > Dipole moment (a.u.): [0.0  0.0  -0.000000001555]  Total: 0.000000001555
                 (debye): [0.0  0.0  -0.000000003953]  Total: 0.000000003953
 
  2: 
  * Electronic dipole moment (a.u.): [0.0  0.0  1.388948701555]
    - computed part:      [0.0  0.0  1.388948701555]
  > Dipole moment (a.u.): [0.0  0.0  -0.000000001555]  Total: 0.000000001555
                 (debye): [0.0  0.0  -0.000000003953]  Total: 0.000000003953
 



=== GROUND STATE ENERGY ===
 
* Electronic ground state energy (Hartree): -1.857275030145
  - computed part:      -1.857275030145
~ Nuclear repulsion energy (Hartree): 0.719968994449
> Total ground state energy (Hartree): -1.137306035696
 
=== EXCITED STATE ENERGIES ===
 
  1: 
* Electronic excited state energy (Hartree): -1.244586756145
> Total excited state energy (Hartree): -0.524617761696
  2: 
* Electronic excited state energy (Hartree): -0.882724356546
> Total excited state energy (Hartree): -0.162755362097
  3: 
* Electronic excited state energy (Hartree): -0.224913459141
> Total excited state energy (Hartree): 0.495055535308
 
=== MEASURED OBSERVABLES ===
 
  0:  # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
  1:  # Particles: 2.000 S: 1.000 S^2: 2.000 M: 0.000
  2:  # Particles: 2.000 S: 0.000 S^2: -0.000 M: 0.000
  3:  # 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.388948961657]
    - computed part:      [0.0  0.0  1.388948961657]
  > Dipole moment (a.u.): [0.0  0.0  -0.000000261657]  Total: 0.000000261657
                 (debye): [0.0  0.0  -0.000000665065]  Total: 0.000000665065
 
  1: 
  * Electronic dipole moment (a.u.): [0.0  0.0  1.388948701647]
    - computed part:      [0.0  0.0  1.388948701647]
  > Dipole moment (a.u.): [0.0  0.0  -0.000000001647]  Total: 0.000000001647
                 (debye): [0.0  0.0  -0.000000004186]  Total: 0.000000004186
 
  2: 
  * Electronic dipole moment (a.u.): [0.0  0.0  1.388949035771]
    - computed part:      [0.0  0.0  1.388949035771]
  > Dipole moment (a.u.): [0.0  0.0  -0.000000335771]  Total: 0.000000335771
                 (debye): [0.0  0.0  -0.000000853445]  Total: 0.000000853445
 
  3: 
  * Electronic dipole moment (a.u.): [0.0  0.0  1.388948738594]
    - computed part:      [0.0  0.0  1.388948738594]
  > Dipole moment (a.u.): [0.0  0.0  -0.000000038594]  Total: 0.000000038594
                 (debye): [0.0  0.0  -0.000000098097]  Total: 0.000000098097
 

One can see from these results that one state is missing from the NumPy results. The reason for this is because the spin is also used as a filter and only singlet states are shown. In the following we use a custom filter function to check our results consistently and only filter out states with the incorrect number of particles (in this case the number of particle is 2) as well as the wrong magnetization (which we enforce to be 0).

In [6]:
import numpy as np


def filter_criterion(eigenstate, eigenvalue, aux_values):
    return np.isclose(aux_values["ParticleNumber"][0], 2.0) and np.isclose(
        aux_values["Magnetization"][0], 0.0
    )


new_numpy_solver = NumPyEigensolver(k=4, filter_criterion=filter_criterion)
new_numpy_excited_states_solver = ExcitedStatesEigensolver(mapper, new_numpy_solver)
new_numpy_results = new_numpy_excited_states_solver.solve(es_problem)

print(new_numpy_results)
=== 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
 
=== EXCITED STATE ENERGIES ===
 
  1: 
* Electronic excited state energy (Hartree): -1.244584549813
> Total excited state energy (Hartree): -0.524615555364
  2: 
* Electronic excited state energy (Hartree): -0.882722150245
> Total excited state energy (Hartree): -0.162753155796
  3: 
* Electronic excited state energy (Hartree): -0.224911252831
> Total excited state energy (Hartree): 0.495057741618
 
=== MEASURED OBSERVABLES ===
 
  0:  # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
  1:  # Particles: 2.000 S: 1.000 S^2: 2.000 M: 0.000
  2:  # Particles: 2.000 S: 0.000 S^2: 0.000 M: 0.000
  3:  # 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.388948701555]
    - computed part:      [0.0  0.0  1.388948701555]
  > Dipole moment (a.u.): [0.0  0.0  -0.000000001555]  Total: 0.000000001555
                 (debye): [0.0  0.0  -0.000000003953]  Total: 0.000000003953
 
  1: 
  * Electronic dipole moment (a.u.): [0.0  0.0  1.388948701555]
    - computed part:      [0.0  0.0  1.388948701555]
  > Dipole moment (a.u.): [0.0  0.0  -0.000000001555]  Total: 0.000000001555
                 (debye): [0.0  0.0  -0.000000003953]  Total: 0.000000003953
 
  2: 
  * Electronic dipole moment (a.u.): [0.0  0.0  1.388948701555]
    - computed part:      [0.0  0.0  1.388948701555]
  > Dipole moment (a.u.): [0.0  0.0  -0.000000001555]  Total: 0.000000001555
                 (debye): [0.0  0.0  -0.000000003953]  Total: 0.000000003953
 
  3: 
  * Electronic dipole moment (a.u.): [0.0  0.0  1.388948701555]
    - computed part:      [0.0  0.0  1.388948701555]
  > Dipole moment (a.u.): [0.0  0.0  -0.000000001555]  Total: 0.000000001555
                 (debye): [0.0  0.0  -0.000000003953]  Total: 0.000000003953
 
In [7]:
import tutorial_magics

%qiskit_version_table
%qiskit_copyright

Version Information

Qiskit SoftwareVersion
qiskit-terra0.24.1
qiskit-nature0.7.0
System information
Python version3.10.11
Python compilerGCC 12.2.1 20221121 (Red Hat 12.2.1-4)
Python buildmain, Apr 5 2023 00:00:00
OSLinux
CPUs8
Memory (Gb)62.48404312133789
Wed Jun 07 10:45:42 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 17, 2026
qcr:2606.08897.1

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

Tools used

Qiskit

Keywords

excited-states
qeom
quantum-chemistry
qiskit
spectroscopy

You may also like5