You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/guide/lre-4-low-level.md
+171-1Lines changed: 171 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -12,4 +12,174 @@ kernelspec:
12
12
---
13
13
14
14
15
-
# What happens when I use LRE?
15
+
# What happens when I use LRE?
16
+
17
+
As shown in the figure below, LRE works in two steps, layerwise noise scaling and extrapolation.
18
+
19
+
The noise-scaled circuits are
20
+
created through the functions in {mod}`mitiq.lre.multivariate_scaling.layerwise_folding` while the error-mitigated expectation value is estimated by using the functions in {mod}`mitiq.lre.inference.multivariate_richardson`.
21
+
22
+
```{figure} ../img/lre_workflow_steps.png
23
+
---
24
+
width: 700px
25
+
name: lre-overview2
26
+
---
27
+
The diagram shows the workflow of the layerwise Richardson extrapolation (LRE) in Mitiq.
28
+
```
29
+
30
+
31
+
**The first step** involves generating and executing layerwise noise-scaled quantum circuits.
32
+
- The user provides a `cirq` circuit.
33
+
34
+
```{danger}
35
+
LRE is currently compatible with quantum programs written using `cirq`.
36
+
Work on making this technique compatible with other frontends is ongoing. 🚧
37
+
```
38
+
39
+
- Mitiq generates a set of layerwise noise-scaled circuits by applying unitary folding based on a set of pre-determined scale factor vectors.
40
+
- The noise-scaled circuits are executed on the noisy backend obtaining a set of noisy expectation values.
41
+
42
+
**The second step** involves inferring the error mitigated expectation value from the measured results through multivariate richardson extrapolation.
43
+
44
+
The function {func}`.execute_with_lre` accomplishes both steps behind the scenes to estimate the error mitigate expectation value. Additional information is available in [](lre-1-intro.md).
45
+
46
+
If one were interested in applying each step individually, the following sections demonstrate how a user can do so.
47
+
48
+
## First step: generating and executing noise-scaled circuits
49
+
50
+
### Problem setup
51
+
52
+
We'll first define a quantum circuit, and a method of executing circuits for demonstration purposes.
53
+
54
+
For simplicity, we define a circuit whose unitary compiles to the identity operation.
55
+
Here we will use a randomized benchmarking circuit on a single qubit, visualized below.
56
+
57
+
```{code-cell} ipython3
58
+
from cirq import LineQubit, Circuit, CZ, CNOT, H
59
+
60
+
61
+
q0, q1, q2, q3 = LineQubit.range(4)
62
+
circuit = Circuit(
63
+
H(q0),
64
+
CNOT.on(q0, q1),
65
+
CZ.on(q1, q2),
66
+
CNOT.on(q2, q3),
67
+
)
68
+
69
+
70
+
print(circuit)
71
+
```
72
+
73
+
We define an [executor](executors.md) which simulates the input circuit subjected to depolarizing noise, and returns the probability of measuring the ground state.
74
+
By altering the value for `noise_level`, ideal and noisy expectation values can be obtained.
75
+
76
+
```{code-cell} ipython3
77
+
from cirq import DensityMatrixSimulator, depolarize
print(f"Error without mitigation: {abs(ideal - noisy) :.5f}")
92
+
```
93
+
94
+
### Create noise-scaled circuits
95
+
96
+
We start by creating a number of noise-scaled circuits which we will pass to the executor. {func}`.get_scale_factor_vectors` determines the scale factor vectors while {func}`.multivariate_layer_scaling` creates the noise scaled circuits.
97
+
98
+
Each noise-scaled circuit is scaled based on some pre-determined values of the scale factor vectors. These vectors depend
99
+
on the degree of polynomial chosen for multivariate extrapolation and the fold multiplier for unitary folding.
100
+
101
+
```{code-cell} ipython3
102
+
import numpy as np
103
+
from mitiq.lre.multivariate_scaling import get_scale_factor_vectors
Each value in the scale factor vector corresponds to how unitary folding is applied to a layer in the circuit. If a scale factor value at some position in the scale factor vector is
116
+
117
+
- greater than 1, then unitary folding is applied to the layer at that position in the circuit.
118
+
- 1, then the layer at that position in the circuit is not scaled.
119
+
120
+
```{code-cell} ipython3
121
+
from mitiq.lre.multivariate_scaling import multivariate_layer_scaling
With the many noise-scaled circuits in hand, we can run them through our executor to obtain the expectation values.
139
+
140
+
```{code-cell} ipython3
141
+
noise_scaled_exp_values = [
142
+
execute(circuit) for circuit in noise_scaled_circuits
143
+
]
144
+
```
145
+
146
+
147
+
## Second step: Multivariate Extrapolation for the error-mitigated expectation value
148
+
149
+
The penultimate step here is to fetch the coefficients we'll use to combine the noisy data we obtained above. Each noise scaled circuit has a coefficient of linear combination and a noisy expectation value associated with it.
150
+
151
+
```{code-cell} ipython3
152
+
from mitiq.lre.inference import multivariate_richardson_coefficients
{func}`.sample_matrix` is used by {func}`.multivariate_richardson_coefficients` behind the scenes to calculate these coefficients as discussed in [](lre-5-theory.md).
163
+
164
+
These coefficients are calculated through solving a system of linear equations $\mathbf{A} c = z$, where each row of the sample matrix $\mathbf{A}$ is formed by the [monomial terms](lre-3-options.md) of the multivariate polynommial evaluated using the values in the scale factor vectors, $z$ is the vector of expectation values and $c$ is the coefficients vector.
165
+
166
+
For example, if the terms in the monomial basis are given by the following:
Each row of the sample matrix is defined by these monomial basis terms. Let one of the scale factor vectors be $(1, 5, 1, 1)$. To get to the sample matrix, each row is then evaluated using the scale factor vectors. A row of the sample matrix is then evaluated using $λ_1=1, λ_2=5, λ_3=1, λ_4=1$.
171
+
172
+
173
+
174
+
### Combine the results
175
+
176
+
The error mitigated expectation value is described as a linear combination of the noisy expectation values where the
177
+
coefficients of linear combination were calculated in the preceding section.
178
+
179
+
```{code-cell} ipython3
180
+
mitigated = sum(
181
+
exp_val * coeff
182
+
for exp_val, coeff in zip(noise_scaled_exp_values, coefficients)
183
+
)
184
+
print(f"Error with mitigation (LRE): {abs(ideal - mitigated):.{3}}")
0 commit comments