-
Notifications
You must be signed in to change notification settings - Fork 603
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
Allow multi controlled x decomposition without working wires #5735
Conversation
allow convert_to_su2 to return global phase
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 #5735 +/- ##
==========================================
- Coverage 99.66% 99.66% -0.01%
==========================================
Files 415 415
Lines 39601 39352 -249
==========================================
- Hits 39469 39219 -250
- Misses 132 133 +1 ☔ View full report in Codecov by Sentry. |
update differntiable test of zyz decomposition
… decomposition and check for Wires(wires)
…ntrolledUnitary unittests
I think the code in line: pennylane/pennylane/ops/op_math/controlled.py Line 799 in 7a216b6
should be modified since ctrl_decomp_zyz can now be used for general unitaries. Is this necessary? Currently the code returns the controlled version of each of the operators in the op.base decomposition. In cases like:
base = qml.SX(0)
op = qml.ops.Controlled(base, control_wires=1)
op.decomposition()
>>> [CRZ(1.5707963267948966, wires=<Wires = [1, 0]>),
CRY(1.5707963267948966, wires=[1, 0])),
CRZ(-3.141592653589793, wires=<Wires = [1, 0]>),
ControlledPhaseShift(1.5707963267948966, wires=<Wires = [1, 0]>)] shouldn't this be further decomposed since we know how to handle the decomposition of each of the controlled operators? |
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.
Looks great! Just one blocking comment about the RuntimeWarning
, but otherwise I'm happy to get this in.
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
…djoint instead of negative power on _decompose_recursive
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 is going to make a lot of people very happy 🎉
… of control_wires in ctrl_decomp_zyz (#757) ### Before submitting Please complete the following checklist when submitting a PR: - [x] 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! - [x] 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`. - [x] Add a new entry to the `.github/CHANGELOG.md` file, summarizing the change, and including a link back to the PR. - [x] 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:** - [X] Fix the issue with initializing `lightning.kokkos` with zero-qubit and - [X] Invalid number of control_wires in ctrl_decomp_zyz (PR PennyLaneAI/pennylane#5735) - [x] Add test for `device('lightning.kokkos', wires=0)` **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** Fixes #751 --------- Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai>
… of control_wires in ctrl_decomp_zyz (#757) Please complete the following checklist when submitting a PR: - [x] 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! - [x] 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`. - [x] Add a new entry to the `.github/CHANGELOG.md` file, summarizing the change, and including a link back to the PR. - [x] 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:** - [X] Fix the issue with initializing `lightning.kokkos` with zero-qubit and - [X] Invalid number of control_wires in ctrl_decomp_zyz (PR PennyLaneAI/pennylane#5735) - [x] Add test for `device('lightning.kokkos', wires=0)` **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** Fixes #751 --------- Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai>
Context:
MultiControlled.decomposition()
gives an error when nowork_wire
is provided.Description of the Change:
Implement decomposition given in Lemma 7.5 of [1] to decompose a general multi controlled unitary gate.
MultiControlledX
being a particular case.The function
ctrl_decomp_zyz
now returns the correct decomposition including a controlled global phase. It now checks that this decomposition only works for single control wire.A decomposition for single controlled
GlobalPhase
is now available using Lemma 5.2 of [1], i.e. adds aPhaseShift
to the control wire. Raise an exception when used with more than one control.Benefits:
Decomposition of a MultiControlledX (and in general any multi controlled unitary) is now possible even if work wires are not provided.
If controlled gate is SU(2), this resorts to the specialized algorithm from Lemma 7.9, yielding a decomposition with$\mathcal{O}(\text{len(control wires)})$ gates. For general unitaries, the decomposition yields $\mathcal{O}(\text{len(control wires)}^2)$ gates.
Sources:
[1] Barenco et al. (1995). https://arxiv.org/abs/quant-ph/9503016
[SC-38954]