PennyLaneAI / pennylane

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.
https://pennylane.ai
Apache License 2.0
2.38k stars 606 forks source link

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

Open WrathfulSpatula opened 4 weeks ago

WrathfulSpatula commented 4 weeks ago

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

mudit2812 commented 3 weeks ago

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