Skip to content

Commit 0340b0b

Browse files
Fixed linting errors
1 parent e5e39ba commit 0340b0b

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

cirq-core/cirq/ops/controlled_gate.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,13 @@ def _decompose_with_context_(
175175
protocols.unitary(self.sub_gate), control_qubits, qubits[-1]
176176
)
177177
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
190185
if isinstance(self.sub_gate, common_gates.CZPowGate):
191186
z_sub_gate = common_gates.ZPowGate(exponent=self.sub_gate.exponent)
192187
num_controls = self.num_controls() + 1

cirq-core/cirq/ops/pauli_string_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2152,4 +2152,4 @@ def test_pauli_ops_identity_gate_operation():
21522152
), f"Addition failed for {p1} + {p2}"
21532153
assert isinstance(
21542154
p1 - p2, (cirq.PauliSum, cirq.PauliString)
2155-
), f"Subtraction failed for {p1} - {p2}"
2155+
), f"Subtraction failed for {p1} - {p2}"

0 commit comments

Comments
 (0)