-
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
Add operations for setting state and basis state and integrate this with skip_initial_state_prep
#955
Conversation
da5eff0
to
3e36012
Compare
@dime10 any comments about the name of the flag in the TOML files being: |
Maybe |
Yes, skip makes no sense to me in the context of the TOML file. Looking at the existing flags that indicate "support" for something:
I would say just |
49b70cf
to
47ed503
Compare
skip_initial_state_prep
skip_initial_state_prep
skip_initial_state_prep
5b30977
to
93e195c
Compare
1b8c01f
to
449dc68
Compare
**Context:** We would like Catalyst to optimize the first instance of `qml.StatePrep` by just setting the state vector in PennyLane lightning. **Description of the Change:** To achieve this, we set a flag in the TOML files where it denotes whether the value for the flag `skip_initial_state_prep` used during decomposition. This flag is already in PennyLane and will skip the initial state preparation. There are other ways to achieve this but this is the least invasive way to do so. Some other alternatives that were discussed: 1. Adding StatePrep to the list of supported operations: this is not a good idea as it would lead StatePrep to not be decomposed ever. 2. Creating a new operation and map StatePrep directly into this new operation only in the context of Catalyst. This would lead to setting this new `qml` Operation in the list of supported operations on the device, even though it would never be seen except when using with Catalyst. The way this was achieved was not to create a new `qml` Operation, only an JAXPR/MLIR operation and bind `StatePrep` to this JAXPR operation and lower it through MLIR. So, no new `qml` operations. **Benefits:** Optimization **Possible Drawbacks:** More flags. No one likes flags. **Related GitHub Issues:** Will be followed by this PennyLaneAI/catalyst#955 pull request in Catalyst. [sc-69069] --------- Co-authored-by: ringo-but-quantum <[email protected]> Co-authored-by: Ali Asadi <[email protected]>
398d9e0
to
e4928a7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #955 +/- ##
==========================================
- Coverage 97.92% 97.89% -0.04%
==========================================
Files 75 75
Lines 10561 10684 +123
Branches 1218 1226 +8
==========================================
+ Hits 10342 10459 +117
- Misses 172 177 +5
- Partials 47 48 +1 ☔ View full report in Codecov by Sentry. |
@dime10 you mentioned that we shouldn't support contextual decomposition. (I.e., if qml.StatePrep is inside grad, it is okay to emit an error). There is a demo with this. I added a small hack. |
I just mentioned that we don't do this for any other operations yet, so it's not a requirement in order to add the support for this op. If you implemented it anyways that's fine 👍 (currently reviewing) |
@dime10 adaptive circuits demo. I just added |
Reminder to update the same changes on lightning kokkos to the lightning repo (e.g. PennyLaneAI/pennylane-lightning#819) |
**Context:** We would like Catalyst to optimize the first instance of `qml.StatePrep` by just setting the state vector in PennyLane lightning. **Description of the Change:** To achieve this, we set a flag in the TOML files where it denotes whether the value for the flag `skip_initial_state_prep` used during decomposition. This flag is already in PennyLane and will skip the initial state preparation. There are other ways to achieve this but this is the least invasive way to do so. Some other alternatives that were discussed: 1. Adding StatePrep to the list of supported operations: this is not a good idea as it would lead StatePrep to not be decomposed ever. 2. Creating a new operation and map StatePrep directly into this new operation only in the context of Catalyst. This would lead to setting this new `qml` Operation in the list of supported operations on the device, even though it would never be seen except when using with Catalyst. The way this was achieved was not to create a new `qml` Operation, only an JAXPR/MLIR operation and bind `StatePrep` to this JAXPR operation and lower it through MLIR. So, no new `qml` operations. **Benefits:** Optimization **Possible Drawbacks:** More flags. No one likes flags. **Related GitHub Issues:** Will be followed by this PennyLaneAI/catalyst#955 pull request in Catalyst. [sc-69069] --------- Co-authored-by: ringo-but-quantum <[email protected]> Co-authored-by: Ali Asadi <[email protected]>
@paul0403 changes will be on this PR: PennyLaneAI/pennylane-lightning#838 Thanks! |
Co-authored-by: David Ittah <[email protected]>
Co-authored-by: David Ittah <[email protected]>
I added building wheels as I want to test macOS specifically for the use of int8_t for the basis state. |
Co-authored-by: David Ittah <[email protected]>
Sounds good, I'm trying to test locally right now but the lightning wheels weren't available, I have notified the perf team though. |
Alright they should all be available now 👍 |
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.
🚀
Do note that coverage is wrong here, coverage is not calculated with OpenQASM3 runtime. |
**Context:** #955 could not test lightning.kokkos due to the changes in the QuantumDevice interface along with the separation of repositories. It can only be tested once lightning.kokkos has been built and released with the changes in the QuantumDevice interface. **Description of the Change:** Restore kokkos tests EDIT: Do not merge until there's a new dev release from lightning.
Context: It has been determined that
qml.StatePrep
takes too long to compile. To facilitate this, it was determined that the optimization of setting the initial state to the operand ofqml.StatePrep
could help. This is already implemented inlightning.qubit
andlightning.kokkos
when using them without@qjit
.Description of the Change: This change adds two new JAXPR and MLIR operations. One for
qml.StatePrep
and another forqml.BasisState
. This change includes:qml.BasisState
which provides validation at runtime. This is needed because when using jax.numpy.arrays all values are staged.It was necessary to add new operations instead of reusing
quantum.custom
op because of the signature of these operations. I.e.,quantum.custom
expects floating point parameters, butqml.StatePrep
expects a vector of complex numbers andqml.BasisState
expects an integer index.Benefits: Possibly faster compile times (has not been verified).
Possible Drawbacks: The introduction of new operations and extension of the runtime for operations that not all devices will need can be seen as a code smell. Kokkos does not implement this since it does not implement the new device API.
Related GitHub Issues: #939
close #939
[sc-69069]