cirq-core 1.6.0.dev20250520054601__py3-none-any.whl → 1.6.0.dev20250520181654__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 +15 -17
- cirq/_compat_test.py +6 -9
- cirq/_doc.py +2 -2
- cirq/_import.py +6 -6
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/_block_diagram_drawer.py +9 -10
- cirq/circuits/_box_drawing_character_data.py +6 -8
- cirq/circuits/_bucket_priority_queue.py +7 -7
- cirq/circuits/circuit.py +118 -125
- cirq/circuits/circuit_operation.py +38 -52
- cirq/circuits/circuit_test.py +4 -4
- cirq/circuits/frozen_circuit.py +13 -23
- cirq/circuits/moment.py +23 -29
- cirq/circuits/optimization_pass.py +4 -4
- cirq/circuits/optimization_pass_test.py +4 -6
- cirq/circuits/qasm_output.py +11 -11
- cirq/circuits/text_diagram_drawer.py +21 -36
- cirq/contrib/acquaintance/bipartite.py +5 -8
- cirq/contrib/acquaintance/executor.py +5 -5
- cirq/contrib/acquaintance/executor_test.py +3 -3
- cirq/contrib/acquaintance/gates.py +16 -26
- cirq/contrib/acquaintance/gates_test.py +3 -3
- cirq/contrib/acquaintance/mutation_utils.py +4 -4
- cirq/contrib/acquaintance/optimizers.py +4 -4
- cirq/contrib/acquaintance/permutation.py +15 -27
- cirq/contrib/acquaintance/shift.py +3 -3
- cirq/contrib/acquaintance/shift_swap_network.py +4 -4
- cirq/contrib/acquaintance/strategies/cubic.py +2 -2
- cirq/contrib/acquaintance/strategies/quartic_paired.py +6 -6
- cirq/contrib/bayesian_network/bayesian_network_gate.py +9 -10
- cirq/contrib/circuitdag/circuit_dag.py +2 -2
- cirq/contrib/custom_simulators/custom_state_simulator.py +3 -3
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +4 -4
- cirq/contrib/graph_device/graph_device.py +5 -5
- cirq/contrib/graph_device/hypergraph.py +12 -12
- cirq/contrib/graph_device/uniform_graph_device.py +4 -4
- cirq/contrib/paulistring/clifford_optimize.py +2 -2
- cirq/contrib/paulistring/clifford_target_gateset.py +7 -7
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +31 -31
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +23 -23
- cirq/contrib/paulistring/recombine.py +3 -3
- cirq/contrib/paulistring/separate.py +2 -2
- cirq/contrib/qasm_import/_parser.py +20 -32
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +3 -5
- cirq/contrib/quantum_volume/quantum_volume.py +24 -24
- cirq/contrib/quimb/density_matrix.py +12 -14
- cirq/contrib/quimb/mps_simulator.py +20 -20
- cirq/contrib/quimb/state_vector.py +6 -10
- cirq/contrib/quirk/export_to_quirk.py +3 -3
- cirq/contrib/quirk/quirk_gate.py +15 -15
- cirq/contrib/routing/device.py +3 -3
- cirq/contrib/routing/greedy.py +10 -21
- cirq/contrib/routing/initialization.py +2 -2
- cirq/contrib/routing/swap_network.py +3 -3
- cirq/contrib/routing/utils.py +2 -2
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +8 -8
- cirq/contrib/svg/svg.py +3 -3
- cirq/devices/grid_device_metadata.py +10 -10
- cirq/devices/grid_qubit.py +20 -20
- cirq/devices/insertion_noise_model.py +5 -5
- cirq/devices/line_qubit.py +13 -13
- cirq/devices/named_topologies.py +18 -29
- cirq/devices/noise_model.py +3 -3
- cirq/devices/noise_properties.py +2 -2
- cirq/devices/noise_properties_test.py +1 -3
- cirq/devices/noise_utils.py +7 -7
- cirq/devices/superconducting_qubits_noise_properties.py +21 -21
- cirq/devices/superconducting_qubits_noise_properties_test.py +5 -7
- cirq/devices/thermal_noise_model.py +14 -14
- cirq/devices/unconstrained_device.py +2 -2
- cirq/experiments/benchmarking/parallel_xeb.py +29 -31
- cirq/experiments/n_qubit_tomography.py +5 -7
- cirq/experiments/qubit_characterizations.py +29 -40
- cirq/experiments/qubit_characterizations_test.py +1 -1
- cirq/experiments/random_quantum_circuit_generation.py +19 -33
- cirq/experiments/random_quantum_circuit_generation_test.py +6 -6
- cirq/experiments/readout_confusion_matrix.py +14 -14
- cirq/experiments/single_qubit_readout_calibration.py +12 -12
- cirq/experiments/t2_decay_experiment.py +7 -7
- cirq/experiments/two_qubit_xeb.py +32 -32
- cirq/experiments/two_qubit_xeb_test.py +5 -5
- cirq/experiments/xeb_fitting.py +25 -25
- cirq/experiments/xeb_sampling.py +22 -33
- cirq/experiments/xeb_simulation.py +5 -5
- cirq/experiments/xeb_simulation_test.py +3 -3
- cirq/experiments/z_phase_calibration.py +19 -19
- cirq/interop/quirk/cells/arithmetic_cells.py +23 -36
- cirq/interop/quirk/cells/cell.py +9 -21
- cirq/interop/quirk/cells/composite_cell.py +7 -22
- cirq/interop/quirk/cells/control_cells.py +8 -8
- cirq/interop/quirk/cells/input_cells.py +4 -4
- cirq/interop/quirk/cells/input_rotation_cells.py +5 -5
- cirq/interop/quirk/cells/parse.py +20 -23
- cirq/interop/quirk/cells/qubit_permutation_cells.py +3 -3
- cirq/interop/quirk/cells/swap_cell.py +3 -3
- cirq/interop/quirk/cells/testing.py +5 -7
- cirq/interop/quirk/url_to_circuit.py +17 -33
- cirq/json_resolver_cache.py +6 -6
- cirq/linalg/decompositions.py +20 -31
- cirq/linalg/diagonalize.py +4 -4
- cirq/linalg/diagonalize_test.py +3 -4
- cirq/linalg/operator_spaces.py +5 -5
- cirq/linalg/predicates.py +7 -7
- cirq/linalg/transformations.py +20 -20
- cirq/ops/arithmetic_operation.py +13 -15
- cirq/ops/boolean_hamiltonian.py +17 -17
- cirq/ops/classically_controlled_operation.py +13 -25
- cirq/ops/clifford_gate.py +31 -35
- cirq/ops/clifford_gate_test.py +2 -3
- cirq/ops/common_channels.py +30 -32
- cirq/ops/common_gates.py +64 -74
- cirq/ops/control_values.py +12 -12
- cirq/ops/controlled_gate.py +15 -30
- cirq/ops/controlled_gate_test.py +5 -5
- cirq/ops/controlled_operation.py +12 -25
- cirq/ops/controlled_operation_test.py +5 -5
- cirq/ops/dense_pauli_string.py +23 -34
- cirq/ops/dense_pauli_string_test.py +1 -2
- cirq/ops/diagonal_gate.py +9 -20
- cirq/ops/diagonal_gate_test.py +1 -3
- cirq/ops/eigen_gate.py +11 -23
- cirq/ops/eigen_gate_test.py +6 -8
- cirq/ops/fourier_transform.py +5 -5
- cirq/ops/fsim_gate.py +14 -14
- cirq/ops/gate_operation.py +23 -44
- cirq/ops/gateset.py +23 -37
- cirq/ops/gateset_test.py +2 -2
- cirq/ops/global_phase_op.py +8 -10
- cirq/ops/greedy_qubit_manager.py +6 -6
- cirq/ops/identity.py +9 -9
- cirq/ops/kraus_channel.py +7 -7
- cirq/ops/linear_combinations.py +29 -48
- cirq/ops/matrix_gates.py +8 -8
- cirq/ops/measure_util.py +13 -14
- cirq/ops/measurement_gate.py +18 -29
- cirq/ops/mixed_unitary_channel.py +8 -8
- cirq/ops/named_qubit.py +10 -10
- cirq/ops/op_tree.py +7 -7
- cirq/ops/parallel_gate.py +5 -5
- cirq/ops/parity_gates.py +14 -14
- cirq/ops/pauli_gates.py +8 -10
- cirq/ops/pauli_interaction_gate.py +6 -6
- cirq/ops/pauli_measurement_gate.py +11 -23
- cirq/ops/pauli_string.py +35 -52
- cirq/ops/pauli_string_phasor.py +4 -14
- cirq/ops/pauli_string_raw_types.py +3 -3
- cirq/ops/pauli_sum_exponential.py +2 -2
- cirq/ops/permutation_gate.py +4 -4
- cirq/ops/phased_iswap_gate.py +9 -9
- cirq/ops/phased_x_gate.py +10 -10
- cirq/ops/phased_x_z_gate.py +11 -11
- cirq/ops/projector.py +6 -6
- cirq/ops/qubit_manager.py +6 -6
- cirq/ops/qubit_order.py +3 -3
- cirq/ops/random_gate_channel.py +4 -4
- cirq/ops/raw_types.py +48 -70
- cirq/ops/state_preparation_channel.py +3 -3
- cirq/ops/swap_gates.py +9 -9
- cirq/ops/tags.py +2 -4
- cirq/ops/three_qubit_gates.py +20 -38
- cirq/ops/two_qubit_diagonal_gate.py +5 -5
- cirq/ops/uniform_superposition_gate.py +2 -2
- cirq/ops/wait_gate.py +5 -5
- cirq/protocols/act_on_protocol_test.py +3 -3
- cirq/protocols/apply_channel_protocol.py +8 -14
- cirq/protocols/apply_mixture_protocol.py +14 -16
- cirq/protocols/apply_mixture_protocol_test.py +5 -6
- cirq/protocols/apply_unitary_protocol.py +17 -19
- cirq/protocols/circuit_diagram_info_protocol.py +19 -30
- cirq/protocols/decompose_protocol.py +30 -34
- cirq/protocols/inverse_protocol.py +7 -7
- cirq/protocols/json_serialization.py +32 -51
- cirq/protocols/json_serialization_test.py +9 -10
- cirq/protocols/kraus_protocol.py +4 -4
- cirq/protocols/kraus_protocol_test.py +3 -3
- cirq/protocols/measurement_key_protocol.py +11 -13
- cirq/protocols/mixture_protocol.py +4 -4
- cirq/protocols/qasm.py +11 -13
- cirq/protocols/qid_shape_protocol.py +6 -8
- cirq/qis/clifford_tableau.py +12 -12
- cirq/qis/measures.py +7 -7
- cirq/qis/quantum_state_representation.py +3 -3
- cirq/qis/states.py +51 -51
- cirq/sim/classical_simulator.py +10 -10
- cirq/sim/clifford/clifford_simulator.py +6 -6
- cirq/sim/clifford/clifford_tableau_simulation_state_test.py +1 -3
- cirq/sim/clifford/stabilizer_sampler.py +4 -4
- cirq/sim/clifford/stabilizer_state_ch_form.py +3 -3
- cirq/sim/density_matrix_simulation_state.py +15 -15
- cirq/sim/density_matrix_simulator.py +11 -11
- cirq/sim/density_matrix_utils.py +9 -9
- cirq/sim/mux.py +9 -9
- cirq/sim/simulation_product_state.py +9 -9
- cirq/sim/simulation_product_state_test.py +2 -2
- cirq/sim/simulation_state.py +14 -27
- cirq/sim/simulation_state_base.py +8 -24
- cirq/sim/simulation_utils.py +3 -4
- cirq/sim/simulator.py +28 -43
- cirq/sim/simulator_base.py +12 -25
- cirq/sim/simulator_base_test.py +6 -6
- cirq/sim/simulator_test.py +7 -7
- cirq/sim/sparse_simulator.py +8 -8
- cirq/sim/state_vector.py +8 -8
- cirq/sim/state_vector_simulation_state.py +17 -17
- cirq/sim/state_vector_simulator.py +4 -4
- cirq/study/flatten_expressions.py +12 -14
- cirq/study/resolver.py +9 -11
- cirq/study/result.py +11 -24
- cirq/study/sweepable.py +5 -5
- cirq/study/sweeps.py +27 -40
- cirq/testing/circuit_compare.py +5 -5
- cirq/testing/consistent_controlled_gate_op_test.py +7 -11
- cirq/testing/consistent_protocols.py +10 -10
- cirq/testing/consistent_protocols_test.py +7 -7
- cirq/testing/consistent_qasm.py +4 -4
- cirq/testing/consistent_qasm_test.py +2 -3
- cirq/testing/devices.py +4 -5
- cirq/testing/equals_tester.py +2 -2
- cirq/testing/equivalent_basis_map.py +4 -4
- cirq/testing/equivalent_repr_eval.py +3 -3
- cirq/testing/json.py +14 -14
- cirq/testing/logs.py +3 -3
- cirq/testing/no_identifier_qubit.py +2 -3
- cirq/testing/random_circuit.py +7 -7
- cirq/testing/random_circuit_test.py +3 -3
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +16 -16
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +13 -13
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +5 -5
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +3 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +3 -3
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +4 -4
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +6 -7
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +2 -2
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +7 -7
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +4 -4
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +7 -7
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +11 -11
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +5 -5
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +14 -14
- cirq/transformers/dynamical_decoupling.py +13 -13
- cirq/transformers/dynamical_decoupling_test.py +4 -4
- cirq/transformers/eject_phased_paulis.py +16 -16
- cirq/transformers/eject_z.py +5 -7
- cirq/transformers/gauge_compiling/gauge_compiling.py +38 -38
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +2 -2
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +8 -8
- cirq/transformers/insertion_sort.py +5 -5
- cirq/transformers/measurement_transformers.py +14 -14
- cirq/transformers/merge_k_qubit_gates_test.py +1 -3
- cirq/transformers/merge_single_qubit_gates_test.py +1 -3
- cirq/transformers/qubit_management_transformers.py +5 -5
- cirq/transformers/routing/initial_mapper.py +4 -4
- cirq/transformers/routing/line_initial_mapper.py +9 -9
- cirq/transformers/routing/mapping_manager.py +7 -7
- cirq/transformers/routing/route_circuit_cqc.py +27 -27
- cirq/transformers/routing/visualize_routed_circuit.py +4 -4
- cirq/transformers/stratify.py +8 -8
- cirq/transformers/synchronize_terminal_measurements.py +6 -6
- cirq/transformers/target_gatesets/compilation_target_gateset.py +8 -8
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +2 -2
- cirq/transformers/target_gatesets/cz_gateset.py +4 -4
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +5 -5
- cirq/transformers/transformer_api.py +11 -26
- cirq/transformers/transformer_primitives.py +24 -36
- cirq/transformers/transformer_primitives_test.py +3 -3
- cirq/value/classical_data.py +18 -18
- cirq/value/condition.py +8 -8
- cirq/value/digits.py +7 -7
- cirq/value/duration.py +12 -12
- cirq/value/linear_dict.py +8 -12
- cirq/value/measurement_key.py +8 -8
- cirq/value/product_state.py +9 -9
- cirq/value/value_equality_attr.py +4 -4
- cirq/vis/heatmap.py +23 -35
- cirq/work/collector.py +9 -17
- cirq/work/observable_grouping.py +4 -7
- cirq/work/observable_measurement.py +29 -41
- cirq/work/observable_measurement_data.py +14 -14
- cirq/work/observable_measurement_test.py +2 -2
- cirq/work/observable_settings.py +9 -10
- cirq/work/pauli_sum_collector.py +5 -5
- cirq/work/sampler.py +17 -17
- cirq/work/zeros_sampler.py +3 -3
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/METADATA +1 -1
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/RECORD +289 -289
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/WHEEL +1 -1
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.6.0.dev20250520054601.dist-info → cirq_core-1.6.0.dev20250520181654.dist-info}/top_level.txt +0 -0
cirq/_compat.py
CHANGED
|
@@ -28,7 +28,7 @@ import sys
|
|
|
28
28
|
import traceback
|
|
29
29
|
import warnings
|
|
30
30
|
from types import ModuleType
|
|
31
|
-
from typing import Any, Callable,
|
|
31
|
+
from typing import Any, Callable, Iterator, overload, TypeVar
|
|
32
32
|
|
|
33
33
|
import numpy as np
|
|
34
34
|
import pandas as pd
|
|
@@ -79,7 +79,7 @@ def cached_method(__func: TFunc) -> TFunc: ...
|
|
|
79
79
|
def cached_method(*, maxsize: int = 128) -> Callable[[TFunc], TFunc]: ...
|
|
80
80
|
|
|
81
81
|
|
|
82
|
-
def cached_method(method:
|
|
82
|
+
def cached_method(method: TFunc | None = None, *, maxsize: int = 128) -> Any:
|
|
83
83
|
"""Decorator that adds a per-instance LRU cache for a method.
|
|
84
84
|
|
|
85
85
|
Can be applied with or without parameters to customize the underlying cache:
|
|
@@ -195,7 +195,7 @@ def proper_repr(value: Any) -> str:
|
|
|
195
195
|
f'\n)'
|
|
196
196
|
)
|
|
197
197
|
|
|
198
|
-
if isinstance(value,
|
|
198
|
+
if isinstance(value, dict):
|
|
199
199
|
return '{' + ','.join(f"{proper_repr(k)}: {proper_repr(v)}" for k, v in value.items()) + '}'
|
|
200
200
|
|
|
201
201
|
if hasattr(value, "__qualname__"):
|
|
@@ -288,7 +288,7 @@ def _validate_deadline(deadline: str):
|
|
|
288
288
|
|
|
289
289
|
|
|
290
290
|
def deprecated(
|
|
291
|
-
*, deadline: str, fix: str, name:
|
|
291
|
+
*, deadline: str, fix: str, name: str | None = None
|
|
292
292
|
) -> Callable[[Callable], Callable]:
|
|
293
293
|
"""Marks a function as deprecated.
|
|
294
294
|
|
|
@@ -329,9 +329,7 @@ def deprecated(
|
|
|
329
329
|
return decorator
|
|
330
330
|
|
|
331
331
|
|
|
332
|
-
def deprecated_class(
|
|
333
|
-
*, deadline: str, fix: str, name: Optional[str] = None
|
|
334
|
-
) -> Callable[[Type], Type]:
|
|
332
|
+
def deprecated_class(*, deadline: str, fix: str, name: str | None = None) -> Callable[[type], type]:
|
|
335
333
|
"""Marks a class as deprecated.
|
|
336
334
|
|
|
337
335
|
Args:
|
|
@@ -348,7 +346,7 @@ def deprecated_class(
|
|
|
348
346
|
|
|
349
347
|
_validate_deadline(deadline)
|
|
350
348
|
|
|
351
|
-
def decorator(clazz:
|
|
349
|
+
def decorator(clazz: type) -> type:
|
|
352
350
|
clazz_new = clazz.__new__
|
|
353
351
|
|
|
354
352
|
def patched_new(cls, *args, **kwargs):
|
|
@@ -378,12 +376,12 @@ def deprecated_parameter(
|
|
|
378
376
|
*,
|
|
379
377
|
deadline: str,
|
|
380
378
|
fix: str,
|
|
381
|
-
func_name:
|
|
379
|
+
func_name: str | None = None,
|
|
382
380
|
parameter_desc: str,
|
|
383
|
-
match: Callable[[
|
|
384
|
-
rewrite:
|
|
385
|
-
Callable[[
|
|
386
|
-
|
|
381
|
+
match: Callable[[tuple[Any, ...], dict[str, Any]], bool],
|
|
382
|
+
rewrite: (
|
|
383
|
+
Callable[[tuple[Any, ...], dict[str, Any]], tuple[tuple[Any, ...], dict[str, Any]]] | None
|
|
384
|
+
) = None,
|
|
387
385
|
) -> Callable[[Callable], Callable]:
|
|
388
386
|
"""Marks a function parameter as deprecated.
|
|
389
387
|
|
|
@@ -447,7 +445,7 @@ def deprecated_parameter(
|
|
|
447
445
|
return decorator
|
|
448
446
|
|
|
449
447
|
|
|
450
|
-
def deprecate_attributes(module_name: str, deprecated_attributes:
|
|
448
|
+
def deprecate_attributes(module_name: str, deprecated_attributes: dict[str, tuple[str, str]]):
|
|
451
449
|
"""Replace module with a wrapper that gives warnings for deprecated attributes.
|
|
452
450
|
|
|
453
451
|
Args:
|
|
@@ -586,7 +584,7 @@ def _is_internal(filename: str) -> bool:
|
|
|
586
584
|
return 'importlib' in filename and '_bootstrap' in filename
|
|
587
585
|
|
|
588
586
|
|
|
589
|
-
_warned:
|
|
587
|
+
_warned: set[str] = set()
|
|
590
588
|
|
|
591
589
|
|
|
592
590
|
def _called_from_test() -> bool:
|
|
@@ -635,7 +633,7 @@ class DeprecatedModuleFinder(importlib.abc.MetaPathFinder):
|
|
|
635
633
|
new_module_name: str,
|
|
636
634
|
old_module_name: str,
|
|
637
635
|
deadline: str,
|
|
638
|
-
broken_module_exception:
|
|
636
|
+
broken_module_exception: BaseException | None,
|
|
639
637
|
):
|
|
640
638
|
"""An aliasing module finder that uses existing module finders to find a python
|
|
641
639
|
module spec and intercept the execution of matching modules.
|
|
@@ -763,7 +761,7 @@ def _setup_deprecated_submodule_attribute(
|
|
|
763
761
|
old_parent: str,
|
|
764
762
|
old_child: str,
|
|
765
763
|
deadline: str,
|
|
766
|
-
new_module:
|
|
764
|
+
new_module: ModuleType | None,
|
|
767
765
|
):
|
|
768
766
|
parent_module = sys.modules[old_parent]
|
|
769
767
|
setattr(parent_module, old_child, new_module)
|
cirq/_compat_test.py
CHANGED
|
@@ -27,7 +27,7 @@ import types
|
|
|
27
27
|
import warnings
|
|
28
28
|
from importlib.machinery import ModuleSpec
|
|
29
29
|
from types import ModuleType
|
|
30
|
-
from typing import Any, Callable
|
|
30
|
+
from typing import Any, Callable
|
|
31
31
|
from unittest import mock
|
|
32
32
|
|
|
33
33
|
import duet
|
|
@@ -764,7 +764,6 @@ def test_metadata_search_path():
|
|
|
764
764
|
def _test_metadata_search_path_inner(): # pragma: no cover
|
|
765
765
|
# initialize the DeprecatedModuleFinders
|
|
766
766
|
# pylint: disable=unused-import
|
|
767
|
-
import cirq.testing._compat_test_data.module_a
|
|
768
767
|
|
|
769
768
|
assert importlib.metadata.metadata('numpy')
|
|
770
769
|
|
|
@@ -882,8 +881,6 @@ def _test_new_module_is_top_level_inner():
|
|
|
882
881
|
# imports a top level module that was also deprecated
|
|
883
882
|
from freezegun import api
|
|
884
883
|
|
|
885
|
-
import cirq.testing._compat_test_data
|
|
886
|
-
|
|
887
884
|
assert api.real_time == time.time
|
|
888
885
|
|
|
889
886
|
|
|
@@ -925,7 +922,7 @@ def test_loader_create_module():
|
|
|
925
922
|
fake_mod = ModuleType('hello')
|
|
926
923
|
|
|
927
924
|
class CreateModuleLoader(importlib.abc.Loader):
|
|
928
|
-
def create_module(self, spec: ModuleSpec) ->
|
|
925
|
+
def create_module(self, spec: ModuleSpec) -> ModuleType | None:
|
|
929
926
|
return fake_mod
|
|
930
927
|
|
|
931
928
|
assert (
|
|
@@ -1017,16 +1014,16 @@ def test_block_overlapping_deprecation():
|
|
|
1017
1014
|
|
|
1018
1015
|
class Bar:
|
|
1019
1016
|
def __init__(self) -> None:
|
|
1020
|
-
self.foo_calls:
|
|
1021
|
-
self.bar_calls:
|
|
1017
|
+
self.foo_calls: dict[int, int] = collections.Counter()
|
|
1018
|
+
self.bar_calls: dict[int, int] = collections.Counter()
|
|
1022
1019
|
|
|
1023
1020
|
@cached_method
|
|
1024
|
-
def foo(self, n: int) ->
|
|
1021
|
+
def foo(self, n: int) -> tuple[int, int]:
|
|
1025
1022
|
self.foo_calls[n] += 1
|
|
1026
1023
|
return (id(self), n)
|
|
1027
1024
|
|
|
1028
1025
|
@cached_method(maxsize=1)
|
|
1029
|
-
def bar(self, n: int) ->
|
|
1026
|
+
def bar(self, n: int) -> tuple[int, int]:
|
|
1030
1027
|
self.bar_calls[n] += 1
|
|
1031
1028
|
return (id(self), 2 * n)
|
|
1032
1029
|
|
cirq/_doc.py
CHANGED
cirq/_import.py
CHANGED
|
@@ -21,7 +21,7 @@ from importlib import abc
|
|
|
21
21
|
from importlib.abc import Loader
|
|
22
22
|
from importlib.machinery import ModuleSpec
|
|
23
23
|
from types import ModuleType
|
|
24
|
-
from typing import Any, Callable, cast
|
|
24
|
+
from typing import Any, Callable, cast
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
class InstrumentedFinder(abc.MetaPathFinder):
|
|
@@ -31,7 +31,7 @@ class InstrumentedFinder(abc.MetaPathFinder):
|
|
|
31
31
|
self,
|
|
32
32
|
finder: Any,
|
|
33
33
|
module_name: str,
|
|
34
|
-
wrap_module: Callable[[ModuleType],
|
|
34
|
+
wrap_module: Callable[[ModuleType], ModuleType | None],
|
|
35
35
|
after_exec: Callable[[ModuleType], None],
|
|
36
36
|
):
|
|
37
37
|
"""A module finder that uses an existing module finder to find a python
|
|
@@ -56,7 +56,7 @@ class InstrumentedFinder(abc.MetaPathFinder):
|
|
|
56
56
|
|
|
57
57
|
self.finder = finder
|
|
58
58
|
self.module_name = module_name
|
|
59
|
-
self.match_components:
|
|
59
|
+
self.match_components: list[str] = []
|
|
60
60
|
if self.module_name:
|
|
61
61
|
self.match_components = self.module_name.split('.')
|
|
62
62
|
self.wrap_module = wrap_module
|
|
@@ -82,7 +82,7 @@ class InstrumentedLoader(abc.Loader):
|
|
|
82
82
|
def __init__(
|
|
83
83
|
self,
|
|
84
84
|
loader: Any,
|
|
85
|
-
wrap_module: Callable[[ModuleType],
|
|
85
|
+
wrap_module: Callable[[ModuleType], ModuleType | None],
|
|
86
86
|
after_exec: Callable[[ModuleType], None],
|
|
87
87
|
):
|
|
88
88
|
"""A module loader that uses an existing module loader and intercepts
|
|
@@ -121,7 +121,7 @@ class InstrumentedLoader(abc.Loader):
|
|
|
121
121
|
@contextmanager
|
|
122
122
|
def wrap_module_executions(
|
|
123
123
|
module_name: str,
|
|
124
|
-
wrap_func: Callable[[ModuleType],
|
|
124
|
+
wrap_func: Callable[[ModuleType], ModuleType | None],
|
|
125
125
|
after_exec: Callable[[ModuleType], None] = lambda m: None,
|
|
126
126
|
assert_meta_path_unchanged: bool = True,
|
|
127
127
|
):
|
|
@@ -157,7 +157,7 @@ def delay_import(module_name: str):
|
|
|
157
157
|
delay = True
|
|
158
158
|
execute_list = []
|
|
159
159
|
|
|
160
|
-
def wrap_func(module: ModuleType) ->
|
|
160
|
+
def wrap_func(module: ModuleType) -> ModuleType | None:
|
|
161
161
|
if delay:
|
|
162
162
|
execute_list.append(module)
|
|
163
163
|
return None # Don't allow the module to be executed yet
|
cirq/_version.py
CHANGED
cirq/_version_test.py
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import collections
|
|
18
|
-
from typing import Dict, List, Optional, Tuple
|
|
19
18
|
|
|
20
19
|
from cirq.circuits._box_drawing_character_data import box_draw_character, BoxDrawCharacterSet
|
|
21
20
|
|
|
@@ -57,7 +56,7 @@ class Block:
|
|
|
57
56
|
left: bool = False,
|
|
58
57
|
right: bool = False,
|
|
59
58
|
bottom: bool = False,
|
|
60
|
-
crossing_char:
|
|
59
|
+
crossing_char: str | None = None,
|
|
61
60
|
):
|
|
62
61
|
"""Draws lines in the box using the given character set.
|
|
63
62
|
|
|
@@ -107,7 +106,7 @@ class Block:
|
|
|
107
106
|
|
|
108
107
|
self._prev_curve_grid_chars = grid_characters
|
|
109
108
|
|
|
110
|
-
def render(self, width: int, height: int) ->
|
|
109
|
+
def render(self, width: int, height: int) -> list[str]:
|
|
111
110
|
"""Returns a list of text lines representing the block's contents.
|
|
112
111
|
|
|
113
112
|
Args:
|
|
@@ -159,9 +158,9 @@ class BlockDiagramDrawer:
|
|
|
159
158
|
"""Aligns text and curve data placed onto an abstract 2d grid of blocks."""
|
|
160
159
|
|
|
161
160
|
def __init__(self) -> None:
|
|
162
|
-
self._blocks:
|
|
163
|
-
self._min_widths:
|
|
164
|
-
self._min_heights:
|
|
161
|
+
self._blocks: dict[tuple[int, int], Block] = collections.defaultdict(Block)
|
|
162
|
+
self._min_widths: dict[int, int] = collections.defaultdict(lambda: 0)
|
|
163
|
+
self._min_heights: dict[int, int] = collections.defaultdict(lambda: 0)
|
|
165
164
|
|
|
166
165
|
# Populate the origin.
|
|
167
166
|
_ = self._blocks[(0, 0)]
|
|
@@ -189,8 +188,8 @@ class BlockDiagramDrawer:
|
|
|
189
188
|
def render(
|
|
190
189
|
self,
|
|
191
190
|
*,
|
|
192
|
-
block_span_x:
|
|
193
|
-
block_span_y:
|
|
191
|
+
block_span_x: int | None = None,
|
|
192
|
+
block_span_y: int | None = None,
|
|
194
193
|
min_block_width: int = 0,
|
|
195
194
|
min_block_height: int = 0,
|
|
196
195
|
) -> str:
|
|
@@ -252,10 +251,10 @@ class BlockDiagramDrawer:
|
|
|
252
251
|
}
|
|
253
252
|
|
|
254
253
|
# Paste together all of the rows of rendered block content.
|
|
255
|
-
out_lines:
|
|
254
|
+
out_lines: list[str] = []
|
|
256
255
|
for y in range(block_span_y):
|
|
257
256
|
for by in range(heights[y]):
|
|
258
|
-
out_line_chunks:
|
|
257
|
+
out_line_chunks: list[str] = []
|
|
259
258
|
for x in range(block_span_x):
|
|
260
259
|
out_line_chunks.extend(block_renders[x, y][by])
|
|
261
260
|
out_lines.append(''.join(out_line_chunks).rstrip())
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
from typing import
|
|
19
|
+
from typing import NamedTuple
|
|
20
20
|
|
|
21
21
|
_BoxDrawCharacterSet = NamedTuple(
|
|
22
22
|
'_BoxDrawCharacterSet',
|
|
@@ -43,7 +43,7 @@ _BoxDrawCharacterSet = NamedTuple(
|
|
|
43
43
|
class BoxDrawCharacterSet(_BoxDrawCharacterSet):
|
|
44
44
|
def char(
|
|
45
45
|
self, top: bool = False, bottom: bool = False, left: bool = False, right: bool = False
|
|
46
|
-
) ->
|
|
46
|
+
) -> str | None:
|
|
47
47
|
parts = []
|
|
48
48
|
if top:
|
|
49
49
|
parts.append('top')
|
|
@@ -118,10 +118,8 @@ _MixedBoxDrawCharacterSet = NamedTuple(
|
|
|
118
118
|
|
|
119
119
|
|
|
120
120
|
class MixedBoxDrawCharacterSet(_MixedBoxDrawCharacterSet):
|
|
121
|
-
def char(
|
|
122
|
-
|
|
123
|
-
) -> Optional[str]:
|
|
124
|
-
def parts_with(val: int) -> List[str]:
|
|
121
|
+
def char(self, *, top: int = 0, bottom: int = 0, left: int = 0, right: int = 0) -> str | None:
|
|
122
|
+
def parts_with(val: int) -> list[str]:
|
|
125
123
|
parts = []
|
|
126
124
|
if top == val:
|
|
127
125
|
parts.append('top')
|
|
@@ -340,14 +338,14 @@ NORMAL_THEN_DOUBLED_MIXED_BOX_CHARS = MixedBoxDrawCharacterSet(
|
|
|
340
338
|
|
|
341
339
|
|
|
342
340
|
def box_draw_character(
|
|
343
|
-
first:
|
|
341
|
+
first: BoxDrawCharacterSet | None,
|
|
344
342
|
second: BoxDrawCharacterSet,
|
|
345
343
|
*,
|
|
346
344
|
top: int = 0,
|
|
347
345
|
bottom: int = 0,
|
|
348
346
|
left: int = 0,
|
|
349
347
|
right: int = 0,
|
|
350
|
-
) ->
|
|
348
|
+
) -> str | None:
|
|
351
349
|
"""Finds a box drawing character based on its connectivity.
|
|
352
350
|
|
|
353
351
|
For example:
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import Any, Generic, Iterable, Iterator,
|
|
17
|
+
from typing import Any, Generic, Iterable, Iterator, TypeVar
|
|
18
18
|
|
|
19
19
|
TItem = TypeVar('TItem')
|
|
20
20
|
|
|
@@ -39,7 +39,7 @@ class BucketPriorityQueue(Generic[TItem]):
|
|
|
39
39
|
"""
|
|
40
40
|
|
|
41
41
|
def __init__(
|
|
42
|
-
self, entries: Iterable[
|
|
42
|
+
self, entries: Iterable[tuple[int, TItem]] = (), *, drop_duplicate_entries: bool = False
|
|
43
43
|
):
|
|
44
44
|
"""Initializes a new priority queue.
|
|
45
45
|
|
|
@@ -50,10 +50,10 @@ class BucketPriorityQueue(Generic[TItem]):
|
|
|
50
50
|
in the priority queue. Note that duplicates of an item may still
|
|
51
51
|
be enqueued, as long as they have different priorities.
|
|
52
52
|
"""
|
|
53
|
-
self._buckets:
|
|
53
|
+
self._buckets: list[list[TItem]] = []
|
|
54
54
|
self._offset = 0
|
|
55
55
|
self._len = 0
|
|
56
|
-
self._drop_set:
|
|
56
|
+
self._drop_set: set[tuple[int, TItem]] | None = set() if drop_duplicate_entries else None
|
|
57
57
|
|
|
58
58
|
for p, e in entries:
|
|
59
59
|
self.enqueue(p, e)
|
|
@@ -70,7 +70,7 @@ class BucketPriorityQueue(Generic[TItem]):
|
|
|
70
70
|
"""Returns how many items are in the priority queue."""
|
|
71
71
|
return self._len
|
|
72
72
|
|
|
73
|
-
def __iter__(self) -> Iterator[
|
|
73
|
+
def __iter__(self) -> Iterator[tuple[int, TItem]]:
|
|
74
74
|
"""Iterates the (priority, item) entries in the queue."""
|
|
75
75
|
for i, bucket in enumerate(self._buckets):
|
|
76
76
|
for item in bucket:
|
|
@@ -122,7 +122,7 @@ class BucketPriorityQueue(Generic[TItem]):
|
|
|
122
122
|
self._len += 1
|
|
123
123
|
return True
|
|
124
124
|
|
|
125
|
-
def dequeue(self) ->
|
|
125
|
+
def dequeue(self) -> tuple[int, TItem]:
|
|
126
126
|
"""Removes and returns an item from the priority queue.
|
|
127
127
|
|
|
128
128
|
Returns:
|
|
@@ -180,6 +180,6 @@ class BucketPriorityQueue(Generic[TItem]):
|
|
|
180
180
|
return not self == other
|
|
181
181
|
|
|
182
182
|
|
|
183
|
-
def _indent(lines:
|
|
183
|
+
def _indent(lines: list[Any]) -> str:
|
|
184
184
|
paragraph = ''.join('\n' + str(line) for line in lines)
|
|
185
185
|
return paragraph.replace('\n', '\n ')
|