cirq-core 1.7.0.dev20251002223432__py3-none-any.whl → 1.7.0.dev20251003181338__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 (58) hide show
  1. cirq/_doc.py +4 -3
  2. cirq/_version.py +1 -1
  3. cirq/_version_test.py +1 -1
  4. cirq/linalg/decompositions.py +3 -0
  5. cirq/linalg/decompositions_test.py +1 -0
  6. cirq/ops/fourier_transform_test.py +2 -4
  7. cirq/ops/raw_types.py +3 -0
  8. cirq/protocols/apply_unitary_protocol_test.py +2 -0
  9. cirq/protocols/kraus_protocol.py +3 -3
  10. cirq/protocols/kraus_protocol_test.py +2 -2
  11. cirq/protocols/unitary_protocol.py +1 -1
  12. cirq/testing/consistent_resolve_parameters.py +1 -1
  13. cirq/testing/consistent_unitary.py +1 -1
  14. cirq/testing/consistent_unitary_test.py +1 -1
  15. cirq/testing/equals_tester.py +2 -2
  16. cirq/testing/equivalent_basis_map.py +3 -1
  17. cirq/testing/json.py +1 -1
  18. cirq/testing/op_tree.py +1 -1
  19. cirq/testing/order_tester.py +2 -2
  20. cirq/testing/repr_pretty_tester.py +3 -3
  21. cirq/transformers/align_test.py +13 -13
  22. cirq/transformers/analytical_decompositions/clifford_decomposition.py +8 -8
  23. cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +5 -5
  24. cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +11 -11
  25. cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +6 -6
  26. cirq/transformers/analytical_decompositions/cphase_to_fsim.py +1 -1
  27. cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +10 -9
  28. cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +5 -5
  29. cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +17 -18
  30. cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +32 -26
  31. cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +1 -1
  32. cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +12 -11
  33. cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +3 -1
  34. cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +3 -3
  35. cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +2 -2
  36. cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +32 -30
  37. cirq/transformers/drop_negligible_operations_test.py +7 -7
  38. cirq/transformers/dynamical_decoupling_test.py +22 -22
  39. cirq/transformers/eject_phased_paulis_test.py +1 -1
  40. cirq/transformers/eject_z.py +2 -2
  41. cirq/transformers/eject_z_test.py +23 -25
  42. cirq/transformers/expand_composite.py +1 -1
  43. cirq/transformers/expand_composite_test.py +14 -14
  44. cirq/transformers/gauge_compiling/gauge_compiling.py +1 -1
  45. cirq/transformers/gauge_compiling/gauge_compiling_test.py +14 -12
  46. cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +3 -3
  47. cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +6 -6
  48. cirq/transformers/measurement_transformers_test.py +45 -39
  49. cirq/transformers/merge_k_qubit_gates_test.py +1 -1
  50. cirq/transformers/merge_single_qubit_gates_test.py +22 -22
  51. cirq/transformers/noise_adding_test.py +2 -2
  52. cirq/transformers/optimize_for_target_gateset_test.py +11 -9
  53. cirq/transformers/qubit_management_transformers_test.py +6 -2
  54. {cirq_core-1.7.0.dev20251002223432.dist-info → cirq_core-1.7.0.dev20251003181338.dist-info}/METADATA +1 -1
  55. {cirq_core-1.7.0.dev20251002223432.dist-info → cirq_core-1.7.0.dev20251003181338.dist-info}/RECORD +58 -58
  56. {cirq_core-1.7.0.dev20251002223432.dist-info → cirq_core-1.7.0.dev20251003181338.dist-info}/WHEEL +0 -0
  57. {cirq_core-1.7.0.dev20251002223432.dist-info → cirq_core-1.7.0.dev20251003181338.dist-info}/licenses/LICENSE +0 -0
  58. {cirq_core-1.7.0.dev20251002223432.dist-info → cirq_core-1.7.0.dev20251003181338.dist-info}/top_level.txt +0 -0
@@ -15,6 +15,7 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import itertools
18
+ from typing import Iterator
18
19
 
19
20
  import numpy as np
20
21
  import pytest
@@ -23,11 +24,11 @@ import sympy
23
24
  import cirq
24
25
 
25
26
 
26
- def random_unitary(seed):
27
+ def random_unitary(seed: cirq.RANDOM_STATE_OR_SEED_LIKE) -> np.ndarray:
27
28
  return cirq.testing.random_unitary(4, random_state=seed)
28
29
 
29
30
 
30
- def random_locals(x, y, z, seed=None):
31
+ def random_locals(x: float, y: float, z: float, seed=None) -> np.ndarray:
31
32
  rng = np.random.RandomState(seed)
32
33
  a0 = cirq.testing.random_unitary(2, random_state=rng)
33
34
  a1 = cirq.testing.random_unitary(2, random_state=rng)
@@ -42,15 +43,14 @@ def random_locals(x, y, z, seed=None):
42
43
  )
43
44
 
44
45
 
45
- def perturbations_unitary(u, amount=1e-10):
46
+ def perturbations_unitary(u: np.ndarray, amount=1e-10) -> Iterator[np.ndarray]:
46
47
  """Returns several unitaries in the neighborhood of u to test for numerical
47
48
  corner cases near critical values."""
48
49
  kak = cirq.kak_decomposition(u)
49
50
  yield u
50
51
  for i in range(3):
51
52
  for neg in (-1, 1):
52
- perturb_xyz = list(kak.interaction_coefficients)
53
- perturb_xyz[i] += neg * amount
53
+ perturb_xyz = tuple(c + neg * amount for c in kak.interaction_coefficients)
54
54
  yield cirq.unitary(
55
55
  cirq.KakDecomposition(
56
56
  global_phase=kak.global_phase,
@@ -61,11 +61,11 @@ def perturbations_unitary(u, amount=1e-10):
61
61
  )
62
62
 
63
63
 
64
- def perturbations_gate(gate, amount=1e-10):
64
+ def perturbations_gate(gate: cirq.SupportsUnitary, amount=1e-10) -> Iterator[np.ndarray]:
65
65
  return perturbations_unitary(cirq.unitary(gate), amount)
66
66
 
67
67
 
68
- def perturbations_weyl(x, y, z, amount=1e-10):
68
+ def perturbations_weyl(x: float, y: float, z: float, amount: float = 1e-10) -> Iterator[np.ndarray]:
69
69
  return perturbations_gate(cirq.KakDecomposition(interaction_coefficients=(x, y, z)), amount)
70
70
 
71
71
 
@@ -211,7 +211,7 @@ def assert_valid_decomp(
211
211
  atol=1e-6,
212
212
  rtol=0,
213
213
  qubit_order=cirq.LineQubit.range(2),
214
- ):
214
+ ) -> None:
215
215
  # Check expected gates
216
216
  for op in operations:
217
217
  if len(op.qubits) == 0 and isinstance(op.gate, cirq.GlobalPhaseGate):
@@ -242,7 +242,7 @@ def assert_valid_decomp(
242
242
  )
243
243
 
244
244
 
245
- def assert_specific_sqrt_iswap_count(operations, count):
245
+ def assert_specific_sqrt_iswap_count(operations, count) -> None:
246
246
  actual = sum(len(op.qubits) == 2 for op in operations)
247
247
  assert actual == count, f'Incorrect sqrt-iSWAP count. Expected {count} but got {actual}.'
248
248
 
@@ -255,7 +255,7 @@ def assert_specific_sqrt_iswap_count(operations, count):
255
255
  cirq.CZPowGate(exponent=sympy.Symbol('t')),
256
256
  ],
257
257
  )
258
- def test_two_qubit_gates_with_symbols(gate: cirq.Gate):
258
+ def test_two_qubit_gates_with_symbols(gate: cirq.Gate) -> None:
259
259
  op = gate(*cirq.LineQubit.range(2))
260
260
  c_new_sqrt_iswap = cirq.Circuit(
261
261
  cirq.parameterized_2q_op_to_sqrt_iswap_operations(op) # type: ignore
@@ -279,12 +279,14 @@ def test_two_qubit_gates_with_symbols(gate: cirq.Gate):
279
279
  )
280
280
 
281
281
 
282
- def test_fsim_gate_with_symbols():
282
+ def test_fsim_gate_with_symbols() -> None:
283
283
  theta, phi = sympy.symbols(['theta', 'phi'])
284
284
  op = cirq.FSimGate(theta=theta, phi=phi).on(*cirq.LineQubit.range(2))
285
- c_new_sqrt_iswap = cirq.Circuit(cirq.parameterized_2q_op_to_sqrt_iswap_operations(op))
285
+ c_new_sqrt_iswap = cirq.Circuit(
286
+ cirq.parameterized_2q_op_to_sqrt_iswap_operations(op) # type: ignore[arg-type]
287
+ )
286
288
  c_new_sqrt_iswap_inv = cirq.Circuit(
287
- cirq.parameterized_2q_op_to_sqrt_iswap_operations(op, use_sqrt_iswap_inv=True)
289
+ cirq.parameterized_2q_op_to_sqrt_iswap_operations(op, use_sqrt_iswap_inv=True) # type: ignore[arg-type]
288
290
  )
289
291
  for theta_val in np.linspace(0, 2 * np.pi, 4):
290
292
  for phi_val in np.linspace(0, 2 * np.pi, 6):
@@ -307,7 +309,7 @@ def test_fsim_gate_with_symbols():
307
309
 
308
310
 
309
311
  @pytest.mark.parametrize('cnt', [-1, 4, 10])
310
- def test_invalid_required_sqrt_iswap_count(cnt):
312
+ def test_invalid_required_sqrt_iswap_count(cnt) -> None:
311
313
  u = TWO_SQRT_ISWAP_UNITARIES[0]
312
314
  q0, q1 = cirq.LineQubit.range(2)
313
315
  with pytest.raises(ValueError, match='required_sqrt_iswap_count'):
@@ -315,7 +317,7 @@ def test_invalid_required_sqrt_iswap_count(cnt):
315
317
 
316
318
 
317
319
  @pytest.mark.parametrize('u', ZERO_UNITARIES)
318
- def test_decomp0(u):
320
+ def test_decomp0(u) -> None:
319
321
  # Decompose unitaries into zero sqrt-iSWAP gates
320
322
  q0, q1 = cirq.LineQubit.range(2)
321
323
  ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, required_sqrt_iswap_count=0)
@@ -326,7 +328,7 @@ def test_decomp0(u):
326
328
  @pytest.mark.parametrize(
327
329
  'u', ONE_SQRT_ISWAP_UNITARIES + TWO_SQRT_ISWAP_UNITARIES + THREE_SQRT_ISWAP_UNITARIES
328
330
  )
329
- def test_decomp0_invalid(u):
331
+ def test_decomp0_invalid(u) -> None:
330
332
  # Attempt to decompose other unitaries into zero SQRT_ISWAP gates
331
333
  q0, q1 = cirq.LineQubit.range(2)
332
334
  with pytest.raises(ValueError, match='cannot be decomposed into exactly 0 sqrt-iSWAP gates'):
@@ -334,7 +336,7 @@ def test_decomp0_invalid(u):
334
336
 
335
337
 
336
338
  @pytest.mark.parametrize('u', ONE_SQRT_ISWAP_UNITARIES)
337
- def test_decomp1(u):
339
+ def test_decomp1(u) -> None:
338
340
  q0, q1 = cirq.LineQubit.range(2)
339
341
  ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, required_sqrt_iswap_count=1)
340
342
  assert_valid_decomp(u, ops)
@@ -344,14 +346,14 @@ def test_decomp1(u):
344
346
  @pytest.mark.parametrize(
345
347
  'u', ZERO_UNITARIES + TWO_SQRT_ISWAP_UNITARIES + THREE_SQRT_ISWAP_UNITARIES
346
348
  )
347
- def test_decomp1_invalid(u):
349
+ def test_decomp1_invalid(u) -> None:
348
350
  q0, q1 = cirq.LineQubit.range(2)
349
351
  with pytest.raises(ValueError, match='cannot be decomposed into exactly 1 sqrt-iSWAP gates'):
350
352
  cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, required_sqrt_iswap_count=1)
351
353
 
352
354
 
353
355
  @pytest.mark.parametrize('u', ZERO_UNITARIES + ONE_SQRT_ISWAP_UNITARIES + TWO_SQRT_ISWAP_UNITARIES)
354
- def test_decomp2(u):
356
+ def test_decomp2(u) -> None:
355
357
  q0, q1 = cirq.LineQubit.range(2)
356
358
  ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, required_sqrt_iswap_count=2)
357
359
  assert_valid_decomp(u, ops)
@@ -359,7 +361,7 @@ def test_decomp2(u):
359
361
 
360
362
 
361
363
  @pytest.mark.parametrize('u', THREE_SQRT_ISWAP_UNITARIES)
362
- def test_decomp2_invalid(u):
364
+ def test_decomp2_invalid(u) -> None:
363
365
  q0, q1 = cirq.LineQubit.range(2)
364
366
  with pytest.raises(ValueError, match='cannot be decomposed into exactly 2 sqrt-iSWAP gates'):
365
367
  cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, required_sqrt_iswap_count=2)
@@ -372,14 +374,14 @@ def test_decomp2_invalid(u):
372
374
  + TWO_SQRT_ISWAP_UNITARIES
373
375
  + THREE_SQRT_ISWAP_UNITARIES,
374
376
  )
375
- def test_decomp3(u):
377
+ def test_decomp3(u) -> None:
376
378
  q0, q1 = cirq.LineQubit.range(2)
377
379
  ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, required_sqrt_iswap_count=3)
378
380
  assert_valid_decomp(u, ops)
379
381
  assert_specific_sqrt_iswap_count(ops, 3)
380
382
 
381
383
 
382
- def test_decomp3_invalid():
384
+ def test_decomp3_invalid() -> None:
383
385
  # All two-qubit gates can be synthesized with three SQRT_ISWAP gates
384
386
  u = cirq.unitary(cirq.X**0.2) # Pass an invalid size unitary
385
387
  q0, q1 = cirq.LineQubit.range(2)
@@ -388,7 +390,7 @@ def test_decomp3_invalid():
388
390
 
389
391
 
390
392
  @pytest.mark.parametrize('u', TWO_SQRT_ISWAP_UNITARIES[:1])
391
- def test_qubit_order(u):
393
+ def test_qubit_order(u) -> None:
392
394
  q0, q1 = cirq.LineQubit.range(2)
393
395
  ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q1, q0, u, required_sqrt_iswap_count=2)
394
396
  assert_valid_decomp(u, ops, qubit_order=(q1, q0))
@@ -396,7 +398,7 @@ def test_qubit_order(u):
396
398
 
397
399
 
398
400
  @pytest.mark.parametrize('u', ZERO_UNITARIES)
399
- def test_decomp_optimal0(u):
401
+ def test_decomp_optimal0(u) -> None:
400
402
  q0, q1 = cirq.LineQubit.range(2)
401
403
  ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u)
402
404
  assert_valid_decomp(u, ops)
@@ -404,7 +406,7 @@ def test_decomp_optimal0(u):
404
406
 
405
407
 
406
408
  @pytest.mark.parametrize('u', ONE_SQRT_ISWAP_UNITARIES)
407
- def test_decomp_optimal1(u):
409
+ def test_decomp_optimal1(u) -> None:
408
410
  q0, q1 = cirq.LineQubit.range(2)
409
411
  ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u)
410
412
  assert_valid_decomp(u, ops)
@@ -412,7 +414,7 @@ def test_decomp_optimal1(u):
412
414
 
413
415
 
414
416
  @pytest.mark.parametrize('u', TWO_SQRT_ISWAP_UNITARIES)
415
- def test_decomp_optimal2(u):
417
+ def test_decomp_optimal2(u) -> None:
416
418
  q0, q1 = cirq.LineQubit.range(2)
417
419
  ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u)
418
420
  assert_valid_decomp(u, ops)
@@ -420,7 +422,7 @@ def test_decomp_optimal2(u):
420
422
 
421
423
 
422
424
  @pytest.mark.parametrize('u', THREE_SQRT_ISWAP_UNITARIES)
423
- def test_decomp_optimal3(u):
425
+ def test_decomp_optimal3(u) -> None:
424
426
  q0, q1 = cirq.LineQubit.range(2)
425
427
  ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u)
426
428
  assert_valid_decomp(u, ops)
@@ -428,7 +430,7 @@ def test_decomp_optimal3(u):
428
430
 
429
431
 
430
432
  @pytest.mark.parametrize('u', ALL_REGION_UNITARIES)
431
- def test_all_weyl_regions(u):
433
+ def test_all_weyl_regions(u) -> None:
432
434
  q0, q1 = cirq.LineQubit.range(2)
433
435
  ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, clean_operations=True)
434
436
  assert_valid_decomp(u, ops, single_qubit_gate_types=(cirq.PhasedXZGate,))
@@ -445,13 +447,13 @@ def test_all_weyl_regions(u):
445
447
  THREE_SQRT_ISWAP_UNITARIES[0],
446
448
  ],
447
449
  )
448
- def test_decomp_sqrt_iswap_inv(u):
450
+ def test_decomp_sqrt_iswap_inv(u) -> None:
449
451
  q0, q1 = cirq.LineQubit.range(2)
450
452
  ops = cirq.two_qubit_matrix_to_sqrt_iswap_operations(q0, q1, u, use_sqrt_iswap_inv=True)
451
453
  assert_valid_decomp(u, ops, two_qubit_gate=cirq.SQRT_ISWAP_INV)
452
454
 
453
455
 
454
- def test_valid_check_raises():
456
+ def test_valid_check_raises() -> None:
455
457
  q0 = cirq.LineQubit(0)
456
458
  with pytest.raises(AssertionError, match='Unitaries are completely different'):
457
459
  assert_valid_decomp(np.eye(4), [cirq.X(q0)], single_qubit_gate_types=(cirq.XPowGate,))
@@ -19,13 +19,13 @@ import cirq
19
19
  NO_COMPILE_TAG = "no_compile_tag"
20
20
 
21
21
 
22
- def test_leaves_big():
22
+ def test_leaves_big() -> None:
23
23
  a = cirq.NamedQubit('a')
24
24
  circuit = cirq.Circuit(cirq.Moment(cirq.Z(a) ** 0.1))
25
25
  cirq.testing.assert_same_circuits(cirq.drop_negligible_operations(circuit, atol=0.001), circuit)
26
26
 
27
27
 
28
- def test_clears_small():
28
+ def test_clears_small() -> None:
29
29
  a = cirq.NamedQubit('a')
30
30
  circuit = cirq.Circuit(cirq.Moment(cirq.Z(a) ** 0.000001))
31
31
  cirq.testing.assert_same_circuits(
@@ -33,7 +33,7 @@ def test_clears_small():
33
33
  )
34
34
 
35
35
 
36
- def test_does_not_clear_small_no_compile():
36
+ def test_does_not_clear_small_no_compile() -> None:
37
37
  a = cirq.NamedQubit('a')
38
38
  circuit = cirq.Circuit(cirq.Moment((cirq.Z(a) ** 0.000001).with_tags(NO_COMPILE_TAG)))
39
39
  cirq.testing.assert_same_circuits(
@@ -44,7 +44,7 @@ def test_does_not_clear_small_no_compile():
44
44
  )
45
45
 
46
46
 
47
- def test_clears_known_empties_even_at_zero_tolerance():
47
+ def test_clears_known_empties_even_at_zero_tolerance() -> None:
48
48
  a, b = cirq.LineQubit.range(2)
49
49
  circuit = cirq.Circuit(
50
50
  cirq.Z(a) ** 0, cirq.Y(a) ** 0.0000001, cirq.X(a) ** -0.0000001, cirq.CZ(a, b) ** 0
@@ -63,7 +63,7 @@ def test_clears_known_empties_even_at_zero_tolerance():
63
63
  )
64
64
 
65
65
 
66
- def test_recursively_runs_inside_circuit_ops_deep():
66
+ def test_recursively_runs_inside_circuit_ops_deep() -> None:
67
67
  a = cirq.NamedQubit('a')
68
68
  small_op = cirq.Z(a) ** 0.000001
69
69
  nested_circuit = cirq.FrozenCircuit(
@@ -92,13 +92,13 @@ def test_recursively_runs_inside_circuit_ops_deep():
92
92
  ),
93
93
  cirq.Moment(),
94
94
  )
95
- context = cirq.TransformerContext(tags_to_ignore=[NO_COMPILE_TAG], deep=True)
95
+ context = cirq.TransformerContext(tags_to_ignore=(NO_COMPILE_TAG,), deep=True)
96
96
  cirq.testing.assert_same_circuits(
97
97
  cirq.drop_negligible_operations(c_orig, context=context, atol=0.001), c_expected
98
98
  )
99
99
 
100
100
 
101
- def test_ignores_large_ops():
101
+ def test_ignores_large_ops() -> None:
102
102
  qnum = 20
103
103
  qubits = cirq.LineQubit.range(qnum)
104
104
  subcircuit = cirq.FrozenCircuit(cirq.X.on_each(*qubits))
@@ -23,7 +23,7 @@ import cirq
23
23
  from cirq import add_dynamical_decoupling, CNOT, CZ, CZPowGate, H, X, Y, Z
24
24
 
25
25
 
26
- def assert_sim_eq(circuit1: cirq.AbstractCircuit, circuit2: cirq.AbstractCircuit):
26
+ def assert_sim_eq(circuit1: cirq.AbstractCircuit, circuit2: cirq.AbstractCircuit) -> None:
27
27
  # Simulate 2 circuits and compare final states.
28
28
  sampler = cirq.Simulator(dtype=np.complex128)
29
29
  psi0 = sampler.simulate(cirq.drop_terminal_measurements(circuit1)).final_state_vector
@@ -37,7 +37,7 @@ def assert_dd(
37
37
  expected_circuit: str | cirq.AbstractCircuit,
38
38
  schema: str | tuple[cirq.Gate, ...] = 'DEFAULT',
39
39
  single_qubit_gate_moments_only: bool = True,
40
- ):
40
+ ) -> None:
41
41
  transformed_circuit = add_dynamical_decoupling(
42
42
  input_circuit, schema=schema, single_qubit_gate_moments_only=single_qubit_gate_moments_only
43
43
  ).freeze()
@@ -53,7 +53,7 @@ def assert_dd(
53
53
  assert_sim_eq(input_circuit, transformed_circuit)
54
54
 
55
55
 
56
- def test_no_insertion():
56
+ def test_no_insertion() -> None:
57
57
  """Test case diagrams.
58
58
  Input:
59
59
  a: ───H───@───────
@@ -81,7 +81,7 @@ def test_no_insertion():
81
81
  'schema,inserted_gates',
82
82
  [('XX_PAIR', (X, X)), ('X_XINV', (X, X**-1)), ('YY_PAIR', (Y, Y)), ('Y_YINV', (Y, Y**-1))],
83
83
  )
84
- def test_insert_provided_schema(schema: str, inserted_gates: Sequence[cirq.Gate]):
84
+ def test_insert_provided_schema(schema: str, inserted_gates: Sequence[cirq.Gate]) -> None:
85
85
  """Test case diagrams.
86
86
  Input:
87
87
  a: ───H───@───────────M───
@@ -113,7 +113,7 @@ def test_insert_provided_schema(schema: str, inserted_gates: Sequence[cirq.Gate]
113
113
  assert_dd(input_circuit, expected_circuit, schema=schema, single_qubit_gate_moments_only=False)
114
114
 
115
115
 
116
- def test_insert_by_customized_dd_sequence():
116
+ def test_insert_by_customized_dd_sequence() -> None:
117
117
  """Test case diagrams.
118
118
  Input:
119
119
  a: ───H───@───────────────────H───
@@ -151,13 +151,13 @@ def test_insert_by_customized_dd_sequence():
151
151
  cirq.Moment(CNOT(b, c), Y(a)),
152
152
  cirq.Moment([H(qubit) for qubit in [a, b, c]]),
153
153
  ),
154
- schema=[X, X, Y, Y],
154
+ schema=(X, X, Y, Y),
155
155
  single_qubit_gate_moments_only=False,
156
156
  )
157
157
 
158
158
 
159
159
  @pytest.mark.parametrize('single_qubit_gate_moments_only', [True, False])
160
- def test_pull_through_h_gate_case1(single_qubit_gate_moments_only: bool):
160
+ def test_pull_through_h_gate_case1(single_qubit_gate_moments_only: bool) -> None:
161
161
  """Test case diagrams.
162
162
  Input:
163
163
  a: ───H───────H───────@───
@@ -193,7 +193,7 @@ def test_pull_through_h_gate_case1(single_qubit_gate_moments_only: bool):
193
193
 
194
194
 
195
195
  @pytest.mark.parametrize('single_qubit_gate_moments_only', [True, False])
196
- def test_pull_through_h_gate_case2(single_qubit_gate_moments_only: bool):
196
+ def test_pull_through_h_gate_case2(single_qubit_gate_moments_only: bool) -> None:
197
197
  """Test case diagrams.
198
198
  Input:
199
199
  a: ───H───────H───────H───
@@ -246,14 +246,14 @@ def test_pull_through_h_gate_case2(single_qubit_gate_moments_only: bool):
246
246
  ),
247
247
  ],
248
248
  )
249
- def test_invalid_dd_schema(schema: str | tuple[cirq.Gate, ...], error_msg_regex):
249
+ def test_invalid_dd_schema(schema: str | tuple[cirq.Gate, ...], error_msg_regex) -> None:
250
250
  a = cirq.NamedQubit('a')
251
251
  input_circuit = cirq.Circuit(H(a))
252
252
  with pytest.raises(ValueError, match=error_msg_regex):
253
253
  add_dynamical_decoupling(input_circuit, schema=schema, single_qubit_gate_moments_only=False)
254
254
 
255
255
 
256
- def test_single_qubit_gate_moments_only_no_updates_succeeds():
256
+ def test_single_qubit_gate_moments_only_no_updates_succeeds() -> None:
257
257
  qubits = cirq.LineQubit.range(9)
258
258
  input_circuit = cirq.Circuit(
259
259
  cirq.Moment([H(qubits[i]) for i in [3, 4, 5]]),
@@ -269,7 +269,7 @@ def test_single_qubit_gate_moments_only_no_updates_succeeds():
269
269
  add_dynamical_decoupling(input_circuit, schema='X_XINV', single_qubit_gate_moments_only=True)
270
270
 
271
271
 
272
- def test_scattered_circuit():
272
+ def test_scattered_circuit() -> None:
273
273
  """Test case diagrams.
274
274
  Input:
275
275
  0: ───────────────────────────────H───@───H───
@@ -424,7 +424,7 @@ def test_scattered_circuit():
424
424
  )
425
425
 
426
426
 
427
- def test_scattered_circuit2():
427
+ def test_scattered_circuit2() -> None:
428
428
  """Test case diagrams.
429
429
  Input:
430
430
  0: ───────────────────@───
@@ -484,7 +484,7 @@ def test_scattered_circuit2():
484
484
  )
485
485
 
486
486
 
487
- def test_pull_through_chain():
487
+ def test_pull_through_chain() -> None:
488
488
  """Test case diagrams.
489
489
  Input:
490
490
  0: ───X───────×───────────X───
@@ -526,7 +526,7 @@ def test_pull_through_chain():
526
526
  )
527
527
 
528
528
 
529
- def test_multiple_clifford_pieces_case1():
529
+ def test_multiple_clifford_pieces_case1() -> None:
530
530
  """Test case diagrams.
531
531
  Input:
532
532
  a: ───H───────H───────@───────────H───────H───
@@ -560,7 +560,7 @@ b: ───H───H───H───H───────@^0.5───H
560
560
  )
561
561
 
562
562
 
563
- def test_multiple_clifford_pieces_case2():
563
+ def test_multiple_clifford_pieces_case2() -> None:
564
564
  """Test case diagrams.
565
565
  Input:
566
566
  a: ───@───PhXZ(a=0.3,x=0.2,z=0)───PhXZ(a=0.3,x=0.2,z=0)───PhXZ(a=0.3,x=0.2,z=0)───@───
@@ -596,7 +596,7 @@ def test_multiple_clifford_pieces_case2():
596
596
  )
597
597
 
598
598
 
599
- def test_insert_new_moment():
599
+ def test_insert_new_moment() -> None:
600
600
  """Test case diagrams.
601
601
  Input:
602
602
  a: ───H───────H───@───@───────
@@ -637,7 +637,7 @@ def test_insert_new_moment():
637
637
  )
638
638
 
639
639
 
640
- def test_with_non_clifford_measurements():
640
+ def test_with_non_clifford_measurements() -> None:
641
641
  """Test case diagrams.
642
642
  Input:
643
643
  0: ───────────H───@───H───M───
@@ -672,7 +672,7 @@ def test_with_non_clifford_measurements():
672
672
  )
673
673
 
674
674
 
675
- def test_cross_clifford_pieces_filling_merge():
675
+ def test_cross_clifford_pieces_filling_merge() -> None:
676
676
  """Test case diagrams.
677
677
  Input:
678
678
  0: ─────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───@─────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───@───PhXZ(a=0.2,x=0.2,z=0.1)───H───
@@ -738,7 +738,7 @@ def test_cross_clifford_pieces_filling_merge():
738
738
  )
739
739
 
740
740
 
741
- def test_pull_through_phxz_gate_case1():
741
+ def test_pull_through_phxz_gate_case1() -> None:
742
742
  """Test case diagrams.
743
743
  Input:
744
744
  a: ───H───────PhXZ(a=0.25,x=-1,z=0)───────@───
@@ -767,7 +767,7 @@ b: ───H───H───H───────────────
767
767
  )
768
768
 
769
769
 
770
- def test_pull_through_phxz_gate_case2():
770
+ def test_pull_through_phxz_gate_case2() -> None:
771
771
  """Test case diagrams.
772
772
  Input:
773
773
  a: ───H───────PhXZ(a=0.2,x=-1,z=0)───────@───
@@ -796,7 +796,7 @@ b: ───H───H───H───────────────
796
796
  )
797
797
 
798
798
 
799
- def test_merge_before_non_cliffords():
799
+ def test_merge_before_non_cliffords() -> None:
800
800
  """Test case diagrams.
801
801
  Input circuit:
802
802
  0: ───X──────────────────────────────────────────────────M───
@@ -860,7 +860,7 @@ def test_merge_before_non_cliffords():
860
860
  )
861
861
  def test_single_qubit_gate_moments_only_true_vs_false(
862
862
  single_qubit_gate_moments_only, expected_diagram
863
- ):
863
+ ) -> None:
864
864
  q0, q1, q2 = cirq.LineQubit.range(3)
865
865
  input_circuit = cirq.Circuit(
866
866
  cirq.Moment([X(q) for q in [q0, q1, q2]]),
@@ -31,7 +31,7 @@ def assert_optimizes(
31
31
  eject_parameterized: bool = False,
32
32
  *,
33
33
  with_context: bool = False,
34
- ):
34
+ ) -> None:
35
35
  context = cirq.TransformerContext(tags_to_ignore=("nocompile",)) if with_context else None
36
36
  circuit = cirq.eject_phased_paulis(
37
37
  before, eject_parameterized=eject_parameterized, context=context
@@ -29,11 +29,11 @@ if TYPE_CHECKING:
29
29
  import cirq
30
30
 
31
31
 
32
- def _is_integer(n):
32
+ def _is_integer(n) -> bool:
33
33
  return np.isclose(n, np.round(n))
34
34
 
35
35
 
36
- def _is_swaplike(gate: cirq.Gate):
36
+ def _is_swaplike(gate: cirq.Gate) -> bool:
37
37
  if isinstance(gate, ops.SwapPowGate):
38
38
  return gate.exponent == 1
39
39