qrunch.quantum.backends.memory_restricted_backend

Module containing a backend using the memory restricted simulator.

Functions

apply_measurement_noise(measurement, ...)

Apply measurement noise to the quantum measurement.

Classes

MemoryRestrictedBackend

Memory restricted backend which uses the memory restricted simulator.

MemoryRestrictedBackendOptions

Options for the MemoryRestrictedBackend.

NoiseModel

Noise model used by the MemoryRestrictedBackend.

class MemoryRestrictedBackend

Bases: Backend

Memory restricted backend which uses the memory restricted simulator.

__init__(device_to_simulate: DeviceData | None = None, compiler: Compiler | None = None, layout_synthesizer: LayoutSynthesizer | None = None, options: MemoryRestrictedBackendOptions | None = None) None

Initialize a memory restricted backend.

The backend calculates the approximate state vector using the allowed number of amplitudes of the given circuit, and uses this to find the probabilities for each possible state in the Hilbert space. The backend supports noisy simulations using the given device data through quantum monte carlo simulation.

The result is representative of results from a quantum computer with the errors from the given device data. However, given the nature of monte carlo simulations the result is not an ensemble average and will very from run to run. Increase the number of monte carlo runs for better convergence to the ensemble average.

Parameters:
  • device_to_simulate (DeviceData | None) – Data for the device to simulate.

  • compiler (Compiler | None) – Compiler for changing into universal gates. Defaults to PerGateCompiler if device_to_simulate is given otherwise compilation is not done.

  • layout_synthesizer (LayoutSynthesizer | None) – Synthesizer to change into the device topology.

  • options (MemoryRestrictedBackendOptions | None) – Options to be parsed to the memory restricted simulator.

Return type:

None

property name: str

Name of the backend.

run(circuits: Circuit | Sequence[Circuit], shots: int | None) SimulatedJob

Run circuit on the backend.

Parameters:
  • circuits (Circuit | Sequence[Circuit]) – circuits to run on backend

  • shots (int | None) – number of shots

Return type:

SimulatedJob

supports_shots_equals_none() bool

Return whether the backend supports shots = None.

The MemoryRestrictedBackend support shots = None, meaning a full state vector simulation.

Return type:

bool

class MemoryRestrictedBackendOptions

Bases: object

Options for the MemoryRestrictedBackend.

All fields are immutable (frozen=True) so an instance can be safely reused.

Parameters:
  • suppress_warnings – Whether to supress warnings due to precision or not. (default=False)

  • max_number_of_amplitudes – Maximum number of amplitudes allowed in the state vector. (default=1_000_000)

  • max_memory_usage_in_kb – Maximum memory allowed for representing the state vector. (default=None)

  • number_of_monte_carlo_runs – Number of monte carlo runs to use for noisy simulations. If no noise_model is given, this option is ignored. (default=100)

  • seed – Default seed for the simulator. Defaults to None. (default=None)

__init__(*, suppress_warnings: bool = False, max_number_of_amplitudes: int | None = 1000000, max_memory_usage_in_kb: int | None = None, number_of_monte_carlo_runs: int = 100, seed: int | None = None, max_measurement_errors: int = 2) None
Parameters:
  • suppress_warnings (bool)

  • max_number_of_amplitudes (int | None)

  • max_memory_usage_in_kb (int | None)

  • number_of_monte_carlo_runs (int)

  • seed (int | None)

  • max_measurement_errors (int)

Return type:

None

build_memory_restricted_simulator_options() MemoryRestrictedSimulatorOptions

Build options for the memory restricted simulator.

Return type:

MemoryRestrictedSimulatorOptions

max_measurement_errors: int = 2
max_memory_usage_in_kb: int | None = None
max_number_of_amplitudes: int | None = 1000000
number_of_monte_carlo_runs: int = 100
seed: int | None = None
suppress_warnings: bool = False
class NoiseModel

Bases: object

Noise model used by the MemoryRestrictedBackend.

Gate errors are also know as infidelities or one minus the fidelity for the gate. The fidelity is the average overlap between the desired operation and the simulated operation. Measurement error is not quantum in nature and are added post-simulation. General addition of measurement error is exponentially hard so the number of measurement errors are restricted.

Parameters:
  • single_qubit_errors – Error on single qubit gates. (default=0.001)

  • two_qubit_error – Error on two qubit gates. (default=0.01)

  • measurement_error – Error on measurements. (default=0.01)

  • max_measurement_errors – Maximum number of measurement errors to include. (default=2)

__init__(single_qubit_errors: float = 0.001, two_qubit_error: float = 0.01, measurement_error: float = 0.01) None
Parameters:
  • single_qubit_errors (float)

  • two_qubit_error (float)

  • measurement_error (float)

Return type:

None

measurement_error: float = 0.01
single_qubit_errors: float = 0.001
two_qubit_error: float = 0.01
apply_measurement_noise(measurement: QuantumMeasurement, measurement_error: float, max_number_of_errors: int) QuantumMeasurement

Apply measurement noise to the quantum measurement.

Parameters:
  • measurement (QuantumMeasurement) – Quantum measurement to add noise too.

  • measurement_error (float) – Probability of a measurement error occurring.

  • max_number_of_errors (int) – Max number of measurement errors in each bit string.

Return type:

QuantumMeasurement