qrunch.quantum.measurement_caches.full_measurement_cache
Module containing a full measurement cache.
Classes
Full measurement cache used for samplers and estimators. |
- class FullMeasurementCache
Bases:
MeasurementCacheFull measurement cache used for samplers and estimators.
This cache saves measurements taken on a circuit. Expectation values are cached indirectly through the measurements. Thus the cache can combine many measurement into calculating one partial expectation value, maximally exploiting previous measurements.
- __init__(cached_measurement_limit: int = 10000) None
Initiate an instance of a minimal cache.
- Parameters:
cached_measurement_limit (int) – Maximum number of cached measurements. Defaults to 10000.
- Return type:
None
- clear() None
Clear the cache.
- Return type:
None
- load_expectation_value_from_cache(circuit: Circuit, observable: HermitianPauliSum, shots: int | None) tuple[HermitianPauliSum, ExpectationValue]
Load an expectation value from the cache.
For the minimal cache, either the observable is either fully returned as a hermitian pauli sum or as an expectation value.
- Parameters:
circuit (Circuit) – Circuit on which the measurement was performed.
observable (HermitianPauliSum) – Observable for which the expectation value is needed.
shots (int | None) – Number of shots.
- Return type:
tuple[HermitianPauliSum, ExpectationValue]
- load_measurement_from_cache(measurement_circuit: MeasurementCircuit, shots: int | None) QuantumMeasurement | None
Load a measurement from cache.
- Parameters:
measurement_circuit (MeasurementCircuit) – Circuit on which the measurement was performed.
shots (int | None) – Number of shots in the needed measurement.
- Return type:
QuantumMeasurement | None
- save_expectation_value_to_cache(circuit: Circuit, observable: HermitianPauliSum, shots: int | None, expectation_value: ExpectationValue) None
Save expectation value to cache.
This included the expectation value and/or the measurement used to obtain the expectation value.
- Parameters:
circuit (Circuit) – Circuit on which the measurement was performed.
observable (HermitianPauliSum) – Observable which has been measured.
shots (int | None) – Number of shots.
expectation_value (ExpectationValue) – Expectation value of the observable.
- Return type:
None
- save_measurement_to_cache(measurement_circuit: MeasurementCircuit, measurement: QuantumMeasurement) None
Save a measurement to the cache.
- Parameters:
measurement_circuit (MeasurementCircuit) – Circuit on which the measurement was performed.
measurement (QuantumMeasurement) – Measurement results.
- Return type:
None