Commit 5533d3e
Decompose controlled 1x1 unitary gates generically, not just GlobalPhaseGate (quantumlib#7283)
## Summary
Fixes quantumlib#7248
This PR improves the decomposition logic for controlled gates in Cirq,
ensuring that controlled 1x1 `MatrixGate` and `GlobalPhaseGate`
instances decompose correctly. It also adds a targeted unit tests to
verify this behavior.
## Details
- Updated the
[_decompose_with_context_](cci:1://file:///Users/revanthgundala/projects/Cirq/cirq-core/cirq/ops/controlled_gate.py:159:4-241:9)
method in
[cirq-core/cirq/ops/controlled_gate.py](cci:7://file:///Users/revanthgundala/projects/Cirq/cirq-core/cirq/ops/controlled_gate.py:0:0-0:0)
to:
- Correctly handle controlled gates with 1x1 unitary (global phase) by
decomposing them into a `DiagonalGate` with the correct phase.
- Added a parameterized test and additional explicit unit tests in
[cirq-core/cirq/ops/controlled_gate_test.py](cci:7://file:///Users/revanthgundala/projects/Cirq/cirq-core/cirq/ops/controlled_gate_test.py:0:0-0:0)
to:
- Check that controlled global phase gates decompose to the correct
diagonal structure for various phases and control configurations.
Supersedes quantumlib#7282
---------
Co-authored-by: Michael Hucka <mhucka@caltech.edu>
Co-authored-by: Dax Fohl <dax.fohl@gmail.com>
Co-authored-by: Pavol Juhas <juhas@google.com>1 parent cacb494 commit 5533d3e
File tree
2 files changed
+50
-28
lines changed- cirq-core/cirq/ops
2 files changed
+50
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
183 | 176 | | |
184 | 177 | | |
185 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
773 | 773 | | |
774 | 774 | | |
775 | 775 | | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
0 commit comments