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.
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 = driver.run()
We setup our
QubitMapper
:
from qiskit_nature.second_q.mappers import JordanWignerMapper
mapper = JordanWignerMapper()
We setup our ansatz:
from qiskit_nature.second_q.circuit.library import UCCSD, HartreeFock
ansatz = UCCSD(
problem.num_spatial_orbitals,
problem.num_particles,
mapper,
initial_state=HartreeFock(
problem.num_spatial_orbitals,
problem.num_particles,
mapper,
),
)
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)
We setup the
AdaptVQE
:
from qiskit_algorithms import AdaptVQE
adapt_vqe = AdaptVQE(vqe)
adapt_vqe.supports_aux_operators = lambda: True # temporary fix
We wrap everything in a
GroundStateEigensolver
:
from qiskit_nature.second_q.algorithms import GroundStateEigensolver
solver = GroundStateEigensolver(mapper, adapt_vqe)
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