cirq-core 1.6.0.dev20250515174529__py3-none-any.whl → 1.6.0.dev20250516154249__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.
- cirq/_compat.py +3 -0
- cirq/_doc.py +2 -0
- cirq/_import.py +2 -0
- cirq/_import_test.py +4 -2
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/_block_diagram_drawer.py +2 -0
- cirq/circuits/_block_diagram_drawer_test.py +2 -0
- cirq/circuits/_box_drawing_character_data.py +2 -0
- cirq/circuits/_box_drawing_character_data_test.py +2 -0
- cirq/circuits/_bucket_priority_queue.py +2 -0
- cirq/circuits/_bucket_priority_queue_test.py +2 -0
- cirq/circuits/circuit_operation_test.py +3 -0
- cirq/circuits/circuit_test.py +2 -0
- cirq/circuits/frozen_circuit_test.py +2 -0
- cirq/circuits/insert_strategy_test.py +2 -0
- cirq/circuits/moment_test.py +2 -0
- cirq/circuits/optimization_pass_test.py +2 -0
- cirq/circuits/qasm_output_test.py +3 -0
- cirq/circuits/text_diagram_drawer_test.py +2 -0
- cirq/contrib/acquaintance/bipartite_test.py +2 -0
- cirq/contrib/acquaintance/devices_test.py +2 -0
- cirq/contrib/acquaintance/executor_test.py +2 -0
- cirq/contrib/acquaintance/inspection_utils_test.py +2 -0
- cirq/contrib/acquaintance/mutation_utils_test.py +2 -0
- cirq/contrib/acquaintance/optimizers_test.py +3 -0
- cirq/contrib/acquaintance/permutation_test.py +2 -0
- cirq/contrib/acquaintance/shift_swap_network_test.py +2 -0
- cirq/contrib/acquaintance/shift_test.py +2 -0
- cirq/contrib/acquaintance/strategies/cubic_test.py +2 -0
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +2 -0
- cirq/contrib/acquaintance/testing.py +2 -0
- cirq/contrib/acquaintance/topological_sort_test.py +2 -0
- cirq/contrib/bayesian_network/bayesian_network_gate_test.py +3 -0
- cirq/contrib/circuitdag/circuit_dag_test.py +2 -0
- cirq/contrib/graph_device/graph_device_test.py +2 -0
- cirq/contrib/graph_device/hypergraph_test.py +2 -0
- cirq/contrib/graph_device/uniform_graph_device.py +2 -0
- cirq/contrib/graph_device/uniform_graph_device_test.py +2 -0
- cirq/contrib/hacks/disable_validation.py +2 -0
- cirq/contrib/hacks/disable_validation_test.py +2 -0
- cirq/contrib/json.py +2 -0
- cirq/contrib/json_test.py +3 -0
- cirq/contrib/noise_models/noise_models_test.py +2 -0
- cirq/contrib/paulistring/clifford_optimize.py +2 -0
- cirq/contrib/paulistring/clifford_optimize_test.py +2 -0
- cirq/contrib/paulistring/clifford_target_gateset_test.py +2 -0
- cirq/contrib/paulistring/optimize.py +2 -0
- cirq/contrib/paulistring/optimize_test.py +2 -0
- cirq/contrib/paulistring/pauli_string_dag.py +2 -0
- cirq/contrib/paulistring/pauli_string_dag_test.py +2 -0
- cirq/contrib/paulistring/pauli_string_optimize.py +5 -1
- cirq/contrib/paulistring/pauli_string_optimize_test.py +2 -0
- cirq/contrib/paulistring/recombine.py +2 -0
- cirq/contrib/paulistring/recombine_test.py +2 -0
- cirq/contrib/paulistring/separate.py +2 -0
- cirq/contrib/paulistring/separate_test.py +2 -0
- cirq/contrib/qasm_import/_lexer.py +2 -0
- cirq/contrib/qasm_import/_lexer_test.py +2 -0
- cirq/contrib/qasm_import/_parser.py +2 -0
- cirq/contrib/qasm_import/_parser_test.py +2 -0
- cirq/contrib/qasm_import/exception.py +2 -0
- cirq/contrib/qasm_import/qasm.py +6 -2
- cirq/contrib/qasm_import/qasm_test.py +3 -0
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +2 -0
- cirq/contrib/qcircuit/qcircuit_diagram_info_test.py +2 -0
- cirq/contrib/qcircuit/qcircuit_pdf.py +7 -2
- cirq/contrib/qcircuit/qcircuit_pdf_test.py +2 -0
- cirq/contrib/qcircuit/qcircuit_test.py +2 -0
- cirq/contrib/quantum_volume/quantum_volume.py +2 -0
- cirq/contrib/quantum_volume/quantum_volume_test.py +2 -0
- cirq/contrib/quimb/density_matrix_test.py +3 -0
- cirq/contrib/quimb/grid_circuits.py +2 -0
- cirq/contrib/quimb/grid_circuits_test.py +3 -0
- cirq/contrib/quimb/mps_simulator_test.py +3 -0
- cirq/contrib/quimb/state_vector_test.py +3 -0
- cirq/contrib/quirk/export_to_quirk.py +2 -0
- cirq/contrib/quirk/export_to_quirk_test.py +2 -0
- cirq/contrib/quirk/linearize_circuit.py +2 -0
- cirq/contrib/routing/device.py +2 -0
- cirq/contrib/routing/device_test.py +2 -0
- cirq/contrib/routing/greedy_test.py +2 -0
- cirq/contrib/routing/initialization_test.py +2 -0
- cirq/contrib/routing/router.py +4 -2
- cirq/contrib/routing/router_test.py +2 -0
- cirq/contrib/routing/swap_network_test.py +2 -0
- cirq/contrib/routing/utils_test.py +3 -0
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +4 -2
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +3 -0
- cirq/contrib/svg/svg_test.py +3 -0
- cirq/devices/device_test.py +3 -0
- cirq/devices/grid_device_metadata_test.py +3 -0
- cirq/interop/quirk/cells/parse_test.py +10 -10
- cirq/ops/pauli_string_phasor.py +1 -1
- cirq/testing/equals_tester_test.py +19 -17
- cirq/value/random_state_test.py +3 -3
- cirq/value/timestamp.py +4 -0
- cirq/value/timestamp_test.py +10 -10
- cirq/vis/density_matrix_test.py +17 -17
- cirq/work/collector_test.py +13 -10
- cirq/work/observable_measurement.py +14 -2
- cirq/work/observable_measurement_data.py +3 -3
- cirq/work/observable_measurement_test.py +43 -27
- cirq/work/observable_settings.py +2 -12
- cirq/work/observable_settings_test.py +7 -7
- cirq/work/pauli_sum_collector_test.py +7 -9
- cirq/work/sampler_test.py +25 -22
- {cirq_core-1.6.0.dev20250515174529.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250515174529.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/RECORD +112 -112
- {cirq_core-1.6.0.dev20250515174529.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/WHEEL +0 -0
- {cirq_core-1.6.0.dev20250515174529.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250515174529.dist-info → cirq_core-1.6.0.dev20250516154249.dist-info}/top_level.txt +0 -0
cirq/contrib/qasm_import/qasm.py
CHANGED
|
@@ -14,11 +14,15 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from
|
|
17
|
+
from typing import TYPE_CHECKING
|
|
18
|
+
|
|
18
19
|
from cirq.contrib.qasm_import._parser import QasmParser
|
|
19
20
|
|
|
21
|
+
if TYPE_CHECKING:
|
|
22
|
+
import cirq
|
|
23
|
+
|
|
20
24
|
|
|
21
|
-
def circuit_from_qasm(qasm: str) ->
|
|
25
|
+
def circuit_from_qasm(qasm: str) -> cirq.Circuit:
|
|
22
26
|
"""Parses an OpenQASM string to `cirq.Circuit`.
|
|
23
27
|
|
|
24
28
|
Args:
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
import numpy as np
|
|
15
18
|
|
|
16
19
|
import cirq
|
|
@@ -13,17 +13,22 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
16
18
|
import errno
|
|
17
19
|
import os
|
|
20
|
+
from typing import TYPE_CHECKING
|
|
18
21
|
|
|
19
22
|
from pylatex import Document, NoEscape, Package
|
|
20
23
|
|
|
21
|
-
from cirq import circuits
|
|
22
24
|
from cirq.contrib.qcircuit.qcircuit_diagram import circuit_to_latex_using_qcircuit
|
|
23
25
|
|
|
26
|
+
if TYPE_CHECKING:
|
|
27
|
+
import cirq
|
|
28
|
+
|
|
24
29
|
|
|
25
30
|
def circuit_to_pdf_using_qcircuit_via_tex(
|
|
26
|
-
circuit:
|
|
31
|
+
circuit: cirq.Circuit,
|
|
27
32
|
filepath: str,
|
|
28
33
|
pdf_kwargs=None,
|
|
29
34
|
qcircuit_kwargs=None,
|
cirq/contrib/routing/device.py
CHANGED
cirq/contrib/routing/router.py
CHANGED
|
@@ -14,13 +14,15 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import Callable, Optional
|
|
17
|
+
from typing import Callable, Optional, TYPE_CHECKING
|
|
18
18
|
|
|
19
19
|
import networkx as nx
|
|
20
20
|
|
|
21
21
|
from cirq import circuits, protocols
|
|
22
22
|
from cirq.contrib.routing.greedy import route_circuit_greedily
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from cirq.contrib.routing.swap_network import SwapNetwork
|
|
24
26
|
|
|
25
27
|
ROUTERS = {'greedy': route_circuit_greedily}
|
|
26
28
|
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
import networkx as nx
|
|
15
18
|
import pytest
|
|
16
19
|
|
|
@@ -17,13 +17,15 @@
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
19
|
import time
|
|
20
|
-
from typing import Dict, List, Optional, Tuple, Union
|
|
20
|
+
from typing import Dict, List, Optional, Tuple, TYPE_CHECKING, Union
|
|
21
21
|
|
|
22
22
|
import numpy as np
|
|
23
23
|
|
|
24
24
|
from cirq import circuits, ops, protocols, work
|
|
25
25
|
from cirq.experiments import SingleQubitReadoutCalibrationResult
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
if TYPE_CHECKING:
|
|
28
|
+
from cirq.study import ResultDict
|
|
27
29
|
|
|
28
30
|
|
|
29
31
|
def _validate_input(
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
import itertools
|
|
15
18
|
|
|
16
19
|
import numpy as np
|
cirq/contrib/svg/svg_test.py
CHANGED
cirq/devices/device_test.py
CHANGED
|
@@ -11,8 +11,11 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
14
15
|
"""Tests for GridDevicemetadata."""
|
|
15
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
import networkx as nx
|
|
17
20
|
import pytest
|
|
18
21
|
|
|
@@ -19,7 +19,7 @@ import sympy
|
|
|
19
19
|
from cirq.interop.quirk.cells.parse import parse_complex, parse_formula, parse_matrix
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
def test_parse_matrix():
|
|
22
|
+
def test_parse_matrix() -> None:
|
|
23
23
|
s = np.sqrt(0.5)
|
|
24
24
|
np.testing.assert_allclose(
|
|
25
25
|
parse_matrix('{{√½,√½},{-√½,√½}}'), np.array([[s, s], [-s, s]]), atol=1e-8
|
|
@@ -32,7 +32,7 @@ def test_parse_matrix():
|
|
|
32
32
|
)
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
def test_parse_matrix_failures():
|
|
35
|
+
def test_parse_matrix_failures() -> None:
|
|
36
36
|
with pytest.raises(ValueError, match='Not surrounded by {{}}'):
|
|
37
37
|
_ = parse_matrix('1')
|
|
38
38
|
with pytest.raises(ValueError, match='Not surrounded by {{}}'):
|
|
@@ -45,7 +45,7 @@ def test_parse_matrix_failures():
|
|
|
45
45
|
_ = parse_matrix('{{x}}')
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
def test_parse_real_formula():
|
|
48
|
+
def test_parse_real_formula() -> None:
|
|
49
49
|
t = sympy.Symbol('t')
|
|
50
50
|
assert parse_formula('1/2') == 0.5
|
|
51
51
|
assert parse_formula('t*t + ln(t)') == t * t + sympy.ln(t)
|
|
@@ -58,12 +58,12 @@ def test_parse_real_formula():
|
|
|
58
58
|
_ = parse_formula('i')
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
def test_parse_formula_failures():
|
|
61
|
+
def test_parse_formula_failures() -> None:
|
|
62
62
|
with pytest.raises(TypeError, match='formula must be a string'):
|
|
63
|
-
_ = parse_formula(2)
|
|
63
|
+
_ = parse_formula(2) # type: ignore[arg-type]
|
|
64
64
|
|
|
65
65
|
with pytest.raises(TypeError, match='formula must be a string'):
|
|
66
|
-
_ = parse_formula([])
|
|
66
|
+
_ = parse_formula([]) # type: ignore[arg-type]
|
|
67
67
|
|
|
68
68
|
with pytest.raises(ValueError, match='Unrecognized token'):
|
|
69
69
|
_ = parse_formula('5*__**DSA **)SADD')
|
|
@@ -72,7 +72,7 @@ def test_parse_formula_failures():
|
|
|
72
72
|
_ = parse_formula('5*x')
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
def test_parse_complex():
|
|
75
|
+
def test_parse_complex() -> None:
|
|
76
76
|
assert parse_complex('0') == 0
|
|
77
77
|
assert parse_complex('1') == 1
|
|
78
78
|
assert parse_complex('i') == 1j
|
|
@@ -84,7 +84,7 @@ def test_parse_complex():
|
|
|
84
84
|
np.testing.assert_allclose(parse_complex('exp 2'), np.e**2, atol=1e-8)
|
|
85
85
|
|
|
86
86
|
|
|
87
|
-
def test_parse_complex_raw_cases_from_quirk():
|
|
87
|
+
def test_parse_complex_raw_cases_from_quirk() -> None:
|
|
88
88
|
assert parse_complex("0") == 0
|
|
89
89
|
assert parse_complex("1") == 1
|
|
90
90
|
assert parse_complex("-1") == -1
|
|
@@ -116,7 +116,7 @@ def test_parse_complex_raw_cases_from_quirk():
|
|
|
116
116
|
np.testing.assert_allclose(parse_complex("2 pi"), 2 * np.pi)
|
|
117
117
|
|
|
118
118
|
|
|
119
|
-
def test_parse_complex_expression_cases_from_quirk():
|
|
119
|
+
def test_parse_complex_expression_cases_from_quirk() -> None:
|
|
120
120
|
np.testing.assert_allclose(parse_complex("1/3"), 1 / 3)
|
|
121
121
|
np.testing.assert_allclose(parse_complex("2/3/5"), (2 / 3) / 5)
|
|
122
122
|
np.testing.assert_allclose(parse_complex("2/3/5*7/13"), ((((2 / 3) / 5)) * 7) / 13)
|
|
@@ -152,7 +152,7 @@ def test_parse_complex_expression_cases_from_quirk():
|
|
|
152
152
|
np.testing.assert_allclose(parse_complex("cos(acos(0.5))"), 0.5, atol=1e-8)
|
|
153
153
|
|
|
154
154
|
|
|
155
|
-
def test_parse_complex_expression_failures():
|
|
155
|
+
def test_parse_complex_expression_failures() -> None:
|
|
156
156
|
with pytest.raises(ValueError, match='Incomplete expression'):
|
|
157
157
|
_ = parse_formula('(')
|
|
158
158
|
with pytest.raises(ValueError, match=r"unmatched '\)'"):
|
cirq/ops/pauli_string_phasor.py
CHANGED
|
@@ -199,7 +199,7 @@ class PauliStringPhasor(gate_operation.GateOperation):
|
|
|
199
199
|
syms = tuple(sym(qubit) for qubit in qubits)
|
|
200
200
|
return protocols.CircuitDiagramInfo(wire_symbols=syms, exponent=self.exponent_relative)
|
|
201
201
|
|
|
202
|
-
def conjugated_by(self, clifford:
|
|
202
|
+
def conjugated_by(self, clifford: cirq.OP_TREE) -> PauliStringPhasor:
|
|
203
203
|
r"""Returns the Pauli string conjugated by a clifford operation.
|
|
204
204
|
|
|
205
205
|
The PauliStringPhasor $P$ conjugated by the Clifford operation $C$ is
|
|
@@ -19,7 +19,7 @@ import pytest
|
|
|
19
19
|
from cirq.testing.equals_tester import EqualsTester
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
def test_add_equality_group_correct():
|
|
22
|
+
def test_add_equality_group_correct() -> None:
|
|
23
23
|
eq = EqualsTester()
|
|
24
24
|
|
|
25
25
|
eq.add_equality_group(fractions.Fraction(1, 1))
|
|
@@ -39,7 +39,7 @@ def test_add_equality_group_correct():
|
|
|
39
39
|
eq.add_equality_group('unrelated')
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
def test_assert_make_equality_group():
|
|
42
|
+
def test_assert_make_equality_group() -> None:
|
|
43
43
|
eq = EqualsTester()
|
|
44
44
|
|
|
45
45
|
with pytest.raises(AssertionError, match="can't be in the same"):
|
|
@@ -57,20 +57,20 @@ def test_assert_make_equality_group():
|
|
|
57
57
|
eq.make_equality_group(lambda: 3)
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
def test_add_equality_group_not_equivalent():
|
|
60
|
+
def test_add_equality_group_not_equivalent() -> None:
|
|
61
61
|
eq = EqualsTester()
|
|
62
62
|
with pytest.raises(AssertionError, match="can't be in the same"):
|
|
63
63
|
eq.add_equality_group(1, 2)
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
def test_add_equality_group_not_disjoint():
|
|
66
|
+
def test_add_equality_group_not_disjoint() -> None:
|
|
67
67
|
eq = EqualsTester()
|
|
68
68
|
eq.add_equality_group(1)
|
|
69
69
|
with pytest.raises(AssertionError, match="can't be in different"):
|
|
70
70
|
eq.add_equality_group(1)
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
def test_add_equality_group_bad_hash():
|
|
73
|
+
def test_add_equality_group_bad_hash() -> None:
|
|
74
74
|
class KeyHash:
|
|
75
75
|
def __init__(self, k, h):
|
|
76
76
|
self._k = k
|
|
@@ -94,7 +94,7 @@ def test_add_equality_group_bad_hash():
|
|
|
94
94
|
eq.add_equality_group(KeyHash('c', 2), KeyHash('c', 3))
|
|
95
95
|
|
|
96
96
|
|
|
97
|
-
def test_add_equality_group_exception_hash():
|
|
97
|
+
def test_add_equality_group_exception_hash() -> None:
|
|
98
98
|
class FailHash:
|
|
99
99
|
def __hash__(self):
|
|
100
100
|
raise ValueError('injected failure')
|
|
@@ -104,7 +104,7 @@ def test_add_equality_group_exception_hash():
|
|
|
104
104
|
eq.add_equality_group(FailHash())
|
|
105
105
|
|
|
106
106
|
|
|
107
|
-
def test_fails_when_forgot_type_check():
|
|
107
|
+
def test_fails_when_forgot_type_check() -> None:
|
|
108
108
|
eq = EqualsTester()
|
|
109
109
|
|
|
110
110
|
class NoTypeCheckEqualImplementation:
|
|
@@ -124,11 +124,12 @@ def test_fails_when_forgot_type_check():
|
|
|
124
124
|
eq.add_equality_group(NoTypeCheckEqualImplementation())
|
|
125
125
|
|
|
126
126
|
|
|
127
|
-
def test_fails_when_equal_to_everything():
|
|
127
|
+
def test_fails_when_equal_to_everything() -> None:
|
|
128
128
|
eq = EqualsTester()
|
|
129
129
|
|
|
130
130
|
class AllEqual:
|
|
131
|
-
__hash__
|
|
131
|
+
def __hash__(self) -> int:
|
|
132
|
+
return 0
|
|
132
133
|
|
|
133
134
|
def __eq__(self, other):
|
|
134
135
|
return True
|
|
@@ -136,11 +137,12 @@ def test_fails_when_equal_to_everything():
|
|
|
136
137
|
def __ne__(self, other):
|
|
137
138
|
return False
|
|
138
139
|
|
|
140
|
+
assert hash(AllEqual()) == 0
|
|
139
141
|
with pytest.raises(AssertionError, match="can't be in different"):
|
|
140
142
|
eq.add_equality_group(AllEqual())
|
|
141
143
|
|
|
142
144
|
|
|
143
|
-
def test_fails_hash_is_default_and_inconsistent():
|
|
145
|
+
def test_fails_hash_is_default_and_inconsistent() -> None:
|
|
144
146
|
eq = EqualsTester()
|
|
145
147
|
|
|
146
148
|
class DefaultHashImplementation:
|
|
@@ -161,7 +163,7 @@ def test_fails_hash_is_default_and_inconsistent():
|
|
|
161
163
|
eq.make_equality_group(DefaultHashImplementation)
|
|
162
164
|
|
|
163
165
|
|
|
164
|
-
def test_fails_when_ne_is_inconsistent():
|
|
166
|
+
def test_fails_when_ne_is_inconsistent() -> None:
|
|
165
167
|
eq = EqualsTester()
|
|
166
168
|
|
|
167
169
|
class InconsistentNeImplementation:
|
|
@@ -185,7 +187,7 @@ def test_fails_when_ne_is_inconsistent():
|
|
|
185
187
|
eq.make_equality_group(InconsistentNeImplementation)
|
|
186
188
|
|
|
187
189
|
|
|
188
|
-
def test_fails_when_ne_is_inconsistent_due_to_not_implemented():
|
|
190
|
+
def test_fails_when_ne_is_inconsistent_due_to_not_implemented() -> None:
|
|
189
191
|
eq = EqualsTester()
|
|
190
192
|
|
|
191
193
|
class InconsistentNeImplementation:
|
|
@@ -207,7 +209,7 @@ def test_fails_when_ne_is_inconsistent_due_to_not_implemented():
|
|
|
207
209
|
eq.make_equality_group(InconsistentNeImplementation)
|
|
208
210
|
|
|
209
211
|
|
|
210
|
-
def test_fails_when_not_reflexive():
|
|
212
|
+
def test_fails_when_not_reflexive() -> None:
|
|
211
213
|
eq = EqualsTester()
|
|
212
214
|
|
|
213
215
|
class NotReflexiveImplementation:
|
|
@@ -226,7 +228,7 @@ def test_fails_when_not_reflexive():
|
|
|
226
228
|
eq.add_equality_group(NotReflexiveImplementation())
|
|
227
229
|
|
|
228
230
|
|
|
229
|
-
def test_fails_when_not_commutative():
|
|
231
|
+
def test_fails_when_not_commutative() -> None:
|
|
230
232
|
eq = EqualsTester()
|
|
231
233
|
|
|
232
234
|
class NotCommutativeImplementation:
|
|
@@ -248,14 +250,14 @@ def test_fails_when_not_commutative():
|
|
|
248
250
|
eq.add_equality_group(NotCommutativeImplementation(1), NotCommutativeImplementation(0))
|
|
249
251
|
|
|
250
252
|
|
|
251
|
-
def test_works_on_types():
|
|
253
|
+
def test_works_on_types() -> None:
|
|
252
254
|
eq = EqualsTester()
|
|
253
255
|
eq.add_equality_group(object)
|
|
254
256
|
eq.add_equality_group(int)
|
|
255
257
|
eq.add_equality_group(object())
|
|
256
258
|
|
|
257
259
|
|
|
258
|
-
def test_returns_not_implemented_for_other_types():
|
|
260
|
+
def test_returns_not_implemented_for_other_types() -> None:
|
|
259
261
|
# First we demonstrate an example of the problem.
|
|
260
262
|
|
|
261
263
|
# FirstClass is the class that is broken.
|
|
@@ -323,7 +325,7 @@ def test_returns_not_implemented_for_other_types():
|
|
|
323
325
|
eq.add_equality_group(ThirdClass("a"), ThirdClass("a"))
|
|
324
326
|
|
|
325
327
|
|
|
326
|
-
def test_not_implemented_error():
|
|
328
|
+
def test_not_implemented_error() -> None:
|
|
327
329
|
# Common bug is to return NotImplementedError instead of NotImplemented.
|
|
328
330
|
class NotImplementedErrorCase:
|
|
329
331
|
def __init__(self, val):
|
cirq/value/random_state_test.py
CHANGED
|
@@ -17,7 +17,7 @@ import numpy as np
|
|
|
17
17
|
import cirq
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
def test_parse_random_state():
|
|
20
|
+
def test_parse_random_state() -> None:
|
|
21
21
|
global_state = np.random.get_state()
|
|
22
22
|
|
|
23
23
|
def rand(prng):
|
|
@@ -34,11 +34,11 @@ def test_parse_random_state():
|
|
|
34
34
|
eq.add_equality_group(*vals)
|
|
35
35
|
|
|
36
36
|
seed = np.random.randint(2**31)
|
|
37
|
-
|
|
37
|
+
prngs1 = [
|
|
38
38
|
np.random.RandomState(seed),
|
|
39
39
|
cirq.value.parse_random_state(np.random.RandomState(seed)),
|
|
40
40
|
cirq.value.parse_random_state(seed),
|
|
41
41
|
]
|
|
42
|
-
vals = [prng.rand() for prng in
|
|
42
|
+
vals = [prng.rand() for prng in prngs1]
|
|
43
43
|
eq = cirq.testing.EqualsTester()
|
|
44
44
|
eq.add_equality_group(*vals)
|
cirq/value/timestamp.py
CHANGED
|
@@ -64,6 +64,10 @@ class Timestamp:
|
|
|
64
64
|
def __sub__(self, other: Duration) -> 'Timestamp':
|
|
65
65
|
pass
|
|
66
66
|
|
|
67
|
+
@overload
|
|
68
|
+
def __sub__(self, other: timedelta) -> 'Timestamp':
|
|
69
|
+
pass
|
|
70
|
+
|
|
67
71
|
def __sub__(self, other):
|
|
68
72
|
if isinstance(other, Duration):
|
|
69
73
|
return Timestamp(picos=self._picos - other.total_picos())
|