qrunch.quantum.measurement_caches.measurement_caches_protocols

Module containing protocols for measurement caching.

Classes

MeasurementCache

Interface for a measurement cache used by samplers and estimators.

class MeasurementCache

Bases: Protocol

Interface for a measurement cache used by samplers and estimators.

__init__(*args, **kwargs)
clear() None

Clear the cache.

This method is used to clear the cache, for example, when the circuit or observable changes significantly.

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.

The loading returns the observable split into two: A pauli sum containing everything not cached, which needs to be remeasured, and an expectation value, which comes from the cache and does not need to be remeasured.

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:
Return type:

None