qc2.algorithms.qiskit.vqe

Module defining VQE algorithm for Qiskit-Nature.

Classes

VQE

Main class for the VQE algorithm with Qiskit-Nature.

Module Contents

class qc2.algorithms.qiskit.vqe.VQE(qc2data=None, ansatz=None, active_space=None, mapper=None, estimator=None, optimizer=None, reference_state=None, init_params=None, verbose=0)[source]

Bases: qc2.algorithms.base.vqe_base.VQEBASE

Main class for the VQE algorithm with Qiskit-Nature.

This class initializes and executes the VQE algorithm using specified quantum components like ansatz, optimizer, and estimator.

active_space[source]

Describes the active space for quantum simulation. Defaults to ActiveSpace((2, 2), 2).

Type:

ActiveSpace

mapper[source]

Strategy for fermionic-to-qubit mapping. Defaults to qiskit.JordanWignerMapper.

Type:

QubitMapper

estimator[source]

Method for estimating the expectation value. Defaults to qiskit.Estimator

Type:

BaseEstimator

optimizer[source]

Optimization routine for circuit variational parameters. Defaults to qiskit_algorithms.SLSQP.

Type:

qiskit.Optmizer

reference_state[source]

Reference state for the VQE algorithm. Defaults to qiskit.HartreeFock.

Type:

QuantumCircuit

ansatz[source]

The ansatz for the VQE algorithm. Defaults to qiskit.UCCSD.

Type:

UCC

params[source]

List of initial VQE circuit parameters. Defaults to a list with entries of zero.

Type:

List

verbose[source]

Verbosity level. Defaults to 0.

Type:

int

active_space[source]
mapper[source]
estimator[source]
optimizer[source]
reference_state[source]
ansatz[source]
params[source]
verbose = 0[source]
static _get_default_reference(active_space: qc2.algorithms.utils.active_space.ActiveSpace, mapper: qiskit_nature.second_q.mappers.QubitMapper) qiskit.circuit.QuantumCircuit[source]

Set up the default reference state circuit based on Hartree Fock.

Parameters:
  • active_space (ActiveSpace) – description of the active space.

  • mapper (mapper) – mapper class instance.

Returns:

Hartree-Fock circuit as the reference state.

Return type:

QuantumCircuit

static _get_default_ansatz(active_space: qc2.algorithms.utils.active_space.ActiveSpace, mapper: qiskit_nature.second_q.mappers.QubitMapper, reference_state: qiskit.circuit.QuantumCircuit) qiskit_nature.second_q.circuit.library.UCC[source]

Set up the default UCC ansatz from a Hartree Fock reference state.

Parameters:
  • active_space (ActiveSpace) – Description of the active space.

  • mapper (QubitMapper) – Mapper class instance.

  • reference_state (QuantumCircuit) – Reference state circuit.

Returns:

UCC ansatz quantum circuit.

Return type:

UCC

static _get_default_init_params(nparams: List) List[source]

Generates a list of initial circuit parameters for the ansatz.

Parameters:

nparams (int) – Number of parameters in the ansatz.

Returns:

List of initial parameter values (all zeros).

Return type:

List[float]

run(*args, **kwargs) qc2.algorithms.algorithms_results.VQEResults[source]

Executes the VQE algorithm.

Parameters:
  • *args – Variable length argument list to be passed to the qiskit_algorithm.VQE class.

  • **kwargs – Arbitrary keyword arguments to be passed to the qiskit_algorithm.VQE class.

Returns:

An instance of qc2.algorithms.qiskit.vqe.VQEResults class with all VQE info.

Return type:

VQEResults

Example

>>> from ase.build import molecule
>>> from qc2.ase import PySCF
>>> from qc2.data import qc2Data
>>> from qc2.algorithms.qiskit import VQE
>>> from qc2.algorithms.utils import ActiveSpace
>>>
>>> mol = molecule('H2O')
>>>
>>> hdf5_file = 'h2o.hdf5'
>>> qc2data = qc2Data(hdf5_file, mol, schema='qcschema')
>>> qc2data.molecule.calc = PySCF()
>>> qc2data.run()
>>> qc2data.algorithm = VQE(
...     active_space=ActiveSpace(
...         num_active_electrons=(2, 2),
...         num_active_spatial_orbitals=4
...     ),
...     optimizer=SLSQP(),
...     estimator=Estimator(),
... )
>>> results = qc2data.algorithm.run()