qrunch.quantum.measurement_caches.noise_reducing_measurement_cache
Module containing a noise reducing measurement cache.
Classes
Noise reducing measurement cache used for samplers and estimators. |
- class NoiseReducingMeasurementCache
Bases:
MeasurementCacheNoise reducing measurement cache used for samplers and estimators.
This cache saves measurements taken on a circuit. Expectation values are cached indirectly through the measurements. This cache does not limit the number of measurements instead it aims to reduce the amount of shots noise. Thus, a uncached loaded pauli sum will contain as many pauli strings as the original. However, the cached measurements are used as additional measurements to lower the shot noise on all pauli strings.
This is optimal for BEAST where 2-3 groups are required for every measurement irrespective of what caching is done.
- __init__(cached_measurement_limit: int = 10000, cached_expectation_value_limit: int = 100) None
Initiate an instance of a noise reducing minimal cache.
- Parameters:
cached_measurement_limit (int) – Maximum number of cached measurements. Defaults to 10000.
cached_expectation_value_limit (int) – Maximum number of cached expectation values. Defaults to 100.
- 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, 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