|
16 | 16 | import warnings |
17 | 17 | from collections import abc |
18 | 18 | from typing import ( |
| 19 | + Any, |
19 | 20 | Dict, |
20 | 21 | Generic, |
21 | 22 | Iterator, |
|
25 | 26 | Sequence, |
26 | 27 | Tuple, |
27 | 28 | TYPE_CHECKING, |
28 | | - Union, |
29 | 29 | ) |
30 | 30 |
|
31 | 31 | import numpy as np |
@@ -120,16 +120,26 @@ def create_merged_state(self) -> TActOnArgs: |
120 | 120 |
|
121 | 121 | def _act_on_fallback_( |
122 | 122 | self, |
123 | | - action: Union['cirq.Operation', 'cirq.Gate'], |
| 123 | + action: Any, |
124 | 124 | qubits: Sequence['cirq.Qid'], |
125 | 125 | allow_decompose: bool = True, |
126 | 126 | ) -> bool: |
127 | | - gate = action.gate if isinstance(action, ops.Operation) else action |
| 127 | + gate_opt = ( |
| 128 | + action |
| 129 | + if isinstance(action, ops.Gate) |
| 130 | + else action.gate |
| 131 | + if isinstance(action, ops.Operation) |
| 132 | + else None |
| 133 | + ) |
128 | 134 |
|
129 | | - if isinstance(gate, ops.IdentityGate): |
| 135 | + if isinstance(gate_opt, ops.IdentityGate): |
130 | 136 | return True |
131 | 137 |
|
132 | | - if isinstance(gate, ops.SwapPowGate) and gate.exponent % 2 == 1 and gate.global_shift == 0: |
| 138 | + if ( |
| 139 | + isinstance(gate_opt, ops.SwapPowGate) |
| 140 | + and gate_opt.exponent % 2 == 1 |
| 141 | + and gate_opt.global_shift == 0 |
| 142 | + ): |
133 | 143 | q0, q1 = qubits |
134 | 144 | args0 = self.args[q0] |
135 | 145 | args1 = self.args[q1] |
@@ -160,8 +170,10 @@ def _act_on_fallback_( |
160 | 170 |
|
161 | 171 | # Decouple any measurements or resets |
162 | 172 | if self.split_untangled_states and ( |
163 | | - isinstance(gate, ops.ResetChannel) |
164 | | - or (isinstance(gate, ops.MeasurementGate) and not op_args.ignore_measurement_results) |
| 173 | + isinstance(gate_opt, ops.ResetChannel) |
| 174 | + or ( |
| 175 | + isinstance(gate_opt, ops.MeasurementGate) and not op_args.ignore_measurement_results |
| 176 | + ) |
165 | 177 | ): |
166 | 178 | for q in qubits: |
167 | 179 | if op_args.allows_factoring: |
|
0 commit comments