qrunch.quantum.algorithms.pauli.vqes.creators

Main builders for vqe and gate selection.

Functions

gate_selector_creator()

Start creating a gate selector.

vqe_creator()

Start creating a VQE algorithm.

Classes

AdaptGateSelectorCreator

Builder of an ADAPT gate selector.

AdaptiveVqeCreator

Builder for the adaptive VQE algorithm.

BasicVqeCreator

Builder for the basic VQE algorithm.

BruteForceGateSelectorCreator

Builder of a brute force gate selector.

FastGateSelectorCreator

Builder for FAST gate selector.

GateSelectorCreator

Builder for all types of gate selectors.

VqeCreator

Builder for all types of VQE algorithms.

class AdaptGateSelectorCreator

Bases: object

Builder of an ADAPT gate selector.

__init__() → None

Initialize builder for the ADAPT gate selector.

Return type:

None

create() → AdaptGateSelector

Create an instance of AdaptGateSelector.

Return type:

AdaptGateSelector

with_estimator(estimator: Estimator) → Self

Set the estimator to use for the ADAPT gate selector.

Parameters:

estimator (Estimator) – The estimator to use. Can be created using the estimator_creator().

Return type:

Self

with_shots(shots: int | None) → Self

Set the number of shots to use in the ADAPT gate selector.

This is the number of shots that will be used in each call to the quantum computer or simulator, and not necessarily the total number of shots. The total number of shots will in many cases be much higher.

Parameters:
  • shots (int | None) – Number of shots to use in the estimator. If None is given, the estimator is assumed to be exact

  • simulator). ((e.g. the excitation gate)

Return type:

Self

with_total_estimator_shots(shots: int | None) → Self

Set the number of shots to use in the ADAPT gate selector.

The total number of shots are then distributed across the different groups in the estimator according to the shots per group strategy of the estimator. This ensures better use of the shot budget, and therefore, better use of the quantum resources.

Parameters:
  • shots (int | None) – Number of shots to use in the estimator. If None is given, the estimator is assumed to be exact

  • simulator). ((e.g. the excitation gate)

Return type:

Self

class AdaptiveVqeCreator

Bases: object

Builder for the adaptive VQE algorithm.

__init__(checkpoints: list[str] | None = None) → None

Initialize builder for the adaptive VQE.

Parameters:

checkpoints (list[str] | None)

Return type:

None

choose_data_persister_manager() → DataPersisterManagerSubCreator[Self]

Choose the data persister manager to use and whether to save and/or load the data.

Return type:

DataPersisterManagerSubCreator[Self]

choose_minimizer() → MinimizerSubCreator[Self]

Chose minimizer to use for the adaptive VQE.

Return type:

MinimizerSubCreator[Self]

choose_reminimizer() → ReMinimizerSubCreator[Self]

Chose reminimizer to use for the adaptive VQE.

Return type:

ReMinimizerSubCreator[Self]

choose_stopping_criterion() → StoppingCriterionSubCreator[Self]

Choose the stopping criterion.

Return type:

StoppingCriterionSubCreator[Self]

create() → AdaptiveVqe

Create an instance of AdaptiveVqe an iterative VQE.

Return type:

AdaptiveVqe

with_analytical_beast_basic_vqe(*, active: bool = True) → Self

Choose to use the analytical basic vqe inside each adaptive iteration, which only works for BEAST.

Instead of having the minimizer call the estimator directly, the estimator is first called to make an analytical expression for the energy as a function of the gate parameter. This expression is then passed to the minimizer, requiring no more measurements.

Note: This feature only works with BEAST with last parameter optimization.

If a reminimizer is chosen, it will be paired with the normal Basic vqe since, only it, supports multiple parameters at once.

Parameters:

active (bool) – Whether to use the analytical beast basic vqe or not.

Return type:

Self

with_estimator(estimator: Estimator) → Self

Choose estimator to use for the adaptive VQE.

Parameters:

estimator (Estimator)

Return type:

Self

with_estimator_shots(shots: int | None) → Self

Set the number of shots to use in the estimator.

Parameters:

shots (int | None)

Return type:

Self

with_gate_selector(gate_selector: GateSelector) → Self

Choose the gate selector to use for the adaptive VQE.

Parameters:

gate_selector (GateSelector)

Return type:

Self

with_options(options: IterativeVqeOptions) → Self

Choose the options to use for the adaptive VQE.

Parameters:
  • options (IterativeVqeOptions) – Options to use. Any dataclass with the attributes specified in the IterativeVqeOptions

  • settings (protocol can be used. To use defaults for some of the)

  • class. (use the DefaultIterativeVqeOptions)

Return type:

Self

with_total_estimator_shots(shots: int | None) → Self

Set the total number of shots to use for each estimator call.

Parameters:

shots (int | None)

Return type:

Self

class BasicVqeCreator

Bases: object

Builder for the basic VQE algorithm.

__init__() → None

Initialize builder for the basic VQE.

Return type:

None

choose_minimizer() → MinimizerSubCreator[Self]

Chose minimizer to use for the VQE.

Return type:

MinimizerSubCreator[Self]

create() → BasicVqe

Create an instance of BasicVqe (fixed ansatz).

Return type:

BasicVqe

with_estimator(estimator: Estimator) → Self

Choose estimator to use for the VQE.

Parameters:

estimator (Estimator)

Return type:

Self

with_estimator_shots(shots: int | None) → Self

Set the number of shots to use in the estimator.

Parameters:

shots (int | None)

Return type:

Self

with_total_estimator_shots(shots: int | None) → Self

Set the total number of shots to use for each estimator call.

Parameters:

shots (int | None)

Return type:

Self

class BruteForceGateSelectorCreator

Bases: object

Builder of a brute force gate selector.

__init__() → None

Initialize builder for the brute force gate selector.

Return type:

None

create() → BruteForceGateSelector

Create an instance of BruteForceGateSelector.

Return type:

BruteForceGateSelector

with_estimator(estimator: Estimator) → Self

Set the estimator to use for the brute force gate selector.

Parameters:

estimator (Estimator) – The estimator to use. Can be created using the estimator_creator().

Return type:

Self

with_minimizer(minimizer: Minimizer) → Self

Set the minimizer to use for the brute force gate selector.

The minimizer is used to optimize the parameter of each candidate gate when evaluating its energy contribution.

Parameters:

minimizer (Minimizer) – The minimizer to use. Can be created using the minimizer_creator().

Return type:

Self

with_total_estimator_shots(shots: int | None) → Self

Set the total number of shots to use in the brute force gate selector.

The total number of shots are then distributed across the different groups in the estimator according to the shots per group strategy of the estimator. This ensures better use of the shot budget, and therefore, better use of the quantum resources.

Parameters:

shots (int | None) – Total number of shots to use. If None is given, the estimator is assumed to be exact (e.g. the excitation gate simulator).

Return type:

Self

class FastGateSelectorCreator

Bases: object

Builder for FAST gate selector.

__init__() → None

Initialize builder for the Fast gate selector.

Return type:

None

create() → FastGateSelector

Create an instance of FastGateSelector.

Return type:

FastGateSelector

with_full_heuristic_gradient() → Self

Use full heuristic gradient for the importance metric.

The full heuristic gradient is the heuristic gradient defined in the FAST article (https://doi.org/10.1103/PhysRevA.108.052422), eq. (11). This importance metric corresponds to dropping all off diagonal terms in the double summation from the gradient used in the ADAPT-VQE algorithm, dropping all front-factors and reintroducing the second sum to include off-diagonal terms.

States with a probability less than \(threshold * mean(P_i)\) are excluded, where \(mean(P_i)\) is the mean probability of the measured states.

Return type:

Self

with_heuristic_gradient() → Self

Use heuristic gradient for the importance metric.

The heuristic gradient is a simplified version of the heuristic gradient defined in the FAST article (https://doi.org/10.1103/PhysRevA.108.052422), which corresponds to eq. (10). This importance metric corresponds to dropping all off diagonal terms in the double summation from the gradient used in the ADAPT-VQE algorithm.

States with a probability less than \(threshold * mean(P_i)\) are excluded, where \(mean(P_i)\) is the mean probability of the measured states.

Return type:

Self

with_heuristic_selected_ci(estimator: Estimator | None = None) → Self

Use heuristic selected CI for the importance metric.

The heuristic selected CI is defined in the FAST article (https://doi.org/10.1103/PhysRevA.108.052422), eq. (12). This importance metric is a heuristic version of a selected CI method.

States with a probability less than \(threshold * mean(P_i)\) are excluded, where \(mean(P_i)\) is the mean probability of the measured states.

Parameters:

estimator (Estimator | None) – Estimator to use, if None it uses same estimator as the adaptive VQE.

Return type:

Self

with_options(options: FastGateSelectorOptions) → Self

Set the options for the FAST gate selector.

Parameters:

options (FastGateSelectorOptions) – The options to use.

Return type:

Self

with_sampler(sampler: Sampler) → Self

Set the sampler to use for the FAST gate selector.

Parameters:

sampler (Sampler) – The sampler to use. Can be created using the sampler_creator().

Return type:

Self

with_shots(shots: int | None) → Self

Set the number of shots to use in the FAST gate selector.

Parameters:

shots (int | None) – Number of shots to use. If None, use exact sampling (requires an exact estimator like the excitation gate estimator).

Return type:

Self

with_threshold_exclusion_rule(threshold: float = 1e-10) → Self

Use a threshold to determine when gate operators are removed from exclusion.

Parameters:

threshold (float) – Threshold to compare the FAST metric to.

Return type:

Self

with_touched_exclusion_rule() → Self

Use as an exclusion rule how many times the qubits hit by a gate operator has been hit by others afterwards.

Return type:

Self

class GateSelectorCreator

Bases: object

Builder for all types of gate selectors.

static adapt() → AdaptGateSelectorCreator

Narrow the gate selector to the ADAPT gate selector.

Return type:

AdaptGateSelectorCreator

static brute_force() → BruteForceGateSelectorCreator

Narrow the gate selector to the brute force gate selector.

Return type:

BruteForceGateSelectorCreator

static fast() → FastGateSelectorCreator

Narrow the gate selector to the FAST gate selector.

Return type:

FastGateSelectorCreator

class VqeCreator

Bases: object

Builder for all types of VQE algorithms.

static fixed_ansatz() → BasicVqeCreator

Configure fixed ansatz (basic) VQE.

Return type:

BasicVqeCreator

static iterative() → AdaptiveVqeCreator

Configure an iterative VQE.

Return type:

AdaptiveVqeCreator

gate_selector_creator() → GateSelectorCreator

Start creating a gate selector.

Return type:

GateSelectorCreator

vqe_creator() → VqeCreator

Start creating a VQE algorithm.

Return type:

VqeCreator