@@ -55,16 +55,9 @@ def optimization_at(
55
55
56
56
switch_to_new = False
57
57
switch_to_new |= any (
58
- len (old_op .qubits ) == 2 and not isinstance (old_op . gate , ops . CZPowGate )
58
+ len (old_op .qubits ) == 2 and not self . _may_keep_old_op (old_op )
59
59
for old_op in old_operations
60
60
)
61
- if not self .allow_partial_czs :
62
- switch_to_new |= any (
63
- isinstance (old_op , ops .GateOperation )
64
- and isinstance (old_op .gate , ops .CZPowGate )
65
- and old_op .gate .exponent != 1
66
- for old_op in old_operations
67
- )
68
61
69
62
# This point cannot be optimized using this method
70
63
if not switch_to_new and old_interaction_count <= 1 :
@@ -89,6 +82,13 @@ def optimization_at(
89
82
new_operations = new_operations ,
90
83
)
91
84
85
+ def _may_keep_old_op (self , old_op : 'cirq.Operation' ) -> bool :
86
+ """Returns True if the old two-qubit operation may be left unchanged
87
+ without decomposition."""
88
+ if self .allow_partial_czs :
89
+ return isinstance (old_op .gate , ops .CZPowGate )
90
+ return isinstance (old_op .gate , ops .CZPowGate ) and old_op .gate .exponent == 1
91
+
92
92
def _op_to_matrix (
93
93
self , op : ops .Operation , qubits : Tuple ['cirq.Qid' , ...]
94
94
) -> Optional [np .ndarray ]:
0 commit comments