-
Notifications
You must be signed in to change notification settings - Fork 41
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
Use native implementation for adjoints in (control) operations #1063
Conversation
Hello. You may have forgotten to update the changelog!
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1063 +/- ##
==========================================
+ Coverage 96.10% 97.35% +1.25%
==========================================
Files 232 111 -121
Lines 39178 16997 -22181
==========================================
- Hits 37651 16547 -21104
+ Misses 1527 450 -1077 ☔ View full report in Codecov by Sentry. |
Only LQ is implemented so far - but if this is OK, I'll propagate it to LK and LG, which is fairly straightforward |
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.
Thanks @josephleekl!💡 Just a few comments before pushing it to master
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.
Thanks @josephleekl
Just a few comments ❄️
**Context:** In PennyLaneAI/pennylane#6991 we are adding an `execution_config` kwarg to `Device.eval_jaxpr`. We need to make sure this change doesn't break lightning. **Description of the Change:** Adds an `execution_config : Optional[ExecutionConfig] = None` keyword argument to `Device.eval_jaxpr`. **Benefits:** Lightning won't break when that change gets merged into pennylane. The lightning device jaxpr execution can be configured in the future. **Possible Drawbacks:** **Related GitHub Issues:** [sc-84916] --------- Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai> Co-authored-by: Amintor Dusko <87949283+AmintorDusko@users.noreply.github.com>
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 @josephleekl! Happy to approve 🎉
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.
Thank you @josephleekl
Happy to approve 🪂
Before submitting
Please complete the following checklist when submitting a PR:
All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to the
tests
directory!All new functions and code must be clearly commented and documented.
If you do make documentation changes, make sure that the docs build and
render correctly by running
make docs
.Ensure that the test suite passes, by running
make test
.Add a new entry to the
.github/CHANGELOG.md
file, summarizing thechange, and including a link back to the PR.
Ensure that code is properly formatted by running
make format
.When all the above are checked, delete everything above the dashed
line and fill in the pull request template.
Context:
Currently in
_apply_lightning
, we check for whether an operation isAdjoint
, then we apply the operation with an adjoint (inv_param
) flag. However, in cases where we have:control(adjoint(gate))
adjoint(control(gate))
,these are all applied as matrices.
Description of the Change:
_apply_lightning
and_apply_lightning_controlled
checks for adjoint in an operation, and if it's an adjoint it applies the base operation with an adjoint flag, instead of treating everything as a matrix.So in effect we have:
control(adjoint(gate))
->control(gate with adjoint)
adjoint(control(gate))
->control(gate with adjoint)
which are implemented natively in C++ (if the
gate
is supported), yielding better performanceBenefits:
adjoint(ctrl()) will see the most speedup, especially with large number of control wires, since we use native control operation which contains less wires than the equivalent matrix, and needs to be operated on less wires. adjoint(ctrl()) will see some speed-up, since we are now able to use the native named gate implementation in C++.
Example timing improvement:
4 ctrl wires
LQ:
Baseline:
LG:
Baseline:
LK:
Baseline:
Possible Drawbacks:
Related GitHub Issues:
[sc-79430]