Skip to content

Attempt canonicalization first when decomposing controlled gates #7242

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

Open
daxfohl opened this issue Apr 8, 2025 · 1 comment · May be fixed by #7269
Open

Attempt canonicalization first when decomposing controlled gates #7242

daxfohl opened this issue Apr 8, 2025 · 1 comment · May be fixed by #7269
Labels
area/decomposition good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" kind/design-issue A conversation around design triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on

Comments

@daxfohl
Copy link
Collaborator

daxfohl commented Apr 8, 2025

Describe your design idea/issue

cirq.ControlledGate(cirq.Z) decomposes to

S(q(0))
Z**1.5(q(1))
(0.7071067811865476+0.7071067811865475j)
Y**-0.5(q(1))
CZ(q(0), q(1))
Y**0.5(q(1))
Z**1.5(q(1))
(0.7071067811865476+0.7071067811865475j)
Y**-0.5(q(1))
CZ(q(0), q(1))
Y**0.5(q(1))
Z(q(1))
-1j

Of course, it is equivalent to CZ and should decompose to CZ.

In ControlledGate._decompose_ it probably makes sense first to try canonicalizing itself, and returning that if there's a canonical form of itself. Something like if self.subgate.controlled(self.controls) != self: return [self.subgate.controlled(self.controls)]. This would allow getting rid of all the cruft from the CZ example above, and there are other cases that would benefit from this approach too. In particular, combined with #7241 and #7238 this would allow getting rid of all the special handling for CZPowGate in ControlledGate._decompose_.

This is a pretty straightforward change, I believe it only requires adding the above logic to ControlledGate._decompose_ and a couple unit tests. Marking as good first issue.

@daxfohl daxfohl added kind/design-issue A conversation around design good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" area/decomposition labels Apr 8, 2025
@mhucka mhucka added the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Apr 16, 2025
@mhucka mhucka added triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on and removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque labels Apr 30, 2025
@mhucka
Copy link
Contributor

mhucka commented Apr 30, 2025

Discussed in Cirq Cynq 2025-04-30: yup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/decomposition good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" kind/design-issue A conversation around design triage/accepted A consensus emerged that this bug report, feature request, or other action should be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants