qrunch.quantum.algorithms.pauli.vqes.vqe_protocols

Interfaces for the VQE classes and their options dataclasses.

Classes

GateSelector

Interface for a GateSelector.

PauliAdaptiveVqeAlgorithm

Protocol for the ADAPT-VQE, FAST-VQE etc.

PauliAdaptiveVqeResult

Result of the AdaptiveVQE calculation.

PauliBasicVqeAlgorithm

Protocol for the BasicVqe algorithms.

VqeResult

Result of the basic VQE calculation.

class GateSelector

Bases: Protocol

Interface for a GateSelector.

A GateSelector is in charge of selecting the best gate (according to some importance metric) from a gate pool for minimizing an observable.

This is used in adaptive variational quantum eigensolvers (VQEs).

__init__(*args, **kwargs)
register_gate_pool(gate_pool: GatePool) None

Register the gate pool.

Parameters:

gate_pool (GatePool) – the gate pool to register in the GateSelector. The GateSelector can only choose gates from this.

Return type:

None

select_gates(observable: HermitianPauliSum, circuit: Circuit, *, number_of_gates: int = 1) list[GatePoolOperator]

Select the best gates from the gate pool for minimizing the expectation value of the observable.

Parameters:
  • observable (HermitianPauliSum) – The observable whose expectation value should be minimized.

  • circuit (Circuit) – The circuit to extend with a gate form the gate pool.

  • number_of_gates (int) – Number of gates to select.

Returns:

List of gate pool operators.

Return type:

list[GatePoolOperator]

class PauliAdaptiveVqeAlgorithm

Bases: Protocol

Protocol for the ADAPT-VQE, FAST-VQE etc. algorithm.

__init__(*args, **kwargs)
clear_cache() None

Clear the cache of the underlying estimator.

Return type:

None

run(observable: int | float | complex | Expression[PauliOperators] | HermitianPauliSum, gate_pool: GatePool, initial_ansatz: Circuit, callback: AdaptiveIterationCallback | None = None, input_result: PauliAdaptiveVqeResult | None = None) PauliAdaptiveVqeResult

Run the adaptive VQE algorithm.

Parameters:
  • observable (int | float | complex | Expression[PauliOperators] | HermitianPauliSum) – The operator whose expectation value should be minimized.

  • gate_pool (GatePool) – The set of gates to choose from when building the ansatz.

  • initial_ansatz (Circuit) – The starting ansatz circuit. Gates from the gate_pool is appended to this.

  • callback (AdaptiveIterationCallback | None) – An optional callback function that is called at each minimizer iteration.

  • input_result (PauliAdaptiveVqeResult | None) – A prior results that should be refined.

Return type:

PauliAdaptiveVqeResult

class PauliAdaptiveVqeResult

Bases: object

Result of the AdaptiveVQE calculation.

All fields are immutable (frozen=True) so an instance can be safely reused.

Parameters:
  • unspecified_circuit – Circuit ansatz

  • parameters – Optimal parameters that minimizes the expectation value of the ansatz

  • estimated_value – Final estimated expectation value of the operator.

  • estimated_value_per_gate_iteration – Estimated expectation value of the operator for every iteration where an additional gate was added.

  • is_converged – True if VQE converged.

  • best_iteration – The iteration with the best estimated cost

__init__(unspecified_circuit: Circuit, parameters: dict[Parameter, float], estimated_value: ExpectationValue, estimated_value_per_gate_iteration: ListOfExpectationValues, is_converged: bool, best_iteration: int) None
Parameters:
Return type:

None

best_iteration: int
estimated_value: ExpectationValue
estimated_value_per_gate_iteration: ListOfExpectationValues
is_converged: bool
parameters: dict[Parameter, float]
property specified_circuit: Circuit

Circuit ansatz with the optimal parameters.

unspecified_circuit: Circuit
class PauliBasicVqeAlgorithm

Bases: Protocol

Protocol for the BasicVqe algorithms.

__init__(*args, **kwargs)
clear_cache() None

Clear the cache of the underlying estimator.

Return type:

None

does_vqe_support_number_of_simultanously_parameters(number_of_parameters: int) bool

Check if the vqe supports the given number of parameters.

Parameters:

number_of_parameters (int) – The number of parameters to check.

Return type:

bool

run(observable: int | float | complex | Expression[PauliOperators], circuit: Circuit, iteration: int | None = None, initial_guess: dict[Parameter, float] | None = None) VqeResult
run(observable: HermitianPauliSum, circuit: Circuit, iteration: int | None = None, initial_guess: dict[Parameter, float] | None = None) VqeResult

Run the basic VQE algorithm.

The VQE algorithm finds optimal parameters for the circuit such that the expectation value of the observable is minimized.

Parameters:
  • observable (int | float | complex | Expression[PauliOperators] | HermitianPauliSum) – The observable whose expectation value should be minimized.

  • circuit (Circuit) – The parametrized circuit to find optimal parameters for. Should contain unspecified parameters.

  • iteration (int | None) – The current iteration number.

  • initial_guess (dict[Parameter, float] | None) – Dict specifying the initial value of each Parameter. If None is given initial guess is 0.0

Return type:

VqeResult

class VqeResult

Bases: object

Result of the basic VQE calculation.

All fields are immutable (frozen=True) so an instance can be safely reused.

Parameters:
  • estimator_shots – The total amount of shots used by the estimator

  • parameters – Optimal parameters that minimizes the expectation value of the ansatz

  • estimated_value – Estimated expectation value of the operator

__init__(estimator_shots: int, parameters: dict[Parameter, float], estimated_value: ExpectationValue) None
Parameters:
Return type:

None

estimated_value: ExpectationValue
estimator_shots: int
parameters: dict[Parameter, float]