Find ground state energy using AdaptVQE#

This guide outlines how the AdaptVQE algorithm can be used to find the ground state solutions of natural science problems.

  1. We obtain an ElectronicStructureProblem which we want to solve:

from qiskit_nature.second_q.drivers import PySCFDriver
driver = PySCFDriver(atom="H 0 0 0; H 0 0 0.735", basis="sto-3g")
problem =
  1. We setup our QubitMapper:

from qiskit_nature.second_q.mappers import JordanWignerMapper
mapper = JordanWignerMapper()
  1. We setup our ansatz:

from qiskit_nature.second_q.circuit.library import UCCSD, HartreeFock
ansatz = UCCSD(
  1. We setup a VQE:

import numpy as np
from qiskit_algorithms import VQE
from qiskit_algorithms.optimizers import SLSQP
from qiskit.primitives import Estimator
vqe = VQE(Estimator(), ansatz, SLSQP())
vqe.initial_point = np.zeros(ansatz.num_parameters)
  1. We setup the AdaptVQE:

from qiskit_algorithms import AdaptVQE
adapt_vqe = AdaptVQE(vqe)
adapt_vqe.supports_aux_operators = lambda: True  # temporary fix
  1. We wrap everything in a GroundStateEigensolver:

from qiskit_nature.second_q.algorithms import GroundStateEigensolver
solver = GroundStateEigensolver(mapper, adapt_vqe)
  1. We solve the problem:

result = solver.solve(problem)

print(f"Total ground state energy = {result.total_energies[0]:.4f}")
Total ground state energy = -1.1373