AdaptVQE

class AdaptVQE(solver, *, gradient_threshold=1e-05, eigenvalue_threshold=1e-05, max_iterations=None, operators=None, reps=1, evolution=None, insert_barriers=False, name='EvolvedOps', parameter_prefix='t', remove_identities=True, initial_state=None, flatten=None)[source]

Bases: VariationalAlgorithm, MinimumEigensolver

The Adaptive Variational Quantum Eigensolver algorithm.

AdaptVQE is a quantum algorithm which creates a compact ansatz from a set of evolution operators. It iteratively extends the ansatz circuit, by selecting the building block that leads to the largest gradient from a set of candidates. In chemistry, this is usually a list of orbital excitations. Thus, a common choice of ansatz to be used with this algorithm is the Unitary Coupled Cluster ansatz implemented in Qiskit Nature. This results in a wavefunction ansatz which is uniquely adapted to the operator whose minimum eigenvalue is being determined. This class relies on a supplied instance of VQE to find the minimum eigenvalue. The performance of AdaptVQE significantly depends on the minimization routine.

from qiskit_algorithms.minimum_eigensolvers import AdaptVQE, VQE
from qiskit_algorithms.optimizers import SLSQP
from qiskit.primitives import StatevectorEstimator
from qiskit.circuit.library import EvolvedOperatorAnsatz
from qiskit import QuantumCircuit

# get your Hamiltonian
hamiltonian = ...

# construct your ansatz
ansatz = EvolvedOperatorAnsatz(...)

vqe = VQE(StatevectorEstimator(), ansatz, SLSQP())

adapt_vqe = AdaptVQE(vqe)

# or you can do it without EvolvedOperatorAnsatz
vqe = VQE(StatevectorEstimator(), QuantumCircuit(1), SLSQP())

adapt_vqe = AdaptVQE(vqe, operators=...)

eigenvalue, _ = adapt_vqe.compute_minimum_eigenvalue(hamiltonian)

The following attributes can be set via the initializer but can also be read and updated once the AdaptVQE object has been constructed.

solver

a VQE instance used internally to compute the minimum eigenvalues. It is a requirement that the ansatz of this solver is of type EvolvedOperatorAnsatz if the operators arguments is not set.

gradient_threshold

once all gradients have an absolute value smaller than this threshold, the algorithm has converged and terminates.

eigenvalue_threshold

once the eigenvalue has changed by less than this threshold from one iteration to the next, the algorithm has converged and terminates. When this case occurs, the excitation included in the final iteration did not result in a significant improvement of the eigenvalue and, thus, the results from this iteration are not considered.

max_iterations

the maximum number of iterations for the adaptive loop. If None, the algorithm is not bound in its number of iterations.

Parameters:
  • solver (VQE) – a VQE instance used internally to compute the minimum eigenvalues. It is a requirement that either the ansatz of this solver is of type EvolvedOperatorAnsatz or that the operators argument is specified. The former is deprecated from the 0.4 version of qiskit-algorithms and this option won’t be possible anymore once the oldest supported Qiskit version is 3.0. In the latter case, this class will build its own ansatz using the evolved_operator_ansatz function.

  • gradient_threshold (float) – once all gradients have an absolute value smaller than this threshold, the algorithm has converged and terminates. Defaults to 1e-5.

  • eigenvalue_threshold (float) – once the eigenvalue has changed by less than this threshold from one iteration to the next, the algorithm has converged and terminates. When this case occurs, the excitation included in the final iteration did not result in a significant improvement of the eigenvalue and, thus, the results from this iteration are not considered.

  • max_iterations (int | None) – the maximum number of iterations for the adaptive loop. If None, the algorithm is not bound in its number of iterations.

  • operators (BaseOperator | Sequence[BaseOperator] | None) – used to build the ansatz using the evolved_operator_ansatz() function. If set, the ansatz of the underlying VQE solver won’t be used.

  • reps (int) – used to build the ansatz using the evolved_operator_ansatz() function.

  • evolution – used to build the ansatz using the evolved_operator_ansatz() function.

  • insert_barriers (bool) – used to build the ansatz using the evolved_operator_ansatz() function.

  • name (str) – used to build the ansatz using the evolved_operator_ansatz() function.

  • parameter_prefix (str | Sequence[str]) – used to build the ansatz using the evolved_operator_ansatz() function.

  • remove_identities (bool) – used to build the ansatz using the evolved_operator_ansatz() function.

  • initial_state (QuantumCircuit | None) – a QuantumCircuit object to prepend to the ansatz.

  • flatten (bool | None) – used to build the ansatz using the evolved_operator_ansatz() function.

Attributes

initial_point

Returns the initial point of the internal VQE solver.

Methods

compute_minimum_eigenvalue(operator, aux_operators=None)[source]

Computes the minimum eigenvalue.

Parameters:
  • operator (BaseOperator) – Operator whose minimum eigenvalue we want to find.

  • aux_operators (List[BaseOperator | None] | Dict[str, BaseOperator] | None) – Additional auxiliary operators to evaluate.

Raises:
  • TypeError – If an ansatz other than EvolvedOperatorAnsatz is provided.

  • AlgorithmError – If all evaluated gradients lie below the convergence threshold in the first iteration of the algorithm.

Returns:

An AdaptVQEResult which is a VQEResult but also includes runtime information about the AdaptVQE algorithm like the number of iterations, termination criterion, and the final maximum gradient.

Return type:

AdaptVQEResult

classmethod supports_aux_operators()[source]

Whether computing the expectation value of auxiliary operators is supported.

If the minimum eigensolver computes an eigenvalue of the main operator then it can compute the expectation value of the aux_operators for that state. Otherwise they will be ignored.

Returns:

True if aux_operator expectations can be evaluated, False otherwise

Return type:

bool