Skip to content

Simulated errors

Running programs on NISQ devices often leads to partially useful results due to the presence of noise. In order to perform realistic simulations, a number of noise models are supported in Qadence and corresponding error mitigation techniques whenever possible.

Readout errors

State Preparation and Measurement (SPAM) in the hardware is a major source of noise in the execution of quantum programs. They are typically described using confusion matrices of the form:

\[ T(x|x')=\delta_{xx'} \]

Qadence offers to simulate readout errors with the Noise protocol to corrupt the output samples of a simulation, through execution via a QuantumModel:

from qadence import QuantumModel, QuantumCircuit, kron, H, Z
from qadence import hamiltonian_factory
from qadence.noise import Noise

# Simple circuit and observable construction.
block = kron(H(0), Z(1))
circuit = QuantumCircuit(2, block)
observable = hamiltonian_factory(circuit.n_qubits, detuning=Z)

# Construct a quantum model.
model = QuantumModel(circuit=circuit, observable=observable)

# Define a noise model to use.
noise = Noise(protocol=Noise.READOUT)

# Run noiseless and noisy simulations.
noiseless_samples = model.sample(n_shots=100)
noisy_samples = model.sample(noise=noise, n_shots=100)
noiseless = [Counter({'00': 52, '10': 48})]
noisy = [Counter({'10': 48, '00': 44, '11': 5, '01': 3})]

It is possible to pass options to the noise model. In the previous example, a noise matrix is implicitly computed from a uniform distribution. The option dictionary argument accepts the following options:

  • seed: defaulted to None, for reproducibility purposes
  • error_probability: defaulted to 0.1, a bit flip probability
  • noise_distribution: defaulted to WhiteNoise.UNIFORM, for non-uniform noise distributions
  • noise_matrix: defaulted to None, if the noise matrix is known from third-party experiments, i.e. hardware calibration.

Noisy simulations go hand-in-hand with measurement protocols discussed in the previous section, to assess the impact of noise on expectation values. In this case, both measurement and noise protocols have to be defined appropriately. Please note that a noise protocol without a measurement protocol will be ignored for expectation values computations.

from qadence.measurements import Measurements

# Define a noise model with options.
options = {"error_probability": 0.01}
noise = Noise(protocol=Noise.READOUT, options=options)

# Define a tomographical measurement protocol with options.
options = {"n_shots": 10000}
measurement = Measurements(protocol=Measurements.TOMOGRAPHY, options=options)

# Run noiseless and noisy simulations.
noiseless_exp = model.expectation(measurement=measurement)
noisy_exp = model.expectation(measurement=measurement, noise=noise)
noiseless = tensor([[0.8076]], grad_fn=<TransposeBackward0>)
noisy = tensor([[0.9832]], grad_fn=<TransposeBackward0>)