qrunch.quantum.algorithms.callbacks.callbacks
Module with callbacks.
Functions
|
Merge a list of parameter-value dicts, keeping values from later dicts. |
Classes
Convenience callback function that tracks the final operator and circuit. |
|
Define the minimal interface for 'beast-to-fast' circuit callbacks. |
|
Convenience callback function that tracks the final operator. |
|
Convenience callback function that tracks sampler calls, adaptive iterations and objective function history. |
- class BeastToFastCircuitCallback
Bases:
BeastToFastCircuitProtocolConvenience callback function that tracks the final operator and circuit.
- __init__() None
Initialize the final operator, circuit, and tracking containers.
- Return type:
None
- property estimated_value: ExpectationValue
Get the estimated value.
- 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 final operator.
- Parameters:
adaptive_iteration (int) – The iteration counter.
unoptimized_circuit (Circuit) – The minimized specified Circuit.
minimized_parameters (dict[Parameter, float]) – The circuit parameters that minimize the operator expectation value.
expectation_value (ExpectationValue) – The expectation value.
n_estimator_shots (int) – The number of estimator shots.
operator (FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol | None) – The operator
- Return type:
None
- to_second_quantization_adaptive_vqe_result() SecondQuantizationAdaptiveVqeResult
Return the final result as a SecondQuantizationAdaptiveVqeResult.
- Return type:
- class BeastToFastCircuitProtocol
Bases:
AdaptiveIterationCallback,ProtocolDefine the minimal interface for ‘beast-to-fast’ circuit callbacks.
Provide access to the latest specified circuit, the running estimate history, and a conversion helper to a standard Adaptive VQE result object.
- __init__(*args, **kwargs)
- property estimated_value: ExpectationValue
Return the most recent expectation value estimate.
- property last_specified_circuit: Circuit
Return the latest circuit with parameters specified.
Raise a ValueError if no circuit or parameters have been recorded yet.
- 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.
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:
adaptive_iteration (int)
unoptimized_circuit (Circuit)
minimized_parameters (dict[Parameter, float])
expectation_value (ExpectationValue)
n_estimator_shots (int)
operator (FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol | None)
- Return type:
None
- to_second_quantization_adaptive_vqe_result() SecondQuantizationAdaptiveVqeResult
Build a SecondQuantizationAdaptiveVqeResult from the recorded state.
- Return type:
- class FinalOperatorCallback
Bases:
AdaptiveIterationCallbackConvenience callback function that tracks the final operator.
- __init__() None
Initialize the final_operator.
- Return type:
None
- 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 final operator.
- Parameters:
adaptive_iteration (int) – The iteration counter.
unoptimized_circuit (Circuit) – The minimized specified Circuit.
minimized_parameters (dict[Parameter, float]) – The circuit parameters that minimize the operator expectation value.
expectation_value (ExpectationValue) – The expectation value.
n_estimator_shots (int) – The number of estimator shots.
operator (FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol | None) – The operator
- Return type:
None
- class ObjectiveHistoryTracker
Bases:
AdaptiveIterationCallbackConvenience callback function that tracks sampler calls, adaptive iterations and objective function history.
- __init__() None
Initialize the history.
- Return type:
None
- 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:
adaptive_iteration (int) – The iteration counter.
unoptimized_circuit (Circuit) – The unspecified Circuit.
minimized_parameters (dict[Parameter, float]) – The circuit parameters that minimize the operator expectation value.
expectation_value (ExpectationValue) – The expectation value.
n_estimator_shots (int) – The number of estimator shots.
operator (FermionHermitianSumProtocol | PairedHardcoreBosonHermitianSumProtocol | None) – The operator
- Return type:
None