-
Notifications
You must be signed in to change notification settings - Fork 188
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
ZNE demo using catalyst #1207
base: master
Are you sure you want to change the base?
ZNE demo using catalyst #1207
Changes from 3 commits
e00303d
1db073f
9038c94
faa3c18
771d508
25e95e1
1a2ccf1
7d91d08
645e763
bfefdf5
af5773b
b6aa337
6fd8aa4
231c26e
dea771a
2e64d80
5d44c20
297bee1
292d20f
6ff56aa
b9478dc
149dddd
f7e1e90
a352984
9236c62
e2233ff
bc929d8
f595a35
7cb3206
c6f704e
b5e4158
09c2728
84ee6fe
e5359ad
19db775
14d83a3
3e5eb5e
0fc80c4
dbc7c19
ed564f4
f6d2aa7
4e5c221
7db6373
aa2e265
65cb5a2
da89e5d
2cb1176
bc166cf
17735ba
aad4b47
527e9be
34c11a4
c3ad24f
e9711ac
e016da8
02f9541
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.. bio:: Nate Stemen | ||
:photo: ../_static/authors/nate_stemen.png | ||
|
||
Nate Stemen is a technical staff member at Unitary Fund, leading the development of Mitiq, a quantum error mitigation library. He earned a master’s degree from the University of Waterloo, where he focused on quantum circuit compilation. He is passionate about advancing effective education in quantum computing. |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,52 @@ | ||||
{ | ||||
"title": "Digital Zero-Noise Extrapolation with Catalyst", | ||||
"authors": [ | ||||
{ | ||||
"id": "nate_stemen", | ||||
"affiliation": "Unitary Fund" | ||||
} | ||||
], | ||||
"dateOfPublication": "2024-09-09T00:00:00+00:00", | ||||
"dateOfLastModification": "2024-09-09T00:00:00+00:00", | ||||
Comment on lines
+11
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tk |
||||
"categories": [ | ||||
"Algorithms", | ||||
"Quantum Computing", | ||||
"How-to" | ||||
cosenal marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
], | ||||
"tags": [], | ||||
"previewImages": [ | ||||
{ | ||||
"type": "thumbnail", | ||||
"uri": "/_static/demo_thumbnails/regular_demo_thumbnails/thumbnail_qrack_catalyst_integration.png" | ||||
}, | ||||
{ | ||||
"type": "large_thumbnail", | ||||
"uri": "/_static/demo_thumbnails/large_demo_thumbnails/thumbnail_large_qrack_catalyst_integration.png" | ||||
} | ||||
], | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tk |
||||
"seoDescription": "Digital Zero-Noise Extrapolation with Catalyst", | ||||
cosenal marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
"doi": "", | ||||
"canonicalURL": "/qml/demos/tutorial_zne_catalyst", | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Removing due to today's repository update. |
||||
"references": [ | ||||
{ | ||||
"id": "DZNEpaper", | ||||
"type": "preprint", | ||||
"title": "Digital zero noise extrapolation for quantum error mitigation", | ||||
"authors": "Tudor Giurgica-Tiron, Yousef Hindy, Ryan LaRose, Andrea Mari, and William J. Zeng", | ||||
"year": "2020", | ||||
"publisher": "", | ||||
"journal": "", | ||||
"doi": "10.48550/arXiv.2005.10921", | ||||
"url": "https://arxiv.org/abs/2005.10921v2" | ||||
} | ||||
], | ||||
"basedOnPapers": [], | ||||
"referencedByPapers": [], | ||||
"relatedContent": [ | ||||
{ | ||||
"type": "demonstration", | ||||
"id": "tutorial_error_mitigation", | ||||
"weight": 1.0 | ||||
} | ||||
] | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,160 @@ | ||||||
r""" | ||||||
Digital Zero-Noise Extrapolation with Catalyst | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
============================================== | ||||||
|
||||||
In this tutorial, you will learn how to use Zero-Noise Extrapolation (ZNE) in combination with | ||||||
Catalyst. We'll demonstrate how to generate noise-scaled circuits, execute them on a noisy quantum | ||||||
simulator, and use extrapolation techniques to estimate the zero-noise result, all while | ||||||
leveraging just-in-time (JIT) compilation through | ||||||
`Catalyst <https://docs.pennylane.ai/projects/catalyst/en/stable/index.html>`_. | ||||||
|
||||||
What is ZNE | ||||||
cosenal marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
----------- | ||||||
|
||||||
Zero-Noise Extrapolation (ZNE) is a technique used to mitigate the effect of noise on quantum | ||||||
computations. First introduced in [#temme2017zne]_, it helps improve the accuracy of quantum | ||||||
results by running circuits at varying noise levels and extrapolating back to a hypothetical | ||||||
zero-noise case. While this tutorial won't delve into the theory behind ZNE in detail, lets first | ||||||
review what happens when using the protocol in practice. | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a great way to explain the steps, but I'm a bit confused by how these three stages related to the following sections. Could we maybe align those two a bit better? Even if you just refer to specific stages within the text/code, that would already be valuable. |
||||||
Stage 1: Generating Noise-Scaled Circuits | ||||||
cosenal marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||
|
||||||
For ZNE to work, we need to generate circuits with **increased** noise. Currently, ZNE in Catalyst | ||||||
supports two methods for generating noise-scaled circuits: | ||||||
|
||||||
1. **Global folding**: If a circuit implements a global unitary :math:`U`, global folding applies | ||||||
:math:`U(U^\dagger U)^n` for some integer :math:`n`, | ||||||
effectively scaling the noise in the entire circuit. | ||||||
2. **Local folding**: Individual gates are repeated (or folded) in contrast with the entire | ||||||
circuit. | ||||||
|
||||||
Stage 2: Running the circuits | ||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||
|
||||||
Once noise-scaled circuits are created, they need to be run! These can be executed on either real | ||||||
quantum hardware or a noisy quantum simulator. In this tutorial, we'll use the | ||||||
`Qrack quantum simulator <https://qrack.readthedocs.io/>`_, which implements a noise model | ||||||
compatible with Catalyst. | ||||||
|
||||||
Stage 3: Combining the results | ||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||
|
||||||
After executing the noise-scaled circuits, we perform an extrapolation to estimate the zero-noise | ||||||
limit---the result we would expect in a noise-free scenario. Catalyst provides two methods for | ||||||
perfoming this extrapolation: | ||||||
|
||||||
1. **Polynomial extrapolation**, and | ||||||
2. **Exponential extrapolation**. | ||||||
|
||||||
|
||||||
Using ZNE in Catalyst | ||||||
--------------------- | ||||||
cosenal marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
Let's see what this workflow looks like using Catalyst. | ||||||
To get things started we'll need two ingredients: | ||||||
|
||||||
1. an example quantum circuit to run | ||||||
2. a way to execute circuits | ||||||
|
||||||
The circuits we use here will be ..., and the method of execution will be a noisy simulation | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup exactly! @cosenal is going to fill in some of the code, and I wasn't sure what he was changing the circuits too :) |
||||||
available through Qrack. The underlying noise model of this simulation is that of depolarizing | ||||||
noise. | ||||||
|
||||||
""" | ||||||
|
||||||
import os | ||||||
|
||||||
import jax | ||||||
|
||||||
import pennylane as qml | ||||||
from pennylane import numpy as np | ||||||
from catalyst import qjit, mitigate_with_zne | ||||||
|
||||||
|
||||||
qubits = 2 | ||||||
NOISE_LEVEL = 0.1 | ||||||
os.environ["QRACK_GATE_DEPOLARIZATION"] = str(NOISE_LEVEL) | ||||||
dev = qml.device("qrack.simulator", qubits, isNoisy=True) | ||||||
|
||||||
|
||||||
@qml.qnode(dev) | ||||||
def circuit(): | ||||||
qml.Hadamard(wires=0) | ||||||
qml.CNOT(wires=[0, 1]) | ||||||
return qml.expval(qml.PauliZ(wires=0)) | ||||||
|
||||||
|
||||||
############################################################################## | ||||||
# With a circuit and simulator defined, we can begin to define some of the necessary parameters | ||||||
# for ZNE. In particular we will need to specify | ||||||
natestemen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
# | ||||||
# 1. The noise scaling factors (i.e. how much to increase the depth of the circuit) | ||||||
# 2. The _method_ for scaling this noise up (in Catalyst there are two options: `global` and | ||||||
# `local`) | ||||||
# 3. The extrapolation technique to use to estimate the ideal value (available in Catalyst are | ||||||
# polynomial, and exponential extrapolation). | ||||||
# | ||||||
# We'll define the scale factors as a `jax.numpy.array` where the scale factors must be odd | ||||||
# integers. | ||||||
|
||||||
scale_factors = jax.numpy.array([1, 3, 5]) | ||||||
|
||||||
############################################################################## | ||||||
# Next we'll choose a method for scaling the noise. This needs to be defined as a python string. | ||||||
natestemen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
folding_method = "local" | ||||||
|
||||||
############################################################################## | ||||||
# Finally, we'll choose the extrapolation technique. Both exponential and polynoamial extrapolation | ||||||
# is available in the `pennylane.transforms` module. Both of these functions can be passed directly | ||||||
# into `mitigate_with_zne`! | ||||||
|
||||||
from pennylane.transforms import exponential_extrapolate, poly_extrapolate | ||||||
|
||||||
extrapolation_method = exponential_extrapolate | ||||||
|
||||||
############################################################################## | ||||||
# We're now ready to run our example using ZNE with Catalyst! Putting these all together we're able | ||||||
# to define a very simple `QNode`! | ||||||
|
||||||
|
||||||
@qjit | ||||||
def mitigated_circuit(): | ||||||
return mitigate_with_zne( | ||||||
circuit, | ||||||
scale_factors=scale_factors, | ||||||
extrapolate=extrapolation_method, | ||||||
folding=folding_method, | ||||||
)() | ||||||
|
||||||
|
||||||
print(circuit()) | ||||||
print(mitigated_circuit()) | ||||||
|
||||||
############################################################################## | ||||||
# But there's still a big unanswered question! _If I can do this all in PennyLane, what is Catalyst | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually a great question and one that took me a while to thoroughly understand and appreciate! |
||||||
# offering here?_ That's a **great** question! In order to explore the difference we'll need to | ||||||
# explore what happens when `catalyst.qjit` is, and is not, used! | ||||||
# ... | ||||||
|
||||||
|
||||||
############################################################################## | ||||||
# | ||||||
# References | ||||||
# ---------- | ||||||
# | ||||||
# .. [#temme2017zne] K. Temme, S. Bravyi, J. M. Gambetta | ||||||
# `"Error Mitigation for Short-Depth Quantum Circuits" <https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.119.180509>`_, | ||||||
# Phys. Rev. Lett. 119, 180509 (2017). | ||||||
# | ||||||
# .. [#DZNEpaper] | ||||||
# Tudor Giurgica-Tiron, Yousef Hindy, Ryan LaRose, Andrea Mari, and William J. Zeng | ||||||
# "Digital zero noise extrapolation for quantum error mitigation" | ||||||
# `arXiv:2005.10921v2 <https://arxiv.org/abs/2005.10921v2>`__, 2020. | ||||||
# | ||||||
|
||||||
############################################################################## | ||||||
# About the author | ||||||
# ---------------- | ||||||
# .. include:: ../_static/authors/nate_stemen.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.