Encontrar la energía del estado fundamental usando AdaptVQE#

Esta guía describe cómo se puede utilizar el algoritmo AdaptVQE para encontrar soluciones del estado fundamental de problemas de ciencias naturales.

  1. Obtenemos un ElectronicStructureProblem que queremos resolver:

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()
  1. Configuramos nuestro QubitMapper:

from qiskit_nature.second_q.mappers import JordanWignerMapper
mapper = JordanWignerMapper()
  1. Configuramos nuestro 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,
    ),
)
  1. Configuramos un 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. Configuramos el AdaptVQE:

from qiskit_algorithms import AdaptVQE
adapt_vqe = AdaptVQE(vqe)
adapt_vqe.supports_aux_operators = lambda: True  # temporary fix
  1. Encapsulamos todo en un GroundStateEigensolver:

from qiskit_nature.second_q.algorithms import GroundStateEigensolver
solver = GroundStateEigensolver(mapper, adapt_vqe)
  1. Resolvemos el problema:

result = solver.solve(problem)

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