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

[BUG] mcm_mode="one-shot" passes all shot requests to custom back end at once #6463

Open
1 task done
WrathfulSpatula opened this issue Oct 28, 2024 · 1 comment
Open
1 task done
Labels
bug 🐛 Something isn't working

Comments

@WrathfulSpatula
Copy link

WrathfulSpatula commented Oct 28, 2024

Expected behavior

(I develop the pennylane-qrack custom back end.) When we run the ZNE tutorial being developed by Unitary Fund and Catalyst, as mcm_mode="one-shot" is used (for "weak simulation condition," for noise simulation), we expect that if we request 1,000 shots, then PennyLane should iterate the process 1,000 times of running the original circuit on the back end and requesting 1 measurement shot output at a time.

Actual behavior

If I run the tutorial with the correct setting and this branch that prints the number of shots received by the back end per request for measurement samples, then the extra print() statement shows that PennyLane is requesting 1,000 shots at once for a single execution of the original circuit on the back end, despite mcm_mode="one-shot".

Additional information

It's important that the circuit is run top-to-bottom for every single individual shot, because Qrack introduces physically-realistic noise via stochastic Pauli noise, such that the circuit actually ends up with hidden gates inserted stochastically by the back end on every single separate shot, modeling physical noise, whereas requesting 1,000 shots from the back end at once gives every single shot the exact same (random) bit-flip and phase-flip errors, which is not the intent or a physically-accurate noise model.

Source code

https://github.com/unitaryfund/qml/blob/zne-catalyst-tutorial/demonstrations/tutorial_zne_catalyst.py
https://github.com/unitaryfund/pennylane-qrack/tree/pennylane_mcm-mode_one-shot_bug

Tracebacks

No response

System information

Name: PennyLane
Version: 0.40.0.dev0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /home/iamu/qrack_venv_3-12/lib/python3.12/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, toml, typing-extensions
Required-by: PennyLane-Catalyst, pennylane-qrack, PennyLane_Lightning

Platform info:           Linux-6.8.0-47-generic-x86_64-with-glibc2.35
Python version:          3.12.7
Numpy version:           1.26.4
Scipy version:           1.12.0
Installed devices:
- qrack.simulator (pennylane-qrack-0.10.1)
- lightning.qubit (PennyLane_Lightning-0.38.0)
- nvidia.custatevec (PennyLane-Catalyst-0.8.1)
- nvidia.cutensornet (PennyLane-Catalyst-0.8.1)
- oqc.cloud (PennyLane-Catalyst-0.8.1)
- softwareq.qpp (PennyLane-Catalyst-0.8.1)
- default.clifford (PennyLane-0.40.0.dev0)
- default.gaussian (PennyLane-0.40.0.dev0)
- default.mixed (PennyLane-0.40.0.dev0)
- default.qubit (PennyLane-0.40.0.dev0)
- default.qutrit (PennyLane-0.40.0.dev0)
- default.qutrit.mixed (PennyLane-0.40.0.dev0)
- default.tensor (PennyLane-0.40.0.dev0)
- null.qubit (PennyLane-0.40.0.dev0)
- reference.qubit (PennyLane-0.40.0.dev0)

Existing GitHub issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@WrathfulSpatula WrathfulSpatula added the bug 🐛 Something isn't working label Oct 28, 2024
@WrathfulSpatula WrathfulSpatula changed the title [BUG] mcm-mode="one-shot" passes all shot requests to custom back end at once [BUG] mcm_mode="one-shot" passes all shot requests to custom back end at once Oct 28, 2024
@mudit2812
Copy link
Contributor

Hi @WrathfulSpatula , I've looked into this and found a couple of reasons why this is not working.

  • In dynamic_one_shot, to store the executable tape in a dense format, we only give one tape to the device, and it is the device's responsibility to loop over the number of shots if it sees "one-shot". We should've documented this better, and will include that as part of the fix that is needed on our side. But, the key takeaway is that the pennylane.qrack backend needs to implement the ability to loop over the number of shots if one-shot is being used. You can find a reference here for how we implement this in PennyLane. simulate_one_shot_native_mcm is the function used for single-shot execution.
  • Additionally, dynamic_one_shot only transforms the original circuit if it has at least one mid-circuit measurement and doesn't transform the circuit if that's not the case. This was an optimization we added as until now, mid-circuit measurements have been the only use-case for us where single-shot execution was useful. We need to update this on our end so that any circuit can be transformed with dynamic_one_shot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants