qrunch.quantum.algorithms.pauli.vqes.adaptive_vqe

Implements the adaptive VQE framework.

Classes

AdaptiveVqe

Class for running adaptive VQE.

IterativeVqeOptions

Default options for the AdaptiveVQE.

class AdaptiveVqe

Bases: PauliAdaptiveVqeAlgorithm

Class for running adaptive VQE.

The adaptive VQE algorithm finds the optimal parameters that minimizes the expectation value of the observable.

In comparison to VQE, which has a frozen parametrized circuit, the adaptive VQE appends parametrized gates to the circuit in each iteration, until no improvement is found.

__init__(vqe: PauliBasicVqeAlgorithm, reminimizer_vqe: BasicVqe | None, gate_selector: GateSelector, options: IterativeVqeOptions | None = None, data_persister_manager: DataPersisterManager | None = None, stopping_criterion: StoppingCriterion | None = None) → None

Initialize the adaptive VQE.

Parameters:
  • vqe (PauliBasicVqeAlgorithm) – The VQE object running the parameter optimization for each added gate.

  • reminimizer_vqe (BasicVqe | None) – The VQE object running the parameter re-optimization at the end of an adaptive run. If None, no reminimization step is performed.

  • gate_selector (GateSelector) – The GateSelector in charge of choosing the next gate from the gate pool.

  • options (IterativeVqeOptions | None) – Options for adaptive VQE

  • data_persister_manager (DataPersisterManager | None) – Manager to handle saving and loading heavy vqe optimizations.

  • stopping_criterion (StoppingCriterion | None) – The stopping criterion to use when performing early stopping.

Return type:

None

static build_circuit_to_optimize(iteration_data: AdaptiveIterationDataHandler, new_gates: list[GatePoolOperator], iteration_count: int) → Circuit

Build circuit to optimize.

The full unoptimized circuit with the new gates are provided.

Parameters:
  • iteration_data (AdaptiveIterationDataHandler) – The iteration data handler.

  • new_gates (list[GatePoolOperator]) – The new_gates to optimize.

  • iteration_count (int) – The iteration count.

Return type:

Circuit

build_metadata(observable: HermitianPauliSum, initial_ansatz: Circuit) → Mapping[str, HasMetadataHashMethod | int | float | str | Mapping[str, HasMetadataHashMethod | int | float | str | HashableStrDict | None] | None]

Create meta-data that represent the input.

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

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

Return type:

Mapping[str, HasMetadataHashMethod | int | float | str | Mapping[str, HasMetadataHashMethod | int | float | str | HashableStrDict | None] | None]

clear_cache() → None

Clear the cache of the VQE and gate selector.

Return type:

None

classmethod persistence_checkpoints() → list[str]

Define the persistence checkpoints used during the adaptive vqe.

These checkpoints specify computational stages where intermediate results can be saved and loaded to optimize computations and ensure reproducibility.

Return type:

list[str]

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 observable 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.

Returns:

PauliAdaptiveVQEResult containing the optimal circuit that minimizes the expectation value.

Return type:

PauliAdaptiveVqeResult

class IterativeVqeOptions

Bases: DataclassPublicAPI

Default options for the AdaptiveVQE.

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

Parameters:
  • max_iterations – The maximum amount of iterations. (default=5)

  • gates_per_iteration – The number of gates to add to the circuit in each iteration. (default=1)

  • new_parameter_guess – Initial guess on the new parameters in each adaptive iteration. (default=0.0)

  • force_all_iterations – Whether to iterate all the way or check for convergence. (default=False)

__init__(*, max_iterations: int = 5, gates_per_iteration: int = 1, new_parameter_guess: float = 0.0, force_all_iterations: bool = False) → None
Parameters:
  • max_iterations (int)

  • gates_per_iteration (int)

  • new_parameter_guess (float)

  • force_all_iterations (bool)

Return type:

None

force_all_iterations: bool = False
gates_per_iteration: int = 1
max_iterations: int = 5
new_parameter_guess: float = 0.0