cirq-core 1.5.0.dev20240823014143__py3-none-any.whl → 1.5.0.dev20240830211827__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 (46) hide show
  1. cirq/_version.py +1 -1
  2. cirq/_version_test.py +1 -1
  3. cirq/circuits/circuit.py +1 -1
  4. cirq/circuits/circuit_operation.py +2 -2
  5. cirq/circuits/qasm_output.py +2 -2
  6. cirq/contrib/acquaintance/bipartite.py +3 -3
  7. cirq/contrib/acquaintance/executor.py +2 -2
  8. cirq/contrib/acquaintance/gates.py +12 -2
  9. cirq/contrib/acquaintance/inspection_utils.py +2 -2
  10. cirq/contrib/acquaintance/permutation.py +3 -2
  11. cirq/contrib/acquaintance/shift.py +2 -2
  12. cirq/contrib/acquaintance/shift_swap_network.py +2 -2
  13. cirq/contrib/bayesian_network/bayesian_network_gate.py +2 -2
  14. cirq/contrib/paulistring/separate.py +2 -2
  15. cirq/experiments/random_quantum_circuit_generation.py +2 -1
  16. cirq/interop/quirk/cells/control_cells.py +1 -1
  17. cirq/interop/quirk/cells/parse.py +3 -1
  18. cirq/ops/diagonal_gate.py +1 -1
  19. cirq/ops/fsim_gate.py +3 -3
  20. cirq/ops/linear_combinations.py +1 -1
  21. cirq/ops/parity_gates.py +3 -3
  22. cirq/ops/pauli_interaction_gate.py +2 -2
  23. cirq/ops/pauli_measurement_gate.py +2 -1
  24. cirq/ops/pauli_string_phasor.py +1 -1
  25. cirq/ops/permutation_gate.py +2 -2
  26. cirq/ops/phased_iswap_gate.py +2 -2
  27. cirq/ops/phased_x_z_gate.py +3 -2
  28. cirq/ops/projector.py +2 -1
  29. cirq/ops/raw_types.py +1 -1
  30. cirq/ops/three_qubit_gates.py +3 -2
  31. cirq/ops/two_qubit_diagonal_gate.py +2 -2
  32. cirq/ops/uniform_superposition_gate.py +2 -2
  33. cirq/sim/state_vector_test.py +27 -32
  34. cirq/transformers/eject_phased_paulis.py +2 -2
  35. cirq/transformers/eject_z.py +2 -2
  36. cirq/transformers/noise_adding.py +1 -1
  37. cirq/transformers/noise_adding_test.py +4 -4
  38. cirq/transformers/transformer_primitives_test.py +3 -3
  39. cirq/value/linear_dict.py +6 -4
  40. cirq/vis/heatmap.py +9 -1
  41. cirq/vis/state_histogram.py +2 -1
  42. {cirq_core-1.5.0.dev20240823014143.dist-info → cirq_core-1.5.0.dev20240830211827.dist-info}/METADATA +1 -1
  43. {cirq_core-1.5.0.dev20240823014143.dist-info → cirq_core-1.5.0.dev20240830211827.dist-info}/RECORD +46 -46
  44. {cirq_core-1.5.0.dev20240823014143.dist-info → cirq_core-1.5.0.dev20240830211827.dist-info}/LICENSE +0 -0
  45. {cirq_core-1.5.0.dev20240823014143.dist-info → cirq_core-1.5.0.dev20240830211827.dist-info}/WHEEL +0 -0
  46. {cirq_core-1.5.0.dev20240823014143.dist-info → cirq_core-1.5.0.dev20240830211827.dist-info}/top_level.txt +0 -0
cirq/_version.py CHANGED
@@ -28,4 +28,4 @@ if sys.version_info < (3, 10, 0): # pragma: no cover
28
28
  'of cirq (e.g. "python -m pip install cirq==1.1.*")'
29
29
  )
30
30
 
31
- __version__ = "1.5.0.dev20240823014143"
31
+ __version__ = "1.5.0.dev20240830211827"
cirq/_version_test.py CHANGED
@@ -3,4 +3,4 @@ import cirq
3
3
 
4
4
 
5
5
  def test_version():
6
- assert cirq.__version__ == "1.5.0.dev20240823014143"
6
+ assert cirq.__version__ == "1.5.0.dev20240830211827"
cirq/circuits/circuit.py CHANGED
@@ -2014,7 +2014,7 @@ class Circuit(AbstractCircuit):
2014
2014
  if callable(qubit_map):
2015
2015
  transform = qubit_map
2016
2016
  elif isinstance(qubit_map, dict):
2017
- transform = lambda q: qubit_map.get(q, q) # type: ignore
2017
+ transform = lambda q: qubit_map.get(q, q)
2018
2018
  else:
2019
2019
  raise TypeError('qubit_map must be a function or dict mapping qubits to qubits.')
2020
2020
 
@@ -267,7 +267,7 @@ class CircuitOperation(ops.Operation):
267
267
  'repeat_until': self.repeat_until,
268
268
  **changes,
269
269
  }
270
- return CircuitOperation(**kwargs) # type: ignore
270
+ return CircuitOperation(**kwargs)
271
271
 
272
272
  def __eq__(self, other) -> bool:
273
273
  if not isinstance(other, type(self)):
@@ -688,7 +688,7 @@ class CircuitOperation(ops.Operation):
688
688
  if callable(qubit_map):
689
689
  transform = qubit_map
690
690
  elif isinstance(qubit_map, dict):
691
- transform = lambda q: qubit_map.get(q, q) # type: ignore
691
+ transform = lambda q: qubit_map.get(q, q)
692
692
  else:
693
693
  raise TypeError('qubit_map must be a function or dict mapping qubits to qubits.')
694
694
  new_map = {}
@@ -14,7 +14,7 @@
14
14
 
15
15
  """Utility classes for representing QASM."""
16
16
 
17
- from typing import Callable, Dict, Optional, Sequence, Set, Tuple, Union, TYPE_CHECKING
17
+ from typing import Callable, Dict, Iterator, Optional, Sequence, Set, Tuple, Union, TYPE_CHECKING
18
18
 
19
19
  import re
20
20
  import numpy as np
@@ -126,7 +126,7 @@ class QasmTwoQubitGate(ops.Gate):
126
126
  def _unitary_(self):
127
127
  return protocols.unitary(self.kak)
128
128
 
129
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
129
+ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
130
130
  q0, q1 = qubits
131
131
  x, y, z = self.kak.interaction_coefficients
132
132
  a = x * -2 / np.pi + 0.5
@@ -14,7 +14,7 @@
14
14
 
15
15
  import enum
16
16
  import itertools
17
- from typing import Dict, Sequence, Tuple, Union, TYPE_CHECKING
17
+ from typing import Dict, Iterator, Sequence, Tuple, Union, TYPE_CHECKING
18
18
 
19
19
  from cirq import ops
20
20
 
@@ -72,7 +72,7 @@ class BipartiteSwapNetworkGate(PermutationGate):
72
72
  )
73
73
  self.swap_gate = swap_gate
74
74
 
75
- def decompose_complete(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
75
+ def decompose_complete(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
76
76
  swap_gate = SwapPermutationGate(self.swap_gate)
77
77
  if self.part_size == 1:
78
78
  yield acquaint(*qubits)
@@ -87,7 +87,7 @@ class BipartiteSwapNetworkGate(PermutationGate):
87
87
  yield acquaint(*qubits[x : x + 2])
88
88
  yield swap_gate(*qubits[x : x + 2])
89
89
 
90
- def decompose_matching(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
90
+ def decompose_matching(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
91
91
  swap_gate = SwapPermutationGate(self.swap_gate)
92
92
  for k in range(-self.part_size + 1, self.part_size):
93
93
  for x in range(abs(k), 2 * self.part_size - abs(k), 2):
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from typing import DefaultDict, Dict, Sequence, TYPE_CHECKING, Optional
15
+ from typing import DefaultDict, Dict, Iterator, Sequence, TYPE_CHECKING, Optional
16
16
 
17
17
  import abc
18
18
  from collections import defaultdict
@@ -208,7 +208,7 @@ class GreedyExecutionStrategy(ExecutionStrategy):
208
208
 
209
209
  def get_operations(
210
210
  self, indices: Sequence[LogicalIndex], qubits: Sequence['cirq.Qid']
211
- ) -> 'cirq.OP_TREE':
211
+ ) -> Iterator['cirq.OP_TREE']:
212
212
  index_set = frozenset(indices)
213
213
  if index_set in self.index_set_to_gates:
214
214
  gates = self.index_set_to_gates.pop(index_set)
@@ -16,7 +16,17 @@ import functools
16
16
  import itertools
17
17
  import math
18
18
  import operator
19
- from typing import Dict, Iterable, List, NamedTuple, Optional, Sequence, Tuple, TYPE_CHECKING
19
+ from typing import (
20
+ Dict,
21
+ Iterable,
22
+ Iterator,
23
+ List,
24
+ NamedTuple,
25
+ Optional,
26
+ Sequence,
27
+ Tuple,
28
+ TYPE_CHECKING,
29
+ )
20
30
 
21
31
  from cirq import ops, protocols, value
22
32
 
@@ -276,7 +286,7 @@ class SwapNetworkGate(PermutationGate):
276
286
  self.part_lens = tuple(part_lens)
277
287
  self.acquaintance_size = acquaintance_size
278
288
 
279
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
289
+ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
280
290
  qubit_to_position = {q: i for i, q in enumerate(qubits)}
281
291
  mapping = dict(qubit_to_position)
282
292
  parts = []
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from typing import FrozenSet, Sequence, Set, TYPE_CHECKING
15
+ from typing import FrozenSet, Iterator, Sequence, Set, TYPE_CHECKING
16
16
 
17
17
  from cirq import devices
18
18
 
@@ -46,7 +46,7 @@ class LogicalAnnotator(ExecutionStrategy):
46
46
 
47
47
  def get_operations(
48
48
  self, indices: Sequence[LogicalIndex], qubits: Sequence['cirq.Qid']
49
- ) -> 'cirq.OP_TREE':
49
+ ) -> Iterator['cirq.OP_TREE']:
50
50
  yield AcquaintanceOperation(qubits, indices)
51
51
 
52
52
 
@@ -18,6 +18,7 @@ from typing import (
18
18
  cast,
19
19
  Dict,
20
20
  Iterable,
21
+ Iterator,
21
22
  Optional,
22
23
  Sequence,
23
24
  Tuple,
@@ -152,7 +153,7 @@ class SwapPermutationGate(PermutationGate):
152
153
  def permutation(self) -> Dict[int, int]:
153
154
  return {0: 1, 1: 0}
154
155
 
155
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
156
+ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
156
157
  yield self.swap_gate(*qubits)
157
158
 
158
159
  def __repr__(self) -> str:
@@ -201,7 +202,7 @@ class LinearPermutationGate(PermutationGate):
201
202
  def permutation(self) -> Dict[int, int]:
202
203
  return self._permutation
203
204
 
204
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
205
+ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
205
206
  swap_gate = SwapPermutationGate(self.swap_gate)
206
207
  n_qubits = len(qubits)
207
208
  mapping = {i: self._permutation.get(i, i) for i in range(n_qubits)}
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
  import itertools
16
- from typing import Any, Dict, Sequence, Tuple, TYPE_CHECKING
16
+ from typing import Any, Dict, Iterator, Sequence, Tuple, TYPE_CHECKING
17
17
 
18
18
  from cirq import ops, value
19
19
  from cirq.contrib.acquaintance.permutation import SwapPermutationGate, PermutationGate
@@ -47,7 +47,7 @@ class CircularShiftGate(PermutationGate):
47
47
  def _value_equality_values_(self) -> Any:
48
48
  return self.shift, self.swap_gate, self.num_qubits()
49
49
 
50
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
50
+ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
51
51
  n = len(qubits)
52
52
  left_shift = self.shift % n
53
53
  right_shift = n - left_shift
@@ -14,7 +14,7 @@
14
14
 
15
15
  import functools
16
16
  import itertools
17
- from typing import Dict, Iterable, Optional, Sequence, Tuple, TYPE_CHECKING
17
+ from typing import Dict, Iterable, Iterator, Optional, Sequence, Tuple, TYPE_CHECKING
18
18
 
19
19
  from cirq import ops
20
20
  from cirq.contrib.acquaintance.gates import acquaint
@@ -65,7 +65,7 @@ class ShiftSwapNetworkGate(PermutationGate):
65
65
  def acquaintance_size(self) -> int:
66
66
  return sum(max(self.part_lens[side]) for side in ('left', 'right'))
67
67
 
68
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
68
+ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
69
69
  part_lens = list(itertools.chain(*(self.part_lens[side] for side in ('left', 'right'))))
70
70
 
71
71
  n_qubits = 0
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
  import math
16
- from typing import Any, cast, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
16
+ from typing import Any, cast, Dict, Iterator, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
17
17
 
18
18
  from sympy.combinatorics import GrayCode
19
19
 
@@ -158,7 +158,7 @@ class BayesianNetworkGate(raw_types.Gate):
158
158
  raise ValueError('Conditional prob should be between 0 and 1.')
159
159
  self._arc_probs = arc_probs
160
160
 
161
- def _decompose_(self, qubits: Sequence['raw_types.Qid']) -> 'cirq.OP_TREE':
161
+ def _decompose_(self, qubits: Sequence['raw_types.Qid']) -> Iterator['cirq.OP_TREE']:
162
162
  parameter_names = [init_prob[0] for init_prob in self._init_probs]
163
163
  qubit_map = dict(zip(parameter_names, qubits))
164
164
 
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from typing import Tuple
15
+ from typing import Iterator, Tuple
16
16
 
17
17
  from cirq import ops, circuits, transformers
18
18
 
@@ -89,7 +89,7 @@ def pauli_string_half(circuit: circuits.Circuit) -> circuits.Circuit:
89
89
  )
90
90
 
91
91
 
92
- def _pull_non_clifford_before(circuit: circuits.Circuit) -> ops.OP_TREE:
92
+ def _pull_non_clifford_before(circuit: circuits.Circuit) -> Iterator[ops.OP_TREE]:
93
93
  def _iter_ops_range_reversed(moment_end):
94
94
  for i in reversed(range(moment_end)):
95
95
  moment = circuit[i]
@@ -21,6 +21,7 @@ from typing import (
21
21
  Container,
22
22
  Dict,
23
23
  Iterable,
24
+ Iterator,
24
25
  List,
25
26
  Sequence,
26
27
  TYPE_CHECKING,
@@ -691,7 +692,7 @@ def _two_qubit_layer(
691
692
  ],
692
693
  layer: GridInteractionLayer,
693
694
  prng: 'np.random.RandomState',
694
- ) -> 'cirq.OP_TREE':
695
+ ) -> Iterator['cirq.OP_TREE']:
695
696
  for a, b in coupled_qubit_pairs:
696
697
  if (a, b) in layer or (b, a) in layer:
697
698
  yield two_qubit_op_factory(a, b, prng)
@@ -109,7 +109,7 @@ class ParityControlCell(Cell):
109
109
  elif gate is not None:
110
110
  column[i] = gate.controlled_by(self.qubits[0])
111
111
 
112
- def basis_change(self) -> 'cirq.OP_TREE':
112
+ def basis_change(self) -> Iterator['cirq.OP_TREE']:
113
113
  yield from self._basis_change
114
114
 
115
115
  # Temporarily move the ZZZ..Z parity observable onto a single qubit.
@@ -191,7 +191,9 @@ def _parse_formula_using_token_map(
191
191
  elif token.unary_action is not None:
192
192
  burn_ops(token.priority)
193
193
  vals.append(None)
194
- ops.append(_HangingNode(func=lambda _, b: token.unary_action(b), weight=np.inf))
194
+ # this avoids mypy complaint about None not being callable
195
+ token_unary_action = token.unary_action
196
+ ops.append(_HangingNode(func=lambda _, b: token_unary_action(b), weight=np.inf))
195
197
  elif token.binary_action is not None:
196
198
  raise ValueError("Bad expression: binary op in bad spot.\ntext={text!r}")
197
199
 
cirq/ops/diagonal_gate.py CHANGED
@@ -166,7 +166,7 @@ class DiagonalGate(raw_types.Gate):
166
166
  self, index: int, bit_flip: int, theta: 'cirq.TParamVal', qubits: Sequence['cirq.Qid']
167
167
  ) -> Iterator[Union['cirq.ZPowGate', 'cirq.CXPowGate']]:
168
168
  if index == 0:
169
- return []
169
+ return
170
170
  largest_digit = self._num_qubits_() - (len(bin(index)) - 2)
171
171
  yield common_gates.rz(2 * theta)(qubits[largest_digit])
172
172
  _flip_bit = self._num_qubits_() - bit_flip - 1
cirq/ops/fsim_gate.py CHANGED
@@ -23,7 +23,7 @@ applies more generally to fermions, thus the name of the gate.
23
23
 
24
24
  import cmath
25
25
  import math
26
- from typing import AbstractSet, Any, Dict, Optional, Tuple
26
+ from typing import AbstractSet, Any, Dict, Iterator, Optional, Tuple
27
27
 
28
28
  import numpy as np
29
29
  import sympy
@@ -187,7 +187,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
187
187
  out[ii] *= cmath.exp(-1j * self.phi)
188
188
  return out
189
189
 
190
- def _decompose_(self, qubits) -> 'cirq.OP_TREE':
190
+ def _decompose_(self, qubits) -> Iterator['cirq.OP_TREE']:
191
191
  a, b = qubits
192
192
  xx = cirq.XXPowGate(exponent=self.theta / np.pi, global_shift=-0.5)
193
193
  yy = cirq.YYPowGate(exponent=self.theta / np.pi, global_shift=-0.5)
@@ -452,7 +452,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
452
452
  out[ii] *= f * f
453
453
  return out
454
454
 
455
- def _decompose_(self, qubits) -> 'cirq.OP_TREE':
455
+ def _decompose_(self, qubits) -> Iterator['cirq.OP_TREE']:
456
456
  """Decomposes self into Z rotations and FSimGate.
457
457
 
458
458
  Note that Z rotations returned by this method have unusual global phase
@@ -805,7 +805,7 @@ class PauliSum:
805
805
  if not isinstance(other, (numbers.Complex, PauliString, PauliSum)):
806
806
  return NotImplemented
807
807
  if isinstance(other, numbers.Complex):
808
- self._linear_dict *= other
808
+ self._linear_dict *= complex(other)
809
809
  elif isinstance(other, PauliString):
810
810
  temp = PauliSum.from_pauli_strings([term * other for term in self])
811
811
  self._linear_dict = temp._linear_dict
cirq/ops/parity_gates.py CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  """Quantum gates that phase with respect to product-of-pauli observables."""
16
16
 
17
- from typing import Any, Dict, List, Optional, Tuple, Union, TYPE_CHECKING, Sequence
17
+ from typing import Any, Dict, List, Iterator, Optional, Tuple, Union, TYPE_CHECKING, Sequence
18
18
  from typing_extensions import Self
19
19
 
20
20
  import numpy as np
@@ -118,7 +118,7 @@ class XXPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
118
118
  def _has_stabilizer_effect_(self) -> bool:
119
119
  return self.exponent % 2 in (0, 0.5, 1, 1.5)
120
120
 
121
- def _decompose_(self, qubits: Tuple['cirq.Qid', ...]) -> 'cirq.OP_TREE':
121
+ def _decompose_(self, qubits: Tuple['cirq.Qid', ...]) -> Iterator['cirq.OP_TREE']:
122
122
  yield common_gates.YPowGate(exponent=-0.5).on_each(*qubits)
123
123
  yield ZZPowGate(exponent=self.exponent, global_shift=self.global_shift)(*qubits)
124
124
  yield common_gates.YPowGate(exponent=0.5).on_each(*qubits)
@@ -227,7 +227,7 @@ class YYPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
227
227
  def _has_stabilizer_effect_(self) -> bool:
228
228
  return self.exponent % 2 in (0, 0.5, 1, 1.5)
229
229
 
230
- def _decompose_(self, qubits: Tuple['cirq.Qid', ...]) -> 'cirq.OP_TREE':
230
+ def _decompose_(self, qubits: Tuple['cirq.Qid', ...]) -> Iterator['cirq.OP_TREE']:
231
231
  yield common_gates.XPowGate(exponent=0.5).on_each(*qubits)
232
232
  yield ZZPowGate(exponent=self.exponent, global_shift=self.global_shift)(*qubits)
233
233
  yield common_gates.XPowGate(exponent=-0.5).on_each(*qubits)
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from typing import Any, Dict, List, Sequence, TYPE_CHECKING, Tuple
15
+ from typing import Any, Dict, Iterator, List, Sequence, TYPE_CHECKING, Tuple
16
16
 
17
17
  import numpy as np
18
18
 
@@ -108,7 +108,7 @@ class PauliInteractionGate(gate_features.InterchangeableQubitsGate, eigen_gate.E
108
108
  comp0 = np.eye(4) - comp1
109
109
  return [(0, comp0), (1, comp1)]
110
110
 
111
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
111
+ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
112
112
  q0, q1 = qubits
113
113
  right_gate0 = SingleQubitCliffordGate.from_single_map(z_to=(self.pauli0, self.invert0))
114
114
  right_gate1 = SingleQubitCliffordGate.from_single_map(z_to=(self.pauli1, self.invert1))
@@ -17,6 +17,7 @@ from typing import (
17
17
  Dict,
18
18
  FrozenSet,
19
19
  Iterable,
20
+ Iterator,
20
21
  Mapping,
21
22
  Tuple,
22
23
  Sequence,
@@ -144,7 +145,7 @@ class PauliMeasurementGate(raw_types.Gate):
144
145
 
145
146
  def _decompose_(
146
147
  self, qubits: Tuple['cirq.Qid', ...]
147
- ) -> 'protocols.decompose_protocol.DecomposeResult':
148
+ ) -> Iterator['protocols.decompose_protocol.DecomposeResult']:
148
149
  any_qubit = qubits[0]
149
150
  to_z_ops = op_tree.freeze_op_tree(self._observable.on(*qubits).to_z_basis_ops())
150
151
  xor_decomp = tuple(pauli_string_phasor.xor_nonlocal_decompose(qubits, any_qubit))
@@ -351,7 +351,7 @@ class PauliStringPhasorGate(raw_types.Gate):
351
351
  """Returns operations to convert the qubits to the computational basis."""
352
352
  return self.dense_pauli_string.on(*qubits).to_z_basis_ops()
353
353
 
354
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
354
+ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
355
355
  if len(self.dense_pauli_string) <= 0:
356
356
  return
357
357
  any_qubit = qubits[0]
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from typing import Any, Dict, Sequence, Tuple, TYPE_CHECKING
15
+ from typing import Any, Dict, Iterator, Sequence, Tuple, TYPE_CHECKING
16
16
 
17
17
  from cirq import protocols, value
18
18
  from cirq.ops import raw_types, swap_gates
@@ -73,7 +73,7 @@ class QubitPermutationGate(raw_types.Gate):
73
73
  def _has_unitary_(self):
74
74
  return True
75
75
 
76
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
76
+ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
77
77
  permutation = [p for p in self.permutation]
78
78
 
79
79
  for i in range(len(permutation)):
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
  """ISWAPPowGate conjugated by tensor product Rz(phi) and Rz(-phi)."""
15
15
 
16
- from typing import AbstractSet, Any, cast, Dict, List, Optional, Sequence, Tuple, Union
16
+ from typing import AbstractSet, Any, cast, Dict, Iterator, List, Optional, Sequence, Tuple, Union
17
17
 
18
18
  import numpy as np
19
19
  import sympy
@@ -157,7 +157,7 @@ class PhasedISwapPowGate(eigen_gate.EigenGate):
157
157
  )
158
158
  return args.available_buffer
159
159
 
160
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
160
+ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
161
161
  if len(qubits) != 2:
162
162
  raise ValueError(f'Expected two qubits, got {len(qubits)}')
163
163
  a, b = qubits
@@ -11,7 +11,8 @@
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
- from typing import AbstractSet, Any, Dict, Optional, Sequence, Tuple, TYPE_CHECKING, Union
14
+
15
+ from typing import AbstractSet, Any, Dict, Iterator, Optional, Sequence, Tuple, TYPE_CHECKING, Union
15
16
  import numbers
16
17
 
17
18
  import numpy as np
@@ -188,7 +189,7 @@ class PhasedXZGate(raw_types.Gate):
188
189
  z_post = protocols.unitary(ops.Z ** (self._axis_phase_exponent + self._z_exponent))
189
190
  return z_post @ x @ z_pre
190
191
 
191
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
192
+ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
192
193
  q = qubits[0]
193
194
  yield ops.Z(q) ** -self._axis_phase_exponent
194
195
  yield ops.X(q) ** self._x_exponent
cirq/ops/projector.py CHANGED
@@ -1,5 +1,6 @@
1
1
  # pylint: disable=wrong-or-nonexistent-copyright-notice
2
2
  import itertools
3
+ import math
3
4
  from typing import Any, Dict, Iterable, List, Mapping, Optional, Union
4
5
 
5
6
  import numpy as np
@@ -61,7 +62,7 @@ class ProjectorString:
61
62
  for qid in projector_qids
62
63
  ]
63
64
 
64
- total_d = np.prod([qid.dimension for qid in projector_qids], dtype=np.int64)
65
+ total_d = math.prod(qid.dimension for qid in projector_qids)
65
66
 
66
67
  ones_idx = []
67
68
  for idx in itertools.product(*idx_to_keep):
cirq/ops/raw_types.py CHANGED
@@ -580,7 +580,7 @@ class Operation(metaclass=abc.ABCMeta):
580
580
  if callable(qubit_map):
581
581
  transform = qubit_map
582
582
  elif isinstance(qubit_map, dict):
583
- transform = lambda q: qubit_map.get(q, q) # type: ignore
583
+ transform = lambda q: qubit_map.get(q, q)
584
584
  else:
585
585
  raise TypeError('qubit_map must be a function or dict mapping qubits to qubits.')
586
586
  return self.with_qubits(*(transform(q) for q in self.qubits))
@@ -19,6 +19,7 @@ from typing import (
19
19
  Any,
20
20
  Collection,
21
21
  Dict,
22
+ Iterator,
22
23
  List,
23
24
  Optional,
24
25
  Sequence,
@@ -573,7 +574,7 @@ class CSwapGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
573
574
 
574
575
  def _decompose_inside_control(
575
576
  self, target1: 'cirq.Qid', control: 'cirq.Qid', target2: 'cirq.Qid'
576
- ) -> 'cirq.OP_TREE':
577
+ ) -> Iterator['cirq.OP_TREE']:
577
578
  """A decomposition assuming the control separates the targets.
578
579
 
579
580
  target1: ─@─X───────T──────@────────@─────────X───@─────X^-0.5─
@@ -617,7 +618,7 @@ class CSwapGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
617
618
 
618
619
  def _decompose_outside_control(
619
620
  self, control: 'cirq.Qid', near_target: 'cirq.Qid', far_target: 'cirq.Qid'
620
- ) -> 'cirq.OP_TREE':
621
+ ) -> Iterator['cirq.OP_TREE']:
621
622
  """A decomposition assuming one of the targets is in the middle.
622
623
 
623
624
  control: ───T──────@────────@───@────────────@────────────────
@@ -18,7 +18,7 @@ The gate is used to create a 4x4 matrix with the diagonal elements
18
18
  passed as a list.
19
19
  """
20
20
 
21
- from typing import AbstractSet, Any, Dict, Tuple, Optional, Sequence, TYPE_CHECKING
21
+ from typing import AbstractSet, Any, Dict, Iterator, Tuple, Optional, Sequence, TYPE_CHECKING
22
22
  import numpy as np
23
23
  import sympy
24
24
 
@@ -93,7 +93,7 @@ class TwoQubitDiagonalGate(raw_types.Gate):
93
93
  return None
94
94
  return np.diag([np.exp(1j * angle) for angle in self._diag_angles_radians])
95
95
 
96
- def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
96
+ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> Iterator['cirq.OP_TREE']:
97
97
  x0, x1, x2, x3 = self._diag_angles_radians
98
98
  q0, q1 = qubits
99
99
  yield common_gates.ZPowGate(exponent=x2 / np.pi).on(q0)
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from typing import Sequence, Any, Dict, TYPE_CHECKING
15
+ from typing import Iterator, Sequence, Any, Dict, TYPE_CHECKING
16
16
 
17
17
  import numpy as np
18
18
  from cirq.ops.common_gates import H, ry
@@ -58,7 +58,7 @@ class UniformSuperpositionGate(raw_types.Gate):
58
58
  self._m_value = m_value
59
59
  self._num_qubits = num_qubits
60
60
 
61
- def _decompose_(self, qubits: Sequence["cirq.Qid"]) -> "cirq.OP_TREE":
61
+ def _decompose_(self, qubits: Sequence["cirq.Qid"]) -> Iterator["cirq.OP_TREE"]:
62
62
  """Decomposes the gate into a sequence of standard gates.
63
63
  Implements the construction from https://arxiv.org/pdf/2306.11747.
64
64
  """