Skip to content
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 decomposition to Controlled #2938

Merged
merged 18 commits into from
Aug 23, 2022
Merged

Add decomposition to Controlled #2938

merged 18 commits into from
Aug 23, 2022

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Aug 11, 2022

Currently, ControlledOperation created by ctrl has some very basic decomposition behaviour. But it at least has more decomposition behaviour than the non-integrated Controlled.

This PR makes Controlled reach feature-parity with ControlledOperation and will allow us to replace it.

@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@albi3ro albi3ro mentioned this pull request Aug 12, 2022
6 tasks
@codecov
Copy link

codecov bot commented Aug 16, 2022

Codecov Report

Merging #2938 (2bce582) into master (8c15817) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2938   +/-   ##
=======================================
  Coverage   99.65%   99.65%           
=======================================
  Files         266      266           
  Lines       22332    22364   +32     
=======================================
+ Hits        22255    22287   +32     
  Misses         77       77           
Impacted Files Coverage Δ
pennylane/ops/op_math/controlled_class.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/matrix_ops.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/non_parametric_ops.py 100.00% <100.00%> (ø)
pennylane/ops/qubit/parametric_ops.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@albi3ro albi3ro added the review-ready 👌 PRs which are ready for review by someone from the core team. label Aug 16, 2022
@AlbertMitjans
Copy link
Contributor

I don't have much time for a full review, but noticed the following:

>>> qml.ops.Controlled(qml.PauliRot(3, "XX", [0, 4]), 2).decomposition()
[C(Hadamard)(wires=[2, 0]),
 C(Hadamard)(wires=[2, 4]),
 C(MultiRZ)(3, wires=[2, 0, 4]),
 C(Hadamard)(wires=[2, 0]),
 C(Hadamard)(wires=[2, 4])]

Shouldn't C(MultiRZ) be decomposed as well?

Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, @albi3ro! 🎉 Just had a few minor questions and a tiny suggestion.
The new _controlled syntax using a return value looks much better!

pennylane/ops/op_math/controlled_class.py Show resolved Hide resolved
pennylane/ops/op_math/controlled_class.py Show resolved Hide resolved
pennylane/ops/qubit/matrix_ops.py Show resolved Hide resolved
pennylane/ops/qubit/matrix_ops.py Show resolved Hide resolved
pennylane/ops/qubit/matrix_ops.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/non_parametric_ops.py Outdated Show resolved Hide resolved
pennylane/ops/qubit/non_parametric_ops.py Outdated Show resolved Hide resolved
tests/ops/op_math/test_controlled_op.py Outdated Show resolved Hide resolved
@albi3ro
Copy link
Contributor Author

albi3ro commented Aug 17, 2022

@AlbertMitjans I want to add more decomposition algorithms in the future, but that would take a bit more work than just translating over what ControlledOperation already does.

Copy link
Contributor

@dwierichs dwierichs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @albi3ro 🎉
Just the disordered wires test case question is open from my side.

tests/ops/op_math/test_controlled_op.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @albi3ro, I can see now how annoying these in place inversions are haha!

@albi3ro albi3ro merged commit 4c8ac1b into master Aug 23, 2022
@albi3ro albi3ro deleted the controlled_decomposition branch August 23, 2022 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-ready 👌 PRs which are ready for review by someone from the core team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants