qrunch.quantum.algorithms.callbacks.callbacks

Module with callbacks.

Functions

merge_parameter_dicts(dicts)

Merge a list of parameter-value dicts, keeping values from later dicts.

Classes

ObjectiveHistoryTracker

Convenience callback function that tracks sampler calls, adaptive iterations and objective function history.

class ObjectiveHistoryTracker

Bases: AdaptiveIterationCallback

Convenience callback function that tracks sampler calls, adaptive iterations and objective function history.

__init__() None

Initialize the history.

Return type:

None

property last_specified_circuit: Circuit

Get the latest specified minimized circuit.

property minimized_circuits: list[Circuit]

Circuit ansatz with the optimal parameters.

record_adaptive_iteration(adaptive_iteration: int, unoptimized_circuit: Circuit, minimized_parameters: dict[Parameter, float], expectation_value: ExpectationValue, n_estimator_shots: int, operator: FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol | None = None) None

Call the callback function with the indicated parameters from the finished adaptive iteration.

Record the objective value at each adaptive iteration.

Note that the adaptive_iteration integer starts at 0 and is incremented with 1 each iteration, except for when reminimizing, then a special value of -1 is given.

Parameters:
Return type:

None

merge_parameter_dicts(dicts: list[dict[Parameter, float]]) dict[Parameter, float]

Merge a list of parameter-value dicts, keeping values from later dicts.

Parameters:

dicts (list[dict[Parameter, float]])

Return type:

dict[Parameter, float]