@@ -175,18 +175,13 @@ def _decompose_with_context_(
175
175
protocols .unitary (self .sub_gate ), control_qubits , qubits [- 1 ]
176
176
)
177
177
return invert_ops + decomposed_ops + invert_ops
178
- if isinstance (self .sub_gate , gp .GlobalPhaseGate ):
179
- # A controlled global phase is a diagonal gate, where each active control value index
180
- # is set equal to the phase angle.
181
- shape = self .control_qid_shape
182
- if protocols .is_parameterized (self .sub_gate ) or set (shape ) != {2 }:
183
- # Could work in theory, but DiagonalGate decompose does not support them.
184
- return NotImplemented
185
- angle = np .angle (complex (self .sub_gate .coefficient ))
186
- rads = np .zeros (shape = shape )
187
- for hot in self .control_values .expand ():
188
- rads [hot ] = angle
189
- return dg .DiagonalGate (diag_angles_radians = [* rads .flatten ()]).on (* qubits )
178
+ unitary = protocols .unitary (self .sub_gate , default = None )
179
+ if (
180
+ unitary is not None
181
+ and unitary .shape == (1 , 1 )
182
+ and np .isclose (np .abs (unitary [0 , 0 ]), 1 )
183
+ ):
184
+ return unitary [0 ][0 ].angle
190
185
if isinstance (self .sub_gate , common_gates .CZPowGate ):
191
186
z_sub_gate = common_gates .ZPowGate (exponent = self .sub_gate .exponent )
192
187
num_controls = self .num_controls () + 1
0 commit comments