cirq-core 1.6.0.dev20250519212157__py3-none-any.whl → 1.6.0.dev20250520002718__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/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/frozen_circuit.py +2 -2
- cirq/contrib/acquaintance/topological_sort.py +2 -2
- cirq/contrib/custom_simulators/custom_state_simulator.py +2 -2
- cirq/contrib/paulistring/clifford_target_gateset.py +2 -2
- cirq/contrib/quantum_volume/quantum_volume.py +5 -3
- cirq/contrib/quimb/grid_circuits.py +4 -3
- cirq/contrib/quimb/state_vector.py +4 -2
- cirq/contrib/routing/router.py +2 -2
- cirq/experiments/qubit_characterizations.py +2 -1
- cirq/experiments/random_quantum_circuit_generation.py +2 -1
- cirq/experiments/two_qubit_xeb.py +2 -1
- cirq/linalg/predicates.py +1 -1
- cirq/ops/gate_operation.py +2 -1
- cirq/ops/linear_combinations.py +5 -5
- cirq/ops/pauli_string_phasor.py +2 -2
- cirq/ops/raw_types.py +2 -1
- cirq/sim/clifford/clifford_tableau_simulation_state.py +2 -2
- cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +2 -2
- cirq/sim/clifford/stabilizer_simulation_state.py +2 -1
- cirq/sim/simulation_state_base.py +2 -1
- cirq/testing/consistent_protocols.py +2 -0
- cirq/testing/consistent_protocols_test.py +4 -2
- cirq/testing/consistent_qasm.py +2 -0
- cirq/testing/consistent_qasm_test.py +2 -0
- cirq/testing/consistent_resolve_parameters.py +2 -0
- cirq/testing/consistent_specified_has_unitary.py +2 -0
- cirq/testing/consistent_specified_has_unitary_test.py +2 -0
- cirq/testing/consistent_unitary.py +2 -0
- cirq/testing/consistent_unitary_test.py +2 -0
- cirq/testing/deprecation.py +3 -0
- cirq/testing/deprecation_test.py +3 -0
- cirq/testing/devices.py +4 -0
- cirq/testing/devices_test.py +3 -0
- cirq/testing/equals_tester.py +2 -0
- cirq/testing/equals_tester_test.py +2 -0
- cirq/testing/equivalent_basis_map.py +2 -0
- cirq/testing/equivalent_basis_map_test.py +3 -0
- cirq/testing/equivalent_repr_eval.py +2 -0
- cirq/testing/equivalent_repr_eval_test.py +2 -0
- cirq/testing/gate_features.py +2 -0
- cirq/testing/gate_features_test.py +2 -0
- cirq/testing/json.py +6 -2
- cirq/testing/json_test.py +2 -0
- cirq/testing/lin_alg_utils_test.py +2 -0
- cirq/testing/logs.py +4 -0
- cirq/testing/logs_test.py +2 -0
- cirq/testing/no_identifier_qubit.py +3 -0
- cirq/testing/no_identifier_qubit_test.py +2 -0
- cirq/testing/op_tree.py +2 -0
- cirq/testing/op_tree_test.py +3 -0
- cirq/testing/order_tester.py +2 -0
- cirq/testing/order_tester_test.py +2 -0
- cirq/testing/pytest_utils.py +2 -0
- cirq/testing/pytest_utils_test.py +2 -0
- cirq/testing/random_circuit_test.py +3 -0
- cirq/testing/repr_pretty_tester.py +1 -0
- cirq/testing/repr_pretty_tester_test.py +2 -0
- cirq/testing/routing_devices_test.py +3 -0
- cirq/testing/sample_circuits_test.py +2 -0
- cirq/testing/sample_gates.py +3 -0
- cirq/testing/sample_gates_test.py +3 -0
- cirq/transformers/align_test.py +2 -0
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +2 -0
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +2 -0
- cirq/transformers/analytical_decompositions/pauli_string_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +2 -0
- cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +2 -0
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +3 -0
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +2 -0
- cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +2 -0
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +2 -0
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py +2 -0
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +2 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +2 -0
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +2 -0
- cirq/transformers/drop_empty_moments_test.py +2 -0
- cirq/transformers/drop_negligible_operations_test.py +2 -0
- cirq/transformers/eject_phased_paulis_test.py +3 -0
- cirq/transformers/eject_z_test.py +2 -0
- cirq/transformers/expand_composite_test.py +2 -0
- cirq/transformers/gauge_compiling/cphase_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling.py +9 -5
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +2 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils_test.py +6 -1
- cirq/transformers/gauge_compiling/iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/iswap_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge.py +2 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +3 -3
- cirq/transformers/gauge_compiling/sqrt_cz_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge_test.py +2 -0
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +3 -0
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +3 -0
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation_test.py +2 -0
- cirq/transformers/insertion_sort_test.py +2 -0
- cirq/transformers/measurement_transformers_test.py +2 -0
- cirq/transformers/merge_single_qubit_gates_test.py +2 -0
- cirq/transformers/noise_adding.py +2 -0
- cirq/transformers/noise_adding_test.py +2 -0
- cirq/transformers/qubit_management_transformers_test.py +2 -0
- cirq/transformers/randomized_measurements_test.py +2 -0
- cirq/transformers/routing/initial_mapper_test.py +2 -0
- cirq/transformers/routing/line_initial_mapper_test.py +2 -0
- cirq/transformers/routing/mapping_manager_test.py +2 -0
- cirq/transformers/routing/route_circuit_cqc_test.py +2 -0
- cirq/transformers/routing/visualize_routed_circuit_test.py +2 -0
- cirq/transformers/stratify_test.py +3 -0
- cirq/transformers/synchronize_terminal_measurements_test.py +2 -0
- cirq/transformers/tag_transformers.py +10 -8
- cirq/transformers/tag_transformers_test.py +2 -0
- cirq/transformers/target_gatesets/cz_gateset_test.py +2 -0
- cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +2 -0
- cirq/transformers/transformer_api_test.py +2 -0
- cirq/value/abc_alt.py +2 -0
- cirq/value/abc_alt_test.py +2 -0
- cirq/value/angle.py +5 -2
- cirq/value/angle_test.py +2 -0
- cirq/value/classical_data_test.py +3 -0
- cirq/value/condition_test.py +2 -0
- cirq/value/digits.py +2 -0
- cirq/value/digits_test.py +2 -0
- cirq/value/duration_test.py +2 -0
- cirq/value/linear_dict_test.py +2 -0
- cirq/value/measurement_key.py +5 -5
- cirq/value/measurement_key_test.py +2 -0
- cirq/value/periodic_value_test.py +2 -0
- cirq/value/probability_test.py +2 -0
- cirq/value/product_state_test.py +3 -0
- cirq/value/random_state.py +2 -0
- cirq/value/random_state_test.py +2 -0
- cirq/value/timestamp.py +8 -5
- cirq/value/timestamp_test.py +2 -0
- cirq/value/type_alias.py +2 -0
- cirq/value/value_equality_attr.py +3 -0
- cirq/value/value_equality_attr_test.py +3 -0
- cirq/vis/density_matrix.py +2 -0
- cirq/vis/density_matrix_test.py +3 -0
- cirq/vis/heatmap_test.py +3 -0
- cirq/vis/histogram.py +3 -0
- cirq/vis/histogram_test.py +3 -0
- cirq/vis/state_histogram.py +4 -2
- cirq/vis/state_histogram_test.py +2 -0
- cirq/vis/vis_utils.py +4 -1
- cirq/vis/vis_utils_test.py +3 -0
- cirq/work/collector_test.py +2 -0
- cirq/work/observable_grouping.py +2 -0
- cirq/work/observable_grouping_test.py +2 -0
- cirq/work/observable_measurement_data_test.py +4 -1
- cirq/work/observable_measurement_test.py +3 -0
- cirq/work/observable_settings_test.py +2 -0
- cirq/work/pauli_sum_collector_test.py +2 -0
- {cirq_core-1.6.0.dev20250519212157.dist-info → cirq_core-1.6.0.dev20250520002718.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250519212157.dist-info → cirq_core-1.6.0.dev20250520002718.dist-info}/RECORD +166 -166
- {cirq_core-1.6.0.dev20250519212157.dist-info → cirq_core-1.6.0.dev20250520002718.dist-info}/WHEEL +0 -0
- {cirq_core-1.6.0.dev20250519212157.dist-info → cirq_core-1.6.0.dev20250520002718.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250519212157.dist-info → cirq_core-1.6.0.dev20250520002718.dist-info}/top_level.txt +0 -0
|
@@ -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 pytest
|
|
15
18
|
|
|
16
19
|
import cirq
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import itertools
|
|
16
18
|
from typing import Callable, Hashable, Optional, TYPE_CHECKING
|
|
17
19
|
|
|
@@ -23,11 +25,11 @@ if TYPE_CHECKING:
|
|
|
23
25
|
|
|
24
26
|
@transformer_api.transformer
|
|
25
27
|
def index_tags(
|
|
26
|
-
circuit:
|
|
28
|
+
circuit: cirq.AbstractCircuit,
|
|
27
29
|
*,
|
|
28
|
-
context: Optional[
|
|
30
|
+
context: Optional[cirq.TransformerContext] = None,
|
|
29
31
|
target_tags: Optional[set[Hashable]] = None,
|
|
30
|
-
) ->
|
|
32
|
+
) -> cirq.Circuit:
|
|
31
33
|
"""Indexes tags in target_tags as tag_0, tag_1, ... per tag.
|
|
32
34
|
|
|
33
35
|
Args:
|
|
@@ -44,7 +46,7 @@ def index_tags(
|
|
|
44
46
|
return circuit.unfreeze(copy=False)
|
|
45
47
|
tag_iter_by_tags = {tag: itertools.count(start=0, step=1) for tag in target_tags}
|
|
46
48
|
|
|
47
|
-
def _map_func(op:
|
|
49
|
+
def _map_func(op: cirq.Operation, _) -> cirq.OP_TREE:
|
|
48
50
|
tag_set = set(op.tags)
|
|
49
51
|
nonlocal tag_iter_by_tags
|
|
50
52
|
for tag in target_tags.intersection(op.tags):
|
|
@@ -60,12 +62,12 @@ def index_tags(
|
|
|
60
62
|
|
|
61
63
|
@transformer_api.transformer
|
|
62
64
|
def remove_tags(
|
|
63
|
-
circuit:
|
|
65
|
+
circuit: cirq.AbstractCircuit,
|
|
64
66
|
*,
|
|
65
|
-
context: Optional[
|
|
67
|
+
context: Optional[cirq.TransformerContext] = None,
|
|
66
68
|
target_tags: Optional[set[Hashable]] = None,
|
|
67
69
|
remove_if: Callable[[Hashable], bool] = lambda _: False,
|
|
68
|
-
) ->
|
|
70
|
+
) -> cirq.Circuit:
|
|
69
71
|
"""Removes tags from the operations based on the input args.
|
|
70
72
|
|
|
71
73
|
Args:
|
|
@@ -82,7 +84,7 @@ def remove_tags(
|
|
|
82
84
|
raise ValueError("remove_tags doesn't support tags_to_ignore, use function args instead.")
|
|
83
85
|
target_tags = target_tags or set()
|
|
84
86
|
|
|
85
|
-
def _map_func(op:
|
|
87
|
+
def _map_func(op: cirq.Operation, _) -> cirq.OP_TREE:
|
|
86
88
|
remaing_tags = set()
|
|
87
89
|
for tag in op.tags:
|
|
88
90
|
if not remove_if(tag) and tag not in target_tags:
|
cirq/value/abc_alt.py
CHANGED
cirq/value/abc_alt_test.py
CHANGED
cirq/value/angle.py
CHANGED
|
@@ -12,12 +12,15 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import Optional, overload, TYPE_CHECKING
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
18
20
|
import sympy
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from cirq.value import type_alias
|
|
21
24
|
|
|
22
25
|
|
|
23
26
|
def chosen_angle_to_half_turns(
|
cirq/value/angle_test.py
CHANGED
|
@@ -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 re
|
|
15
18
|
|
|
16
19
|
import pytest
|
cirq/value/condition_test.py
CHANGED
cirq/value/digits.py
CHANGED
cirq/value/digits_test.py
CHANGED
cirq/value/duration_test.py
CHANGED
cirq/value/linear_dict_test.py
CHANGED
cirq/value/measurement_key.py
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import dataclasses
|
|
16
18
|
from typing import Any, Dict, FrozenSet, Mapping, Optional, Tuple
|
|
17
19
|
|
|
@@ -49,7 +51,7 @@ class MeasurementKey:
|
|
|
49
51
|
'`MeasurementKey.parse_serialized` for correct behavior.'
|
|
50
52
|
)
|
|
51
53
|
|
|
52
|
-
def replace(self, **changes) ->
|
|
54
|
+
def replace(self, **changes) -> MeasurementKey:
|
|
53
55
|
"""Returns a copy of this MeasurementKey with the specified changes."""
|
|
54
56
|
return dataclasses.replace(self, **changes)
|
|
55
57
|
|
|
@@ -102,7 +104,7 @@ class MeasurementKey:
|
|
|
102
104
|
return cls(name=name, path=tuple(path))
|
|
103
105
|
|
|
104
106
|
@classmethod
|
|
105
|
-
def parse_serialized(cls, key_str: str) ->
|
|
107
|
+
def parse_serialized(cls, key_str: str) -> MeasurementKey:
|
|
106
108
|
"""Parses the serialized string representation of `Measurementkey` into a `MeasurementKey`.
|
|
107
109
|
|
|
108
110
|
This is the only way to construct a `MeasurementKey` from a nested string representation
|
|
@@ -124,9 +126,7 @@ class MeasurementKey:
|
|
|
124
126
|
"""
|
|
125
127
|
return self.replace(path=path_component + self.path)
|
|
126
128
|
|
|
127
|
-
def _with_rescoped_keys_(
|
|
128
|
-
self, path: Tuple[str, ...], bindable_keys: FrozenSet['MeasurementKey']
|
|
129
|
-
):
|
|
129
|
+
def _with_rescoped_keys_(self, path: Tuple[str, ...], bindable_keys: FrozenSet[MeasurementKey]):
|
|
130
130
|
return self.replace(path=path + self.path)
|
|
131
131
|
|
|
132
132
|
def _with_measurement_key_mapping_(self, key_map: Mapping[str, str]):
|
cirq/value/probability_test.py
CHANGED
cirq/value/product_state_test.py
CHANGED
cirq/value/random_state.py
CHANGED
cirq/value/random_state_test.py
CHANGED
cirq/value/timestamp.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
|
"""A typed location in time that supports picosecond accuracy."""
|
|
15
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
from datetime import timedelta
|
|
17
20
|
from typing import overload
|
|
18
21
|
|
|
@@ -45,27 +48,27 @@ class Timestamp:
|
|
|
45
48
|
"""The timestamp's location in picoseconds from arbitrary time zero."""
|
|
46
49
|
return self._picos
|
|
47
50
|
|
|
48
|
-
def __add__(self, other) ->
|
|
51
|
+
def __add__(self, other) -> Timestamp:
|
|
49
52
|
if isinstance(other, timedelta):
|
|
50
53
|
return Timestamp(picos=self._picos + other.total_seconds() * 10**12)
|
|
51
54
|
if not isinstance(other, Duration):
|
|
52
55
|
return NotImplemented
|
|
53
56
|
return Timestamp(picos=self._picos + other.total_picos())
|
|
54
57
|
|
|
55
|
-
def __radd__(self, other) ->
|
|
58
|
+
def __radd__(self, other) -> Timestamp:
|
|
56
59
|
return self.__add__(other)
|
|
57
60
|
|
|
58
61
|
# pylint: disable=function-redefined
|
|
59
62
|
@overload
|
|
60
|
-
def __sub__(self, other:
|
|
63
|
+
def __sub__(self, other: Timestamp) -> Duration:
|
|
61
64
|
pass
|
|
62
65
|
|
|
63
66
|
@overload
|
|
64
|
-
def __sub__(self, other: Duration) ->
|
|
67
|
+
def __sub__(self, other: Duration) -> Timestamp:
|
|
65
68
|
pass
|
|
66
69
|
|
|
67
70
|
@overload
|
|
68
|
-
def __sub__(self, other: timedelta) ->
|
|
71
|
+
def __sub__(self, other: timedelta) -> Timestamp:
|
|
69
72
|
pass
|
|
70
73
|
|
|
71
74
|
def __sub__(self, other):
|
cirq/value/timestamp_test.py
CHANGED
cirq/value/type_alias.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
|
"""Defines `@cirq.value_equality`, for easy __eq__/__hash__ methods."""
|
|
15
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
from typing import Any, Callable, Dict, Optional, overload, Union
|
|
17
20
|
|
|
18
21
|
from typing_extensions import Protocol
|
|
@@ -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 pytest
|
|
15
18
|
|
|
16
19
|
import cirq
|
cirq/vis/density_matrix.py
CHANGED
cirq/vis/density_matrix_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 Density Matrix Plotter."""
|
|
15
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
import numpy as np
|
|
17
20
|
import pytest
|
|
18
21
|
from matplotlib import axis, lines, patches, pyplot as plt, spines, text
|
cirq/vis/heatmap_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 Heatmap."""
|
|
15
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
import pathlib
|
|
17
20
|
import shutil
|
|
18
21
|
import string
|
cirq/vis/histogram.py
CHANGED
|
@@ -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
|
from typing import Any, Mapping, Optional, Sequence, SupportsFloat, Union
|
|
15
18
|
|
|
16
19
|
import numpy as np
|
cirq/vis/histogram_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 Histogram."""
|
|
15
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
import matplotlib.pyplot as plt
|
|
17
20
|
import numpy as np
|
|
18
21
|
import pytest
|
cirq/vis/state_histogram.py
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
"""Tool to visualize the results of a study."""
|
|
16
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
17
19
|
import collections
|
|
18
20
|
from typing import Optional, Sequence, SupportsFloat, Union
|
|
19
21
|
|
|
@@ -23,7 +25,7 @@ import numpy as np
|
|
|
23
25
|
import cirq.study.result as result
|
|
24
26
|
|
|
25
27
|
|
|
26
|
-
def get_state_histogram(result:
|
|
28
|
+
def get_state_histogram(result: result.Result) -> np.ndarray:
|
|
27
29
|
"""Computes a state histogram from a single result with repetitions.
|
|
28
30
|
|
|
29
31
|
Args:
|
|
@@ -52,7 +54,7 @@ def get_state_histogram(result: 'result.Result') -> np.ndarray:
|
|
|
52
54
|
|
|
53
55
|
|
|
54
56
|
def plot_state_histogram(
|
|
55
|
-
data: Union[
|
|
57
|
+
data: Union[result.Result, collections.Counter, Sequence[SupportsFloat]],
|
|
56
58
|
ax: Optional[plt.Axes] = None,
|
|
57
59
|
*,
|
|
58
60
|
tick_label: Optional[Sequence[str]] = None,
|
cirq/vis/state_histogram_test.py
CHANGED
cirq/vis/vis_utils.py
CHANGED
|
@@ -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
|
from typing import TYPE_CHECKING
|
|
15
18
|
|
|
16
19
|
import numpy as np
|
|
@@ -19,7 +22,7 @@ if TYPE_CHECKING:
|
|
|
19
22
|
from numpy.typing import ArrayLike
|
|
20
23
|
|
|
21
24
|
|
|
22
|
-
def relative_luminance(color:
|
|
25
|
+
def relative_luminance(color: ArrayLike) -> float:
|
|
23
26
|
"""Returns the relative luminance according to W3C specification.
|
|
24
27
|
|
|
25
28
|
Spec: https://www.w3.org/TR/WCAG21/#dfn-relative-luminance.
|