-
Notifications
You must be signed in to change notification settings - Fork 40
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
Generalize seeding for measurements #1003
Conversation
Hello. You may have forgotten to update the changelog!
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1003 +/- ##
==========================================
- Coverage 97.71% 91.65% -6.06%
==========================================
Files 228 176 -52
Lines 36479 24744 -11735
==========================================
- Hits 35645 22680 -12965
- Misses 834 2064 +1230 ☔ View full report in Codecov by Sentry. |
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.
This looks like a clean solution to me! 💯 Have you tested that the randomness is now completely fixed for all measurements (e.g. decimals do not vary in an expval etc)?
Sorry to ask, but how can I test this :) |
https://github.com/PennyLaneAI/catalyst/blob/main/frontend/test/pytest/test_seeded_qjit.py What I would do is on your local branch you can build catalyst first (make all ), this installs whatever lightning specified in wherever, then you can build your own lightning branch locally so it overwrites the previous installation |
In addition to running those tests for existing functionality, we should check that something like @qml.qnode(qml.device("lightning.qubit", wires=1, shots=100))
def circuit():
qml.RY(0.7, wires=0)
return qml.expval(qml.PauliZ(0)) produces the same decimals with repeated runs if seeded. |
Acatully, I just remembered you can test this directly in lightning-catalyst, and no need to go through frontend https://github.com/PennyLaneAI/pennylane-lightning/pull/927/files#diff-934a38a9af759b117f260f29c5b2732bee701b7cd3b49a4bdf22da7f69973ad8 Edit: although adding expval/probs to the catalyst frontend tests mentioned above might also be necessary, just to make sure nothing's wrong during mlir. |
Can we have tests similar to https://github.com/PennyLaneAI/pennylane-lightning/pull/927/files#diff-934a38a9af759b117f260f29c5b2732bee701b7cd3b49a4bdf22da7f69973ad8? So tests with the lightning-catalyst interface, not just the lightning base classes. |
pennylane_lightning/core/src/simulators/lightning_qubit/measurements/MeasurementsLQubit.hpp
Outdated
Show resolved
Hide resolved
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.
Nice work @rauletorresc! Happy to review the complete version of the support
pennylane_lightning/core/src/measurements/tests/Test_MeasurementsBase.cpp
Outdated
Show resolved
Hide resolved
Looks good! Thanks @rauletorresc for working on this! 💯 As a final sanity check, can you maybe build against the lightning in this branch, and do some catalyst frontend tests like https://github.com/PennyLaneAI/catalyst/blob/main/frontend/test/pytest/test_seeded_qjit.py? For example, dev = qml.device("lightning.qubit", wires=2, shots=100)
@qjit(seed=37)
def workflow():
@qml.qnode(dev)
def circuit():
qml.Hadamard(wires=[0])
qml.RX(12.34, wires=[1])
return qml.probs()
return circuit(), circuit(), circuit(), circuit()
trail1 = workflow() # [probs10, probs11, probs12, probs13]
trail2 = workflow() # [probs20, probs21, probs22, probs23]
for (probs1i, probs2i) in zip(trail1, trail2):
assert probs1i == probs2i // or whatever the equivalent pytest syntax is Note that within the same (This should also be a PR in catalyst, after this lightning PR is merged) |
Something like that I am doing at the Catalyst side here: PennyLaneAI/catalyst#1344 |
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.
💯 🥳
All good from my side! I'm unfamiliar with the lightning codecov so maybe someone from performance can suggest there.
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.
Nice work @rauletorresc! Happy to approve 🥳
...ane_lightning/core/src/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUMeasures.cpp
Outdated
Show resolved
Hide resolved
...ane_lightning/core/src/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUMeasures.cpp
Outdated
Show resolved
Hide resolved
...ane_lightning/core/src/simulators/lightning_gpu/catalyst/tests/Test_LightningGPUMeasures.cpp
Outdated
Show resolved
Hide resolved
...ghtning/core/src/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosMeasures.cpp
Outdated
Show resolved
Hide resolved
...ghtning/core/src/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosMeasures.cpp
Outdated
Show resolved
Hide resolved
...ghtning/core/src/simulators/lightning_kokkos/catalyst/tests/Test_LightningKokkosMeasures.cpp
Outdated
Show resolved
Hide resolved
...lane_lightning/core/src/simulators/lightning_qubit/catalyst/tests/Test_LightningMeasures.cpp
Outdated
Show resolved
Hide resolved
...lane_lightning/core/src/simulators/lightning_qubit/catalyst/tests/Test_LightningMeasures.cpp
Outdated
Show resolved
Hide resolved
...lane_lightning/core/src/simulators/lightning_qubit/catalyst/tests/Test_LightningMeasures.cpp
Outdated
Show resolved
Hide resolved
**Context:** Once PennyLaneAI/pennylane-lightning#1003 gets merged into Lightning, we can test `expval`, `var` and `probs` with a seed from the Catalyst frontend. **Description of the Change:** Add the corresponding tests. [sc-77124]
Context: Currently, only
catalyst.measure()
,qml.sample()
andqml.counts()
can be seeded with qjit(seed=N). It would be nice to be able to seed all circuit readout methods, likeprobs()
,expval()
,var()
, when executing a device with shots.Description of the Change: Let the base measurement class store the device seed so it can be propagated when necessary to newly created derived measurements. Move the logic from the simulator to the base measurement class.
Benefits: All measurements using the
generate_samples
method will be seeded.Measures to test locally:
expval
var
probs
sample
counts
Devices to modify
TODO
[sc-77124]