cirq-core 1.6.0.dev20250521011052__py3-none-any.whl → 1.6.0.dev20250522221502__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 (77) hide show
  1. cirq/_version.py +1 -1
  2. cirq/_version_test.py +1 -1
  3. cirq/circuits/circuit.py +3 -3
  4. cirq/circuits/circuit_operation_test.py +1 -2
  5. cirq/contrib/acquaintance/devices.py +2 -2
  6. cirq/contrib/acquaintance/inspection_utils.py +2 -2
  7. cirq/contrib/qasm_import/_lexer.py +1 -2
  8. cirq/contrib/routing/router.py +3 -3
  9. cirq/devices/device.py +4 -4
  10. cirq/experiments/fidelity_estimation.py +4 -4
  11. cirq/experiments/t1_decay_experiment.py +2 -2
  12. cirq/experiments/xeb_fitting.py +1 -1
  13. cirq/interop/quirk/cells/measurement_cells.py +2 -2
  14. cirq/linalg/combinators.py +3 -3
  15. cirq/linalg/decompositions.py +1 -1
  16. cirq/linalg/predicates.py +2 -2
  17. cirq/linalg/tolerance.py +2 -2
  18. cirq/ops/arithmetic_operation.py +5 -5
  19. cirq/ops/arithmetic_operation_test.py +2 -4
  20. cirq/ops/common_gate_families.py +7 -7
  21. cirq/ops/controlled_gate_test.py +2 -2
  22. cirq/ops/controlled_operation_test.py +2 -2
  23. cirq/ops/linear_combinations_test.py +8 -9
  24. cirq/ops/op_tree.py +1 -1
  25. cirq/ops/qid_util.py +2 -2
  26. cirq/ops/qubit_order_or_list.py +2 -2
  27. cirq/ops/raw_types.py +1 -1
  28. cirq/protocols/act_on_protocol.py +4 -4
  29. cirq/protocols/commutes_protocol.py +5 -7
  30. cirq/protocols/control_key_protocol.py +4 -4
  31. cirq/protocols/decompose_protocol_test.py +1 -2
  32. cirq/protocols/has_stabilizer_effect_protocol.py +5 -5
  33. cirq/protocols/has_unitary_protocol.py +5 -5
  34. cirq/protocols/pauli_expansion_protocol.py +3 -3
  35. cirq/protocols/pow_protocol.py +5 -5
  36. cirq/protocols/trace_distance_bound.py +4 -4
  37. cirq/protocols/unitary_protocol.py +7 -7
  38. cirq/protocols/unitary_protocol_test.py +1 -3
  39. cirq/qis/entropy.py +2 -2
  40. cirq/sim/clifford/clifford_tableau_simulation_state.py +4 -4
  41. cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +5 -5
  42. cirq/sim/clifford/stabilizer_simulation_state.py +5 -5
  43. cirq/sim/density_matrix_simulator_test.py +45 -46
  44. cirq/sim/sparse_simulator_test.py +38 -39
  45. cirq/sim/state_vector_simulation_state_test.py +2 -2
  46. cirq/sim/state_vector_test.py +3 -3
  47. cirq/study/sweepable.py +5 -5
  48. cirq/testing/consistent_act_on.py +5 -7
  49. cirq/testing/consistent_controlled_gate_op.py +3 -5
  50. cirq/testing/deprecation.py +2 -2
  51. cirq/testing/lin_alg_utils.py +2 -2
  52. cirq/transformers/align.py +3 -3
  53. cirq/transformers/drop_empty_moments.py +2 -2
  54. cirq/transformers/drop_negligible_operations.py +2 -2
  55. cirq/transformers/expand_composite.py +2 -2
  56. cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +3 -3
  57. cirq/transformers/merge_k_qubit_gates.py +5 -5
  58. cirq/transformers/merge_single_qubit_gates.py +5 -5
  59. cirq/transformers/optimize_for_target_gateset.py +6 -6
  60. cirq/transformers/optimize_for_target_gateset_test.py +3 -3
  61. cirq/transformers/tag_transformers.py +5 -5
  62. cirq/transformers/target_gatesets/cz_gateset_test.py +2 -2
  63. cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +1 -3
  64. cirq/transformers/transformer_api_test.py +7 -8
  65. cirq/value/abc_alt.py +2 -2
  66. cirq/value/abc_alt_test.py +3 -3
  67. cirq/value/angle.py +7 -7
  68. cirq/value/type_alias.py +3 -5
  69. cirq/vis/density_matrix.py +2 -4
  70. cirq/vis/histogram.py +6 -6
  71. cirq/vis/state_histogram.py +7 -7
  72. cirq/work/observable_readout_calibration.py +2 -2
  73. {cirq_core-1.6.0.dev20250521011052.dist-info → cirq_core-1.6.0.dev20250522221502.dist-info}/METADATA +1 -1
  74. {cirq_core-1.6.0.dev20250521011052.dist-info → cirq_core-1.6.0.dev20250522221502.dist-info}/RECORD +77 -77
  75. {cirq_core-1.6.0.dev20250521011052.dist-info → cirq_core-1.6.0.dev20250522221502.dist-info}/WHEEL +0 -0
  76. {cirq_core-1.6.0.dev20250521011052.dist-info → cirq_core-1.6.0.dev20250522221502.dist-info}/licenses/LICENSE +0 -0
  77. {cirq_core-1.6.0.dev20250521011052.dist-info → cirq_core-1.6.0.dev20250522221502.dist-info}/top_level.txt +0 -0
@@ -16,7 +16,6 @@ from __future__ import annotations
16
16
 
17
17
  import itertools
18
18
  import random
19
- from typing import Type, Union
20
19
  from unittest import mock
21
20
 
22
21
  import numpy as np
@@ -33,7 +32,7 @@ def test_invalid_dtype():
33
32
 
34
33
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
35
34
  @pytest.mark.parametrize('split', [True, False])
36
- def test_run_no_measurements(dtype: Type[np.complexfloating], split: bool):
35
+ def test_run_no_measurements(dtype: type[np.complexfloating], split: bool):
37
36
  q0, q1 = cirq.LineQubit.range(2)
38
37
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
39
38
 
@@ -44,7 +43,7 @@ def test_run_no_measurements(dtype: Type[np.complexfloating], split: bool):
44
43
 
45
44
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
46
45
  @pytest.mark.parametrize('split', [True, False])
47
- def test_run_no_results(dtype: Type[np.complexfloating], split: bool):
46
+ def test_run_no_results(dtype: type[np.complexfloating], split: bool):
48
47
  q0, q1 = cirq.LineQubit.range(2)
49
48
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
50
49
 
@@ -55,7 +54,7 @@ def test_run_no_results(dtype: Type[np.complexfloating], split: bool):
55
54
 
56
55
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
57
56
  @pytest.mark.parametrize('split', [True, False])
58
- def test_run_empty_circuit(dtype: Type[np.complexfloating], split: bool):
57
+ def test_run_empty_circuit(dtype: type[np.complexfloating], split: bool):
59
58
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
60
59
  with pytest.raises(ValueError, match="no measurements"):
61
60
  simulator.run(cirq.Circuit())
@@ -63,7 +62,7 @@ def test_run_empty_circuit(dtype: Type[np.complexfloating], split: bool):
63
62
 
64
63
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
65
64
  @pytest.mark.parametrize('split', [True, False])
66
- def test_run_reset(dtype: Type[np.complexfloating], split: bool):
65
+ def test_run_reset(dtype: type[np.complexfloating], split: bool):
67
66
  q0, q1 = cirq.LineQid.for_qid_shape((2, 3))
68
67
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
69
68
  circuit = cirq.Circuit(
@@ -83,7 +82,7 @@ def test_run_reset(dtype: Type[np.complexfloating], split: bool):
83
82
 
84
83
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
85
84
  @pytest.mark.parametrize('split', [True, False])
86
- def test_run_bit_flips(dtype: Type[np.complexfloating], split: bool):
85
+ def test_run_bit_flips(dtype: type[np.complexfloating], split: bool):
87
86
  q0, q1 = cirq.LineQubit.range(2)
88
87
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
89
88
  for b0 in [0, 1]:
@@ -97,7 +96,7 @@ def test_run_bit_flips(dtype: Type[np.complexfloating], split: bool):
97
96
 
98
97
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
99
98
  @pytest.mark.parametrize('split', [True, False])
100
- def test_run_measure_at_end_no_repetitions(dtype: Type[np.complexfloating], split: bool):
99
+ def test_run_measure_at_end_no_repetitions(dtype: type[np.complexfloating], split: bool):
101
100
  q0, q1 = cirq.LineQubit.range(2)
102
101
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
103
102
  with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
@@ -123,7 +122,7 @@ def test_run_repetitions_terminal_measurement_stochastic():
123
122
 
124
123
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
125
124
  @pytest.mark.parametrize('split', [True, False])
126
- def test_run_repetitions_measure_at_end(dtype: Type[np.complexfloating], split: bool):
125
+ def test_run_repetitions_measure_at_end(dtype: type[np.complexfloating], split: bool):
127
126
  q0, q1 = cirq.LineQubit.range(2)
128
127
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
129
128
  with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
@@ -143,7 +142,7 @@ def test_run_repetitions_measure_at_end(dtype: Type[np.complexfloating], split:
143
142
 
144
143
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
145
144
  @pytest.mark.parametrize('split', [True, False])
146
- def test_run_invert_mask_measure_not_terminal(dtype: Type[np.complexfloating], split: bool):
145
+ def test_run_invert_mask_measure_not_terminal(dtype: type[np.complexfloating], split: bool):
147
146
  q0, q1 = cirq.LineQubit.range(2)
148
147
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
149
148
  with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
@@ -164,7 +163,7 @@ def test_run_invert_mask_measure_not_terminal(dtype: Type[np.complexfloating], s
164
163
 
165
164
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
166
165
  @pytest.mark.parametrize('split', [True, False])
167
- def test_run_partial_invert_mask_measure_not_terminal(dtype: Type[np.complexfloating], split: bool):
166
+ def test_run_partial_invert_mask_measure_not_terminal(dtype: type[np.complexfloating], split: bool):
168
167
  q0, q1 = cirq.LineQubit.range(2)
169
168
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
170
169
  with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
@@ -185,7 +184,7 @@ def test_run_partial_invert_mask_measure_not_terminal(dtype: Type[np.complexfloa
185
184
 
186
185
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
187
186
  @pytest.mark.parametrize('split', [True, False])
188
- def test_run_measurement_not_terminal_no_repetitions(dtype: Type[np.complexfloating], split: bool):
187
+ def test_run_measurement_not_terminal_no_repetitions(dtype: type[np.complexfloating], split: bool):
189
188
  q0, q1 = cirq.LineQubit.range(2)
190
189
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
191
190
  with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
@@ -209,7 +208,7 @@ def test_run_measurement_not_terminal_no_repetitions(dtype: Type[np.complexfloat
209
208
 
210
209
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
211
210
  @pytest.mark.parametrize('split', [True, False])
212
- def test_run_repetitions_measurement_not_terminal(dtype: Type[np.complexfloating], split: bool):
211
+ def test_run_repetitions_measurement_not_terminal(dtype: type[np.complexfloating], split: bool):
213
212
  q0, q1 = cirq.LineQubit.range(2)
214
213
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
215
214
  with mock.patch.object(simulator, '_core_iterator', wraps=simulator._core_iterator) as mock_sim:
@@ -234,7 +233,7 @@ def test_run_repetitions_measurement_not_terminal(dtype: Type[np.complexfloating
234
233
 
235
234
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
236
235
  @pytest.mark.parametrize('split', [True, False])
237
- def test_run_param_resolver(dtype: Type[np.complexfloating], split: bool):
236
+ def test_run_param_resolver(dtype: type[np.complexfloating], split: bool):
238
237
  q0, q1 = cirq.LineQubit.range(2)
239
238
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
240
239
  for b0 in [0, 1]:
@@ -253,7 +252,7 @@ def test_run_param_resolver(dtype: Type[np.complexfloating], split: bool):
253
252
 
254
253
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
255
254
  @pytest.mark.parametrize('split', [True, False])
256
- def test_run_mixture(dtype: Type[np.complexfloating], split: bool):
255
+ def test_run_mixture(dtype: type[np.complexfloating], split: bool):
257
256
  q0 = cirq.LineQubit(0)
258
257
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
259
258
  circuit = cirq.Circuit(cirq.bit_flip(0.5)(q0), cirq.measure(q0))
@@ -263,7 +262,7 @@ def test_run_mixture(dtype: Type[np.complexfloating], split: bool):
263
262
 
264
263
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
265
264
  @pytest.mark.parametrize('split', [True, False])
266
- def test_run_mixture_with_gates(dtype: Type[np.complexfloating], split: bool):
265
+ def test_run_mixture_with_gates(dtype: type[np.complexfloating], split: bool):
267
266
  q0 = cirq.LineQubit(0)
268
267
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split, seed=23)
269
268
  circuit = cirq.Circuit(cirq.H(q0), cirq.phase_flip(0.5)(q0), cirq.H(q0), cirq.measure(q0))
@@ -274,7 +273,7 @@ def test_run_mixture_with_gates(dtype: Type[np.complexfloating], split: bool):
274
273
 
275
274
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
276
275
  @pytest.mark.parametrize('split', [True, False])
277
- def test_run_correlations(dtype: Type[np.complexfloating], split: bool):
276
+ def test_run_correlations(dtype: type[np.complexfloating], split: bool):
278
277
  q0, q1 = cirq.LineQubit.range(2)
279
278
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
280
279
  circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1), cirq.measure(q0, q1))
@@ -286,7 +285,7 @@ def test_run_correlations(dtype: Type[np.complexfloating], split: bool):
286
285
 
287
286
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
288
287
  @pytest.mark.parametrize('split', [True, False])
289
- def test_run_measure_multiple_qubits(dtype: Type[np.complexfloating], split: bool):
288
+ def test_run_measure_multiple_qubits(dtype: type[np.complexfloating], split: bool):
290
289
  q0, q1 = cirq.LineQubit.range(2)
291
290
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
292
291
  for b0 in [0, 1]:
@@ -298,7 +297,7 @@ def test_run_measure_multiple_qubits(dtype: Type[np.complexfloating], split: boo
298
297
 
299
298
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
300
299
  @pytest.mark.parametrize('split', [True, False])
301
- def test_run_sweeps_param_resolvers(dtype: Type[np.complexfloating], split: bool):
300
+ def test_run_sweeps_param_resolvers(dtype: type[np.complexfloating], split: bool):
302
301
  q0, q1 = cirq.LineQubit.range(2)
303
302
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
304
303
  for b0 in [0, 1]:
@@ -324,7 +323,7 @@ def test_run_sweeps_param_resolvers(dtype: Type[np.complexfloating], split: bool
324
323
 
325
324
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
326
325
  @pytest.mark.parametrize('split', [True, False])
327
- def test_simulate_random_unitary(dtype: Type[np.complexfloating], split: bool):
326
+ def test_simulate_random_unitary(dtype: type[np.complexfloating], split: bool):
328
327
  q0, q1 = cirq.LineQubit.range(2)
329
328
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
330
329
  for _ in range(10):
@@ -342,7 +341,7 @@ def test_simulate_random_unitary(dtype: Type[np.complexfloating], split: bool):
342
341
 
343
342
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
344
343
  @pytest.mark.parametrize('split', [True, False])
345
- def test_simulate_no_circuit(dtype: Type[np.complexfloating], split: bool):
344
+ def test_simulate_no_circuit(dtype: type[np.complexfloating], split: bool):
346
345
  q0, q1 = cirq.LineQubit.range(2)
347
346
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
348
347
  circuit = cirq.Circuit()
@@ -353,7 +352,7 @@ def test_simulate_no_circuit(dtype: Type[np.complexfloating], split: bool):
353
352
 
354
353
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
355
354
  @pytest.mark.parametrize('split', [True, False])
356
- def test_simulate(dtype: Type[np.complexfloating], split: bool):
355
+ def test_simulate(dtype: type[np.complexfloating], split: bool):
357
356
  q0, q1 = cirq.LineQubit.range(2)
358
357
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
359
358
  circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1))
@@ -375,7 +374,7 @@ class _TestMixture(cirq.Gate):
375
374
 
376
375
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
377
376
  @pytest.mark.parametrize('split', [True, False])
378
- def test_simulate_qudits(dtype: Type[np.complexfloating], split: bool):
377
+ def test_simulate_qudits(dtype: type[np.complexfloating], split: bool):
379
378
  q0, q1 = cirq.LineQid.for_qid_shape((3, 4))
380
379
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
381
380
  circuit = cirq.Circuit(cirq.XPowGate(dimension=3)(q0), cirq.XPowGate(dimension=4)(q1) ** 3)
@@ -388,7 +387,7 @@ def test_simulate_qudits(dtype: Type[np.complexfloating], split: bool):
388
387
 
389
388
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
390
389
  @pytest.mark.parametrize('split', [True, False])
391
- def test_simulate_mixtures(dtype: Type[np.complexfloating], split: bool):
390
+ def test_simulate_mixtures(dtype: type[np.complexfloating], split: bool):
392
391
  q0 = cirq.LineQubit(0)
393
392
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
394
393
  circuit = cirq.Circuit(cirq.bit_flip(0.5)(q0), cirq.measure(q0))
@@ -406,7 +405,7 @@ def test_simulate_mixtures(dtype: Type[np.complexfloating], split: bool):
406
405
  @pytest.mark.parametrize(
407
406
  'dtype, split', itertools.product([np.complex64, np.complex128], [True, False])
408
407
  )
409
- def test_simulate_qudit_mixtures(dtype: Type[np.complexfloating], split: bool):
408
+ def test_simulate_qudit_mixtures(dtype: type[np.complexfloating], split: bool):
410
409
  q0 = cirq.LineQid(0, 3)
411
410
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
412
411
  mixture = _TestMixture(
@@ -432,7 +431,7 @@ def test_simulate_qudit_mixtures(dtype: Type[np.complexfloating], split: bool):
432
431
 
433
432
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
434
433
  @pytest.mark.parametrize('split', [True, False])
435
- def test_simulate_bit_flips(dtype: Type[np.complexfloating], split: bool):
434
+ def test_simulate_bit_flips(dtype: type[np.complexfloating], split: bool):
436
435
  q0, q1 = cirq.LineQubit.range(2)
437
436
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
438
437
  for b0 in [0, 1]:
@@ -454,9 +453,9 @@ def test_simulate_bit_flips(dtype: Type[np.complexfloating], split: bool):
454
453
  [1, cirq.StateVectorSimulationState(initial_state=1, qubits=cirq.LineQubit.range(2))],
455
454
  )
456
455
  def test_simulate_initial_state(
457
- dtype: Type[np.complexfloating],
456
+ dtype: type[np.complexfloating],
458
457
  split: bool,
459
- initial_state: Union[int, cirq.StateVectorSimulationState],
458
+ initial_state: int | cirq.StateVectorSimulationState,
460
459
  ):
461
460
  q0, q1 = cirq.LineQubit.range(2)
462
461
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
@@ -471,7 +470,7 @@ def test_simulate_initial_state(
471
470
 
472
471
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
473
472
  @pytest.mark.parametrize('split', [True, False])
474
- def test_simulation_state(dtype: Type[np.complexfloating], split: bool):
473
+ def test_simulation_state(dtype: type[np.complexfloating], split: bool):
475
474
  q0, q1 = cirq.LineQubit.range(2)
476
475
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
477
476
  for b0 in [0, 1]:
@@ -486,7 +485,7 @@ def test_simulation_state(dtype: Type[np.complexfloating], split: bool):
486
485
 
487
486
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
488
487
  @pytest.mark.parametrize('split', [True, False])
489
- def test_simulate_qubit_order(dtype: Type[np.complexfloating], split: bool):
488
+ def test_simulate_qubit_order(dtype: type[np.complexfloating], split: bool):
490
489
  q0, q1 = cirq.LineQubit.range(2)
491
490
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
492
491
  for b0 in [0, 1]:
@@ -500,7 +499,7 @@ def test_simulate_qubit_order(dtype: Type[np.complexfloating], split: bool):
500
499
 
501
500
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
502
501
  @pytest.mark.parametrize('split', [True, False])
503
- def test_simulate_param_resolver(dtype: Type[np.complexfloating], split: bool):
502
+ def test_simulate_param_resolver(dtype: type[np.complexfloating], split: bool):
504
503
  q0, q1 = cirq.LineQubit.range(2)
505
504
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
506
505
  for b0 in [0, 1]:
@@ -519,7 +518,7 @@ def test_simulate_param_resolver(dtype: Type[np.complexfloating], split: bool):
519
518
 
520
519
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
521
520
  @pytest.mark.parametrize('split', [True, False])
522
- def test_simulate_measure_multiple_qubits(dtype: Type[np.complexfloating], split: bool):
521
+ def test_simulate_measure_multiple_qubits(dtype: type[np.complexfloating], split: bool):
523
522
  q0, q1 = cirq.LineQubit.range(2)
524
523
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
525
524
  for b0 in [0, 1]:
@@ -531,7 +530,7 @@ def test_simulate_measure_multiple_qubits(dtype: Type[np.complexfloating], split
531
530
 
532
531
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
533
532
  @pytest.mark.parametrize('split', [True, False])
534
- def test_simulate_sweeps_param_resolver(dtype: Type[np.complexfloating], split: bool):
533
+ def test_simulate_sweeps_param_resolver(dtype: type[np.complexfloating], split: bool):
535
534
  q0, q1 = cirq.LineQubit.range(2)
536
535
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
537
536
  for b0 in [0, 1]:
@@ -558,7 +557,7 @@ def test_simulate_sweeps_param_resolver(dtype: Type[np.complexfloating], split:
558
557
 
559
558
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
560
559
  @pytest.mark.parametrize('split', [True, False])
561
- def test_simulate_moment_steps(dtype: Type[np.complexfloating], split: bool):
560
+ def test_simulate_moment_steps(dtype: type[np.complexfloating], split: bool):
562
561
  q0, q1 = cirq.LineQubit.range(2)
563
562
  circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1), cirq.H(q0), cirq.H(q1))
564
563
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
@@ -571,7 +570,7 @@ def test_simulate_moment_steps(dtype: Type[np.complexfloating], split: bool):
571
570
 
572
571
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
573
572
  @pytest.mark.parametrize('split', [True, False])
574
- def test_simulate_moment_steps_empty_circuit(dtype: Type[np.complexfloating], split: bool):
573
+ def test_simulate_moment_steps_empty_circuit(dtype: type[np.complexfloating], split: bool):
575
574
  circuit = cirq.Circuit()
576
575
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
577
576
  step = None
@@ -583,7 +582,7 @@ def test_simulate_moment_steps_empty_circuit(dtype: Type[np.complexfloating], sp
583
582
 
584
583
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
585
584
  @pytest.mark.parametrize('split', [True, False])
586
- def test_simulate_moment_steps_sample(dtype: Type[np.complexfloating], split: bool):
585
+ def test_simulate_moment_steps_sample(dtype: type[np.complexfloating], split: bool):
587
586
  q0, q1 = cirq.LineQubit.range(2)
588
587
  circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1))
589
588
  simulator = cirq.Simulator(dtype=dtype, split_untangled_states=split)
@@ -605,7 +604,7 @@ def test_simulate_moment_steps_sample(dtype: Type[np.complexfloating], split: bo
605
604
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
606
605
  @pytest.mark.parametrize('split', [True, False])
607
606
  def test_simulate_moment_steps_intermediate_measurement(
608
- dtype: Type[np.complexfloating], split: bool
607
+ dtype: type[np.complexfloating], split: bool
609
608
  ):
610
609
  q0 = cirq.LineQubit(0)
611
610
  circuit = cirq.Circuit(cirq.H(q0), cirq.measure(q0), cirq.H(q0))
@@ -623,7 +622,7 @@ def test_simulate_moment_steps_intermediate_measurement(
623
622
 
624
623
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
625
624
  @pytest.mark.parametrize('split', [True, False])
626
- def test_simulate_expectation_values(dtype: Type[np.complexfloating], split: bool):
625
+ def test_simulate_expectation_values(dtype: type[np.complexfloating], split: bool):
627
626
  # Compare with test_expectation_from_state_vector_two_qubit_states
628
627
  # in file: cirq/ops/linear_combinations_test.py
629
628
  q0, q1 = cirq.LineQubit.range(2)
@@ -648,7 +647,7 @@ def test_simulate_expectation_values(dtype: Type[np.complexfloating], split: boo
648
647
 
649
648
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
650
649
  @pytest.mark.parametrize('split', [True, False])
651
- def test_simulate_expectation_values_terminal_measure(dtype: Type[np.complexfloating], split: bool):
650
+ def test_simulate_expectation_values_terminal_measure(dtype: type[np.complexfloating], split: bool):
652
651
  q0 = cirq.LineQubit(0)
653
652
  circuit = cirq.Circuit(cirq.H(q0), cirq.measure(q0))
654
653
  obs = cirq.Z(q0)
@@ -686,7 +685,7 @@ def test_simulate_expectation_values_terminal_measure(dtype: Type[np.complexfloa
686
685
 
687
686
  @pytest.mark.parametrize('dtype', [np.complex64, np.complex128])
688
687
  @pytest.mark.parametrize('split', [True, False])
689
- def test_simulate_expectation_values_qubit_order(dtype: Type[np.complexfloating], split: bool):
688
+ def test_simulate_expectation_values_qubit_order(dtype: type[np.complexfloating], split: bool):
690
689
  q0, q1, q2 = cirq.LineQubit.range(3)
691
690
  circuit = cirq.Circuit(cirq.H(q0), cirq.H(q1), cirq.X(q2))
692
691
  obs = cirq.X(q0) + cirq.X(q1) - cirq.Z(q2)
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import cast, Type
17
+ from typing import cast
18
18
  from unittest import mock
19
19
 
20
20
  import numpy as np
@@ -173,7 +173,7 @@ def test_act_using_adaptive_two_qubit_channel() -> None:
173
173
  qubits=cirq.LineQubit.range(4),
174
174
  prng=mock_prng,
175
175
  initial_state=np.copy(state),
176
- dtype=cast(Type[np.complexfloating], state.dtype),
176
+ dtype=cast(type[np.complexfloating], state.dtype),
177
177
  )
178
178
  cirq.act_on(Decay11(), args, [cirq.LineQubit(1), cirq.LineQubit(3)])
179
179
  return args.target_tensor
@@ -17,7 +17,7 @@
17
17
  from __future__ import annotations
18
18
 
19
19
  import itertools
20
- from typing import Iterator, Optional
20
+ from typing import Iterator
21
21
  from unittest import mock
22
22
 
23
23
  import numpy as np
@@ -37,7 +37,7 @@ def use_np_transpose(request) -> Iterator[bool]:
37
37
 
38
38
  def test_state_mixin():
39
39
  class TestClass(cirq.StateVectorMixin):
40
- def state_vector(self, copy: Optional[bool] = None) -> np.ndarray:
40
+ def state_vector(self, copy: bool | None = None) -> np.ndarray:
41
41
  return np.array([0, 0, 1, 0])
42
42
 
43
43
  qubits = cirq.LineQubit.range(2)
@@ -360,7 +360,7 @@ def test_measure_state_empty_state(use_np_transpose: bool):
360
360
 
361
361
 
362
362
  class BasicStateVector(cirq.StateVectorMixin):
363
- def state_vector(self, copy: Optional[bool] = None) -> np.ndarray:
363
+ def state_vector(self, copy: bool | None = None) -> np.ndarray:
364
364
  return np.array([0, 1, 0, 0])
365
365
 
366
366
 
cirq/study/sweepable.py CHANGED
@@ -17,7 +17,7 @@
17
17
  from __future__ import annotations
18
18
 
19
19
  import warnings
20
- from typing import cast, Iterable, Iterator, Sequence, Union
20
+ from typing import cast, Iterable, Iterator, Sequence
21
21
 
22
22
  from typing_extensions import Protocol
23
23
 
@@ -33,7 +33,7 @@ class _Sweepable(Protocol):
33
33
  """An intermediate class allowing for recursive definition of Sweepable,
34
34
  since recursive union definitions are not yet supported in mypy."""
35
35
 
36
- def __iter__(self) -> Iterator[Union[SweepLike, _Sweepable]]:
36
+ def __iter__(self) -> Iterator[SweepLike | _Sweepable]:
37
37
  pass
38
38
 
39
39
 
@@ -73,9 +73,9 @@ def to_sweeps(sweepable: Sweepable, metadata: dict | None = None) -> list[Sweep]
73
73
 
74
74
 
75
75
  def to_sweep(
76
- sweep_or_resolver_list: Union[
77
- Sweep, ParamResolverOrSimilarType, Iterable[ParamResolverOrSimilarType]
78
- ],
76
+ sweep_or_resolver_list: (
77
+ Sweep | ParamResolverOrSimilarType | Iterable[ParamResolverOrSimilarType]
78
+ ),
79
79
  ) -> Sweep:
80
80
  """Converts the argument into a ``cirq.Sweep``.
81
81
 
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Any, cast, Optional, Type, TYPE_CHECKING
17
+ from typing import Any, cast, TYPE_CHECKING
18
18
 
19
19
  import numpy as np
20
20
 
@@ -52,9 +52,9 @@ def state_vector_has_stabilizer(
52
52
  """
53
53
 
54
54
  qubits = LineQubit.range(protocols.num_qubits(stabilizer))
55
- complex_dtype: Type[np.complexfloating] = np.complex64
55
+ complex_dtype: type[np.complexfloating] = np.complex64
56
56
  if np.issubdtype(state_vector.dtype, np.complexfloating):
57
- complex_dtype = cast(Type[np.complexfloating], state_vector.dtype)
57
+ complex_dtype = cast(type[np.complexfloating], state_vector.dtype)
58
58
  args = state_vector_simulation_state.StateVectorSimulationState(
59
59
  available_buffer=np.empty_like(state_vector),
60
60
  qubits=qubits,
@@ -151,9 +151,7 @@ def assert_all_implemented_act_on_effects_match_unitary(
151
151
  )
152
152
 
153
153
 
154
- def _final_clifford_tableau(
155
- circuit: Circuit, qubit_map
156
- ) -> Optional[clifford_tableau.CliffordTableau]:
154
+ def _final_clifford_tableau(circuit: Circuit, qubit_map) -> clifford_tableau.CliffordTableau | None:
157
155
  """Evolves a default CliffordTableau through the input circuit.
158
156
 
159
157
  Initializes a CliffordTableau with default args for the given qubits and
@@ -181,7 +179,7 @@ def _final_clifford_tableau(
181
179
 
182
180
  def _final_stabilizer_state_ch_form(
183
181
  circuit: Circuit, qubit_map
184
- ) -> Optional[stabilizer_state_ch_form.StabilizerStateChForm]:
182
+ ) -> stabilizer_state_ch_form.StabilizerStateChForm | None:
185
183
  """Evolves a default StabilizerStateChForm through the input circuit.
186
184
 
187
185
  Initializes a StabilizerStateChForm with default args for the given qubits
@@ -14,7 +14,7 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- from typing import Collection, Optional, Sequence, Union
17
+ from typing import Collection, Sequence
18
18
 
19
19
  import numpy as np
20
20
 
@@ -25,7 +25,7 @@ def assert_controlled_and_controlled_by_identical(
25
25
  gate: ops.Gate,
26
26
  *,
27
27
  num_controls: Sequence[int] = (2, 1, 3, 10),
28
- control_values: Optional[Sequence[Optional[Sequence[Union[int, Collection[int]]]]]] = None,
28
+ control_values: Sequence[Sequence[int | Collection[int]] | None] | None = None,
29
29
  ) -> None:
30
30
  """Checks that gate.on().controlled_by() == gate.controlled().on()"""
31
31
  if control_values is not None:
@@ -52,9 +52,7 @@ def assert_controlled_unitary_consistent(gate: ops.Gate):
52
52
 
53
53
 
54
54
  def _assert_gate_consistent(
55
- gate: ops.Gate,
56
- num_controls: int,
57
- control_values: Optional[Sequence[Union[int, Collection[int]]]],
55
+ gate: ops.Gate, num_controls: int, control_values: Sequence[int | Collection[int]] | None
58
56
  ) -> None:
59
57
  gate_controlled = gate.controlled(num_controls, control_values)
60
58
  qubits = devices.LineQid.for_gate(gate_controlled)
@@ -17,13 +17,13 @@ from __future__ import annotations
17
17
  import contextlib
18
18
  import logging
19
19
  import os
20
- from typing import Iterator, Optional
20
+ from typing import Iterator
21
21
 
22
22
  from cirq._compat import ALLOW_DEPRECATION_IN_TEST
23
23
 
24
24
 
25
25
  @contextlib.contextmanager
26
- def assert_deprecated(*msgs: str, deadline: str, count: Optional[int] = 1) -> Iterator[None]:
26
+ def assert_deprecated(*msgs: str, deadline: str, count: int | None = 1) -> Iterator[None]:
27
27
  """Allows deprecated functions, classes, decorators in tests.
28
28
 
29
29
  It acts as a contextmanager that can be used in with statements:
@@ -16,7 +16,7 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- from typing import Optional, TYPE_CHECKING
19
+ from typing import TYPE_CHECKING
20
20
 
21
21
  import numpy as np
22
22
 
@@ -120,7 +120,7 @@ def random_orthogonal(
120
120
 
121
121
 
122
122
  def random_special_unitary(
123
- dim: int, *, random_state: Optional[np.random.RandomState] = None
123
+ dim: int, *, random_state: np.random.RandomState | None = None
124
124
  ) -> np.ndarray:
125
125
  """Returns a random special unitary distributed with Haar measure.
126
126
 
@@ -17,7 +17,7 @@
17
17
  from __future__ import annotations
18
18
 
19
19
  import dataclasses
20
- from typing import Optional, TYPE_CHECKING
20
+ from typing import TYPE_CHECKING
21
21
 
22
22
  from cirq import circuits, ops
23
23
  from cirq.transformers import transformer_api
@@ -28,7 +28,7 @@ if TYPE_CHECKING:
28
28
 
29
29
  @transformer_api.transformer(add_deep_support=True)
30
30
  def align_left(
31
- circuit: cirq.AbstractCircuit, *, context: Optional[cirq.TransformerContext] = None
31
+ circuit: cirq.AbstractCircuit, *, context: cirq.TransformerContext | None = None
32
32
  ) -> cirq.Circuit:
33
33
  """Align gates to the left of the circuit.
34
34
 
@@ -60,7 +60,7 @@ def align_left(
60
60
 
61
61
  @transformer_api.transformer(add_deep_support=True)
62
62
  def align_right(
63
- circuit: cirq.AbstractCircuit, *, context: Optional[cirq.TransformerContext] = None
63
+ circuit: cirq.AbstractCircuit, *, context: cirq.TransformerContext | None = None
64
64
  ) -> cirq.Circuit:
65
65
  """Align gates to the right of the circuit.
66
66
 
@@ -16,7 +16,7 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- from typing import Optional, TYPE_CHECKING
19
+ from typing import TYPE_CHECKING
20
20
 
21
21
  from cirq.transformers import transformer_api, transformer_primitives
22
22
 
@@ -26,7 +26,7 @@ if TYPE_CHECKING:
26
26
 
27
27
  @transformer_api.transformer
28
28
  def drop_empty_moments(
29
- circuit: cirq.AbstractCircuit, *, context: Optional[cirq.TransformerContext] = None
29
+ circuit: cirq.AbstractCircuit, *, context: cirq.TransformerContext | None = None
30
30
  ) -> cirq.Circuit:
31
31
  """Removes empty moments from a circuit.
32
32
 
@@ -16,7 +16,7 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- from typing import Optional, TYPE_CHECKING
19
+ from typing import TYPE_CHECKING
20
20
 
21
21
  from cirq import protocols
22
22
  from cirq.transformers import transformer_api, transformer_primitives
@@ -29,7 +29,7 @@ if TYPE_CHECKING:
29
29
  def drop_negligible_operations(
30
30
  circuit: cirq.AbstractCircuit,
31
31
  *,
32
- context: Optional[cirq.TransformerContext] = None,
32
+ context: cirq.TransformerContext | None = None,
33
33
  atol: float = 1e-8,
34
34
  ) -> cirq.Circuit:
35
35
  """Removes operations with tiny effects.
@@ -16,7 +16,7 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- from typing import Callable, Optional, TYPE_CHECKING
19
+ from typing import Callable, TYPE_CHECKING
20
20
 
21
21
  from cirq import circuits, ops, protocols
22
22
  from cirq.transformers import transformer_api, transformer_primitives
@@ -29,7 +29,7 @@ if TYPE_CHECKING:
29
29
  def expand_composite(
30
30
  circuit: cirq.AbstractCircuit,
31
31
  *,
32
- context: Optional[cirq.TransformerContext] = None,
32
+ context: cirq.TransformerContext | None = None,
33
33
  no_decomp: Callable[[ops.Operation], bool] = (lambda _: False),
34
34
  ):
35
35
  """A transformer that expands composite operations via `cirq.decompose`.
@@ -3,13 +3,13 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import itertools
6
- from typing import Optional, Sequence, Union
6
+ from typing import Sequence
7
7
 
8
8
  import numpy as np
9
9
 
10
10
  from cirq.value import random_state
11
11
 
12
- _RealArraylike = Union[np.ndarray, float]
12
+ _RealArraylike = np.ndarray | float
13
13
 
14
14
 
15
15
  def _single_qubit_unitary(
@@ -48,7 +48,7 @@ def _single_qubit_unitary(
48
48
  def random_qubit_unitary(
49
49
  shape: Sequence[int] = (),
50
50
  randomize_global_phase: bool = False,
51
- rng: Optional[np.random.RandomState] = None,
51
+ rng: np.random.RandomState | None = None,
52
52
  ) -> np.ndarray:
53
53
  """Random qubit unitary distributed over the Haar measure.
54
54
 
@@ -16,7 +16,7 @@
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- from typing import Callable, cast, Optional, TYPE_CHECKING
19
+ from typing import Callable, cast, TYPE_CHECKING
20
20
 
21
21
  from cirq import circuits, ops, protocols
22
22
  from cirq.transformers import transformer_api, transformer_primitives
@@ -28,9 +28,9 @@ if TYPE_CHECKING:
28
28
  def _rewrite_merged_k_qubit_unitaries(
29
29
  circuit: cirq.AbstractCircuit,
30
30
  *,
31
- context: Optional[cirq.TransformerContext] = None,
31
+ context: cirq.TransformerContext | None = None,
32
32
  k: int = 0,
33
- rewriter: Optional[Callable[[cirq.CircuitOperation], cirq.OP_TREE]] = None,
33
+ rewriter: Callable[[cirq.CircuitOperation], cirq.OP_TREE] | None = None,
34
34
  merged_circuit_op_tag: str = "_merged_k_qubit_unitaries_component",
35
35
  ) -> cirq.Circuit:
36
36
  deep = context.deep if context else False
@@ -70,9 +70,9 @@ def _rewrite_merged_k_qubit_unitaries(
70
70
  def merge_k_qubit_unitaries(
71
71
  circuit: cirq.AbstractCircuit,
72
72
  *,
73
- context: Optional[cirq.TransformerContext] = None,
73
+ context: cirq.TransformerContext | None = None,
74
74
  k: int = 0,
75
- rewriter: Optional[Callable[[cirq.CircuitOperation], cirq.OP_TREE]] = None,
75
+ rewriter: Callable[[cirq.CircuitOperation], cirq.OP_TREE] | None = None,
76
76
  ) -> cirq.Circuit:
77
77
  """Merges connected components of unitary operations, acting on <= k qubits.
78
78