-
Notifications
You must be signed in to change notification settings - Fork 43
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
Correctly querying wire IDs for SetState
and SetBasisState
in runtime
#1047
Conversation
…hether there is stateprep in a previous device to judge whether the device should be recycled.
Should we not look into why it crashes in the first place? |
Yes, draft 1 is trying to contain this issue within Catalyst but I agree the root cause needs to be addressed in Lightning. Chatted with @maliasadi regarding how the two repos see each other (also tagging to keep Ali in the loop on this issue). |
@erick-xanadu Root cause: not properly resetting the wires' catalyst/runtime/lib/capi/RuntimeCAPI.cpp Line 467 in 1950dd1
e.g. for a 2-wire circuit, the first execution will make this Potentially this is not a va_list issue, but an issue with the device init/reset and allocation Good news for @maliasadi @mlxd : from what I can tell this is not an issue with how setstate is implemented in lightning, but with how setstate is called in catalyst, aka no action required from lightning's end |
A supernatural feeling when it's Friday 6pm and you spent a whole day on a bug and the fix is one line |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v0.8.0-rc #1047 +/- ##
============================================
Coverage ? 97.89%
============================================
Files ? 75
Lines ? 10737
Branches ? 1239
============================================
Hits ? 10511
Misses ? 178
Partials ? 48 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
This bug came from mismatched indices. Consider the following IR we send to the runtime capi (compiled from the added test example):
The first call, The Then, when |
The root cause is because |
SetState
and BasisState
in runtime
SetState
and BasisState
in runtimeSetState
and SetBasisState
in runtime
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 makes sense! Thanks! I must have forgotten to add the getDeviceWires
function call. All good on my part.
I guess we need to update the kokkos ones in lightning as well? https://github.com/PennyLaneAI/pennylane-lightning/blob/4c6e4bb750b7d976fe661677895692ef6c129723/pennylane_lightning/core/src/simulators/lightning_kokkos/catalyst/LightningKokkosSimulator.cpp#L140 Interestingly, the failure in #1044 does not happen on kokkos. The commit we track from lightning apparently doesn't even have the catalyst setstate and setbasisstate APIs ~~Since CI tracks lastest/stable/rc lightning (~~
nvm, CI tracks that specific commit as well https://github.com/PennyLaneAI/catalyst/actions/runs/10564765994/job/29267907745?pr=1047#step:4:52 |
@@ -108,14 +108,16 @@ void LightningSimulator::SetState(DataView<std::complex<double>, 1> &data, | |||
std::vector<QubitIdType> &wires) | |||
{ | |||
std::vector<std::complex<double>> data_vector(data.begin(), data.end()); | |||
std::vector<std::size_t> wires_size_t(wires.begin(), wires.end()); | |||
auto &&dev_wires = getDeviceWires(wires); | |||
std::vector<std::size_t> wires_size_t(dev_wires.begin(), dev_wires.end()); |
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.
I don't think we need to repackage the wires into an additional vector
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 was suggested on the lightning side too (PennyLaneAI/pennylane-lightning#869), I will change this
…kos (#869) **Context:** Catalyst recently fixed a bug where recycling a device when a previous execution involves stateprep causes a crash: PennyLaneAI/catalyst#1047 The fix is made to `lightning.qubit`, and thus we need to fix it for `lightning.kokkos` here as well. **Description of the Change:** In `LightningKokkosSimulator`, `SetState` and `SetBasisState` now correctly query the DevQubits from the SimQubits in its qubit_manger's map. **Benefits:** We can now have multiple qnode functions involving stateprep in a workflow **Possible Drawbacks:** **Related GitHub Issues:** PennyLaneAI/catalyst#1044 --------- Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai> Co-authored-by: Vincent Michaud-Rioux <vincentm@nanoacademic.com> Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com>
…r.cpp/`SetState` (and `SetBasisState`) (#1061) **Context:** Eliminating an unnecessary in-between variable in runtime/LightningSimulator.cpp/setstate and setbasisstate, when getting dev_wires from sim_wires in the qubit manager's map. See PennyLaneAI/pennylane-lightning#869 (comment), and #1047 (comment) **Benefits:** One less object initialization
…kos (#869) **Context:** Catalyst recently fixed a bug where recycling a device when a previous execution involves stateprep causes a crash: PennyLaneAI/catalyst#1047 The fix is made to `lightning.qubit`, and thus we need to fix it for `lightning.kokkos` here as well. **Description of the Change:** In `LightningKokkosSimulator`, `SetState` and `SetBasisState` now correctly query the DevQubits from the SimQubits in its qubit_manger's map. **Benefits:** We can now have multiple qnode functions involving stateprep in a workflow **Possible Drawbacks:** **Related GitHub Issues:** PennyLaneAI/catalyst#1044 --------- Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai> Co-authored-by: Vincent Michaud-Rioux <vincentm@nanoacademic.com> Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com>
…okkos (#878) **Context:** Catalyst recently fixed a bug where recycling a device when a previous execution involves stateprep causes a crash: PennyLaneAI/catalyst#1047 The fix is made to `lightning.qubit`, and thus we need to fix it for `lightning.kokkos` here as well. **Description of the Change:** In `LightningKokkosSimulator`, `SetState` and `SetBasisState` now correctly query the DevQubits from the SimQubits in its qubit_manger's map. **Benefits:** We can now have multiple qnode functions involving stateprep in a workflow **Possible Drawbacks:** **Related GitHub Issues:** PennyLaneAI/catalyst#1044 --------- Co-authored-by: paul0403 <79805239+paul0403@users.noreply.github.com> Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai> Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com>
…okkos (#878) **Context:** Catalyst recently fixed a bug where recycling a device when a previous execution involves stateprep causes a crash: PennyLaneAI/catalyst#1047 The fix is made to `lightning.qubit`, and thus we need to fix it for `lightning.kokkos` here as well. **Description of the Change:** In `LightningKokkosSimulator`, `SetState` and `SetBasisState` now correctly query the DevQubits from the SimQubits in its qubit_manger's map. **Benefits:** We can now have multiple qnode functions involving stateprep in a workflow **Possible Drawbacks:** **Related GitHub Issues:** PennyLaneAI/catalyst#1044 --------- Co-authored-by: paul0403 <79805239+paul0403@users.noreply.github.com> Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai> Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com>
…okkos (#878) **Context:** Catalyst recently fixed a bug where recycling a device when a previous execution involves stateprep causes a crash: PennyLaneAI/catalyst#1047 The fix is made to `lightning.qubit`, and thus we need to fix it for `lightning.kokkos` here as well. **Description of the Change:** In `LightningKokkosSimulator`, `SetState` and `SetBasisState` now correctly query the DevQubits from the SimQubits in its qubit_manger's map. **Benefits:** We can now have multiple qnode functions involving stateprep in a workflow **Possible Drawbacks:** **Related GitHub Issues:** PennyLaneAI/catalyst#1044 --------- Co-authored-by: paul0403 <79805239+paul0403@users.noreply.github.com> Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai> Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com>
Context:
Recycling a device when a previous execution involves stateprep causes a crash. See #1044
Description of the Change:
In
LightningSimulator
,SetState
andSetBasisState
now correctly query the DevQubits from the SimQubits in its qubit_manger's map.Benefits: We can now have multiple qnode functions involving stateprep in a workflow
Related GitHub Issues: closes #1044
[sc-71894]