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.
- 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:
- Return type:
- 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:
- Raises:
ValueError – Raised if the amount by which the noise should be scaled is not an odd integer.
- Return type:
- 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:
- 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:
- 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:
- Return type:
- 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.
- 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:
- 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:
- 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}\).
- 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.
- 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.
- 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:
- Raises:
ValueError – Raised if the degree of the polynomial inputted is negative, or too high to fit to the data.
- Return type:
- 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:
- Raises:
ValueError – Raised if the degree of the polynomial is negative, or too high to fit the data to.
- Return type:
- Returns:
Extrapolation to zero noise limit using the best fitting polynomial function of the specified degree.
- 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:
- 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:
- 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.
- 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.