qermit.zero_noise_extrapolation

qermit.zero_noise_extrapolation.zne.gen_ZNE_MitEx(backend, noise_scaling_list, **kwargs)[source]

Generates MitEx object which mitigates for noise using Zero Noise Extrapolation. This is the process by which noise is amplified incrementally, and the zero noise case arrived at by extrapolating backwards. For further explanantion see https://arxiv.org/abs/2005.10921.

Parameters:
  • backend (Backend) – Backend on which the circuits are to be run.

  • noise_scaling_list (List[float]) – A list of the amounts by which the noise should be scaled.

Return type:

MitEx

Returns:

MitEx object performing noise mitigation by ZNE.

qermit.zero_noise_extrapolation.zne.gen_noise_scaled_mitex(backend, noise_scaling, **kwargs)[source]

Generates MitEx with noise scaled by the Qermit Folding methods.

Parameters:
  • backend (Backend) – Backend on which circuits are run.

  • noise_scaling (float) – Factor by which noise is scaled.

Return type:

MitEx

Returns:

MitEx with scaled noise.

Key experiment_mitres:

MitRes on which circuits are run, defaults to a MitRes wrapped around the given backend.

Key experiment_mitex:

MitEx on which the circuits are run, defaults to a MitEx wrapped around experiment_mitres

Key allow_approx_fold:

Allow approximate folding which may occur as a result of discreet folding due to adding gates.

Key folding_type:

The noise scaling method to use.

class qermit.zero_noise_extrapolation.zne.Folding(value)[source]

Folding techniques used to increase the noise levels.

Returns:

Circuit with gate count increased to scale noise. The unitary implemented by the circuit has not changed.

static circuit(circ, noise_scaling, **kwargs)[source]

Noise scaling by circuit folding. In this case the folded circuit is of the form \(CC^{-1}CC^{-1}...C\) where \(C\) is the original circuit. As such noise may be scaled by odd integers. The Unitary implemented is unchanged by this process.

Parameters:
  • circ (Circuit) – Original circuit to be folded.

  • noise_scaling (int) – Factor by which to scale the noise. This must be an odd integer.

Raises:

ValueError – Raised if the amount by which the noise should be scaled is not an odd integer.

Return type:

List[Circuit]

Returns:

Folded circuit implementing identical unitary to the initial circuit.

static gate(circ, noise_scaling, **kwargs)[source]

Noise scaling by gate folding. In this case gates \(G\) are replaced at random with \(GG^{-1}G\) until the number of gates is sufficiently scaled.

Parameters:
  • circ (Circuit) – Original circuit to be folded.

  • noise_scaling (float) – Factor by which to increase the noise.

Key _allow_approx_fold:

Allows for the noise to be increased by an amount close to that requested, as opposed to by exactly the amount requested. This is necessary as there are cases where the exact noise scaling cannot be achieved. This occurs due to the discrete amounts by which the noise can be increased (i.e. the discrete amount by which one gate increases the noise).

Raises:

ValueError – Raised if the requested noise scaling cannot be exactly achieved. This can be avoided by appropriately setting _allow_approx_fold.

Return type:

List[Circuit]

Returns:

Folded circuit implementing identical unitary to the initial circuit.

static noise_aware(circ, noise_scaling, **kwargs)[source]

Scale noise in a circuit by adding noisy gates as defined by the given noise model.

Parameters:
  • circ (Circuit) – Circuit with noise to be scaled.

  • noise_scaling (int) – Factor by which noise should be scaled.

Return type:

List[Circuit]

Returns:

List of circuits with additional noise gates added.

Key noise_model:

Noise model defining noise types and rates. Defaults to noiseless model.

Key n_noisy_circuit_samples:

The number of random noisy circuits to generate. Defaults to 1.

static odd_gate(circ, noise_scaling, **kwargs)[source]

Noise scaling by gate folding. In this case odd gates \(G\) are replaced \(GG^{-1}G\) until the number of gates is sufficiently scaled.

Parameters:
  • circ (Circuit) – Original circuit to be folded.

  • noise_scaling (int) – Factor by which to increase the noise.

Return type:

List[Circuit]

Returns:

Folded circuit implementing identical unitary to the initial circuit.

static two_qubit_gate(circ, noise_scaling, **kwargs)[source]

Noise scaling by folding 2 qubit gates. It is implicitly assumed that the noise on the 2 qubit gates dominate. Two qubit gates \(G\) are replaced by \(GG^{-1}G...G^{-1}G\). If noise_scaling is of the form (#gates + 2i)/#gates, where #gates is the number of gates in the compiled circuit and i is an integer, then the noise scaling is exact. It will otherwise be as close as possible to but smaller then noise_scaling.

Parameters:
  • circ (Circuit) – Original circuit to be folded.

  • noise_scaling (float) – Factor by which the noise should be scaled.

Raises:
  • ValueError – Raised if noise_scaling is less than 1.

  • ValueError – Raised if the noise cannot be scaled by exactly noise_scaling and _allow_approx_fold is not True.

  • RuntimeError – Raised if there are no valid gates to fold.

  • RuntimeError – Raised if the circuit includes boxes.

Key _allow_approx_fold:

True or false depending on if approximate folding is allowed. Defaults to True.

Return type:

List[Circuit]

Returns:

Circuit with noise scaled.

class qermit.zero_noise_extrapolation.zne.Fit(value)[source]

Functions to fit to expectation values as they change with noise.

Returns:

Extrapolation of expectation values to the zero noise limit.

static cube_root(x, y, _show_fit, *args)[source]

Fit data to a cube root function. This is to say a function of the form \(a + b(x+c)^{1/3}\).

Parameters:
  • x (List[float]) – Noise scaling values.

  • y (List[float]) – Expectation values.

  • _show_fit (bool) – Plot data and resulting fitted function.

Return type:

float

Returns:

Extrapolation of data to zero noise limit using the best fitting cube root function.

static exponential(x, y, _show_fit, *args)[source]

Fit data to an exponential function. This is to say a function of the form \(a+e^{(b+x)}\). Note that this is a special case of the poly-exponential function.

Parameters:
  • x (List[float]) – Noise scaling values.

  • y (List[float]) – Expectation values.

  • _show_fit (bool) – Plot data and resulting fitting function.

Return type:

float

Returns:

Extrapolation to zero noise limit using the best fitting exponential function.

static linear(x, y, _show_fit, *args)[source]

Fit data to a linear function. This is to say a function of the form \(ax+b\). Note that this is a special case of the polynomial fitting function.

Parameters:
  • x (List[float]) – Noise scaling values.

  • y (List[float]) – Expectation values.

  • _show_fit (bool) – Plot data and resulting fitted function.

Return type:

float

Returns:

Extrapolation to zero noise limit using the best fitting linear function.

static poly_exponential(x, y, _show_fit, deg)[source]

Fit data to a poly-exponential, which is to say a function of the form \(a+e^{z}\), where \(z\) is a polynomial.

Parameters:
  • x (List[float]) – Noise scaling values.

  • y (List[float]) – Expectation values.

  • _show_fit (bool) – Plot data and resulting fitted function.

  • deg (int) – The degree of the polynomial in the exponential.

Raises:

ValueError – Raised if the degree of the polynomial inputted is negative, or too high to fit to the data.

Return type:

float

Returns:

Extrapolation of data to the zero noise limit using the best fitting poly-exponential function of the specified degree.

static polynomial(x, y, _show_fit, deg)[source]

Fit data to a polynomial function.

Parameters:
  • x (List[float]) – Noise scaling values.

  • y (List[float]) – Expectation values.

  • _show_fit (bool) – Plot data and resulting fitting function.

  • deg (int) – The degree of the function to fit to.

Raises:

ValueError – Raised if the degree of the polynomial is negative, or too high to fit the data to.

Return type:

float

Returns:

Extrapolation to zero noise limit using the best fitting polynomial function of the specified degree.

static richardson(x, y, _show_fit, *args)[source]

Use richardson extrapolation. This amounts to fitting to a polynomial of degree one less than the number of data points.

Parameters:
  • x (List[float]) – Noise scaling values.

  • y (List[float]) – Expectation values.

  • _show_fit (bool) – Plot data and resulting fitted function.

Return type:

float

Returns:

Extrapolation to zero noise limit using Richardson extrapolation.

qermit.zero_noise_extrapolation.zne.digital_folding_task_gen(backend, noise_scaling, _folding_type, _allow_approx_fold, **kwargs)[source]

Generates task transforming a circuit in order to amplify the noise. The noise is increased by a factor noise_scaling using the inputted folding method.

Parameters:
  • backend (Backend) – This will be used to compile the circuit after folding to ensure that the gate set matches those available on the backend.

  • noise_scaling (float) – The factor by which the noise is increased.

  • _folding_type (Folding) – The means by which the noise should be increased.

  • _allow_approx_fold (bool) – Allows for the noise to be increased by an amount close to that requested, as opposed to by exactly the amount requested. This is necessary as there are cases where the exact noise scaling cannot be achieved. This occurs due to the discrete amounts by which the noise can be increased (i.e. the discrete amount by which one gate increases the noise).

Return type:

MitTask

qermit.zero_noise_extrapolation.zne.merge_experiments_task_gen()[source]

Generates task merging qubit pauli strings when they belong to the same experiment.

Return type:

MitTask

Returns:

MitTask performing the merge.

qermit.zero_noise_extrapolation.zne.extrapolation_task_gen(noise_scaling_list, _fit_type, _show_fit, deg)[source]

Generates task extrapolating to the zero noise limit using results from many folded circuits.

Parameters:
  • noise_scaling_list (List[float]) – A list of the values by which the noise has been folded.

  • _fit_type (Fit) – The function used to fit to the resulting data.

  • _show_fit (bool) – Plot data and resulting fitted function.

  • deg (int) – The degree of polynomials used.

Return type:

MitTask

qermit.zero_noise_extrapolation.zne.gen_initial_compilation_task(backend, optimisation_level=1)[source]

Perform compilation to the backend. Note that this will relabel the nodes of the device, and so should be followed by gen_qubit_relabel_task in the task graph.

Parameters:
  • backend (Backend) – Backend to compile to

  • optimisation_level (int) – level of default compiler, defaults to 1

Return type:

MitTask

qermit.zero_noise_extrapolation.zne.gen_qubit_relabel_task()[source]

Task reversing the relabelling of qubits performed during compilation. This should follow gen_initial_compilation_task

Return type:

MitTask

Returns:

Task performing relabelling.

qermit.zero_noise_extrapolation.zne.gen_duplication_task(duplicates, **kwargs)[source]

Duplicate the inputted experiment wire

Parameters:

duplicates (int) – The number of times to duplicate the input wire.

Return type:

MitTask