qermit.zero_noise_extrapolation#

zne.gen_ZNE_MitEx(noise_scaling_list: List[float], **kwargs) MitEx#

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.

Returns:

MitEx object performing noise mitigation by ZNE.

Return type:

MitEx

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.

Return type:

Circuit

static circuit(circ: Circuit, noise_scaling: int, **kwargs) Circuit[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.

Returns:

Folded circuit implementing identical unitary to the initial circuit.

Return type:

Circuit

static gate(circ: Circuit, noise_scaling: float, **kwargs) Circuit[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.

Returns:

Folded circuit implementing identical unitary to the initial circuit.

Return type:

Circuit

static odd_gate(circ: Circuit, noise_scaling: int, **kwargs) Circuit[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 (float) – Factor by which to increase the noise.

Returns:

Folded circuit implementing identical unitary to the initial circuit.

Return type:

Circuit

static two_qubit_gate(circ: Circuit, noise_scaling: float, **kwargs) Circuit[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 (int) – 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.

Returns:

Circuit with noise scaled.

Return type:

Circuit

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.

Return type:

float

static cube_root(x: List[float], y: List[float], _show_fit: bool, *args) float[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.

Returns:

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

Return type:

float

static exponential(x: List[float], y: List[float], _show_fit: bool, *args) float[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.

Returns:

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

Return type:

float

static linear(x: List[float], y: List[float], _show_fit: bool, *args) float[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.

Returns:

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

Return type:

float

static poly_exponential(x: List[float], y: List[float], _show_fit: bool, deg: int) float[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.

Returns:

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

Return type:

float

static polynomial(x: List[float], y: List[float], _show_fit: bool, deg: int) float[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.

Returns:

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

Return type:

float

static richardson(x: List[float], y: List[float], _show_fit: bool, *args) float[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.

Returns:

Extrapolation to zero noise limit using Richardson extrapolation.

Return type:

float

zne.digital_folding_task_gen(noise_scaling: float, _folding_type: Folding, _allow_approx_fold: bool) MitTask#

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).

zne.extrapolation_task_gen(_fit_type: Fit, _show_fit: bool, deg: int) MitTask#

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.

zne.gen_initial_compilation_task(optimisation_level: int = 1) MitTask#

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, optional) – level of default compiler, defaults to 1

zne.gen_qubit_relabel_task() MitTask#

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

Returns:

Task performing relabelling.

Return type:

MitTask

zne.gen_duplication_task(**kwargs) MitTask#

Duplicate the inputted experiment wire

Parameters:

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