cirq-core 1.7.0.dev20250819195403__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.dev20250819195403.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/METADATA +1 -1
  54. {cirq_core-1.7.0.dev20250819195403.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/RECORD +57 -57
  55. {cirq_core-1.7.0.dev20250819195403.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/WHEEL +0 -0
  56. {cirq_core-1.7.0.dev20250819195403.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/licenses/LICENSE +0 -0
  57. {cirq_core-1.7.0.dev20250819195403.dist-info → cirq_core-1.7.0.dev20250820205919.dist-info}/top_level.txt +0 -0
@@ -36,7 +36,7 @@ q0, q1, q2, q3 = cirq.LineQubit.range(4)
36
36
  {cirq.TOFFOLI: 0.5j, cirq.FREDKIN: 0.5},
37
37
  ),
38
38
  )
39
- def test_linear_combination_of_gates_accepts_consistent_gates(terms):
39
+ def test_linear_combination_of_gates_accepts_consistent_gates(terms) -> None:
40
40
  combination_1 = cirq.LinearCombinationOfGates(terms)
41
41
 
42
42
  combination_2 = cirq.LinearCombinationOfGates({})
@@ -57,7 +57,7 @@ def test_linear_combination_of_gates_accepts_consistent_gates(terms):
57
57
  {cirq.TOFFOLI: 0.5j, cirq.S: 0.5},
58
58
  ),
59
59
  )
60
- def test_linear_combination_of_gates_rejects_inconsistent_gates(terms):
60
+ def test_linear_combination_of_gates_rejects_inconsistent_gates(terms) -> None:
61
61
  with pytest.raises(ValueError):
62
62
  cirq.LinearCombinationOfGates(terms)
63
63
 
@@ -72,7 +72,7 @@ def test_linear_combination_of_gates_rejects_inconsistent_gates(terms):
72
72
 
73
73
 
74
74
  @pytest.mark.parametrize('gate', (cirq.X, cirq.Y, cirq.XX, cirq.CZ, cirq.CSWAP, cirq.FREDKIN))
75
- def test_empty_linear_combination_of_gates_accepts_all_gates(gate):
75
+ def test_empty_linear_combination_of_gates_accepts_all_gates(gate) -> None:
76
76
  combination = cirq.LinearCombinationOfGates({})
77
77
  combination[gate] = -0.5j
78
78
  assert len(combination) == 1
@@ -87,12 +87,12 @@ def test_empty_linear_combination_of_gates_accepts_all_gates(gate):
87
87
  ({cirq.CCZ: 0.1, cirq.CSWAP: 0.2}, 3),
88
88
  ),
89
89
  )
90
- def test_linear_combination_of_gates_has_correct_num_qubits(terms, expected_num_qubits):
90
+ def test_linear_combination_of_gates_has_correct_num_qubits(terms, expected_num_qubits) -> None:
91
91
  combination = cirq.LinearCombinationOfGates(terms)
92
92
  assert combination.num_qubits() == expected_num_qubits
93
93
 
94
94
 
95
- def test_empty_linear_combination_of_gates_has_no_matrix():
95
+ def test_empty_linear_combination_of_gates_has_no_matrix() -> None:
96
96
  empty = cirq.LinearCombinationOfGates({})
97
97
  assert empty.num_qubits() is None
98
98
  with pytest.raises(ValueError):
@@ -110,7 +110,7 @@ def test_empty_linear_combination_of_gates_has_no_matrix():
110
110
  ({cirq.CCZ: 3j}, np.diag([3j, 3j, 3j, 3j, 3j, 3j, 3j, -3j])),
111
111
  ),
112
112
  )
113
- def test_linear_combination_of_gates_has_correct_matrix(terms, expected_matrix):
113
+ def test_linear_combination_of_gates_has_correct_matrix(terms, expected_matrix) -> None:
114
114
  combination = cirq.LinearCombinationOfGates(terms)
115
115
  assert np.all(combination.matrix() == expected_matrix)
116
116
 
@@ -128,7 +128,7 @@ def test_linear_combination_of_gates_has_correct_matrix(terms, expected_matrix):
128
128
  ),
129
129
  ),
130
130
  )
131
- def test_unitary_linear_combination_of_gates_has_correct_unitary(terms, expected_unitary):
131
+ def test_unitary_linear_combination_of_gates_has_correct_unitary(terms, expected_unitary) -> None:
132
132
  combination = cirq.LinearCombinationOfGates(terms)
133
133
  assert cirq.has_unitary(combination)
134
134
  assert np.allclose(cirq.unitary(combination), expected_unitary)
@@ -137,7 +137,7 @@ def test_unitary_linear_combination_of_gates_has_correct_unitary(terms, expected
137
137
  @pytest.mark.parametrize(
138
138
  'terms', ({cirq.X: 2}, {cirq.Y ** sympy.Symbol('t'): 1}, {cirq.X: 1, cirq.S: 1})
139
139
  )
140
- def test_non_unitary_linear_combination_of_gates_has_no_unitary(terms):
140
+ def test_non_unitary_linear_combination_of_gates_has_no_unitary(terms) -> None:
141
141
  combination = cirq.LinearCombinationOfGates(terms)
142
142
  assert not cirq.has_unitary(combination)
143
143
  with pytest.raises((TypeError, ValueError)):
@@ -160,7 +160,7 @@ def test_non_unitary_linear_combination_of_gates_has_no_unitary(terms):
160
160
  ),
161
161
  ),
162
162
  )
163
- def test_linear_combination_of_gates_has_correct_pauli_expansion(terms, expected_expansion):
163
+ def test_linear_combination_of_gates_has_correct_pauli_expansion(terms, expected_expansion) -> None:
164
164
  combination = cirq.LinearCombinationOfGates(terms)
165
165
  actual_expansion = cirq.pauli_expansion(combination)
166
166
  assert set(actual_expansion.keys()) == set(expected_expansion.keys())
@@ -184,7 +184,7 @@ def test_linear_combination_of_gates_has_correct_pauli_expansion(terms, expected
184
184
  ({cirq.X: 0.4, cirq.Y: 0.4}, 0, {cirq.I: 1}),
185
185
  ),
186
186
  )
187
- def test_linear_combinations_of_gates_valid_powers(terms, exponent, expected_terms):
187
+ def test_linear_combinations_of_gates_valid_powers(terms, exponent, expected_terms) -> None:
188
188
  combination = cirq.LinearCombinationOfGates(terms)
189
189
  actual_result = combination**exponent
190
190
  expected_result = cirq.LinearCombinationOfGates(expected_terms)
@@ -203,7 +203,7 @@ def test_linear_combinations_of_gates_valid_powers(terms, exponent, expected_ter
203
203
  ({cirq.Y: 1}, sympy.Symbol('k')),
204
204
  ),
205
205
  )
206
- def test_linear_combinations_of_gates_invalid_powers(terms, exponent):
206
+ def test_linear_combinations_of_gates_invalid_powers(terms, exponent) -> None:
207
207
  combination = cirq.LinearCombinationOfGates(terms)
208
208
  with pytest.raises(TypeError):
209
209
  _ = combination**exponent
@@ -220,7 +220,7 @@ def test_linear_combinations_of_gates_invalid_powers(terms, exponent):
220
220
  @pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
221
221
  def test_parameterized_linear_combination_of_gates(
222
222
  terms, is_parameterized, parameter_names, resolve_fn
223
- ):
223
+ ) -> None:
224
224
  gate = cirq.LinearCombinationOfGates(terms)
225
225
  assert cirq.is_parameterized(gate) == is_parameterized
226
226
  assert cirq.parameter_names(gate) == parameter_names
@@ -292,7 +292,7 @@ def assert_linear_combinations_are_equal(
292
292
  ((cirq.X + cirq.Z) * sympy.Symbol('s') / np.sqrt(2), cirq.H * sympy.Symbol('s')),
293
293
  ),
294
294
  )
295
- def test_gate_expressions(expression, expected_result):
295
+ def test_gate_expressions(expression, expected_result) -> None:
296
296
  assert_linear_combinations_are_equal(expression, expected_result)
297
297
 
298
298
 
@@ -304,7 +304,7 @@ def test_gate_expressions(expression, expected_result):
304
304
  (cirq.TOFFOLI, cirq.TOFFOLI, cirq.FREDKIN),
305
305
  ),
306
306
  )
307
- def test_in_place_manipulations_of_linear_combination_of_gates(gates):
307
+ def test_in_place_manipulations_of_linear_combination_of_gates(gates) -> None:
308
308
  a = cirq.LinearCombinationOfGates({})
309
309
  b = cirq.LinearCombinationOfGates({})
310
310
 
@@ -333,7 +333,7 @@ def test_in_place_manipulations_of_linear_combination_of_gates(gates):
333
333
  cirq.PauliString({q0: cirq.X, q1: cirq.Y, q2: cirq.Z}),
334
334
  ),
335
335
  )
336
- def test_empty_linear_combination_of_operations_accepts_all_operations(op):
336
+ def test_empty_linear_combination_of_operations_accepts_all_operations(op) -> None:
337
337
  combination = cirq.LinearCombinationOfOperations({})
338
338
  combination[op] = -0.5j
339
339
  assert len(combination) == 1
@@ -348,7 +348,7 @@ def test_empty_linear_combination_of_operations_accepts_all_operations(op):
348
348
  {cirq.X(q0): 1 + 1j, cirq.CZ(q1, q2): 0.5},
349
349
  ),
350
350
  )
351
- def test_linear_combination_of_operations_is_consistent(terms):
351
+ def test_linear_combination_of_operations_is_consistent(terms) -> None:
352
352
  combination_1 = cirq.LinearCombinationOfOperations(terms)
353
353
 
354
354
  combination_2 = cirq.LinearCombinationOfOperations({})
@@ -371,7 +371,7 @@ def test_linear_combination_of_operations_is_consistent(terms):
371
371
  ({cirq.Z(q0): -1j, cirq.CNOT(q1, q2): 0.25}, (q0, q1, q2)),
372
372
  ),
373
373
  )
374
- def test_linear_combination_of_operations_has_correct_qubits(terms, expected_qubits):
374
+ def test_linear_combination_of_operations_has_correct_qubits(terms, expected_qubits) -> None:
375
375
  combination = cirq.LinearCombinationOfOperations(terms)
376
376
  assert combination.qubits == expected_qubits
377
377
 
@@ -590,7 +590,7 @@ def test_linear_combination_of_operations_has_correct_qubits(terms, expected_qub
590
590
  ),
591
591
  ),
592
592
  )
593
- def test_linear_combination_of_operations_has_correct_matrix(terms, expected_matrix):
593
+ def test_linear_combination_of_operations_has_correct_matrix(terms, expected_matrix) -> None:
594
594
  combination = cirq.LinearCombinationOfOperations(terms)
595
595
  assert np.allclose(combination.matrix(), expected_matrix)
596
596
 
@@ -622,7 +622,9 @@ def test_linear_combination_of_operations_has_correct_matrix(terms, expected_mat
622
622
  ),
623
623
  ),
624
624
  )
625
- def test_unitary_linear_combination_of_operations_has_correct_unitary(terms, expected_unitary):
625
+ def test_unitary_linear_combination_of_operations_has_correct_unitary(
626
+ terms, expected_unitary
627
+ ) -> None:
626
628
  combination = cirq.LinearCombinationOfOperations(terms)
627
629
  assert cirq.has_unitary(combination)
628
630
  assert np.allclose(cirq.unitary(combination), expected_unitary)
@@ -636,7 +638,7 @@ def test_unitary_linear_combination_of_operations_has_correct_unitary(terms, exp
636
638
  {cirq.X(q0): 1, cirq.S(q0): 1},
637
639
  ),
638
640
  )
639
- def test_non_unitary_linear_combination_of_operations_has_no_unitary(terms):
641
+ def test_non_unitary_linear_combination_of_operations_has_no_unitary(terms) -> None:
640
642
  combination = cirq.LinearCombinationOfOperations(terms)
641
643
  assert not cirq.has_unitary(combination)
642
644
  with pytest.raises((TypeError, ValueError)):
@@ -676,7 +678,9 @@ def test_non_unitary_linear_combination_of_operations_has_no_unitary(terms):
676
678
  ),
677
679
  ),
678
680
  )
679
- def test_linear_combination_of_operations_has_correct_pauli_expansion(terms, expected_expansion):
681
+ def test_linear_combination_of_operations_has_correct_pauli_expansion(
682
+ terms, expected_expansion
683
+ ) -> None:
680
684
  combination = cirq.LinearCombinationOfOperations(terms)
681
685
  actual_expansion = cirq.pauli_expansion(combination)
682
686
  assert set(actual_expansion.keys()) == set(expected_expansion.keys())
@@ -700,7 +704,7 @@ def test_linear_combination_of_operations_has_correct_pauli_expansion(terms, exp
700
704
  ({cirq.Y(q1): 2, cirq.Z(q1): 3}, 0, {cirq.I(q1): 1}),
701
705
  ),
702
706
  )
703
- def test_linear_combinations_of_operations_valid_powers(terms, exponent, expected_terms):
707
+ def test_linear_combinations_of_operations_valid_powers(terms, exponent, expected_terms) -> None:
704
708
  combination = cirq.LinearCombinationOfOperations(terms)
705
709
  actual_result = combination**exponent
706
710
  expected_result = cirq.LinearCombinationOfOperations(expected_terms)
@@ -720,7 +724,7 @@ def test_linear_combinations_of_operations_valid_powers(terms, exponent, expecte
720
724
  ({cirq.X(q0): 1}, sympy.Symbol('k')),
721
725
  ),
722
726
  )
723
- def test_linear_combinations_of_operations_invalid_powers(terms, exponent):
727
+ def test_linear_combinations_of_operations_invalid_powers(terms, exponent) -> None:
724
728
  combination = cirq.LinearCombinationOfOperations(terms)
725
729
  with pytest.raises(TypeError):
726
730
  _ = combination**exponent
@@ -737,7 +741,7 @@ def test_linear_combinations_of_operations_invalid_powers(terms, exponent):
737
741
  @pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
738
742
  def test_parameterized_linear_combination_of_ops(
739
743
  terms, is_parameterized, parameter_names, resolve_fn
740
- ):
744
+ ) -> None:
741
745
  op = cirq.LinearCombinationOfOperations(terms)
742
746
  assert cirq.is_parameterized(op) == is_parameterized
743
747
  assert cirq.parameter_names(op) == parameter_names
@@ -810,11 +814,11 @@ def test_parameterized_linear_combination_of_ops(
810
814
  ),
811
815
  ),
812
816
  )
813
- def test_operation_expressions(expression, expected_result):
817
+ def test_operation_expressions(expression, expected_result) -> None:
814
818
  assert_linear_combinations_are_equal(expression, expected_result)
815
819
 
816
820
 
817
- def test_pauli_sum_construction():
821
+ def test_pauli_sum_construction() -> None:
818
822
  q = cirq.LineQubit.range(2)
819
823
  pstr1 = cirq.X(q[0]) * cirq.X(q[1])
820
824
  pstr2 = cirq.Y(q[0]) * cirq.Y(q[1])
@@ -839,7 +843,7 @@ def test_pauli_sum_construction():
839
843
  ),
840
844
  ),
841
845
  )
842
- def test_unitary_pauli_sum_has_correct_unitary(psum, expected_unitary):
846
+ def test_unitary_pauli_sum_has_correct_unitary(psum, expected_unitary) -> None:
843
847
  assert cirq.has_unitary(psum)
844
848
  assert np.allclose(cirq.unitary(psum), expected_unitary)
845
849
 
@@ -852,7 +856,7 @@ def test_unitary_pauli_sum_has_correct_unitary(psum, expected_unitary):
852
856
  cirq.X(q0) * cirq.Z(q1) - cirq.Z(q1) * cirq.X(q0),
853
857
  ),
854
858
  )
855
- def test_non_pauli_sum_has_no_unitary(psum):
859
+ def test_non_pauli_sum_has_no_unitary(psum) -> None:
856
860
  assert isinstance(psum, cirq.PauliSum)
857
861
  assert not cirq.has_unitary(psum)
858
862
  with pytest.raises(ValueError):
@@ -869,7 +873,7 @@ def test_non_pauli_sum_has_no_unitary(psum):
869
873
  (cirq.X(q0) * cirq.Y(q1) + cirq.Y(q1) * cirq.Z(q3), (q0, q1, q3)),
870
874
  ),
871
875
  )
872
- def test_pauli_sum_qubits(psum, expected_qubits):
876
+ def test_pauli_sum_qubits(psum, expected_qubits) -> None:
873
877
  assert psum.qubits == expected_qubits
874
878
 
875
879
 
@@ -884,7 +888,7 @@ def test_pauli_sum_qubits(psum, expected_qubits):
884
888
  ),
885
889
  ),
886
890
  )
887
- def test_pauli_sum_with_qubits(psum, expected_psum):
891
+ def test_pauli_sum_with_qubits(psum, expected_psum) -> None:
888
892
  if len(expected_psum.qubits) == len(psum.qubits):
889
893
  assert psum.with_qubits(*expected_psum.qubits) == expected_psum
890
894
  else:
@@ -892,7 +896,7 @@ def test_pauli_sum_with_qubits(psum, expected_psum):
892
896
  psum.with_qubits(*expected_psum.qubits)
893
897
 
894
898
 
895
- def test_pauli_sum_from_single_pauli():
899
+ def test_pauli_sum_from_single_pauli() -> None:
896
900
  q = cirq.LineQubit.range(2)
897
901
  psum1 = cirq.X(q[0]) + cirq.Y(q[1])
898
902
  assert psum1 == cirq.PauliSum.from_pauli_strings([cirq.X(q[0]) * 1, cirq.Y(q[1]) * 1])
@@ -906,7 +910,7 @@ def test_pauli_sum_from_single_pauli():
906
910
  assert psum3 == psum2
907
911
 
908
912
 
909
- def test_pauli_sub():
913
+ def test_pauli_sub() -> None:
910
914
  q = cirq.LineQubit.range(2)
911
915
  pstr1 = cirq.X(q[0]) * cirq.X(q[1])
912
916
  pstr2 = cirq.Y(q[0]) * cirq.Y(q[1])
@@ -916,7 +920,7 @@ def test_pauli_sub():
916
920
  assert psum == psum2
917
921
 
918
922
 
919
- def test_pauli_sub_simplify():
923
+ def test_pauli_sub_simplify() -> None:
920
924
  q = cirq.LineQubit.range(2)
921
925
  pstr1 = cirq.X(q[0]) * cirq.X(q[1])
922
926
  pstr2 = cirq.X(q[0]) * cirq.X(q[1])
@@ -926,7 +930,7 @@ def test_pauli_sub_simplify():
926
930
  assert psum == psum2
927
931
 
928
932
 
929
- def test_pauli_sum_neg():
933
+ def test_pauli_sum_neg() -> None:
930
934
  q = cirq.LineQubit.range(2)
931
935
  pstr1 = cirq.X(q[0]) * cirq.X(q[1])
932
936
  pstr2 = cirq.Y(q[0]) * cirq.Y(q[1])
@@ -941,12 +945,12 @@ def test_pauli_sum_neg():
941
945
  assert psum1 == -psum2
942
946
 
943
947
 
944
- def test_paulisum_validation():
948
+ def test_paulisum_validation() -> None:
945
949
  q = cirq.LineQubit.range(2)
946
950
  pstr1 = cirq.X(q[0]) * cirq.X(q[1])
947
951
  pstr2 = cirq.Y(q[0]) * cirq.Y(q[1])
948
952
  with pytest.raises(ValueError) as e:
949
- cirq.PauliSum([pstr1, pstr2])
953
+ cirq.PauliSum([pstr1, pstr2]) # type: ignore[arg-type]
950
954
  assert e.match("Consider using")
951
955
 
952
956
  with pytest.raises(ValueError):
@@ -959,12 +963,12 @@ def test_paulisum_validation():
959
963
  cirq.PauliSum(ld)
960
964
 
961
965
  with pytest.raises(ValueError):
962
- key = frozenset([(q[0], cirq.H)])
963
- ld = cirq.LinearDict({key: 2.0})
966
+ key1 = frozenset([(q[0], cirq.H)])
967
+ ld = cirq.LinearDict({key1: 2.0})
964
968
  cirq.PauliSum(ld)
965
969
 
966
- key = frozenset([(q[0], cirq.X)])
967
- ld = cirq.LinearDict({key: 2.0})
970
+ key2 = frozenset([(q[0], cirq.X)])
971
+ ld = cirq.LinearDict({key2: 2.0})
968
972
  assert cirq.PauliSum(ld) == cirq.PauliSum.from_pauli_strings([2 * cirq.X(q[0])])
969
973
 
970
974
  ps = cirq.PauliSum()
@@ -976,14 +980,14 @@ def test_paulisum_validation():
976
980
  assert ps == cirq.PauliSum(cirq.LinearDict({frozenset(): complex(-1)}))
977
981
 
978
982
 
979
- def test_add_number_paulisum():
983
+ def test_add_number_paulisum() -> None:
980
984
  q = cirq.LineQubit.range(2)
981
985
  pstr1 = cirq.X(q[0]) * cirq.X(q[1])
982
986
  psum = cirq.PauliSum.from_pauli_strings([pstr1]) + 1.3
983
987
  assert psum == cirq.PauliSum.from_pauli_strings([pstr1, cirq.PauliString({}, 1.3)])
984
988
 
985
989
 
986
- def test_add_number_paulistring():
990
+ def test_add_number_paulistring() -> None:
987
991
  a, b = cirq.LineQubit.range(2)
988
992
  pstr1 = cirq.X(a) * cirq.X(b)
989
993
  psum = pstr1 + 1.3
@@ -1005,7 +1009,7 @@ def test_add_number_paulistring():
1005
1009
  )
1006
1010
 
1007
1011
 
1008
- def test_pauli_sum_formatting():
1012
+ def test_pauli_sum_formatting() -> None:
1009
1013
  q = cirq.LineQubit.range(2)
1010
1014
  pauli = cirq.X(q[0])
1011
1015
  assert str(pauli) == 'X(q(0))'
@@ -1023,7 +1027,7 @@ def test_pauli_sum_formatting():
1023
1027
  assert str(empty) == "0.000"
1024
1028
 
1025
1029
 
1026
- def test_pauli_sum_matrix():
1030
+ def test_pauli_sum_matrix() -> None:
1027
1031
  q = cirq.LineQubit.range(3)
1028
1032
  paulisum = cirq.X(q[0]) * cirq.X(q[1]) + cirq.Z(q[0])
1029
1033
  H1 = np.array(
@@ -1052,7 +1056,7 @@ def test_pauli_sum_matrix():
1052
1056
  assert np.allclose(H3, paulisum.matrix([q[1], q[2], q[0]]))
1053
1057
 
1054
1058
 
1055
- def test_pauli_sum_repr():
1059
+ def test_pauli_sum_repr() -> None:
1056
1060
  q = cirq.LineQubit.range(2)
1057
1061
  pstr1 = cirq.X(q[0]) * cirq.X(q[1])
1058
1062
  pstr2 = cirq.Y(q[0]) * cirq.Y(q[1])
@@ -1060,7 +1064,7 @@ def test_pauli_sum_repr():
1060
1064
  cirq.testing.assert_equivalent_repr(psum)
1061
1065
 
1062
1066
 
1063
- def test_bad_arithmetic():
1067
+ def test_bad_arithmetic() -> None:
1064
1068
  q = cirq.LineQubit.range(2)
1065
1069
  pstr1 = cirq.X(q[0]) * cirq.X(q[1])
1066
1070
  pstr2 = cirq.Y(q[0]) * cirq.Y(q[1])
@@ -1099,9 +1103,11 @@ def test_bad_arithmetic():
1099
1103
  _ = psum ** "string"
1100
1104
 
1101
1105
 
1102
- def test_paulisum_mul_paulistring():
1106
+ def test_paulisum_mul_paulistring() -> None:
1103
1107
  q0, q1 = cirq.LineQubit.range(2)
1104
1108
 
1109
+ x0: cirq.PauliString[cirq.LineQubit]
1110
+ y1: cirq.PauliString[cirq.LineQubit]
1105
1111
  psum1 = cirq.X(q0) + 2 * cirq.Y(q0) + 3 * cirq.Z(q0)
1106
1112
  x0 = cirq.PauliString(cirq.X(q0))
1107
1113
  y1 = cirq.PauliString(cirq.Y(q1))
@@ -1121,7 +1127,7 @@ def test_paulisum_mul_paulistring():
1121
1127
  assert psum1 == -1j * cirq.Y(q0) + 2j * cirq.X(q0) + 3
1122
1128
 
1123
1129
 
1124
- def test_paulisum_mul_paulisum():
1130
+ def test_paulisum_mul_paulisum() -> None:
1125
1131
  q0, q1, q2 = cirq.LineQubit.range(3)
1126
1132
 
1127
1133
  psum1 = cirq.X(q0) + 2 * cirq.Y(q0) * cirq.Y(q1)
@@ -1158,7 +1164,7 @@ def test_paulisum_mul_paulisum():
1158
1164
  )
1159
1165
 
1160
1166
 
1161
- def test_pauli_sum_pow():
1167
+ def test_pauli_sum_pow() -> None:
1162
1168
  identity = cirq.PauliSum.from_pauli_strings([cirq.PauliString(coefficient=1)])
1163
1169
  psum1 = cirq.X(q0) + cirq.Y(q0)
1164
1170
  assert psum1**2 == psum1 * psum1
@@ -1215,7 +1221,7 @@ def test_pauli_sum_pow():
1215
1221
  ('x0 ^ x1 ^ x2', ['(-0.5+0j)*Z(x0)*Z(x1)*Z(x2)', '(0.5+0j)*I']),
1216
1222
  ],
1217
1223
  )
1218
- def test_from_boolean_expression(boolean_expr, expected_pauli_sum):
1224
+ def test_from_boolean_expression(boolean_expr, expected_pauli_sum) -> None:
1219
1225
  boolean = sympy_parser.parse_expr(boolean_expr)
1220
1226
  qubit_map = {name: cirq.NamedQubit(name) for name in sorted(cirq.parameter_names(boolean))}
1221
1227
  actual = cirq.PauliSum.from_boolean_expression(boolean, qubit_map)
@@ -1226,14 +1232,14 @@ def test_from_boolean_expression(boolean_expr, expected_pauli_sum):
1226
1232
  assert expected_pauli_sum == actual_items
1227
1233
 
1228
1234
 
1229
- def test_unsupported_op():
1235
+ def test_unsupported_op() -> None:
1230
1236
  not_a_boolean = sympy_parser.parse_expr('x * x')
1231
1237
  qubit_map = {name: cirq.NamedQubit(name) for name in cirq.parameter_names(not_a_boolean)}
1232
1238
  with pytest.raises(ValueError, match='Unsupported type'):
1233
1239
  cirq.PauliSum.from_boolean_expression(not_a_boolean, qubit_map)
1234
1240
 
1235
1241
 
1236
- def test_imul_aliasing():
1242
+ def test_imul_aliasing() -> None:
1237
1243
  q0, q1, q2 = cirq.LineQubit.range(3)
1238
1244
  psum1 = cirq.X(q0) + cirq.Y(q1)
1239
1245
  psum2 = psum1
@@ -1242,7 +1248,7 @@ def test_imul_aliasing():
1242
1248
  assert psum1 == psum2
1243
1249
 
1244
1250
 
1245
- def test_expectation_from_state_vector_invalid_input():
1251
+ def test_expectation_from_state_vector_invalid_input() -> None:
1246
1252
  q0, q1, q2, q3 = cirq.LineQubit.range(4)
1247
1253
  psum = cirq.X(q0) + 2 * cirq.Y(q1) + 3 * cirq.Z(q3)
1248
1254
  q_map = {q0: 0, q1: 1, q3: 2}
@@ -1285,7 +1291,7 @@ def test_expectation_from_state_vector_invalid_input():
1285
1291
  psum.expectation_from_state_vector(wf.reshape((4, 4, 1)), q_map_2)
1286
1292
 
1287
1293
 
1288
- def test_expectation_from_state_vector_check_preconditions():
1294
+ def test_expectation_from_state_vector_check_preconditions() -> None:
1289
1295
  q0, q1, q2, q3 = cirq.LineQubit.range(4)
1290
1296
  psum = cirq.X(q0) + 2 * cirq.Y(q1) + 3 * cirq.Z(q3)
1291
1297
  q_map = {q0: 0, q1: 1, q2: 2, q3: 3}
@@ -1298,7 +1304,7 @@ def test_expectation_from_state_vector_check_preconditions():
1298
1304
  )
1299
1305
 
1300
1306
 
1301
- def test_expectation_from_state_vector_basis_states():
1307
+ def test_expectation_from_state_vector_basis_states() -> None:
1302
1308
  q = cirq.LineQubit.range(2)
1303
1309
  psum = cirq.X(q[0]) + 2 * cirq.Y(q[0]) + 3 * cirq.Z(q[0])
1304
1310
  q_map = {x: i for i, x in enumerate(q)}
@@ -1335,7 +1341,7 @@ def test_expectation_from_state_vector_basis_states():
1335
1341
  )
1336
1342
 
1337
1343
 
1338
- def test_expectation_from_state_vector_two_qubit_states():
1344
+ def test_expectation_from_state_vector_two_qubit_states() -> None:
1339
1345
  q = cirq.LineQubit.range(2)
1340
1346
  q_map = {x: i for i, x in enumerate(q)}
1341
1347
 
@@ -1371,7 +1377,7 @@ def test_expectation_from_state_vector_two_qubit_states():
1371
1377
  )
1372
1378
 
1373
1379
 
1374
- def test_expectation_from_density_matrix_invalid_input():
1380
+ def test_expectation_from_density_matrix_invalid_input() -> None:
1375
1381
  q0, q1, q2, q3 = cirq.LineQubit.range(4)
1376
1382
  psum = cirq.X(q0) + 2 * cirq.Y(q1) + 3 * cirq.Z(q3)
1377
1383
  q_map = {q0: 0, q1: 1, q3: 2}
@@ -1427,7 +1433,7 @@ def test_expectation_from_density_matrix_invalid_input():
1427
1433
  psum.expectation_from_density_matrix(rho.reshape((-1)), q_map)
1428
1434
 
1429
1435
 
1430
- def test_expectation_from_density_matrix_check_preconditions():
1436
+ def test_expectation_from_density_matrix_check_preconditions() -> None:
1431
1437
  q0, q1, _, q3 = cirq.LineQubit.range(4)
1432
1438
  psum = cirq.X(q0) + 2 * cirq.Y(q1) + 3 * cirq.Z(q3)
1433
1439
  q_map = {q0: 0, q1: 1, q3: 2}
@@ -1441,7 +1447,7 @@ def test_expectation_from_density_matrix_check_preconditions():
1441
1447
  _ = psum.expectation_from_density_matrix(not_psd, q_map, check_preconditions=False)
1442
1448
 
1443
1449
 
1444
- def test_expectation_from_density_matrix_basis_states():
1450
+ def test_expectation_from_density_matrix_basis_states() -> None:
1445
1451
  q = cirq.LineQubit.range(2)
1446
1452
  psum = cirq.X(q[0]) + 2 * cirq.Y(q[0]) + 3 * cirq.Z(q[0])
1447
1453
  q_map = {x: i for i, x in enumerate(q)}
@@ -1476,7 +1482,7 @@ def test_expectation_from_density_matrix_basis_states():
1476
1482
  )
1477
1483
 
1478
1484
 
1479
- def test_expectation_from_density_matrix_two_qubit_states():
1485
+ def test_expectation_from_density_matrix_two_qubit_states() -> None:
1480
1486
  q = cirq.LineQubit.range(2)
1481
1487
  q_map = {x: i for i, x in enumerate(q)}
1482
1488
 
@@ -1507,7 +1513,7 @@ def test_expectation_from_density_matrix_two_qubit_states():
1507
1513
  )
1508
1514
 
1509
1515
 
1510
- def test_projector_sum_expectations_matrix():
1516
+ def test_projector_sum_expectations_matrix() -> None:
1511
1517
  q0 = cirq.NamedQubit('q0')
1512
1518
 
1513
1519
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(
@@ -1524,7 +1530,7 @@ def test_projector_sum_expectations_matrix():
1524
1530
  )
1525
1531
 
1526
1532
 
1527
- def test_projector_sum_expectations_from_state_vector():
1533
+ def test_projector_sum_expectations_from_state_vector() -> None:
1528
1534
  q0 = cirq.NamedQubit('q0')
1529
1535
 
1530
1536
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(
@@ -1545,7 +1551,7 @@ def test_projector_sum_expectations_from_state_vector():
1545
1551
  )
1546
1552
 
1547
1553
 
1548
- def test_projector_sum_expectations_from_density_matrix():
1554
+ def test_projector_sum_expectations_from_density_matrix() -> None:
1549
1555
  q0 = cirq.NamedQubit('q0')
1550
1556
 
1551
1557
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(
@@ -1567,7 +1573,7 @@ def test_projector_sum_expectations_from_density_matrix():
1567
1573
  )
1568
1574
 
1569
1575
 
1570
- def test_projector_sum_accessor():
1576
+ def test_projector_sum_accessor() -> None:
1571
1577
  q0 = cirq.NamedQubit('q0')
1572
1578
 
1573
1579
  projector_string_1 = cirq.ProjectorString({q0: 0}, 0.2016)
@@ -1582,7 +1588,7 @@ def test_projector_sum_accessor():
1582
1588
  assert expanded_projector_strings == [projector_string_1, projector_string_2]
1583
1589
 
1584
1590
 
1585
- def test_projector_bool_operation():
1591
+ def test_projector_bool_operation() -> None:
1586
1592
  q0 = cirq.NamedQubit('q0')
1587
1593
 
1588
1594
  empty_projector_sum = cirq.ProjectorSum.from_projector_strings([])
@@ -1594,7 +1600,7 @@ def test_projector_bool_operation():
1594
1600
  assert non_empty_projector_sum
1595
1601
 
1596
1602
 
1597
- def test_projector_sum_addition():
1603
+ def test_projector_sum_addition() -> None:
1598
1604
  q0 = cirq.NamedQubit('q0')
1599
1605
 
1600
1606
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(cirq.ProjectorString({q0: 0}))
@@ -1612,10 +1618,10 @@ def test_projector_sum_addition():
1612
1618
  np.testing.assert_allclose(one_projector_sum.matrix().toarray(), [[0.0, 0.0], [0.0, 1.0]])
1613
1619
 
1614
1620
  with pytest.raises(TypeError):
1615
- _ = zero_projector_sum + 0.20160913
1621
+ _ = zero_projector_sum + 0.20160913 # type: ignore[operator]
1616
1622
 
1617
1623
 
1618
- def test_projector_sum_subtraction():
1624
+ def test_projector_sum_subtraction() -> None:
1619
1625
  q0 = cirq.NamedQubit('q0')
1620
1626
 
1621
1627
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(cirq.ProjectorString({q0: 0}))
@@ -1633,10 +1639,10 @@ def test_projector_sum_subtraction():
1633
1639
  np.testing.assert_allclose(one_projector_sum.matrix().toarray(), [[0.0, 0.0], [0.0, 1.0]])
1634
1640
 
1635
1641
  with pytest.raises(TypeError):
1636
- _ = zero_projector_sum - 0.87539319
1642
+ _ = zero_projector_sum - 0.87539319 # type: ignore[operator]
1637
1643
 
1638
1644
 
1639
- def test_projector_sum_negation():
1645
+ def test_projector_sum_negation() -> None:
1640
1646
  q0 = cirq.NamedQubit('q0')
1641
1647
 
1642
1648
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(cirq.ProjectorString({q0: 0}))
@@ -1648,7 +1654,7 @@ def test_projector_sum_negation():
1648
1654
  np.testing.assert_allclose(zero_projector_sum.matrix().toarray(), [[1.0, 0.0], [0.0, 0.0]])
1649
1655
 
1650
1656
 
1651
- def test_projector_sum_incrementation():
1657
+ def test_projector_sum_incrementation() -> None:
1652
1658
  q0 = cirq.NamedQubit('q0')
1653
1659
 
1654
1660
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(cirq.ProjectorString({q0: 0}))
@@ -1668,10 +1674,10 @@ def test_projector_sum_incrementation():
1668
1674
  np.testing.assert_allclose(one_projector_sum.matrix().toarray(), [[0.0, 0.0], [0.0, 1.0]])
1669
1675
 
1670
1676
  with pytest.raises(TypeError):
1671
- zero_projector_sum += 0.6963472309248
1677
+ zero_projector_sum += 0.6963472309248 # type: ignore[arg-type]
1672
1678
 
1673
1679
 
1674
- def test_projector_sum_decrementation():
1680
+ def test_projector_sum_decrementation() -> None:
1675
1681
  q0 = cirq.NamedQubit('q0')
1676
1682
 
1677
1683
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(cirq.ProjectorString({q0: 0}))
@@ -1691,10 +1697,10 @@ def test_projector_sum_decrementation():
1691
1697
  np.testing.assert_allclose(one_projector_sum.matrix().toarray(), [[0.0, 0.0], [0.0, 1.0]])
1692
1698
 
1693
1699
  with pytest.raises(TypeError):
1694
- zero_projector_sum -= 0.12345
1700
+ zero_projector_sum -= 0.12345 # type: ignore[arg-type]
1695
1701
 
1696
1702
 
1697
- def test_projector_sum_multiplication_left():
1703
+ def test_projector_sum_multiplication_left() -> None:
1698
1704
  q0 = cirq.NamedQubit('q0')
1699
1705
 
1700
1706
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(cirq.ProjectorString({q0: 0}))
@@ -1706,16 +1712,18 @@ def test_projector_sum_multiplication_left():
1706
1712
  np.testing.assert_allclose(multiplication_int.matrix().toarray(), [[2.0, 0.0], [0.0, 0.0]])
1707
1713
 
1708
1714
  multiplication_complex = 2j * zero_projector_sum
1709
- np.testing.assert_allclose(multiplication_complex.matrix().toarray(), [[2.0j, 0.0], [0.0, 0.0]])
1715
+ np.testing.assert_allclose(
1716
+ multiplication_complex.matrix().toarray(), [[2.0j, 0.0j], [0.0j, 0.0j]]
1717
+ )
1710
1718
 
1711
1719
  # Check that the input is not changed:
1712
1720
  np.testing.assert_allclose(zero_projector_sum.matrix().toarray(), [[1.0, 0.0], [0.0, 0.0]])
1713
1721
 
1714
1722
  with pytest.raises(TypeError):
1715
- _ = 'not_the_correct_type' * zero_projector_sum
1723
+ _ = 'not_the_correct_type' * zero_projector_sum # type: ignore[operator]
1716
1724
 
1717
1725
 
1718
- def test_projector_sum_multiplication_right():
1726
+ def test_projector_sum_multiplication_right() -> None:
1719
1727
  q0 = cirq.NamedQubit('q0')
1720
1728
 
1721
1729
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(cirq.ProjectorString({q0: 0}))
@@ -1727,16 +1735,18 @@ def test_projector_sum_multiplication_right():
1727
1735
  np.testing.assert_allclose(multiplication_int.matrix().toarray(), [[2.0, 0.0], [0.0, 0.0]])
1728
1736
 
1729
1737
  multiplication_complex = zero_projector_sum * 2j
1730
- np.testing.assert_allclose(multiplication_complex.matrix().toarray(), [[2.0j, 0.0], [0.0, 0.0]])
1738
+ np.testing.assert_allclose(
1739
+ multiplication_complex.matrix().toarray(), [[2.0j, 0.0j], [0.0j, 0.0j]]
1740
+ )
1731
1741
 
1732
1742
  # Check that the input is not changed:
1733
- np.testing.assert_allclose(zero_projector_sum.matrix().toarray(), [[1.0, 0.0], [0.0, 0.0]])
1743
+ np.testing.assert_allclose(zero_projector_sum.matrix().toarray(), [[1.0, 0.0j], [0.0j, 0.0j]])
1734
1744
 
1735
1745
  with pytest.raises(TypeError):
1736
- _ = zero_projector_sum * 'not_the_correct_type'
1746
+ _ = zero_projector_sum * 'not_the_correct_type' # type: ignore[operator]
1737
1747
 
1738
1748
 
1739
- def test_projector_sum_self_multiplication():
1749
+ def test_projector_sum_self_multiplication() -> None:
1740
1750
  q0 = cirq.NamedQubit('q0')
1741
1751
 
1742
1752
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(cirq.ProjectorString({q0: 0}))
@@ -1751,13 +1761,15 @@ def test_projector_sum_self_multiplication():
1751
1761
 
1752
1762
  multiplication_complex = zero_projector_sum.copy()
1753
1763
  multiplication_complex *= 2j
1754
- np.testing.assert_allclose(multiplication_complex.matrix().toarray(), [[2.0j, 0.0], [0.0, 0.0]])
1764
+ np.testing.assert_allclose(
1765
+ multiplication_complex.matrix().toarray(), [[2.0j, 0.0j], [0.0j, 0.0j]]
1766
+ )
1755
1767
 
1756
1768
  with pytest.raises(TypeError):
1757
- zero_projector_sum *= 'not_the_correct_type'
1769
+ zero_projector_sum *= 'not_the_correct_type' # type: ignore[arg-type]
1758
1770
 
1759
1771
 
1760
- def test_projector_sum_weighted_sum():
1772
+ def test_projector_sum_weighted_sum() -> None:
1761
1773
  q0 = cirq.NamedQubit('q0')
1762
1774
 
1763
1775
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(cirq.ProjectorString({q0: 0}))
@@ -1771,7 +1783,7 @@ def test_projector_sum_weighted_sum():
1771
1783
  np.testing.assert_allclose(one_projector_sum.matrix().toarray(), [[0.0, 0.0], [0.0, 1.0]])
1772
1784
 
1773
1785
 
1774
- def test_projector_sum_division():
1786
+ def test_projector_sum_division() -> None:
1775
1787
  q0 = cirq.NamedQubit('q0')
1776
1788
 
1777
1789
  zero_projector_sum = cirq.ProjectorSum.from_projector_strings(cirq.ProjectorString({q0: 0}))
@@ -1783,13 +1795,15 @@ def test_projector_sum_division():
1783
1795
  np.testing.assert_allclose(true_division_int.matrix().toarray(), [[0.5, 0.0], [0.0, 0.0]])
1784
1796
 
1785
1797
  true_division_complex = zero_projector_sum / 2j
1786
- np.testing.assert_allclose(true_division_complex.matrix().toarray(), [[-0.5j, 0.0], [0.0, 0.0]])
1798
+ np.testing.assert_allclose(
1799
+ true_division_complex.matrix().toarray(), [[-0.5j, 0.0j], [0.0j, 0.0j]]
1800
+ )
1787
1801
 
1788
1802
  # Check that the input is not changed:
1789
1803
  np.testing.assert_allclose(zero_projector_sum.matrix().toarray(), [[1.0, 0.0], [0.0, 0.0]])
1790
1804
 
1791
1805
  with pytest.raises(TypeError):
1792
- _ = zero_projector_sum / 'not_the_correct_type'
1806
+ _ = zero_projector_sum / 'not_the_correct_type' # type: ignore[operator]
1793
1807
 
1794
1808
 
1795
1809
  @pytest.mark.parametrize(
@@ -1801,6 +1815,6 @@ def test_projector_sum_division():
1801
1815
  ([cirq.ProjectorString({q0: 0, q1: 1})], (q0, q1)),
1802
1816
  ),
1803
1817
  )
1804
- def test_projector_sum_has_correct_qubits(terms, expected_qubits):
1818
+ def test_projector_sum_has_correct_qubits(terms, expected_qubits) -> None:
1805
1819
  combination = cirq.ProjectorSum.from_projector_strings(terms)
1806
1820
  assert combination.qubits == expected_qubits