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:
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)
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 toNone
, for reproducibility purposeserror_probability
: defaulted to 0.1, a bit flip probabilitynoise_distribution
: defaulted toWhiteNoise.UNIFORM
, for non-uniform noise distributionsnoise_matrix
: defaulted toNone
, 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)