cirq-core 1.6.0.dev20250423233500__py3-none-any.whl → 1.6.0.dev20250425004112__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cirq-core might be problematic. Click here for more details.

Files changed (57) hide show
  1. cirq/_version.py +1 -1
  2. cirq/_version_test.py +1 -1
  3. cirq/ops/dense_pauli_string.py +28 -28
  4. cirq/ops/diagonal_gate.py +12 -14
  5. cirq/ops/eigen_gate.py +8 -5
  6. cirq/ops/fourier_transform.py +8 -12
  7. cirq/ops/fsim_gate.py +38 -37
  8. cirq/ops/gate_operation.py +25 -27
  9. cirq/ops/gateset.py +7 -5
  10. cirq/ops/global_phase_op.py +11 -11
  11. cirq/ops/greedy_qubit_manager.py +9 -7
  12. cirq/ops/identity.py +8 -6
  13. cirq/ops/kraus_channel.py +7 -4
  14. cirq/ops/linear_combinations.py +36 -34
  15. cirq/ops/matrix_gates.py +10 -10
  16. cirq/ops/measure_util.py +6 -4
  17. cirq/ops/measurement_gate.py +12 -12
  18. cirq/ops/mixed_unitary_channel.py +7 -4
  19. cirq/ops/named_qubit.py +8 -5
  20. cirq/ops/op_tree.py +4 -2
  21. cirq/ops/parallel_gate.py +11 -13
  22. cirq/ops/parity_gates.py +15 -17
  23. cirq/ops/pauli_gates.py +20 -17
  24. cirq/ops/pauli_interaction_gate.py +10 -14
  25. cirq/ops/pauli_measurement_gate.py +20 -20
  26. cirq/ops/pauli_string.py +76 -79
  27. cirq/ops/pauli_string_phasor.py +30 -30
  28. cirq/ops/pauli_string_raw_types.py +6 -4
  29. cirq/ops/pauli_sum_exponential.py +11 -11
  30. cirq/ops/permutation_gate.py +5 -3
  31. cirq/ops/phased_iswap_gate.py +8 -8
  32. cirq/ops/phased_x_gate.py +8 -9
  33. cirq/ops/phased_x_z_gate.py +15 -13
  34. cirq/ops/qid_util.py +6 -4
  35. cirq/ops/qubit_manager.py +9 -7
  36. cirq/ops/random_gate_channel.py +9 -7
  37. cirq/ops/raw_types.py +70 -72
  38. cirq/ops/raw_types_test.py +10 -6
  39. cirq/ops/state_preparation_channel.py +4 -4
  40. cirq/ops/swap_gates.py +7 -9
  41. cirq/ops/three_qubit_gates.py +22 -28
  42. cirq/ops/two_qubit_diagonal_gate.py +8 -8
  43. cirq/ops/uniform_superposition_gate.py +3 -1
  44. cirq/ops/wait_gate.py +12 -9
  45. cirq/protocols/act_on_protocol.py +6 -4
  46. cirq/protocols/act_on_protocol_test.py +8 -5
  47. cirq/protocols/apply_unitary_protocol.py +10 -8
  48. cirq/protocols/circuit_diagram_info_protocol.py +10 -8
  49. cirq/protocols/control_key_protocol.py +5 -3
  50. cirq/protocols/decompose_protocol.py +25 -22
  51. cirq/protocols/decompose_protocol_test.py +5 -2
  52. cirq/protocols/inverse_protocol.py +10 -8
  53. {cirq_core-1.6.0.dev20250423233500.dist-info → cirq_core-1.6.0.dev20250425004112.dist-info}/METADATA +1 -1
  54. {cirq_core-1.6.0.dev20250423233500.dist-info → cirq_core-1.6.0.dev20250425004112.dist-info}/RECORD +57 -57
  55. {cirq_core-1.6.0.dev20250423233500.dist-info → cirq_core-1.6.0.dev20250425004112.dist-info}/WHEEL +0 -0
  56. {cirq_core-1.6.0.dev20250423233500.dist-info → cirq_core-1.6.0.dev20250425004112.dist-info}/licenses/LICENSE +0 -0
  57. {cirq_core-1.6.0.dev20250423233500.dist-info → cirq_core-1.6.0.dev20250425004112.dist-info}/top_level.txt +0 -0
cirq/ops/parity_gates.py CHANGED
@@ -14,6 +14,8 @@
14
14
 
15
15
  """Quantum gates that phase with respect to product-of-pauli observables."""
16
16
 
17
+ from __future__ import annotations
18
+
17
19
  from typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
18
20
 
19
21
  import numpy as np
@@ -117,14 +119,14 @@ class XXPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
117
119
  def _has_stabilizer_effect_(self) -> bool:
118
120
  return self.exponent % 2 in (0, 0.5, 1, 1.5)
119
121
 
120
- def _decompose_(self, qubits: Tuple['cirq.Qid', ...]) -> Iterator['cirq.OP_TREE']:
122
+ def _decompose_(self, qubits: Tuple[cirq.Qid, ...]) -> Iterator[cirq.OP_TREE]:
121
123
  yield common_gates.YPowGate(exponent=-0.5).on_each(*qubits)
122
124
  yield ZZPowGate(exponent=self.exponent, global_shift=self.global_shift)(*qubits)
123
125
  yield common_gates.YPowGate(exponent=0.5).on_each(*qubits)
124
126
 
125
127
  def _circuit_diagram_info_(
126
- self, args: 'cirq.CircuitDiagramInfoArgs'
127
- ) -> Union[str, 'protocols.CircuitDiagramInfo']:
128
+ self, args: cirq.CircuitDiagramInfoArgs
129
+ ) -> Union[str, protocols.CircuitDiagramInfo]:
128
130
  return protocols.CircuitDiagramInfo(
129
131
  wire_symbols=('XX', 'XX'), exponent=self._diagram_exponent(args)
130
132
  )
@@ -226,14 +228,12 @@ class YYPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
226
228
  def _has_stabilizer_effect_(self) -> bool:
227
229
  return self.exponent % 2 in (0, 0.5, 1, 1.5)
228
230
 
229
- def _decompose_(self, qubits: Tuple['cirq.Qid', ...]) -> Iterator['cirq.OP_TREE']:
231
+ def _decompose_(self, qubits: Tuple[cirq.Qid, ...]) -> Iterator[cirq.OP_TREE]:
230
232
  yield common_gates.XPowGate(exponent=0.5).on_each(*qubits)
231
233
  yield ZZPowGate(exponent=self.exponent, global_shift=self.global_shift)(*qubits)
232
234
  yield common_gates.XPowGate(exponent=-0.5).on_each(*qubits)
233
235
 
234
- def _circuit_diagram_info_(
235
- self, args: 'cirq.CircuitDiagramInfoArgs'
236
- ) -> 'cirq.CircuitDiagramInfo':
236
+ def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
237
237
  return protocols.CircuitDiagramInfo(
238
238
  wire_symbols=('YY', 'YY'), exponent=self._diagram_exponent(args)
239
239
  )
@@ -281,8 +281,8 @@ class ZZPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
281
281
  )(qubits[0], qubits[1])
282
282
 
283
283
  def _decompose_into_clifford_with_qubits_(
284
- self, qubits: Sequence['cirq.Qid']
285
- ) -> Sequence[Union['cirq.Operation', Sequence['cirq.Operation']]]:
284
+ self, qubits: Sequence[cirq.Qid]
285
+ ) -> Sequence[Union[cirq.Operation, Sequence[cirq.Operation]]]:
286
286
  if not self._has_stabilizer_effect_():
287
287
  return NotImplemented
288
288
  if self.exponent % 2 == 0:
@@ -319,14 +319,12 @@ class ZZPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
319
319
  return None
320
320
  return abs(np.sin(self._exponent * 0.5 * np.pi))
321
321
 
322
- def _circuit_diagram_info_(
323
- self, args: 'cirq.CircuitDiagramInfoArgs'
324
- ) -> 'cirq.CircuitDiagramInfo':
322
+ def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
325
323
  return protocols.CircuitDiagramInfo(
326
324
  wire_symbols=('ZZ', 'ZZ'), exponent=self._diagram_exponent(args)
327
325
  )
328
326
 
329
- def _apply_unitary_(self, args: 'protocols.ApplyUnitaryArgs') -> Optional[np.ndarray]:
327
+ def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> Optional[np.ndarray]:
330
328
  if protocols.is_parameterized(self):
331
329
  return None
332
330
 
@@ -342,7 +340,7 @@ class ZZPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
342
340
 
343
341
  return args.target_tensor
344
342
 
345
- def _phase_by_(self, phase_turns: float, qubit_index: int) -> "ZZPowGate":
343
+ def _phase_by_(self, phase_turns: float, qubit_index: int) -> ZZPowGate:
346
344
  return self
347
345
 
348
346
  def __str__(self) -> str:
@@ -382,8 +380,8 @@ class MSGate(XXPowGate):
382
380
  return type(self)(rads=exponent * np.pi / 2)
383
381
 
384
382
  def _circuit_diagram_info_(
385
- self, args: 'cirq.CircuitDiagramInfoArgs'
386
- ) -> Union[str, 'protocols.CircuitDiagramInfo']:
383
+ self, args: cirq.CircuitDiagramInfoArgs
384
+ ) -> Union[str, protocols.CircuitDiagramInfo]:
387
385
  angle_str = self._format_exponent_as_angle(args, order=4)
388
386
  symbol = f'MS({angle_str})'
389
387
  return protocols.CircuitDiagramInfo(wire_symbols=(symbol, symbol))
@@ -407,7 +405,7 @@ class MSGate(XXPowGate):
407
405
  return protocols.obj_to_dict_helper(self, ["rads"])
408
406
 
409
407
  @classmethod
410
- def _from_json_dict_(cls, rads: float, **kwargs: Any) -> 'MSGate':
408
+ def _from_json_dict_(cls, rads: float, **kwargs: Any) -> MSGate:
411
409
  return cls(rads=rads)
412
410
 
413
411
 
cirq/ops/pauli_gates.py CHANGED
@@ -11,6 +11,9 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
+
15
+ from __future__ import annotations
16
+
14
17
  import abc
15
18
  from types import NotImplementedType
16
19
  from typing import Any, cast, Dict, Tuple, TYPE_CHECKING, Union
@@ -39,14 +42,14 @@ class Pauli(raw_types.Gate, metaclass=abc.ABCMeta):
39
42
  of private subclasses are the X, Y, or Z Pauli gates defined below.
40
43
  """
41
44
 
42
- _XYZ: Tuple['Pauli', 'Pauli', 'Pauli']
45
+ _XYZ: Tuple[Pauli, Pauli, Pauli]
43
46
 
44
47
  @staticmethod
45
- def by_index(index: int) -> 'Pauli':
48
+ def by_index(index: int) -> Pauli:
46
49
  return Pauli._XYZ[index % 3]
47
50
 
48
51
  @staticmethod
49
- def by_relative_index(p: 'Pauli', relative_index: int) -> 'Pauli':
52
+ def by_relative_index(p: Pauli, relative_index: int) -> Pauli:
50
53
  return Pauli._XYZ[(p._index + relative_index) % 3]
51
54
 
52
55
  def __init__(self, index: int, name: str) -> None:
@@ -63,16 +66,16 @@ class Pauli(raw_types.Gate, metaclass=abc.ABCMeta):
63
66
  return NotImplemented
64
67
  return self is other
65
68
 
66
- def third(self, second: 'Pauli') -> 'Pauli':
69
+ def third(self, second: Pauli) -> Pauli:
67
70
  return Pauli._XYZ[(-self._index - second._index) % 3]
68
71
 
69
- def relative_index(self, second: 'Pauli') -> int:
72
+ def relative_index(self, second: Pauli) -> int:
70
73
  """Relative index of self w.r.t. second in the (X, Y, Z) cycle."""
71
74
  return (self._index - second._index + 1) % 3 - 1
72
75
 
73
76
  def phased_pauli_product(
74
- self, other: Union['cirq.Pauli', 'identity.IdentityGate']
75
- ) -> Tuple[complex, Union['cirq.Pauli', 'identity.IdentityGate']]:
77
+ self, other: Union[cirq.Pauli, identity.IdentityGate]
78
+ ) -> Tuple[complex, Union[cirq.Pauli, identity.IdentityGate]]:
76
79
  if self == other:
77
80
  return 1, identity.I
78
81
  if other is identity.I:
@@ -89,7 +92,7 @@ class Pauli(raw_types.Gate, metaclass=abc.ABCMeta):
89
92
  return NotImplemented
90
93
  return (other._index - self._index) % 3 == 1
91
94
 
92
- def on(self, *qubits: 'cirq.Qid') -> 'SingleQubitPauliStringGateOperation':
95
+ def on(self, *qubits: cirq.Qid) -> SingleQubitPauliStringGateOperation:
93
96
  """Returns an application of this gate to the given qubits.
94
97
 
95
98
  Args:
@@ -109,10 +112,10 @@ class _PauliX(Pauli, common_gates.XPowGate):
109
112
  Pauli.__init__(self, index=0, name='X')
110
113
  common_gates.XPowGate.__init__(self, exponent=1.0)
111
114
 
112
- def __pow__(self, exponent: 'cirq.TParamVal') -> common_gates.XPowGate:
115
+ def __pow__(self, exponent: cirq.TParamVal) -> common_gates.XPowGate:
113
116
  return common_gates.XPowGate(exponent=exponent) if exponent != 1 else _PauliX()
114
117
 
115
- def _with_exponent(self, exponent: 'cirq.TParamVal') -> common_gates.XPowGate:
118
+ def _with_exponent(self, exponent: cirq.TParamVal) -> common_gates.XPowGate:
116
119
  return self.__pow__(exponent)
117
120
 
118
121
  @classmethod
@@ -122,7 +125,7 @@ class _PauliX(Pauli, common_gates.XPowGate):
122
125
  return Pauli._XYZ[0]
123
126
 
124
127
  @property
125
- def basis(self) -> Dict[int, '_XEigenState']:
128
+ def basis(self) -> Dict[int, _XEigenState]:
126
129
  from cirq.value.product_state import _XEigenState
127
130
 
128
131
  return {+1: _XEigenState(+1), -1: _XEigenState(-1)}
@@ -133,10 +136,10 @@ class _PauliY(Pauli, common_gates.YPowGate):
133
136
  Pauli.__init__(self, index=1, name='Y')
134
137
  common_gates.YPowGate.__init__(self, exponent=1.0)
135
138
 
136
- def __pow__(self, exponent: 'cirq.TParamVal') -> common_gates.YPowGate:
139
+ def __pow__(self, exponent: cirq.TParamVal) -> common_gates.YPowGate:
137
140
  return common_gates.YPowGate(exponent=exponent) if exponent != 1 else _PauliY()
138
141
 
139
- def _with_exponent(self, exponent: 'cirq.TParamVal') -> common_gates.YPowGate:
142
+ def _with_exponent(self, exponent: cirq.TParamVal) -> common_gates.YPowGate:
140
143
  return self.__pow__(exponent)
141
144
 
142
145
  @classmethod
@@ -146,7 +149,7 @@ class _PauliY(Pauli, common_gates.YPowGate):
146
149
  return Pauli._XYZ[1]
147
150
 
148
151
  @property
149
- def basis(self) -> Dict[int, '_YEigenState']:
152
+ def basis(self) -> Dict[int, _YEigenState]:
150
153
  from cirq.value.product_state import _YEigenState
151
154
 
152
155
  return {+1: _YEigenState(+1), -1: _YEigenState(-1)}
@@ -157,10 +160,10 @@ class _PauliZ(Pauli, common_gates.ZPowGate):
157
160
  Pauli.__init__(self, index=2, name='Z')
158
161
  common_gates.ZPowGate.__init__(self, exponent=1.0)
159
162
 
160
- def __pow__(self, exponent: 'cirq.TParamVal') -> common_gates.ZPowGate:
163
+ def __pow__(self, exponent: cirq.TParamVal) -> common_gates.ZPowGate:
161
164
  return common_gates.ZPowGate(exponent=exponent) if exponent != 1 else _PauliZ()
162
165
 
163
- def _with_exponent(self, exponent: 'cirq.TParamVal') -> common_gates.ZPowGate:
166
+ def _with_exponent(self, exponent: cirq.TParamVal) -> common_gates.ZPowGate:
164
167
  return self.__pow__(exponent)
165
168
 
166
169
  @classmethod
@@ -170,7 +173,7 @@ class _PauliZ(Pauli, common_gates.ZPowGate):
170
173
  return Pauli._XYZ[2]
171
174
 
172
175
  @property
173
- def basis(self) -> Dict[int, '_ZEigenState']:
176
+ def basis(self) -> Dict[int, _ZEigenState]:
174
177
  from cirq.value.product_state import _ZEigenState
175
178
 
176
179
  return {+1: _ZEigenState(+1), -1: _ZEigenState(-1)}
@@ -12,6 +12,8 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ from __future__ import annotations
16
+
15
17
  from typing import Any, Dict, Iterator, List, Sequence, Tuple, TYPE_CHECKING
16
18
 
17
19
  import numpy as np
@@ -35,8 +37,8 @@ PAULI_EIGEN_MAP: Dict[pauli_gates.Pauli, Tuple[np.ndarray, np.ndarray]] = {
35
37
  class PauliInteractionGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
36
38
  """A CZ conjugated by arbitrary single qubit Cliffords."""
37
39
 
38
- CZ: 'PauliInteractionGate'
39
- CNOT: 'PauliInteractionGate'
40
+ CZ: PauliInteractionGate
41
+ CNOT: PauliInteractionGate
40
42
 
41
43
  def __init__(
42
44
  self,
@@ -66,7 +68,7 @@ class PauliInteractionGate(gate_features.InterchangeableQubitsGate, eigen_gate.E
66
68
  self._invert1 = invert1
67
69
 
68
70
  @property
69
- def pauli0(self) -> 'cirq.Pauli':
71
+ def pauli0(self) -> cirq.Pauli:
70
72
  return self._pauli0
71
73
 
72
74
  @property
@@ -74,7 +76,7 @@ class PauliInteractionGate(gate_features.InterchangeableQubitsGate, eigen_gate.E
74
76
  return self._invert0
75
77
 
76
78
  @property
77
- def pauli1(self) -> 'cirq.Pauli':
79
+ def pauli1(self) -> cirq.Pauli:
78
80
  return self._pauli1
79
81
 
80
82
  @property
@@ -98,7 +100,7 @@ class PauliInteractionGate(gate_features.InterchangeableQubitsGate, eigen_gate.E
98
100
  return 0
99
101
  return index
100
102
 
101
- def _with_exponent(self, exponent: value.TParamVal) -> 'PauliInteractionGate':
103
+ def _with_exponent(self, exponent: value.TParamVal) -> PauliInteractionGate:
102
104
  return PauliInteractionGate(
103
105
  self.pauli0, self.invert0, self.pauli1, self.invert1, exponent=exponent
104
106
  )
@@ -114,7 +116,7 @@ class PauliInteractionGate(gate_features.InterchangeableQubitsGate, eigen_gate.E
114
116
  comp0 = np.eye(4) - comp1
115
117
  return [(0, comp0), (1, comp1)]
116
118
 
117
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
119
+ def _decompose_(self, qubits: Sequence[cirq.Qid]) -> Iterator[cirq.OP_TREE]:
118
120
  q0, q1 = qubits
119
121
  right_gate0 = SingleQubitCliffordGate.from_single_map(z_to=(self.pauli0, self.invert0))
120
122
  right_gate1 = SingleQubitCliffordGate.from_single_map(z_to=(self.pauli1, self.invert1))
@@ -127,14 +129,8 @@ class PauliInteractionGate(gate_features.InterchangeableQubitsGate, eigen_gate.E
127
129
  yield right_gate0(q0)
128
130
  yield right_gate1(q1)
129
131
 
130
- def _circuit_diagram_info_(
131
- self, args: 'cirq.CircuitDiagramInfoArgs'
132
- ) -> 'cirq.CircuitDiagramInfo':
133
- labels: Dict['cirq.Pauli', str] = {
134
- pauli_gates.X: 'X',
135
- pauli_gates.Y: 'Y',
136
- pauli_gates.Z: '@',
137
- }
132
+ def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
133
+ labels: Dict[cirq.Pauli, str] = {pauli_gates.X: 'X', pauli_gates.Y: 'Y', pauli_gates.Z: '@'}
138
134
  l0 = labels[self.pauli0]
139
135
  l1 = labels[self.pauli1]
140
136
  # Add brackets around letter if inverted
@@ -12,6 +12,8 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ from __future__ import annotations
16
+
15
17
  from typing import (
16
18
  Any,
17
19
  cast,
@@ -50,8 +52,8 @@ class PauliMeasurementGate(raw_types.Gate):
50
52
 
51
53
  def __init__(
52
54
  self,
53
- observable: Union['cirq.BaseDensePauliString', Iterable['cirq.Pauli']],
54
- key: Union[str, 'cirq.MeasurementKey'] = '',
55
+ observable: Union[cirq.BaseDensePauliString, Iterable[cirq.Pauli]],
56
+ key: Union[str, cirq.MeasurementKey] = '',
55
57
  ) -> None:
56
58
  """Inits PauliMeasurementGate.
57
59
 
@@ -89,7 +91,7 @@ class PauliMeasurementGate(raw_types.Gate):
89
91
  return str(self.mkey)
90
92
 
91
93
  @property
92
- def mkey(self) -> 'cirq.MeasurementKey':
94
+ def mkey(self) -> cirq.MeasurementKey:
93
95
  return self._mkey
94
96
 
95
97
  def _qid_shape_(self) -> Tuple[int, ...]:
@@ -98,29 +100,29 @@ class PauliMeasurementGate(raw_types.Gate):
98
100
  def _has_unitary_(self) -> bool:
99
101
  return False
100
102
 
101
- def with_key(self, key: Union[str, 'cirq.MeasurementKey']) -> 'PauliMeasurementGate':
103
+ def with_key(self, key: Union[str, cirq.MeasurementKey]) -> PauliMeasurementGate:
102
104
  """Creates a pauli measurement gate with a new key but otherwise identical."""
103
105
  if key == self.key:
104
106
  return self
105
107
  return PauliMeasurementGate(self._observable, key=key)
106
108
 
107
- def _with_key_path_(self, path: Tuple[str, ...]) -> 'PauliMeasurementGate':
109
+ def _with_key_path_(self, path: Tuple[str, ...]) -> PauliMeasurementGate:
108
110
  return self.with_key(self.mkey._with_key_path_(path))
109
111
 
110
- def _with_key_path_prefix_(self, prefix: Tuple[str, ...]) -> 'PauliMeasurementGate':
112
+ def _with_key_path_prefix_(self, prefix: Tuple[str, ...]) -> PauliMeasurementGate:
111
113
  return self.with_key(self.mkey._with_key_path_prefix_(prefix))
112
114
 
113
115
  def _with_rescoped_keys_(
114
- self, path: Tuple[str, ...], bindable_keys: FrozenSet['cirq.MeasurementKey']
115
- ) -> 'PauliMeasurementGate':
116
+ self, path: Tuple[str, ...], bindable_keys: FrozenSet[cirq.MeasurementKey]
117
+ ) -> PauliMeasurementGate:
116
118
  return self.with_key(protocols.with_rescoped_keys(self.mkey, path, bindable_keys))
117
119
 
118
- def _with_measurement_key_mapping_(self, key_map: Mapping[str, str]) -> 'PauliMeasurementGate':
120
+ def _with_measurement_key_mapping_(self, key_map: Mapping[str, str]) -> PauliMeasurementGate:
119
121
  return self.with_key(protocols.with_measurement_key_mapping(self.mkey, key_map))
120
122
 
121
123
  def with_observable(
122
- self, observable: Union['cirq.BaseDensePauliString', Iterable['cirq.Pauli']]
123
- ) -> 'PauliMeasurementGate':
124
+ self, observable: Union[cirq.BaseDensePauliString, Iterable[cirq.Pauli]]
125
+ ) -> PauliMeasurementGate:
124
126
  """Creates a pauli measurement gate with the new observable and same key."""
125
127
  if (
126
128
  observable
@@ -136,16 +138,16 @@ class PauliMeasurementGate(raw_types.Gate):
136
138
  def _measurement_key_name_(self) -> str:
137
139
  return self.key
138
140
 
139
- def _measurement_key_obj_(self) -> 'cirq.MeasurementKey':
141
+ def _measurement_key_obj_(self) -> cirq.MeasurementKey:
140
142
  return self.mkey
141
143
 
142
- def observable(self) -> 'cirq.DensePauliString':
144
+ def observable(self) -> cirq.DensePauliString:
143
145
  """Pauli observable which should be measured by the gate."""
144
146
  return self._observable
145
147
 
146
148
  def _decompose_(
147
- self, qubits: Tuple['cirq.Qid', ...]
148
- ) -> Iterator['protocols.decompose_protocol.DecomposeResult']:
149
+ self, qubits: Tuple[cirq.Qid, ...]
150
+ ) -> Iterator[protocols.decompose_protocol.DecomposeResult]:
149
151
  any_qubit = qubits[0]
150
152
  to_z_ops = op_tree.freeze_op_tree(self._observable.on(*qubits).to_z_basis_ops())
151
153
  xor_decomp = tuple(pauli_string_phasor.xor_nonlocal_decompose(qubits, any_qubit))
@@ -157,9 +159,7 @@ class PauliMeasurementGate(raw_types.Gate):
157
159
  yield protocols.inverse(xor_decomp)
158
160
  yield protocols.inverse(to_z_ops)
159
161
 
160
- def _circuit_diagram_info_(
161
- self, args: 'cirq.CircuitDiagramInfoArgs'
162
- ) -> 'cirq.CircuitDiagramInfo':
162
+ def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
163
163
  coefficient = '' if self._observable.coefficient == 1 else '-'
164
164
  symbols = [
165
165
  f'M({"" if i else coefficient}{self._observable[i]})'
@@ -176,7 +176,7 @@ class PauliMeasurementGate(raw_types.Gate):
176
176
 
177
177
  return protocols.CircuitDiagramInfo(tuple(symbols))
178
178
 
179
- def _op_repr_(self, qubits: Sequence['cirq.Qid']) -> str:
179
+ def _op_repr_(self, qubits: Sequence[cirq.Qid]) -> str:
180
180
  args = [repr(self._observable.on(*qubits))]
181
181
  if self.key != _default_measurement_key(qubits):
182
182
  args.append(f'key={self.mkey!r}')
@@ -193,7 +193,7 @@ class PauliMeasurementGate(raw_types.Gate):
193
193
  return {'observable': self._observable, 'key': self.key}
194
194
 
195
195
  @classmethod
196
- def _from_json_dict_(cls, observable, key, **kwargs) -> 'PauliMeasurementGate':
196
+ def _from_json_dict_(cls, observable, key, **kwargs) -> PauliMeasurementGate:
197
197
  return cls(observable=observable, key=value.MeasurementKey.parse_serialized(key))
198
198
 
199
199