Attempt canonicalization first when decomposing controlled gates #7242
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
Describe your design idea/issue
cirq.ControlledGate(cirq.Z)
decomposes toOf course, it is equivalent to
CZ
and should decompose toCZ
.In
ControlledGate._decompose_
it probably makes sense first to try canonicalizing itself, and returning that if there's a canonical form of itself. Something likeif self.subgate.controlled(self.controls) != self: return [self.subgate.controlled(self.controls)]
. This would allow getting rid of all the cruft from theCZ
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 forCZPowGate
inControlledGate._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.The text was updated successfully, but these errors were encountered: