cirq-core 1.7.0.dev20250818230756__py3-none-any.whl → 1.7.0.dev20250820205919__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/experiments/z_phase_calibration_test.py +8 -7
  4. cirq/interop/quirk/cells/arithmetic_cells.py +1 -1
  5. cirq/interop/quirk/cells/cell_test.py +5 -5
  6. cirq/interop/quirk/cells/composite_cell_test.py +5 -3
  7. cirq/interop/quirk/cells/control_cells.py +2 -2
  8. cirq/interop/quirk/cells/input_cells.py +3 -3
  9. cirq/interop/quirk/cells/input_rotation_cells.py +2 -2
  10. cirq/interop/quirk/cells/swap_cell.py +2 -2
  11. cirq/interop/quirk/cells/testing.py +1 -1
  12. cirq/interop/quirk/url_to_circuit.py +2 -2
  13. cirq/interop/quirk/url_to_circuit_test.py +11 -11
  14. cirq/linalg/decompositions.py +1 -1
  15. cirq/linalg/decompositions_test.py +52 -50
  16. cirq/linalg/diagonalize_test.py +2 -2
  17. cirq/linalg/predicates.py +1 -1
  18. cirq/linalg/predicates_test.py +24 -24
  19. cirq/linalg/transformations.py +6 -4
  20. cirq/neutral_atoms/neutral_atom_devices.py +1 -1
  21. cirq/ops/classically_controlled_operation.py +2 -2
  22. cirq/ops/clifford_gate.py +1 -1
  23. cirq/ops/common_channels_test.py +1 -1
  24. cirq/ops/common_gates.py +2 -2
  25. cirq/ops/controlled_operation.py +2 -2
  26. cirq/ops/controlled_operation_test.py +17 -16
  27. cirq/ops/dense_pauli_string_test.py +41 -37
  28. cirq/ops/eigen_gate_test.py +0 -7
  29. cirq/ops/gateset.py +3 -3
  30. cirq/ops/gateset_test.py +23 -23
  31. cirq/ops/linear_combinations.py +1 -1
  32. cirq/ops/linear_combinations_test.py +103 -89
  33. cirq/ops/matrix_gates_test.py +31 -31
  34. cirq/ops/measure_util_test.py +11 -10
  35. cirq/ops/measurement_gate_test.py +23 -22
  36. cirq/ops/pauli_gates.py +1 -1
  37. cirq/ops/pauli_measurement_gate_test.py +12 -12
  38. cirq/ops/pauli_string_phasor_test.py +45 -40
  39. cirq/ops/pauli_string_raw_types_test.py +5 -4
  40. cirq/ops/pauli_string_test.py +190 -118
  41. cirq/ops/permutation_gate.py +1 -1
  42. cirq/ops/raw_types.py +3 -4
  43. cirq/ops/raw_types_test.py +1 -1
  44. cirq/ops/three_qubit_gates.py +3 -3
  45. cirq/protocols/act_on_protocol.py +1 -1
  46. cirq/protocols/act_on_protocol_test.py +4 -4
  47. cirq/protocols/apply_channel_protocol_test.py +19 -18
  48. cirq/protocols/apply_mixture_protocol_test.py +20 -19
  49. cirq/protocols/apply_unitary_protocol_test.py +31 -23
  50. cirq/protocols/approximate_equality_protocol_test.py +22 -16
  51. cirq/protocols/circuit_diagram_info_protocol.py +4 -4
  52. cirq/protocols/commutes_protocol_test.py +4 -4
  53. {cirq_core-1.7.0.dev20250818230756.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/METADATA +1 -1
  54. {cirq_core-1.7.0.dev20250818230756.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/RECORD +57 -57
  55. {cirq_core-1.7.0.dev20250818230756.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/WHEEL +0 -0
  56. {cirq_core-1.7.0.dev20250818230756.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/licenses/LICENSE +0 -0
  57. {cirq_core-1.7.0.dev20250818230756.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/top_level.txt +0 -0
cirq/_version.py CHANGED
@@ -28,4 +28,4 @@ if sys.version_info < (3, 11, 0): # pragma: no cover
28
28
  'of Cirq (e.g. "python -m pip install cirq==1.5.0")'
29
29
  )
30
30
 
31
- __version__ = "1.7.0.dev20250818230756"
31
+ __version__ = "1.7.0.dev20250820205919"
cirq/_version_test.py CHANGED
@@ -3,4 +3,4 @@ import cirq
3
3
 
4
4
 
5
5
  def test_version() -> None:
6
- assert cirq.__version__ == "1.7.0.dev20250818230756"
6
+ assert cirq.__version__ == "1.7.0.dev20250820205919"
@@ -88,7 +88,7 @@ class _TestSimulator(cirq.Simulator):
88
88
  @pytest.mark.parametrize(
89
89
  ['angles', 'error', 'characterization_flags'], _create_tests(n=10, with_options=True)
90
90
  )
91
- def test_calibrate_z_phases(angles, error, characterization_flags):
91
+ def test_calibrate_z_phases(angles, error, characterization_flags) -> None:
92
92
 
93
93
  original_gate = cirq.PhasedFSimGate(**{k: v for k, v in zip(_ANGLES, angles)})
94
94
  actual_gate = cirq.PhasedFSimGate(**{k: v + e for k, v, e in zip(_ANGLES, angles, error)})
@@ -127,7 +127,7 @@ def test_calibrate_z_phases(angles, error, characterization_flags):
127
127
 
128
128
 
129
129
  @pytest.mark.parametrize(['angles', 'error'], _create_tests(n=3))
130
- def test_calibrate_z_phases_no_options(angles, error):
130
+ def test_calibrate_z_phases_no_options(angles, error) -> None:
131
131
 
132
132
  original_gate = cirq.PhasedFSimGate(**{k: v for k, v in zip(_ANGLES, angles)})
133
133
  actual_gate = cirq.PhasedFSimGate(**{k: v + e for k, v, e in zip(_ANGLES, angles, error)})
@@ -162,7 +162,7 @@ def test_calibrate_z_phases_no_options(angles, error):
162
162
 
163
163
 
164
164
  @pytest.mark.parametrize(['angles', 'error'], _create_tests(n=3))
165
- def test_calibrate_z_phases_workflow_no_options(angles, error):
165
+ def test_calibrate_z_phases_workflow_no_options(angles, error) -> None:
166
166
 
167
167
  original_gate = cirq.PhasedFSimGate(**{k: v for k, v in zip(_ANGLES, angles)})
168
168
  actual_gate = cirq.PhasedFSimGate(**{k: v + e for k, v, e in zip(_ANGLES, angles, error)})
@@ -189,7 +189,7 @@ def test_calibrate_z_phases_workflow_no_options(angles, error):
189
189
  assert 'theta' not in params
190
190
 
191
191
 
192
- def test_plot_z_phase_calibration_result():
192
+ def test_plot_z_phase_calibration_result() -> None:
193
193
  df = pd.DataFrame()
194
194
  qs = cirq.q(0, 0), cirq.q(0, 1), cirq.q(0, 2)
195
195
  df.index = [qs[:2], qs[-2:]]
@@ -211,13 +211,14 @@ def test_plot_z_phase_calibration_result():
211
211
 
212
212
 
213
213
  @pytest.mark.parametrize('angles', 2 * np.pi * np.random.random((10, 10)))
214
- def test_transform_circuit(angles):
214
+ def test_transform_circuit(angles) -> None:
215
215
  theta, phi = angles[:2]
216
216
  old_zs = angles[2:6]
217
217
  new_zs = angles[6:]
218
218
  gate = cirq.PhasedFSimGate.from_fsim_rz(theta, phi, old_zs[:2], old_zs[2:])
219
219
  fsim = cirq.PhasedFSimGate.from_fsim_rz(theta, phi, new_zs[:2], new_zs[2:])
220
220
  c = cirq.Circuit(gate(cirq.q(0), cirq.q(1)))
221
+ replacement_map: dict[tuple[cirq.Qid, cirq.Qid], cirq.PhasedFSimGate]
221
222
  replacement_map = {(cirq.q(1), cirq.q(0)): fsim}
222
223
 
223
224
  new_circuit = CalibrationTransformer(gate, replacement_map)(c)
@@ -230,11 +231,11 @@ def test_transform_circuit(angles):
230
231
  np.testing.assert_allclose(cirq.unitary(circuit_with_replacement_gate), cirq.unitary(c))
231
232
 
232
233
 
233
- def test_transform_circuit_invalid_gate_raises():
234
+ def test_transform_circuit_invalid_gate_raises() -> None:
234
235
  with pytest.raises(ValueError, match="is not equivalent to a PhasedFSimGate"):
235
236
  _ = CalibrationTransformer(cirq.XX, {})
236
237
 
237
238
 
238
- def test_transform_circuit_uncalibrated_gates_pass():
239
+ def test_transform_circuit_uncalibrated_gates_pass() -> None:
239
240
  c = cirq.Circuit(cirq.CZ(cirq.q(0), cirq.q(1)), cirq.measure(cirq.q(0)))
240
241
  assert c == CalibrationTransformer(cirq.CZ, {})(c)
@@ -205,7 +205,7 @@ class ArithmeticCell(Cell):
205
205
  )
206
206
 
207
207
  @property
208
- def operation(self):
208
+ def operation(self) -> _QuirkArithmeticCallable:
209
209
  return ARITHMETIC_OP_TABLE[self.identifier]
210
210
 
211
211
  def with_input(self, letter: str, register: Sequence[cirq.Qid] | int) -> ArithmeticCell:
@@ -20,7 +20,7 @@ import cirq
20
20
  from cirq.interop.quirk.cells.cell import Cell, ExplicitOperationsCell
21
21
 
22
22
 
23
- def test_cell_defaults():
23
+ def test_cell_defaults() -> None:
24
24
  class BasicCell(Cell):
25
25
  def with_line_qubits_mapped_to(self, qubits):
26
26
  raise NotImplementedError()
@@ -32,12 +32,12 @@ def test_cell_defaults():
32
32
  assert c.operations() == ()
33
33
  assert c.basis_change() == ()
34
34
  assert c.controlled_by(cirq.LineQubit(0)) is c
35
- x = []
35
+ x: list[Cell | None] = []
36
36
  c.modify_column(x)
37
37
  assert x == []
38
38
 
39
39
 
40
- def test_cell_replace_utils():
40
+ def test_cell_replace_utils() -> None:
41
41
  a, b, c = cirq.NamedQubit.range(3, prefix='q')
42
42
  assert Cell._replace_qubit(cirq.LineQubit(1), [a, b, c]) == b
43
43
  with pytest.raises(ValueError, match='only map from line qubits'):
@@ -48,7 +48,7 @@ def test_cell_replace_utils():
48
48
  _ = Cell._replace_qubit(cirq.LineQubit(999), [a, b, c])
49
49
 
50
50
 
51
- def test_explicit_operations_cell_equality():
51
+ def test_explicit_operations_cell_equality() -> None:
52
52
  a = cirq.LineQubit(0)
53
53
  eq = cirq.testing.EqualsTester()
54
54
  eq.add_equality_group(ExplicitOperationsCell([], []), ExplicitOperationsCell([]))
@@ -56,7 +56,7 @@ def test_explicit_operations_cell_equality():
56
56
  eq.add_equality_group(ExplicitOperationsCell([], [cirq.Y(a)]))
57
57
 
58
58
 
59
- def test_explicit_operations_cell():
59
+ def test_explicit_operations_cell() -> None:
60
60
  a, b = cirq.LineQubit.range(2)
61
61
  v = ExplicitOperationsCell([cirq.X(a)], [cirq.S(a)])
62
62
  assert v.operations() == (cirq.X(a),)
@@ -14,6 +14,8 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
+ from typing import Iterable
18
+
17
19
  import pytest
18
20
 
19
21
  import cirq
@@ -22,7 +24,7 @@ from cirq.interop.quirk.cells.composite_cell import _iterator_to_iterable
22
24
  from cirq.interop.quirk.cells.testing import assert_url_to_circuit_returns
23
25
 
24
26
 
25
- def test_iterator_to_iterable():
27
+ def test_iterator_to_iterable() -> None:
26
28
  k = 0
27
29
 
28
30
  def counter():
@@ -32,7 +34,7 @@ def test_iterator_to_iterable():
32
34
 
33
35
  # Normal iterator usage.
34
36
  k = 0
35
- generator = (counter() for _ in range(10))
37
+ generator: Iterable[int] = (counter() for _ in range(10))
36
38
  assert k == 0
37
39
  assert list(generator) == list(range(10))
38
40
  assert k == 10
@@ -73,7 +75,7 @@ def test_iterator_to_iterable():
73
75
  assert k == 10
74
76
 
75
77
 
76
- def test_custom_circuit_gate():
78
+ def test_custom_circuit_gate() -> None:
77
79
  a, b, c, d, e = cirq.LineQubit.range(5)
78
80
 
79
81
  # Without name.
@@ -53,7 +53,7 @@ class ControlCell(Cell):
53
53
  ),
54
54
  )
55
55
 
56
- def modify_column(self, column: list[Cell | None]):
56
+ def modify_column(self, column: list[Cell | None]) -> None:
57
57
  for i in range(len(column)):
58
58
  gate = column[i]
59
59
  if gate is not None:
@@ -97,7 +97,7 @@ class ParityControlCell(Cell):
97
97
  ),
98
98
  )
99
99
 
100
- def modify_column(self, column: list[Cell | None]):
100
+ def modify_column(self, column: list[Cell | None]) -> None:
101
101
  for i in range(len(column)):
102
102
  gate = column[i]
103
103
  if gate is self:
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Iterable, Iterator, TYPE_CHECKING
17
+ from typing import Callable, Iterable, Iterator, TYPE_CHECKING
18
18
 
19
19
  from cirq.interop.quirk.cells.cell import Cell, CELL_SIZES, CellMaker
20
20
 
@@ -35,7 +35,7 @@ class InputCell(Cell):
35
35
  def with_line_qubits_mapped_to(self, qubits: list[cirq.Qid]) -> Cell:
36
36
  return InputCell(qubits=Cell._replace_qubits(self.qubits, qubits), letter=self.letter)
37
37
 
38
- def modify_column(self, column: list[Cell | None]):
38
+ def modify_column(self, column: list[Cell | None]) -> None:
39
39
  for i in range(len(column)):
40
40
  cell = column[i]
41
41
  if cell is not None:
@@ -55,7 +55,7 @@ class SetDefaultInputCell(Cell):
55
55
  def with_line_qubits_mapped_to(self, qubits: list[cirq.Qid]) -> Cell:
56
56
  return self
57
57
 
58
- def persistent_modifiers(self):
58
+ def persistent_modifiers(self) -> dict[str, Callable[[Cell], Cell]]:
59
59
  return {f'set_default_{self.letter}': lambda cell: cell.with_input(self.letter, self.value)}
60
60
 
61
61
 
@@ -77,7 +77,7 @@ class InputRotationCell(Cell):
77
77
  )
78
78
  return self
79
79
 
80
- def controlled_by(self, qubit: cirq.Qid):
80
+ def controlled_by(self, qubit: cirq.Qid) -> InputRotationCell:
81
81
  return InputRotationCell(
82
82
  self.identifier,
83
83
  self.register,
@@ -118,7 +118,7 @@ class QuirkInputRotationOperation(ops.Operation):
118
118
  def qubits(self) -> tuple[cirq.Qid, ...]:
119
119
  return tuple(self.base_operation.qubits) + self.register
120
120
 
121
- def with_qubits(self, *new_qubits):
121
+ def with_qubits(self, *new_qubits) -> QuirkInputRotationOperation:
122
122
  k = len(self.base_operation.qubits)
123
123
  new_op_qubits = new_qubits[:k]
124
124
  new_register = new_qubits[k:]
@@ -38,7 +38,7 @@ class SwapCell(Cell):
38
38
  controls=Cell._replace_qubits(self._controls, qubits),
39
39
  )
40
40
 
41
- def modify_column(self, column: list[Cell | None]):
41
+ def modify_column(self, column: list[Cell | None]) -> None:
42
42
  # Swallow other swap cells.
43
43
  for i in range(len(column)):
44
44
  gate = column[i]
@@ -52,7 +52,7 @@ class SwapCell(Cell):
52
52
  raise ValueError('Wrong number of swap gates in a column.')
53
53
  return ops.SWAP(*self._qubits).controlled_by(*self._controls)
54
54
 
55
- def controlled_by(self, qubit: cirq.Qid):
55
+ def controlled_by(self, qubit: cirq.Qid) -> SwapCell:
56
56
  return SwapCell(self._qubits, self._controls + [qubit])
57
57
 
58
58
  def _value_equality_values_(self) -> Any:
@@ -28,7 +28,7 @@ def assert_url_to_circuit_returns(
28
28
  diagram: str | None = None,
29
29
  output_amplitudes_from_quirk: list[dict[str, float]] | None = None,
30
30
  maps: dict[int, int] | None = None,
31
- ):
31
+ ) -> None:
32
32
  """Assert that `quirk_url_to_circuit` functions correctly.
33
33
 
34
34
  Args:
@@ -39,7 +39,7 @@ def quirk_url_to_circuit(
39
39
  quirk_url: str,
40
40
  *,
41
41
  qubits: Sequence[cirq.Qid] | None = None,
42
- extra_cell_makers: dict[str, cirq.Gate] | Iterable[cirq.interop.quirk.cells.CellMaker] = (),
42
+ extra_cell_makers: Mapping[str, cirq.Gate] | Iterable[cirq.interop.quirk.cells.CellMaker] = (),
43
43
  max_operation_count: int = 10**6,
44
44
  ) -> cirq.Circuit:
45
45
  """Parses a Cirq circuit out of a Quirk URL.
@@ -140,7 +140,7 @@ def quirk_json_to_circuit(
140
140
  data: dict,
141
141
  *,
142
142
  qubits: Sequence[cirq.Qid] | None = None,
143
- extra_cell_makers: dict[str, cirq.Gate] | Iterable[cirq.interop.quirk.cells.CellMaker] = (),
143
+ extra_cell_makers: Mapping[str, cirq.Gate] | Iterable[cirq.interop.quirk.cells.CellMaker] = (),
144
144
  quirk_url: str | None = None,
145
145
  max_operation_count: int = 10**6,
146
146
  ) -> cirq.Circuit:
@@ -25,7 +25,7 @@ from cirq import quirk_json_to_circuit, quirk_url_to_circuit
25
25
  from cirq.interop.quirk.cells.testing import assert_url_to_circuit_returns
26
26
 
27
27
 
28
- def test_parse_simple_cases():
28
+ def test_parse_simple_cases() -> None:
29
29
  a, b = cirq.LineQubit.range(2)
30
30
 
31
31
  assert quirk_url_to_circuit('http://algassert.com/quirk') == cirq.Circuit()
@@ -47,7 +47,7 @@ def test_parse_simple_cases():
47
47
  ('http://algassert.com/quirk#circuit=', json.JSONDecodeError, None),
48
48
  ],
49
49
  )
50
- def test_parse_url_failures(url, error_cls, msg):
50
+ def test_parse_url_failures(url, error_cls, msg) -> None:
51
51
  with pytest.raises(error_cls, match=msg):
52
52
  _ = quirk_url_to_circuit(url)
53
53
 
@@ -70,7 +70,7 @@ def test_parse_url_failures(url, error_cls, msg):
70
70
  ),
71
71
  ],
72
72
  )
73
- def test_parse_failures(url, msg):
73
+ def test_parse_failures(url, msg) -> None:
74
74
  parsed_url = urllib.parse.urlparse(url)
75
75
  data = json.loads(parsed_url.fragment[len('circuit=') :])
76
76
 
@@ -81,7 +81,7 @@ def test_parse_failures(url, msg):
81
81
  _ = quirk_json_to_circuit(data)
82
82
 
83
83
 
84
- def test_parse_with_qubits():
84
+ def test_parse_with_qubits() -> None:
85
85
  a = cirq.GridQubit(0, 0)
86
86
  b = cirq.GridQubit(0, 1)
87
87
  c = cirq.GridQubit(0, 2)
@@ -103,7 +103,7 @@ def test_parse_with_qubits():
103
103
  )
104
104
 
105
105
 
106
- def test_extra_cell_makers():
106
+ def test_extra_cell_makers() -> None:
107
107
  assert cirq.quirk_url_to_circuit(
108
108
  'http://algassert.com/quirk#circuit={"cols":[["iswap"]]}',
109
109
  extra_cell_makers=[
@@ -140,7 +140,7 @@ def test_extra_cell_makers():
140
140
  )
141
141
 
142
142
 
143
- def test_init():
143
+ def test_init() -> None:
144
144
  b, c, d, e, f = cirq.LineQubit.range(1, 6)
145
145
  assert_url_to_circuit_returns(
146
146
  '{"cols":[],"init":[0,1,"+","-","i","-i"]}',
@@ -176,7 +176,7 @@ def test_init():
176
176
  _ = cirq.quirk_url_to_circuit('http://algassert.com/quirk#circuit={"cols":[],"init":[2]}')
177
177
 
178
178
 
179
- def test_custom_gate_parse_failures():
179
+ def test_custom_gate_parse_failures() -> None:
180
180
  with pytest.raises(ValueError, match='must be a list'):
181
181
  _ = quirk_url_to_circuit('https://algassert.com/quirk#circuit={"cols":[],"gates":5}')
182
182
 
@@ -229,7 +229,7 @@ def test_custom_gate_parse_failures():
229
229
  )
230
230
 
231
231
 
232
- def test_custom_matrix_gate():
232
+ def test_custom_matrix_gate() -> None:
233
233
  a, b = cirq.LineQubit.range(2)
234
234
 
235
235
  # Without name.
@@ -259,7 +259,7 @@ def test_custom_matrix_gate():
259
259
  )
260
260
 
261
261
 
262
- def test_survives_a_billion_laughs():
262
+ def test_survives_a_billion_laughs() -> None:
263
263
  # If this test is timing out, it means you made a change that accidentally
264
264
  # iterated over the circuit contents before they were counted and checked
265
265
  # against the maximum. It is not possible to test for the billion laughs
@@ -301,7 +301,7 @@ def test_survives_a_billion_laughs():
301
301
  )
302
302
 
303
303
 
304
- def test_completes_weight_zero_billion_laughs():
304
+ def test_completes_weight_zero_billion_laughs() -> None:
305
305
  circuit = cirq.quirk_url_to_circuit(
306
306
  'https://algassert.com/quirk#circuit={'
307
307
  '"cols":[["~z"]],'
@@ -339,7 +339,7 @@ def test_completes_weight_zero_billion_laughs():
339
339
  assert circuit == cirq.Circuit()
340
340
 
341
341
 
342
- def test_example_qft_circuit():
342
+ def test_example_qft_circuit() -> None:
343
343
  qft_example_diagram = """
344
344
  0: ───×───────────────H───@───────────@────────────────────@──────────────────────────────@─────────────────────────────────────────@───────────────────────────────────────────────────@─────────────────────────────────────────────────────────────@───────────────────────────────────────────────────────────────────────
345
345
  │ │ │ │ │ │ │ │
@@ -518,7 +518,7 @@ def scatter_plot_normalized_kak_interaction_coefficients(
518
518
  include_frame: bool = True,
519
519
  ax: mplot3d.axes3d.Axes3D | None = None,
520
520
  **kwargs,
521
- ):
521
+ ) -> mplot3d.axes3d.Axes3D:
522
522
  r"""Plots the interaction coefficients of many two-qubit operations.
523
523
 
524
524
  Plots: