Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for VD #2653

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
64 changes: 64 additions & 0 deletions docs/source/guide/vd-1-intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---

## What is VD?
Virtual distillation is an error mitigation technique based on the following paper: [VD article](https://arxiv.org/pdf/2011.07064). VD leverages $M$ copies of a state $\rho$ to suppress the error term. Virtual distillation describes the approximation of the error-free expectation value of an operator $O$ as:

$$
<O>_{corrected} = \dfrac{Tr(O\rho^M)}{Tr(\rho^M)}
$$,

As described in the paper, we make use of the following equality:

$$
Tr(O\rho^M) = Tr(O^{\textbf{i}}S^{(M)}\rho^{\otimes M})
$$

This equation allows us to use $M$ copies of $\rho$m instead of calculating $\rho^M$ directly.


# How do I use VD?

As with all techniques, Virtual Distillation (VD) is compatible with any frontend supported by Mitiq:

```{code-cell} ipython3
import mitiq

mitiq.SUPPORTED_PROGRAM_TYPES.keys()
```

For the purpose of this tutorial we will use `cirq`:
```{code-cell} ipython3
frontend = "cirq"
```

## Problem setup
Similarly to other techniques available in `mitiq`, we use an executor to run VD - in our case the exact function is: `vd.execute_with_vd`. We need to supply the following parameters to our function:
1. A quantum circuit, which we want to run VD on

Note that currently, we do not support custom observables or values of `M` different than 2, but this will most likely change in the future.

[comment]: <> (TODO: finalize this section once the code for VD is finalized)

## Applying VD
Below we provide an example of applying VD - you can use it to run VD on your own circuits, as the necessary steps will remain largely the same:

```{code-cell} ipython3
from mitiq import vd

mitigated_result = vd.execute_with_vd(circuit, execute)
```

In this case we see that VD indeed works in bringing the expectation closer to the noiseless value. However, it is also crucial to note that for very large error rates (relative to the circuit), the results obtained from VD might not be as good given the large drift from the noiseless eigenstates.

[comment]: <> (TODO: finalize this section once the code for VD is finalized)
35 changes: 35 additions & 0 deletions docs/source/guide/vd-2-use-case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.10.3
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---

# When should I use VD?

## Advantages

- VD can exponentially reduce the contributions of non-dominant eigenvectors in the density matrix, bringing the effective state closer to the ideal noise-free state as the number of copies M increases.

- VD can be used complementarily with other error mitigation and calibration techniques, allowing for higher levels of errors reduction.

- The explicit preparation of the $\rho$ density matrix is not required, thus allowing for higher suppression and more computational efficiency.


## Disadvantages

- Virtual Distillation requires multiple copies of a single state, which will increase the number of required qubits by a factor of M.

- Real errors and noise on the hardware will lead to population in states that are not orthogonal to the target state, which results in a drift of the dominant eigenvector. This results in limiting the potential error mitigation of VD: instead of a quadratic suppression in errors there will be a constant factor improvement instead {cite}`Huggins_2021`.

- Currently the implementation of VD only allows for measurement on the Z observable and will not function if non-Z observables are passed to it.

- The VD implementation occasional results in a divide by zero error. This occurs only when the number of iterations is even and typically when that number is fairly low (under 100). In order to circumvent this known issue, if an even number K of iterations is passed to the function then this value will be reduced by 1. This ensures that the circuits are never run more times than expected.

- The current implementation only allows for M = 2 number of copies.
30 changes: 30 additions & 0 deletions docs/source/guide/vd-3-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---

# What additional options are available when using VD?

The function used for virtual distillation is `execute_with_vd()`. The standard mitiq error mitigation options will be available. These are the `circuit` on which this error mitigation technique must run, the `executor` and the single qubit observable of which the expectation value will be calculated and corrected by VD. This observable function is currently restriced to the pauli Z observable.

```{code-cell} ipython3
from mitiq.vd import execute_with_vd

vd_value: List[float] = execute_with_vd(
circuit,
executor,
observable=Z,
K_iters,
num_copies=2
)
```

Next to the standard options, another argument has to be given, `K_iters`, which decides for how many iterations the VD algorithm should run. Each iteration, the circuit presented in section 4 of the documention is ran. The results are then combined to return a corrected list of the expectation values of the single qubit observable on each qubit. The `num_copies` argument decides how many copies are used in the VD algorithm. Currently only `num_copies=2` is supported. The reasoning for these copies is found in section 5, the theory section, of the documentation. Disadvantages of using a higher value for this variable are outlined in section 2.
39 changes: 39 additions & 0 deletions docs/source/guide/vd-4-low-level.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
kernelspec:
display_name: Python 3
language: python
name: python3
---

# What happens when I use VD?
There are several steps that happen in the backend when you call the `vd.execute_with_vd` function

[comment]: <> (TODO: create the workflow diagram once the code is finalized)
```{figure} ../img/vd_workflow.png
---
width: 400
name: figvd
---
The diagram shows the workflow of the virtual distillation (VD) method in Mitiq.
```

In case you prefer a more detailed and theoretical explanation of the workflow, please view the [paper](https://arxiv.org/pdf/2011.07064) describing VD (particularly **Algorithm 1**).

In the following sections we will provide a mitiq-specific workflow:

1. The user provides a `QPROGRAM`, which can be a quantum circuit created in any of the frontends supported by mitiq.
2. $M$ copies of $\rho$ (essentially $M$ copies of the circuit) are created
3. A series of SWAP gates are performed such that the qubits from the $M$ copies are aligned with each other
4. A basis change unitary is applied
5. A $B_i$ diagonalization gate is generated and applied to the circuits
5. The circuits are measured
6. The corrected expectation value is calculated

## Detailed steps
[comment]: <> (TODO: finalize this section once the code for VD is finalized)
70 changes: 70 additions & 0 deletions docs/source/guide/vd-5-theory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
kernelspec:
display_name: Python 3
language: python
name: python3
---

# What is the theory behind VD?

Virtual Distillation (VD) is a quantum error mitigation technique introduced and explained in much greater detail in the paper {cite}`Huggins_2021`. This method is designed to suppress noise in NISQ devices by using multiple noisy copies of a quantum state to estimate expectation values with respect to a "virtually distilled" state, $\frac{\rho^M}{\text{Tr}(\rho^M)}$.

The error-free observable is approximated as $\langle O\rangle_{\text{corrected}} := \frac{\text{Tr}(O \rho^M)}{\text{Tr}(\rho^M)} $. By doing so, VD effectively reduces the influence of non-dominant eigenvectors in the density matrixand the estimator converges exponentially quickly towards the closest pure state to ρ as M is increased. Crucially, VD does not require the explicit preparation of the purified state, making it computationally efficient for near-term quantum devices.

To evaluate the numerator and denominators of the $\langle O\rangle_{\text{corrected}}$, the equality below can be used:

$$\text{Tr}(O \rho^M) = \text{Tr}(O^i S^{(M)} \rho^{\otimes M})$$

$O^i$ represents the observable acting upon one of the M subsystems, and $S^{(M)}$ is the cyclic shift operator performend on M subsystems.

To better explain the exact mechanics of the VD protocol, a specific of example for M=2 is expanded upon below:

## When M = 2 with observable Z

### Obtain Multiple Copies of the Noisy State.
The method begins by preparing M independent noisy copies of the quantum state ⍴, with M = 2 being a common starting point for balancing resource requirements with error suppression. The copies are assumed to experience similar noise characteristics.

### Diagonalizing Gate
First a symmetrized version of the observable is defined as $O^{(M)} = \frac{1}{M} \sum_{i=0}^{M} O^i$.

For the example of $M=2$ and $O=Z$, this equalities can be rewritten as: $Z^{(2)}_k=\frac{1}{2}(Z^1_k+Z^2_k)$. This can be used to rewrite the corrected observable as:

$$\langle O\rangle_{\text{corrected}} = \frac{\text{Tr}(Z^{(2)}_k S^{(2)} \rho^{\otimes 2})}{\text{Tr}(S^{(2)} \rho^{\otimes 2})}$$

Both $S^{(2)}$ and $Z^{(2)}S^{(2)}$ need to be diagonalized, which can be done using the two-qubit unitary that acts on the $i$ th qubit defined as $B^{(2)}_i$.
$$B_i^{(2)} =
\begin{bmatrix}
1 & 0 & 0 & 0 \\
0 & \frac{\sqrt{2}}{2} & \frac{\sqrt{2}}{2} & 0 \\
0 & \frac{\sqrt{2}}{2} & -\frac{\sqrt{2}}{2} & 0 \\
0 & 0 & 0 & 1
\end{bmatrix}$$

Next, the B^{(2)}_i$ gate is applied between each qubit $i$ in the first copy and the corresponding qubit $i$ in the second copy.


### Measure and Compute Expectation value

Perform a standard measurement on all qubits in both copies of the quantum state. These measurement outcomes are stored as $z^1_i$ for the $i$ th qubit in the first copy and $z^2_i$ for the $i$ th qubit in the second copy.

The numerator value can now be calculated by computing for each qubit:
$$
E_i \mathrel{+}= \frac{1}{2N} \left( z^1_i + z^2_i \right) \prod_{j \neq i} \left( 1 + z^1_j - z^2_j + z^1_j z^2_j \right)
$$

The denomiator is calculated using the equation:
$$
D \mathrel{+}= \frac{1}{2N} \prod_{j=1}^{N} \left( 1 + z^1_j - z^2_j + z^1_j z^2_j \right)
$$

The final value of $ \langle Z_i \rangle_\text{corrected}$ can thus be calculated as $\frac{E_i}{D}$.



VD has been shown to reduce errors by orders of magnitude in numerical simulations for a variety of quantum circuits and noise models. Its simplicity, effectiveness, and compatibility with NISQ devices make it a powerful addition to the suite of error mitigation techniques available today. However, its performance depends on factors such as the quality of the noisy state copies, the observables being measured, and the underlying noise model.
31 changes: 31 additions & 0 deletions docs/source/guide/vd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Virtual Distillation

Virtual Distillation (VD) is an error mitigation technique in which


```{figure} ../img/vd_workflow.svg
---
width: 700px
name: vd-workflow-overview
---
Workflow of the VD technique in Mitiq, detailed in the [What happens when I use VD?](vd-4-low-level.md) section.
```

Below you can find sections of the documentation that address the following questions:

```{toctree}
---
maxdepth: 1
---
vd-1-intro.md
vd-2-use-case.md
vd-3-options.md
vd-4-low-level.md
vd-5-theory.md
```

Here is a tutorial on how to use VD in Mitiq:

[VD example tutorial](TODO: link to notebook)

You can find many more examples on a variety of error mitigation techniques in the **[Examples](../examples/examples.md)** section of the documentation.
25 changes: 25 additions & 0 deletions docs/source/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,19 @@ @article{Hashim_2021_PRX
url = {https://link.aps.org/doi/10.1103/PhysRevX.11.041039}
}

@article{Huggins_2021,
title={Virtual Distillation for Quantum Error Mitigation},
volume={11},
ISSN={2160-3308},
url={http://dx.doi.org/10.1103/PhysRevX.11.041036},
DOI={10.1103/physrevx.11.041036},
number={4},
journal={Physical Review X},
publisher={American Physical Society (APS)},
author={Huggins, William J. and McArdle, Sam and O’Brien, Thomas E. and Lee, Joonho and Rubin, Nicholas C. and Boixo, Sergio and Whaley, K. Birgitta and Babbush, Ryan and McClean, Jarrod R.},
year={2021},
month=nov }

# Letter I
# Letter J

Expand Down Expand Up @@ -451,6 +464,18 @@ @article{Knill_2005_Nature
pages = {39–44},
}

@article{Koczor_2021,
title={Exponential Error Suppression for Near-Term Quantum Devices},
volume={11},
ISSN={2160-3308},
url={http://dx.doi.org/10.1103/PhysRevX.11.031057},
DOI={10.1103/physrevx.11.031057},
number={3},
journal={Physical Review X},
publisher={American Physical Society (APS)},
author={Koczor, Bálint},
year={2021},
month=sep }

# Letter L

Expand Down
Loading