qml.transforms.mitigate_with_zne¶

mitigate_with_zne
(circuit: Union[pennylane.qnode.QNode, pennylane.tape.tape.QuantumTape], scale_factors: Sequence[float], folding: callable, extrapolate: callable, folding_kwargs: Optional[Dict[str, Any]] = None, extrapolate_kwargs: Optional[Dict[str, Any]] = None, reps_per_factor=1) → float[source]¶ Mitigate an input circuit using zeronoise extrapolation.
Error mitigation is a precursor to error correction and is compatible with nearterm quantum devices. It aims to lower the impact of noise when evaluating a circuit on a quantum device by evaluating multiple variations of the circuit and postprocessing the results into a noisereduced estimate. This transform implements the zeronoise extrapolation (ZNE) method originally introduced by Temme et al. and Li et al..
Details on the functions passed to the
folding
andextrapolate
arguments of this transform can be found in the usage details. This transform is compatible with functionality from the Mitiq package (version 0.11.0 and above), see the example and usage details for further information.Warning
Calculating the gradient of mitigated circuits is not supported when using the Mitiq package as a backend for folding or extrapolation.
 Parameters
circuit (callable or QuantumTape) – the circuit to be errormitigated
scale_factors (Sequence[float]) – the range of noise scale factors used
folding (callable) – a function that returns a folded circuit for a specified scale factor
extrapolate (callable) – a function that returns an extrapolated result when provided a range of scale factors and corresponding results
folding_kwargs (dict) – optional keyword arguments passed to the
folding
functionextrapolate_kwargs (dict) – optional keyword arguments passed to the
extrapolate
functionreps_per_factor (int) – Number of circuits generated for each scale factor. Useful when the folding function is stochastic.
 Returns
the result of evaluating the circuit when mitigated using ZNE
 Return type
float
Example:
We first create a noisy device using
default.mixed
by addingAmplitudeDamping
to each gate of circuits executed on the device using theinsert()
transform:import pennylane as qml noise_strength = 0.05 dev = qml.device("default.mixed", wires=2) dev = qml.transforms.insert(qml.AmplitudeDamping, noise_strength)(dev)
We can now set up a mitigated QNode by harnessing functionality from the Mitiq package:
from pennylane import numpy as np from pennylane import qnode from mitiq.zne.scaling import fold_global from mitiq.zne.inference import RichardsonFactory n_wires = 2 n_layers = 2 shapes = qml.SimplifiedTwoDesign.shape(n_wires, n_layers) np.random.seed(0) w1, w2 = [np.random.random(s) for s in shapes] @qml.transforms.mitigate_with_zne([1, 2, 3], fold_global, RichardsonFactory.extrapolate) @qnode(dev) def circuit(w1, w2): qml.SimplifiedTwoDesign(w1, w2, wires=range(2)) return qml.expval(qml.PauliZ(0))
Executions of
circuit
will now be mitigated:>>> circuit(w1, w2) 0.19113067083636542
The unmitigated circuit result is
0.33652776
while the ideal circuit result is0.23688169
and we can hence see that mitigation has helped reduce our estimation error.Usage Details
Theoretical details
A summary of ZNE can be found in LaRose et al.. The method works by assuming that the amount of noise present when a circuit is run on a noisy device is enumerated by a parameter \(\gamma\). Suppose we have an input circuit that experiences an amount of noise equal to \(\gamma = \gamma_{0}\) when executed. Ideally, we would like to evaluate the result of the circuit in the \(\gamma = 0\) noisefree setting.
To do this, we create a family of equivalent circuits whose ideal noisefree value is the same as our input circuit. However, when run on a noisy device, each circuit experiences a noise equal to \(\gamma = s \gamma_{0}\) for some scale factor \(s\). By evaluating the noisy outputs of each circuit, we can extrapolate to \(s=0\) to estimate the result of running a noisefree circuit.
A key element of ZNE is the ability to run equivalent circuits for a range of scale factors \(s\). When the noise present in a circuit scales with the number of gates, \(s\) can be varied using unitary folding. Unitary folding works by noticing that a unitary \(U\) is equivalent to \(U U^{\dagger} U\). This type of transform can be applied to individual gates in the circuit or to the whole circuit. When no folding occurs, the scale factor is \(s=1\) and we are running our input circuit. On the other hand, when each gate has been folded once, we have tripled the amount of noise in the circuit so that \(s=3\). For \(s \geq 3\), each gate in the circuit will be folded more than once. A typical choice of scale parameters is \((1, 2, 3)\).
Unitary folding
This transform applies ZNE to an input circuit using the unitary folding approach. It requires a callable to be passed as the
folding
argument with signaturefn(circuit, scale_factor, **folding_kwargs)
where
circuit
is a quantum tape,scale_factor
is a float, andfolding_kwargs
are optional keyword arguments.
The output of the function should be the folded circuit as a quantum tape. Folding functionality is available from the Mitiq package (version 0.11.0 and above) in the zne.scaling.folding module.
Extrapolation
This transform also requires a callable to be passed to the
extrapolate
argument that returns the extrapolated value(s). Its function should befn(scale_factors, results, **extrapolate_kwargs)
where
scale_factors
are the ZNE scale factors,results
are the execution results of the circuit at the specified scale factors of shape(len(scale_factors), len(qnode_returns))
, andextrapolate_kwargs
are optional keyword arguments.
The output of the extrapolate
fn
should be a flat array of lengthlen(qnode_returns)
.Extrapolation functionality is available using
extrapolate
methods of the factories in the mitiq.zne.inference module.
Contents
Using PennyLane
Development
API
Downloads