-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use native implementation for adjoints in (control) operations (#1063)
### 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`](../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 the change, 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 is `Adjoint`, then we apply the operation with an adjoint (`inv_param`) flag. However, in cases where we have: - adjoint(s) within control - e.g. `control(adjoint(gate))` - control within adjoint - e.g. `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 performance **Benefits:** 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: | LQ, 25 qubits, 500 repeats | master | branch | |-------------------------------------|--------|-------| | ctrl(adjoint(IsingXX)) | 9.6s | 6.0s | | ctrl(adjoint(DoubleExcitationPlus)) | 27.6s | 9.2s | | LQ, 25 qubits, 100 repeats | master | branch | |-------------------------------------|------------------|--------| | adjoint(ctrl(IsingXX)) | 267s | 2.9s| | adjoint(ctrl(DoubleExcitationPlus)) | 1002s| 3.6s | Baseline: | LQ, 25 qubits, 500 repeats | master | branch | |-------------------------------------|--------|--------| | ctrl(IsingXX) | 6.1s |6.1s | | ctrl(DoubleExcitationPlus)| 9.1s | 9.1s | LG: | LG, 31 qubits, 1000 repeats | master | branch | |-------------------------------------|--------|--------| | ctrl(adjoint(IsingXX)) | 4.9s | 4.8s | | ctrl(adjoint(DoubleExcitationPlus)) | 5.0s | 4.9s | | LG, 31 qubits, 1000 repeats | master | branch | |-------------------------------------|-------------|--------| | adjoint(ctrl(IsingXX)) | 119s | 4.8s| | adjoint(ctrl(DoubleExcitationPlus)) | 208s | 4.9s | Baseline: | LG, 31 qubits, 1000 repeats | master | branch | |-------------------------------------|-------------------|--------| | ctrl(IsingXX) | 4.8s | 4.8s | | ctrl(DoubleExcitationPlus)| 4.9s | 4.9s | LK: | LK, 25 qubits, 500 repeats | master | branch | |-------------------------------------|--------|--------| | ctrl(adjoint(IsingXX)) | 8.5s |5.7s | | ctrl(adjoint(DoubleExcitationPlus)) | 24.5s | 7.6s | | LK, 25 qubits, 100 repeats | master | branch | |-------------------------------------|-----|--------| | adjoint(ctrl(IsingXX)) | 235s | 2.6s | | adjoint(ctrl(DoubleExcitationPlus)) | 867s | 2.9s | Baseline: | LK, 25 qubits, 500 repeats | master |branch | |-------------------------------------|-------------|--------| | ctrl(IsingXX) | 5.6s |5.8s | | ctrl(DoubleExcitationPlus)| 7.7s | 7.6 s | **Possible Drawbacks:** **Related GitHub Issues:** [sc-79430] --------- Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai> Co-authored-by: Christina Lee <chrissie.c.l@gmail.com> Co-authored-by: Amintor Dusko <87949283+AmintorDusko@users.noreply.github.com>
- Loading branch information
1 parent
aad3e59
commit 98a9292
Showing
9 changed files
with
408 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,4 @@ | |
Version number (major.minor.patch[-label]) | ||
""" | ||
|
||
__version__ = "0.41.0-dev24" | ||
__version__ = "0.41.0-dev25" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.