SamplingVQE#
- class SamplingVQE(sampler, ansatz, optimizer, *, initial_point=None, aggregation=None, callback=None)[source]#
Bases:
VariationalAlgorithm
,SamplingMinimumEigensolver
The Variational Quantum Eigensolver algorithm, optimized for diagonal Hamiltonians.
VQE is a hybrid quantum-classical algorithm that uses a variational technique to find the minimum eigenvalue of a given diagonal Hamiltonian operator \(H_{\text{diag}}\).
In contrast to the
VQE
class, theSamplingVQE
algorithm is executed using asampler
primitive.An instance of
SamplingVQE
also requires anansatz
, a parameterizedQuantumCircuit
, to prepare the trial state \(|\psi(\vec\theta)\rangle\). It also needs a classicaloptimizer
which varies the circuit parameters \(\vec\theta\) to minimize the objective function, which depends on the chosenaggregation
.The optimizer can either be one of Qiskit’s optimizers, such as
SPSA
or a callable with the following signature:from qiskit_algorithms.optimizers import OptimizerResult def my_minimizer(fun, x0, jac=None, bounds=None) -> OptimizerResult: # Note that the callable *must* have these argument names! # Args: # fun (callable): the function to minimize # x0 (np.ndarray): the initial point for the optimization # jac (callable, optional): the gradient of the objective function # bounds (list, optional): a list of tuples specifying the parameter bounds result = OptimizerResult() result.x = # optimal parameters result.fun = # optimal function value return result
The above signature also allows one to use any SciPy minimizer, for instance as
from functools import partial from scipy.optimize import minimize optimizer = partial(minimize, method="L-BFGS-B")
The following attributes can be set via the initializer but can also be read and updated once the
SamplingVQE
object has been constructed.- sampler#
The sampler primitive to sample the circuits.
- Type:
BaseSampler
- ansatz#
A parameterized quantum circuit to prepare the trial state.
- Type:
QuantumCircuit
- optimizer#
A classical optimizer to find the minimum energy. This can either be an
Optimizer
or a callable implementing theMinimizer
protocol.
- aggregation#
A float or callable to specify how the objective function evaluated on the basis states should be aggregated. If a float, this specifies the \(\alpha \in [0,1]\) parameter for a CVaR expectation value [1]. If a callable, it takes a list of basis state measurements specified as
[(probability, objective_value)]
and return an objective value as float. If None, all an ordinary expectation value is calculated.
- callback#
A callback that can access the intermediate data at each optimization step. These data are: the evaluation count, the optimizer parameters for the ansatz, the evaluated value, and the metadata dictionary.
References
- [1]: Barkoutsos, P. K., Nannicini, G., Robert, A., Tavernelli, I., and Woerner, S.,
“Improving Variational Quantum Optimization using CVaR” arXiv:1907.04769
- Parameters:
sampler (BaseSampler) – The sampler primitive to sample the circuits.
ansatz (QuantumCircuit) – A parameterized quantum circuit to prepare the trial state.
optimizer (Optimizer | Minimizer) – A classical optimizer to find the minimum energy. This can either be an
Optimizer
or a callable implementing theMinimizer
protocol.initial_point (np.ndarray | None) – An optional initial point (i.e. initial parameter values) for the optimizer. The length of the initial point must match the number of
ansatz
parameters. IfNone
, a random point will be generated within certain parameter bounds.SamplingVQE
will look to the ansatz for these bounds. If the ansatz does not specify bounds, bounds of \(-2\pi\), \(2\pi\) will be used.aggregation (float | Callable[[list[float]], float] | None) – A float or callable to specify how the objective function evaluated on the basis states should be aggregated.
callback (Callable[[int, np.ndarray, float, dict[str, Any]], None] | None) – A callback that can access the intermediate data at each optimization step. These data are: the evaluation count, the optimizer parameters for the ansatz, the estimated value, and the metadata dictionary.
Attributes
- initial_point#
Return the initial point.
Methods
- compute_minimum_eigenvalue(operator, aux_operators=None)[source]#
Compute the minimum eigenvalue of a diagonal operator.
- Parameters:
operator (BaseOperator) – Diagonal qubit operator.
aux_operators (ListOrDict[BaseOperator] | None) – Optional list of auxiliary operators to be evaluated with the final state.
- Returns:
A
SamplingMinimumEigensolverResult
containing the optimization result.- Return type:
- classmethod supports_aux_operators()[source]#
Whether computing the expectation value of auxiliary operators is supported.
If the minimum eigensolver computes an eigenstate 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: