Find ground state energy using the NumPyMinimumEigensolver#
In order to ensure a physically meaningful ground state of a hamiltonian is found when using the
NumPyMinimumEigensolver
one needs to set the
filter_criterion
attribute
of the solver.
Subclasses of BaseProblem
in Qiskit Nature provide the
get_default_filter_criterion()
method which
provides a default implementation of such a filter criterion for commonly encountered cases.
Below we show how you can use this setting.
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
NumPyMinimumEigensolver
:
from qiskit_algorithms import NumPyMinimumEigensolver
algo = NumPyMinimumEigensolver()
algo.filter_criterion = problem.get_default_filter_criterion()
We wrap everything in a
GroundStateEigensolver
:
from qiskit_nature.second_q.algorithms import GroundStateEigensolver
solver = GroundStateEigensolver(mapper, algo)
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