-
Notifications
You must be signed in to change notification settings - Fork 2
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
One-shot for noise in Python #26
Conversation
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.
LGTM. Mostly minor comments and a question.
Hey @WrathfulSpatula . Based on the changes in this PR, it looks to me like no changes might be needed on the PennyLane side to get the noisy circuit functionality to work with native Python on the qrack simulator. Could you test the ZNE demo against this branch and let me know if that's the case? We need to know soon so that we know how to proceed. If the demo does not work with just the changes in this PR, my preference would be for us to have a meeting at your earliest convenience to try and understand what is needed. |
Thanks, @WrathfulSpatula ! Just to add, we'd need to know as soon as possible if any issues remain after testing the demo against this branch. If it's still not working, the best approach would be to schedule a meeting first thing tomorrow to figure out a path forward and ensure this is fixed as soon as possible this week, ahead of our Monday release. We have a couple of alternatives in mind. Let us know if that works for you! |
Co-authored-by: Vincent Russo <[email protected]>
@mudit2812 @Alex-Preciado Thanks for checking in! Apologies, I spoke at Harvard last night, and it's roughly a 5 hour drive for me, each way, to get there and back. Due to an unforeseen issue, I also had no laptop, overnight. (I opened this PR on a phone!) However, yes, this should fix the tutorial without modifying PennyLane. However, it implies that we should follow this same approach for Catalyst, and that's the part that just isn't friendly to (C++) back end developers. I'll take another look at the Catalyst side after lunch. |
@WrathfulSpatula Wrt:Catalyst, didn't @rmoyard showed to us how in the IR you have each call to circuit using a device with a single shot? Why do you think it's going to be an issue on Catalyst too? |
@cosenal I agree there is no issue with Catalyst, as the produced IR calls the device n times with 1 shot |
Hi team, have you had a chance to verify that the ZNE tutorial works with these changes? We tried testing on our end, but we couldn’t find instructions on how to build the plugin correctly. We’re encountering some errors, but likely due to local build issues while attempting to make the plugin work locally by patching it. We need to address any outstanding issues by tomorrow, Friday, at 5:00 PM (EST) to stay on track for our Monday release. |
@Alex-Preciado yes, we have tested the tutorial with the latest
There seems to be a divergence between PennyLane and Catalyst ZNE results. However, the "Error without mitigation" line is also from PennyLane rather than Catalyst, indicating that |
But it looks like the error with native Pennylane is higher than the error without mitigation. Is that expected? |
I tested it with the following example, which is simpler than the one in the tutorial, and I consistently get results that make sense to me. This is focused only on PennyLane, not Catalyst. import numpy as np
from functools import partial
from pennylane import qnode
import pennylane as qml
from pennylane.transforms import fold_global, poly_extrapolate
n_wires = 2
dev = qml.device("qrack.simulator", n_wires, shots=100, noise=0.1)
@partial(
qml.transforms.mitigate_with_zne,
scale_factors=[1, 3, 5],
folding=fold_global,
extrapolate=poly_extrapolate,
extrapolate_kwargs={'order': 2})
@qnode(dev)
def circuit():
qml.PauliX(wires=0)
qml.CNOT(wires=[0, 1])
return qml.expval(qml.PauliZ(0))
print(circuit()) OutputIn the three example runs below, first line is exp values of scaled circuits, second line is after extrapolation. Noiseless scenario (noise=0.0)
Noisy scenario (noise=0.1)Run 1:
Run 2:
Run 3:
|
The tutorial now gives me this output, for example (verbatim, on my laptop with a discrete NVIDIA GPU):
This looks correct. I think we're set! |
@Alex-Preciado @mudit2812 I am not going to merge the tutorial yet, but you can go ahead with your Monday release. |
Thanks for confirming! Glad to see it working. |
Nice! Thanks for the updates @cosenal, @WrathfulSpatula !! Let us know if there's anything else we can do to support. |
@WrathfulSpatula I don’t have the necessary context here, but the errors with and without mitigation seem pretty similar. Is this the expected outcome? |
PennyLane development teams says in PennyLaneAI/pennylane#6463 (comment) that implementing one-shot mode is the back end developers' responsibility. This is a problem, because, if it's our responsibility in Catalyst, too, it becomes very complicated to save the circuit to run for every single shot. We basically need to completely redundantly implement our own equivalent of a circuit "tape."
However, this fix handles it on the Python side. I'm on the road to Boston, but, @cosenal or @vprusso, please go ahead and fix the merge, if you can, or I'll try to do after my talk at Harvard.