cirq-core 1.5.0.dev20250409225226__py3-none-any.whl → 1.6.0__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/__init__.py +16 -17
- cirq/_compat.py +21 -20
- cirq/_compat_test.py +14 -34
- cirq/_doc.py +4 -2
- cirq/_import.py +8 -6
- cirq/_import_test.py +4 -2
- cirq/_version.py +6 -6
- cirq/_version_test.py +2 -2
- cirq/circuits/_block_diagram_drawer.py +11 -10
- cirq/circuits/_block_diagram_drawer_test.py +8 -6
- cirq/circuits/_box_drawing_character_data.py +8 -8
- cirq/circuits/_box_drawing_character_data_test.py +3 -1
- cirq/circuits/_bucket_priority_queue.py +9 -7
- cirq/circuits/_bucket_priority_queue_test.py +22 -20
- cirq/circuits/circuit.py +248 -172
- cirq/circuits/circuit_operation.py +73 -83
- cirq/circuits/circuit_operation_test.py +128 -90
- cirq/circuits/circuit_test.py +211 -151
- cirq/circuits/frozen_circuit.py +23 -60
- cirq/circuits/frozen_circuit_test.py +31 -8
- cirq/circuits/insert_strategy.py +7 -5
- cirq/circuits/insert_strategy_test.py +4 -2
- cirq/circuits/moment.py +88 -40
- cirq/circuits/moment_test.py +128 -51
- cirq/circuits/optimization_pass.py +5 -5
- cirq/circuits/optimization_pass_test.py +10 -10
- cirq/circuits/qasm_output.py +11 -11
- cirq/circuits/qasm_output_test.py +25 -22
- cirq/circuits/text_diagram_drawer.py +23 -38
- cirq/circuits/text_diagram_drawer_test.py +19 -17
- cirq/conftest.py +4 -3
- cirq/contrib/__init__.py +4 -4
- cirq/contrib/acquaintance/__init__.py +1 -1
- cirq/contrib/acquaintance/bipartite.py +5 -8
- cirq/contrib/acquaintance/bipartite_test.py +18 -13
- cirq/contrib/acquaintance/devices.py +2 -2
- cirq/contrib/acquaintance/devices_test.py +5 -3
- cirq/contrib/acquaintance/executor.py +5 -5
- cirq/contrib/acquaintance/executor_test.py +13 -9
- cirq/contrib/acquaintance/gates.py +18 -28
- cirq/contrib/acquaintance/gates_test.py +24 -20
- cirq/contrib/acquaintance/inspection_utils.py +8 -4
- cirq/contrib/acquaintance/inspection_utils_test.py +4 -2
- cirq/contrib/acquaintance/mutation_utils.py +4 -4
- cirq/contrib/acquaintance/mutation_utils_test.py +4 -2
- cirq/contrib/acquaintance/optimizers.py +4 -4
- cirq/contrib/acquaintance/optimizers_test.py +4 -1
- cirq/contrib/acquaintance/permutation.py +15 -27
- cirq/contrib/acquaintance/permutation_test.py +26 -17
- cirq/contrib/acquaintance/shift.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network_test.py +9 -6
- cirq/contrib/acquaintance/shift_test.py +8 -6
- cirq/contrib/acquaintance/strategies/cubic.py +2 -2
- cirq/contrib/acquaintance/strategies/cubic_test.py +4 -2
- cirq/contrib/acquaintance/strategies/quartic_paired.py +6 -6
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +10 -6
- cirq/contrib/acquaintance/testing.py +2 -0
- cirq/contrib/acquaintance/topological_sort.py +2 -2
- cirq/contrib/acquaintance/topological_sort_test.py +3 -1
- cirq/contrib/bayesian_network/bayesian_network_gate.py +9 -10
- cirq/contrib/bayesian_network/bayesian_network_gate_test.py +14 -9
- cirq/contrib/circuitdag/circuit_dag.py +4 -4
- cirq/contrib/circuitdag/circuit_dag_test.py +17 -15
- cirq/contrib/custom_simulators/custom_state_simulator.py +5 -5
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +22 -17
- cirq/contrib/graph_device/graph_device.py +12 -11
- cirq/contrib/graph_device/graph_device_test.py +18 -14
- cirq/contrib/graph_device/hypergraph.py +16 -14
- cirq/contrib/graph_device/hypergraph_test.py +13 -11
- cirq/contrib/graph_device/uniform_graph_device.py +6 -4
- cirq/contrib/graph_device/uniform_graph_device_test.py +11 -3
- cirq/contrib/hacks/disable_validation.py +6 -1
- cirq/contrib/hacks/disable_validation_test.py +3 -1
- cirq/contrib/json.py +31 -5
- cirq/contrib/json_test.py +6 -3
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.json +6 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.json +5 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/__init__.py +17 -0
- cirq/contrib/json_test_data/spec.py +32 -0
- cirq/contrib/noise_models/noise_models.py +119 -5
- cirq/contrib/noise_models/noise_models_test.py +37 -9
- cirq/contrib/paulistring/clifford_optimize.py +6 -4
- cirq/contrib/paulistring/clifford_optimize_test.py +6 -5
- cirq/contrib/paulistring/clifford_target_gateset.py +10 -10
- cirq/contrib/paulistring/clifford_target_gateset_test.py +13 -11
- cirq/contrib/paulistring/optimize.py +2 -0
- cirq/contrib/paulistring/optimize_test.py +4 -3
- cirq/contrib/paulistring/pauli_string_dag.py +2 -0
- cirq/contrib/paulistring/pauli_string_dag_test.py +3 -1
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +255 -120
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +398 -19
- cirq/contrib/paulistring/pauli_string_optimize.py +7 -1
- cirq/contrib/paulistring/pauli_string_optimize_test.py +5 -3
- cirq/contrib/paulistring/recombine.py +6 -4
- cirq/contrib/paulistring/recombine_test.py +3 -1
- cirq/contrib/paulistring/separate.py +9 -6
- cirq/contrib/paulistring/separate_test.py +3 -1
- cirq/contrib/qasm_import/_lexer.py +3 -2
- cirq/contrib/qasm_import/_lexer_test.py +49 -13
- cirq/contrib/qasm_import/_parser.py +547 -83
- cirq/contrib/qasm_import/_parser_test.py +988 -97
- cirq/contrib/qasm_import/exception.py +2 -0
- cirq/contrib/qasm_import/qasm.py +8 -2
- cirq/contrib/qasm_import/qasm_test.py +7 -4
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +5 -5
- cirq/contrib/qcircuit/qcircuit_diagram_info_test.py +4 -1
- cirq/contrib/qcircuit/qcircuit_pdf.py +7 -3
- cirq/contrib/qcircuit/qcircuit_pdf_test.py +3 -1
- cirq/contrib/qcircuit/qcircuit_test.py +10 -8
- cirq/contrib/quantum_volume/quantum_volume.py +31 -27
- cirq/contrib/quantum_volume/quantum_volume_test.py +19 -16
- cirq/contrib/quimb/density_matrix.py +15 -14
- cirq/contrib/quimb/density_matrix_test.py +10 -7
- cirq/contrib/quimb/grid_circuits.py +5 -2
- cirq/contrib/quimb/grid_circuits_test.py +3 -0
- cirq/contrib/quimb/mps_simulator.py +20 -20
- cirq/contrib/quimb/mps_simulator_test.py +3 -0
- cirq/contrib/quimb/state_vector.py +12 -11
- cirq/contrib/quimb/state_vector_test.py +3 -0
- cirq/contrib/quirk/export_to_quirk.py +5 -3
- cirq/contrib/quirk/export_to_quirk_test.py +18 -16
- cirq/contrib/quirk/linearize_circuit.py +2 -0
- cirq/contrib/quirk/quirk_gate.py +18 -17
- cirq/contrib/routing/device.py +5 -3
- cirq/contrib/routing/device_test.py +2 -0
- cirq/contrib/routing/greedy.py +10 -21
- cirq/contrib/routing/greedy_test.py +4 -2
- cirq/contrib/routing/initialization.py +2 -2
- cirq/contrib/routing/initialization_test.py +5 -3
- cirq/contrib/routing/router.py +9 -5
- cirq/contrib/routing/router_test.py +2 -0
- cirq/contrib/routing/swap_network.py +3 -3
- cirq/contrib/routing/swap_network_test.py +3 -1
- cirq/contrib/routing/utils.py +2 -2
- cirq/contrib/routing/utils_test.py +3 -0
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +15 -9
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +3 -0
- cirq/contrib/svg/svg.py +3 -3
- cirq/contrib/svg/svg_test.py +8 -5
- cirq/devices/device.py +4 -4
- cirq/devices/device_test.py +7 -4
- cirq/devices/grid_device_metadata.py +10 -10
- cirq/devices/grid_device_metadata_test.py +3 -0
- cirq/devices/grid_qubit.py +29 -21
- cirq/devices/grid_qubit_test.py +3 -0
- cirq/devices/insertion_noise_model.py +7 -7
- cirq/devices/insertion_noise_model_test.py +7 -5
- cirq/devices/line_qubit.py +13 -13
- cirq/devices/line_qubit_test.py +2 -0
- cirq/devices/named_topologies.py +18 -29
- cirq/devices/named_topologies_test.py +13 -10
- cirq/devices/noise_model.py +3 -3
- cirq/devices/noise_model_test.py +19 -15
- cirq/devices/noise_properties.py +15 -6
- cirq/devices/noise_properties_test.py +34 -3
- cirq/devices/noise_utils.py +11 -9
- cirq/devices/noise_utils_test.py +2 -0
- cirq/devices/superconducting_qubits_noise_properties.py +23 -22
- cirq/devices/superconducting_qubits_noise_properties_test.py +6 -6
- cirq/devices/thermal_noise_model.py +107 -37
- cirq/devices/thermal_noise_model_test.py +21 -0
- cirq/devices/unconstrained_device.py +5 -3
- cirq/devices/unconstrained_device_test.py +2 -0
- cirq/experiments/__init__.py +4 -2
- cirq/experiments/benchmarking/__init__.py +17 -0
- cirq/experiments/benchmarking/parallel_xeb.py +677 -0
- cirq/experiments/benchmarking/parallel_xeb_test.py +447 -0
- cirq/experiments/fidelity_estimation.py +14 -8
- cirq/experiments/fidelity_estimation_test.py +3 -0
- cirq/experiments/n_qubit_tomography.py +17 -16
- cirq/experiments/n_qubit_tomography_test.py +8 -5
- cirq/experiments/purity_estimation.py +2 -0
- cirq/experiments/purity_estimation_test.py +2 -0
- cirq/experiments/qubit_characterizations.py +207 -103
- cirq/experiments/qubit_characterizations_test.py +40 -12
- cirq/experiments/random_quantum_circuit_generation.py +56 -70
- cirq/experiments/random_quantum_circuit_generation_test.py +11 -8
- cirq/experiments/readout_confusion_matrix.py +24 -22
- cirq/experiments/readout_confusion_matrix_test.py +2 -0
- cirq/experiments/single_qubit_readout_calibration.py +30 -15
- cirq/experiments/single_qubit_readout_calibration_test.py +5 -2
- cirq/experiments/t1_decay_experiment.py +9 -7
- cirq/experiments/t1_decay_experiment_test.py +13 -11
- cirq/experiments/t2_decay_experiment.py +16 -13
- cirq/experiments/t2_decay_experiment_test.py +2 -0
- cirq/experiments/two_qubit_xeb.py +64 -57
- cirq/experiments/two_qubit_xeb_test.py +10 -6
- cirq/experiments/xeb_fitting.py +39 -35
- cirq/experiments/xeb_sampling.py +37 -44
- cirq/experiments/xeb_sampling_test.py +3 -0
- cirq/experiments/xeb_simulation.py +14 -10
- cirq/experiments/xeb_simulation_test.py +5 -5
- cirq/experiments/z_phase_calibration.py +32 -29
- cirq/experiments/z_phase_calibration_test.py +3 -4
- cirq/interop/quirk/cells/__init__.py +1 -1
- cirq/interop/quirk/cells/all_cells.py +7 -2
- cirq/interop/quirk/cells/arithmetic_cells.py +29 -41
- cirq/interop/quirk/cells/arithmetic_cells_test.py +17 -14
- cirq/interop/quirk/cells/cell.py +19 -28
- cirq/interop/quirk/cells/cell_test.py +3 -0
- cirq/interop/quirk/cells/composite_cell.py +13 -28
- cirq/interop/quirk/cells/composite_cell_test.py +2 -0
- cirq/interop/quirk/cells/control_cells.py +15 -15
- cirq/interop/quirk/cells/control_cells_test.py +7 -5
- cirq/interop/quirk/cells/frequency_space_cells.py +4 -3
- cirq/interop/quirk/cells/frequency_space_cells_test.py +3 -1
- cirq/interop/quirk/cells/ignored_cells.py +3 -0
- cirq/interop/quirk/cells/ignored_cells_test.py +3 -1
- cirq/interop/quirk/cells/input_cells.py +7 -5
- cirq/interop/quirk/cells/input_cells_test.py +7 -5
- cirq/interop/quirk/cells/input_rotation_cells.py +15 -13
- cirq/interop/quirk/cells/input_rotation_cells_test.py +9 -7
- cirq/interop/quirk/cells/measurement_cells.py +5 -2
- cirq/interop/quirk/cells/measurement_cells_test.py +3 -1
- cirq/interop/quirk/cells/parse.py +22 -23
- cirq/interop/quirk/cells/parse_test.py +12 -10
- cirq/interop/quirk/cells/qubit_permutation_cells.py +5 -3
- cirq/interop/quirk/cells/qubit_permutation_cells_test.py +9 -7
- cirq/interop/quirk/cells/scalar_cells.py +4 -1
- cirq/interop/quirk/cells/scalar_cells_test.py +3 -1
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +5 -2
- cirq/interop/quirk/cells/single_qubit_rotation_cells_test.py +5 -3
- cirq/interop/quirk/cells/swap_cell.py +8 -6
- cirq/interop/quirk/cells/swap_cell_test.py +6 -4
- cirq/interop/quirk/cells/testing.py +6 -6
- cirq/interop/quirk/cells/testing_test.py +8 -6
- cirq/interop/quirk/cells/unsupported_cells.py +3 -0
- cirq/interop/quirk/cells/unsupported_cells_test.py +4 -2
- cirq/interop/quirk/url_to_circuit.py +23 -36
- cirq/interop/quirk/url_to_circuit_test.py +4 -1
- cirq/json_resolver_cache.py +14 -12
- cirq/linalg/__init__.py +4 -6
- cirq/linalg/combinators.py +7 -5
- cirq/linalg/combinators_test.py +10 -7
- cirq/linalg/decompositions.py +24 -35
- cirq/linalg/decompositions_test.py +3 -1
- cirq/linalg/diagonalize.py +6 -4
- cirq/linalg/diagonalize_test.py +15 -14
- cirq/linalg/operator_spaces.py +14 -14
- cirq/linalg/operator_spaces_test.py +13 -11
- cirq/linalg/predicates.py +18 -9
- cirq/linalg/predicates_test.py +5 -0
- cirq/linalg/tolerance.py +6 -3
- cirq/linalg/tolerance_test.py +6 -4
- cirq/linalg/transformations.py +23 -20
- cirq/linalg/transformations_test.py +73 -43
- cirq/neutral_atoms/convert_to_neutral_atom_gates.py +9 -3
- cirq/neutral_atoms/convert_to_neutral_atom_gates_test.py +3 -1
- cirq/neutral_atoms/neutral_atom_devices.py +2 -0
- cirq/ops/__init__.py +2 -0
- cirq/ops/arithmetic_operation.py +21 -21
- cirq/ops/arithmetic_operation_test.py +7 -8
- cirq/ops/boolean_hamiltonian.py +23 -22
- cirq/ops/boolean_hamiltonian_test.py +12 -9
- cirq/ops/classically_controlled_operation.py +31 -36
- cirq/ops/classically_controlled_operation_test.py +121 -117
- cirq/ops/clifford_gate.py +98 -81
- cirq/ops/clifford_gate_test.py +72 -57
- cirq/ops/common_channels.py +44 -44
- cirq/ops/common_channels_test.py +83 -81
- cirq/ops/common_gate_families.py +9 -7
- cirq/ops/common_gate_families_test.py +11 -7
- cirq/ops/common_gates.py +164 -183
- cirq/ops/common_gates_test.py +135 -95
- cirq/ops/control_values.py +23 -26
- cirq/ops/control_values_test.py +22 -20
- cirq/ops/controlled_gate.py +64 -112
- cirq/ops/controlled_gate_test.py +130 -35
- cirq/ops/controlled_operation.py +24 -35
- cirq/ops/controlled_operation_test.py +8 -6
- cirq/ops/dense_pauli_string.py +38 -49
- cirq/ops/dense_pauli_string_test.py +4 -2
- cirq/ops/diagonal_gate.py +18 -31
- cirq/ops/diagonal_gate_test.py +13 -13
- cirq/ops/eigen_gate.py +29 -29
- cirq/ops/eigen_gate_test.py +45 -28
- cirq/ops/fourier_transform.py +14 -20
- cirq/ops/fourier_transform_test.py +15 -12
- cirq/ops/fsim_gate.py +43 -42
- cirq/ops/fsim_gate_test.py +29 -29
- cirq/ops/gate_features.py +2 -0
- cirq/ops/gate_features_test.py +5 -3
- cirq/ops/gate_operation.py +43 -65
- cirq/ops/gate_operation_test.py +46 -42
- cirq/ops/gateset.py +28 -40
- cirq/ops/gateset_test.py +4 -2
- cirq/ops/global_phase_op.py +45 -20
- cirq/ops/global_phase_op_test.py +44 -20
- cirq/ops/greedy_qubit_manager.py +10 -8
- cirq/ops/greedy_qubit_manager_test.py +5 -3
- cirq/ops/identity.py +14 -12
- cirq/ops/identity_test.py +24 -20
- cirq/ops/kraus_channel.py +11 -8
- cirq/ops/kraus_channel_test.py +14 -11
- cirq/ops/linear_combinations.py +65 -77
- cirq/ops/linear_combinations_test.py +14 -9
- cirq/ops/matrix_gates.py +21 -18
- cirq/ops/matrix_gates_test.py +16 -0
- cirq/ops/measure_util.py +15 -20
- cirq/ops/measure_util_test.py +2 -0
- cirq/ops/measurement_gate.py +26 -37
- cirq/ops/measurement_gate_test.py +2 -0
- cirq/ops/mixed_unitary_channel.py +12 -9
- cirq/ops/mixed_unitary_channel_test.py +14 -11
- cirq/ops/named_qubit.py +16 -13
- cirq/ops/named_qubit_test.py +15 -13
- cirq/ops/op_tree.py +9 -7
- cirq/ops/op_tree_test.py +22 -19
- cirq/ops/parallel_gate.py +15 -17
- cirq/ops/parallel_gate_test.py +18 -16
- cirq/ops/parity_gates.py +23 -25
- cirq/ops/parity_gates_test.py +36 -32
- cirq/ops/pauli_gates.py +22 -21
- cirq/ops/pauli_gates_test.py +29 -20
- cirq/ops/pauli_interaction_gate.py +15 -19
- cirq/ops/pauli_interaction_gate_test.py +10 -8
- cirq/ops/pauli_measurement_gate.py +23 -35
- cirq/ops/pauli_measurement_gate_test.py +2 -0
- cirq/ops/pauli_string.py +92 -120
- cirq/ops/pauli_string_phasor.py +52 -45
- cirq/ops/pauli_string_phasor_test.py +4 -5
- cirq/ops/pauli_string_raw_types.py +9 -7
- cirq/ops/pauli_string_raw_types_test.py +2 -0
- cirq/ops/pauli_string_test.py +31 -154
- cirq/ops/pauli_sum_exponential.py +12 -12
- cirq/ops/pauli_sum_exponential_test.py +12 -10
- cirq/ops/permutation_gate.py +8 -6
- cirq/ops/permutation_gate_test.py +10 -8
- cirq/ops/phased_iswap_gate.py +16 -16
- cirq/ops/phased_iswap_gate_test.py +17 -15
- cirq/ops/phased_x_gate.py +16 -17
- cirq/ops/phased_x_gate_test.py +18 -16
- cirq/ops/phased_x_z_gate.py +24 -22
- cirq/ops/phased_x_z_gate_test.py +17 -11
- cirq/ops/projector.py +16 -11
- cirq/ops/projector_test.py +19 -16
- cirq/ops/qid_util.py +7 -5
- cirq/ops/qid_util_test.py +2 -0
- cirq/ops/qubit_manager.py +11 -9
- cirq/ops/qubit_manager_test.py +6 -4
- cirq/ops/qubit_order.py +11 -14
- cirq/ops/qubit_order_or_list.py +4 -2
- cirq/ops/qubit_order_test.py +12 -10
- cirq/ops/random_gate_channel.py +12 -10
- cirq/ops/random_gate_channel_test.py +14 -11
- cirq/ops/raw_types.py +109 -129
- cirq/ops/raw_types_test.py +63 -57
- cirq/ops/state_preparation_channel.py +7 -7
- cirq/ops/state_preparation_channel_test.py +11 -9
- cirq/ops/swap_gates.py +13 -15
- cirq/ops/swap_gates_test.py +19 -17
- cirq/ops/tags.py +5 -3
- cirq/ops/tags_test.py +4 -2
- cirq/ops/three_qubit_gates.py +43 -76
- cirq/ops/three_qubit_gates_test.py +19 -17
- cirq/ops/two_qubit_diagonal_gate.py +13 -13
- cirq/ops/two_qubit_diagonal_gate_test.py +10 -8
- cirq/ops/uniform_superposition_gate.py +5 -3
- cirq/ops/uniform_superposition_gate_test.py +5 -3
- cirq/ops/wait_gate.py +17 -14
- cirq/ops/wait_gate_test.py +9 -6
- cirq/protocols/__init__.py +0 -3
- cirq/protocols/act_on_protocol.py +8 -6
- cirq/protocols/act_on_protocol_test.py +15 -12
- cirq/protocols/apply_channel_protocol.py +10 -14
- cirq/protocols/apply_channel_protocol_test.py +2 -0
- cirq/protocols/apply_mixture_protocol.py +13 -42
- cirq/protocols/apply_mixture_protocol_test.py +7 -5
- cirq/protocols/apply_unitary_protocol.py +39 -34
- cirq/protocols/apply_unitary_protocol_test.py +4 -1
- cirq/protocols/approximate_equality_protocol.py +2 -0
- cirq/protocols/approximate_equality_protocol_test.py +2 -0
- cirq/protocols/circuit_diagram_info_protocol.py +58 -42
- cirq/protocols/circuit_diagram_info_protocol_test.py +70 -12
- cirq/protocols/commutes_protocol.py +8 -7
- cirq/protocols/commutes_protocol_test.py +2 -0
- cirq/protocols/control_key_protocol.py +6 -4
- cirq/protocols/control_key_protocol_test.py +3 -1
- cirq/protocols/decompose_protocol.py +49 -48
- cirq/protocols/decompose_protocol_test.py +27 -16
- cirq/protocols/equal_up_to_global_phase_protocol.py +2 -0
- cirq/protocols/equal_up_to_global_phase_protocol_test.py +9 -6
- cirq/protocols/has_stabilizer_effect_protocol.py +7 -5
- cirq/protocols/has_stabilizer_effect_protocol_test.py +7 -5
- cirq/protocols/has_unitary_protocol.py +10 -6
- cirq/protocols/has_unitary_protocol_test.py +13 -8
- cirq/protocols/hash_from_pickle_test.py +2 -11
- cirq/protocols/inverse_protocol.py +13 -16
- cirq/protocols/inverse_protocol_test.py +5 -3
- cirq/protocols/json_serialization.py +35 -54
- cirq/protocols/json_serialization_test.py +14 -21
- cirq/protocols/json_test_data/CXSWAP.json +46 -0
- cirq/protocols/json_test_data/CXSWAP.repr +13 -0
- cirq/protocols/json_test_data/CZSWAP.json +46 -0
- cirq/protocols/json_test_data/CZSWAP.repr +13 -0
- cirq/protocols/json_test_data/CircuitOperation.json +6 -3
- cirq/protocols/json_test_data/CircuitOperation.repr_inward +4 -2
- cirq/protocols/json_test_data/Moment.json +24 -1
- cirq/protocols/json_test_data/Moment.repr +6 -1
- cirq/protocols/json_test_data/ThermalNoiseModel.json +32 -0
- cirq/protocols/json_test_data/ThermalNoiseModel.repr +1 -0
- cirq/protocols/json_test_data/spec.py +6 -2
- cirq/protocols/kraus_protocol.py +47 -7
- cirq/protocols/kraus_protocol_test.py +86 -12
- cirq/protocols/measurement_key_protocol.py +15 -16
- cirq/protocols/measurement_key_protocol_test.py +13 -11
- cirq/protocols/mixture_protocol.py +7 -5
- cirq/protocols/mixture_protocol_test.py +4 -2
- cirq/protocols/mul_protocol.py +2 -3
- cirq/protocols/mul_protocol_test.py +2 -0
- cirq/protocols/pauli_expansion_protocol.py +6 -3
- cirq/protocols/pauli_expansion_protocol_test.py +5 -3
- cirq/protocols/phase_protocol.py +2 -0
- cirq/protocols/phase_protocol_test.py +3 -1
- cirq/protocols/pow_protocol.py +11 -16
- cirq/protocols/pow_protocol_test.py +2 -0
- cirq/protocols/qasm.py +14 -20
- cirq/protocols/qasm_test.py +6 -3
- cirq/protocols/qid_shape_protocol.py +8 -8
- cirq/protocols/qid_shape_protocol_test.py +3 -1
- cirq/protocols/resolve_parameters.py +5 -3
- cirq/protocols/resolve_parameters_test.py +8 -7
- cirq/protocols/trace_distance_bound.py +6 -4
- cirq/protocols/trace_distance_bound_test.py +3 -1
- cirq/protocols/unitary_protocol.py +17 -7
- cirq/protocols/unitary_protocol_test.py +12 -2
- cirq/qis/channels.py +6 -2
- cirq/qis/channels_test.py +20 -16
- cirq/qis/clifford_tableau.py +21 -19
- cirq/qis/clifford_tableau_test.py +2 -2
- cirq/qis/entropy.py +14 -3
- cirq/qis/entropy_test.py +3 -1
- cirq/qis/measures.py +13 -13
- cirq/qis/measures_test.py +20 -14
- cirq/qis/noise_utils.py +2 -0
- cirq/qis/noise_utils_test.py +9 -7
- cirq/qis/quantum_state_representation.py +7 -8
- cirq/qis/states.py +58 -56
- cirq/qis/states_test.py +2 -0
- cirq/sim/classical_simulator.py +23 -22
- cirq/sim/classical_simulator_test.py +2 -0
- cirq/sim/clifford/clifford_simulator.py +23 -21
- cirq/sim/clifford/clifford_simulator_test.py +7 -4
- cirq/sim/clifford/clifford_tableau_simulation_state.py +10 -7
- cirq/sim/clifford/clifford_tableau_simulation_state_test.py +5 -5
- cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +8 -6
- cirq/sim/clifford/stabilizer_ch_form_simulation_state_test.py +8 -6
- cirq/sim/clifford/stabilizer_sampler.py +9 -7
- cirq/sim/clifford/stabilizer_sampler_test.py +4 -2
- cirq/sim/clifford/stabilizer_simulation_state.py +14 -13
- cirq/sim/clifford/stabilizer_simulation_state_test.py +6 -4
- cirq/sim/clifford/stabilizer_state_ch_form.py +13 -11
- cirq/sim/clifford/stabilizer_state_ch_form_test.py +4 -2
- cirq/sim/density_matrix_simulation_state.py +26 -27
- cirq/sim/density_matrix_simulation_state_test.py +10 -8
- cirq/sim/density_matrix_simulator.py +30 -28
- cirq/sim/density_matrix_simulator_test.py +48 -48
- cirq/sim/density_matrix_utils.py +13 -11
- cirq/sim/density_matrix_utils_test.py +38 -36
- cirq/sim/mux.py +33 -31
- cirq/sim/mux_test.py +3 -0
- cirq/sim/simulation_product_state.py +15 -15
- cirq/sim/simulation_product_state_test.py +29 -26
- cirq/sim/simulation_state.py +29 -38
- cirq/sim/simulation_state_base.py +21 -32
- cirq/sim/simulation_state_test.py +15 -13
- cirq/sim/simulation_utils.py +5 -2
- cirq/sim/simulation_utils_test.py +5 -2
- cirq/sim/simulator.py +90 -106
- cirq/sim/simulator_base.py +33 -45
- cirq/sim/simulator_base_test.py +20 -15
- cirq/sim/simulator_test.py +23 -14
- cirq/sim/sparse_simulator.py +19 -17
- cirq/sim/sparse_simulator_test.py +41 -40
- cirq/sim/state_vector.py +15 -12
- cirq/sim/state_vector_simulation_state.py +31 -31
- cirq/sim/state_vector_simulation_state_test.py +16 -14
- cirq/sim/state_vector_simulator.py +17 -14
- cirq/sim/state_vector_simulator_test.py +2 -0
- cirq/sim/state_vector_test.py +6 -3
- cirq/study/flatten_expressions.py +16 -15
- cirq/study/flatten_expressions_test.py +13 -11
- cirq/study/resolver.py +18 -17
- cirq/study/resolver_test.py +22 -20
- cirq/study/result.py +17 -27
- cirq/study/result_test.py +2 -0
- cirq/study/sweepable.py +12 -10
- cirq/study/sweepable_test.py +3 -0
- cirq/study/sweeps.py +42 -61
- cirq/study/sweeps_test.py +33 -0
- cirq/testing/__init__.py +7 -11
- cirq/testing/_compat_test_data/module_a/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/module_b/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/sub/__init__.py +1 -0
- cirq/testing/circuit_compare.py +8 -17
- cirq/testing/circuit_compare_test.py +2 -0
- cirq/testing/consistent_act_on.py +13 -11
- cirq/testing/consistent_act_on_test.py +5 -3
- cirq/testing/consistent_channels.py +2 -0
- cirq/testing/consistent_channels_test.py +10 -8
- cirq/testing/consistent_controlled_gate_op.py +5 -5
- cirq/testing/consistent_controlled_gate_op_test.py +18 -18
- cirq/testing/consistent_decomposition.py +2 -2
- cirq/testing/consistent_decomposition_test.py +4 -2
- cirq/testing/consistent_pauli_expansion.py +2 -0
- cirq/testing/consistent_pauli_expansion_test.py +3 -1
- cirq/testing/consistent_phase_by.py +2 -0
- cirq/testing/consistent_phase_by_test.py +3 -1
- cirq/testing/consistent_protocols.py +14 -20
- cirq/testing/consistent_protocols_test.py +13 -11
- cirq/testing/consistent_qasm.py +6 -4
- cirq/testing/consistent_qasm_test.py +7 -7
- cirq/testing/consistent_resolve_parameters.py +2 -0
- cirq/testing/consistent_specified_has_unitary.py +2 -2
- cirq/testing/consistent_specified_has_unitary_test.py +6 -4
- cirq/testing/consistent_unitary.py +1 -0
- cirq/testing/consistent_unitary_test.py +4 -2
- cirq/testing/deprecation.py +5 -2
- cirq/testing/deprecation_test.py +5 -2
- cirq/testing/devices.py +7 -4
- cirq/testing/devices_test.py +7 -4
- cirq/testing/equals_tester.py +4 -2
- cirq/testing/equals_tester_test.py +21 -17
- cirq/testing/equivalent_basis_map.py +6 -4
- cirq/testing/equivalent_basis_map_test.py +6 -4
- cirq/testing/equivalent_repr_eval.py +6 -4
- cirq/testing/equivalent_repr_eval_test.py +5 -3
- cirq/testing/gate_features.py +2 -0
- cirq/testing/gate_features_test.py +7 -5
- cirq/testing/json.py +19 -15
- cirq/testing/json_test.py +5 -3
- cirq/testing/lin_alg_utils.py +10 -11
- cirq/testing/lin_alg_utils_test.py +14 -12
- cirq/testing/logs.py +7 -6
- cirq/testing/logs_test.py +9 -7
- cirq/testing/no_identifier_qubit.py +4 -2
- cirq/testing/no_identifier_qubit_test.py +5 -3
- cirq/testing/op_tree.py +2 -0
- cirq/testing/op_tree_test.py +4 -1
- cirq/testing/order_tester.py +2 -0
- cirq/testing/order_tester_test.py +8 -6
- cirq/testing/pytest_utils.py +2 -0
- cirq/testing/pytest_utils_test.py +4 -2
- cirq/testing/random_circuit.py +21 -20
- cirq/testing/random_circuit_test.py +12 -9
- cirq/testing/repr_pretty_tester.py +1 -0
- cirq/testing/repr_pretty_tester_test.py +5 -3
- cirq/testing/routing_devices.py +4 -1
- cirq/testing/routing_devices_test.py +9 -6
- cirq/testing/sample_circuits.py +4 -1
- cirq/testing/sample_circuits_test.py +3 -1
- cirq/testing/sample_gates.py +3 -0
- cirq/testing/sample_gates_test.py +5 -2
- cirq/transformers/__init__.py +11 -4
- cirq/transformers/align.py +9 -7
- cirq/transformers/align_test.py +2 -0
- cirq/transformers/analytical_decompositions/__init__.py +3 -6
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +18 -16
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +19 -16
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +11 -9
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition_test.py +5 -3
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +141 -44
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +35 -1
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +8 -7
- cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +2 -0
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +7 -4
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +3 -0
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +11 -19
- cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py +8 -33
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +9 -11
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +2 -0
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +91 -27
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +36 -7
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +20 -21
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py +8 -6
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +13 -15
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +3 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +39 -41
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +2 -0
- cirq/transformers/drop_empty_moments.py +5 -3
- cirq/transformers/drop_empty_moments_test.py +4 -2
- cirq/transformers/drop_negligible_operations.py +7 -5
- cirq/transformers/drop_negligible_operations_test.py +2 -0
- cirq/transformers/dynamical_decoupling.py +49 -42
- cirq/transformers/dynamical_decoupling_test.py +223 -205
- cirq/transformers/eject_phased_paulis.py +28 -26
- cirq/transformers/eject_phased_paulis_test.py +12 -9
- cirq/transformers/eject_z.py +12 -12
- cirq/transformers/eject_z_test.py +2 -2
- cirq/transformers/expand_composite.py +6 -4
- cirq/transformers/expand_composite_test.py +3 -1
- cirq/transformers/gauge_compiling/__init__.py +3 -1
- cirq/transformers/gauge_compiling/cphase_gauge.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 +45 -41
- 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 +5 -1
- cirq/transformers/gauge_compiling/iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/iswap_gauge_test.py +1 -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 +7 -6
- 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 +6 -3
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +3 -0
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +12 -9
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation_test.py +9 -7
- cirq/transformers/insertion_sort.py +8 -6
- cirq/transformers/insertion_sort_test.py +3 -1
- cirq/transformers/measurement_transformers.py +29 -29
- cirq/transformers/measurement_transformers_test.py +2 -0
- cirq/transformers/merge_k_qubit_gates.py +12 -10
- cirq/transformers/merge_k_qubit_gates_test.py +18 -18
- cirq/transformers/merge_single_qubit_gates.py +197 -20
- cirq/transformers/merge_single_qubit_gates_test.py +177 -5
- cirq/transformers/noise_adding.py +5 -3
- cirq/transformers/noise_adding_test.py +2 -0
- cirq/transformers/optimize_for_target_gateset.py +19 -17
- cirq/transformers/optimize_for_target_gateset_test.py +11 -8
- cirq/transformers/qubit_management_transformers.py +13 -11
- cirq/transformers/qubit_management_transformers_test.py +5 -3
- cirq/transformers/randomized_measurements.py +16 -14
- cirq/transformers/randomized_measurements_test.py +10 -4
- cirq/transformers/routing/initial_mapper.py +6 -4
- cirq/transformers/routing/initial_mapper_test.py +2 -0
- cirq/transformers/routing/line_initial_mapper.py +16 -14
- cirq/transformers/routing/line_initial_mapper_test.py +9 -7
- cirq/transformers/routing/mapping_manager.py +10 -10
- cirq/transformers/routing/mapping_manager_test.py +2 -0
- cirq/transformers/routing/route_circuit_cqc.py +33 -31
- cirq/transformers/routing/route_circuit_cqc_test.py +15 -13
- cirq/transformers/routing/visualize_routed_circuit.py +8 -7
- cirq/transformers/routing/visualize_routed_circuit_test.py +4 -2
- cirq/transformers/stratify.py +17 -15
- cirq/transformers/stratify_test.py +3 -0
- cirq/transformers/symbolize.py +103 -0
- cirq/transformers/symbolize_test.py +62 -0
- cirq/transformers/synchronize_terminal_measurements.py +10 -10
- cirq/transformers/synchronize_terminal_measurements_test.py +12 -10
- cirq/transformers/tag_transformers.py +97 -0
- cirq/transformers/tag_transformers_test.py +103 -0
- cirq/transformers/target_gatesets/compilation_target_gateset.py +21 -19
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +20 -16
- cirq/transformers/target_gatesets/cz_gateset.py +7 -5
- cirq/transformers/target_gatesets/cz_gateset_test.py +21 -19
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +9 -7
- cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +25 -25
- cirq/transformers/transformer_api.py +34 -47
- cirq/transformers/transformer_api_test.py +9 -8
- cirq/transformers/transformer_primitives.py +39 -49
- cirq/transformers/transformer_primitives_test.py +10 -17
- cirq/value/abc_alt.py +6 -4
- cirq/value/abc_alt_test.py +5 -3
- cirq/value/angle.py +11 -12
- cirq/value/angle_test.py +5 -3
- cirq/value/classical_data.py +27 -27
- cirq/value/classical_data_test.py +11 -8
- cirq/value/condition.py +26 -24
- cirq/value/condition_test.py +2 -0
- cirq/value/digits.py +14 -11
- cirq/value/digits_test.py +2 -0
- cirq/value/duration.py +23 -20
- cirq/value/duration_test.py +2 -0
- cirq/value/linear_dict.py +25 -30
- cirq/value/linear_dict_test.py +10 -8
- cirq/value/measurement_key.py +12 -12
- cirq/value/measurement_key_test.py +2 -0
- cirq/value/periodic_value.py +4 -4
- cirq/value/periodic_value_test.py +11 -7
- cirq/value/probability.py +3 -1
- cirq/value/probability_test.py +4 -2
- cirq/value/product_state.py +15 -13
- cirq/value/product_state_test.py +4 -1
- cirq/value/random_state.py +2 -0
- cirq/value/random_state_test.py +5 -3
- cirq/value/timestamp.py +11 -7
- cirq/value/timestamp_test.py +14 -12
- cirq/value/type_alias.py +4 -4
- cirq/value/value_equality_attr.py +8 -9
- cirq/value/value_equality_attr_test.py +14 -11
- cirq/vis/density_matrix.py +3 -3
- cirq/vis/density_matrix_test.py +20 -17
- cirq/vis/heatmap.py +24 -37
- cirq/vis/heatmap_test.py +3 -0
- cirq/vis/histogram.py +9 -6
- cirq/vis/histogram_test.py +5 -2
- cirq/vis/state_histogram.py +10 -8
- cirq/vis/state_histogram_test.py +7 -5
- cirq/vis/vis_utils.py +4 -1
- cirq/vis/vis_utils_test.py +4 -1
- cirq/work/collector.py +12 -18
- cirq/work/collector_test.py +15 -10
- cirq/work/observable_grouping.py +6 -7
- cirq/work/observable_grouping_test.py +10 -9
- cirq/work/observable_measurement.py +47 -45
- cirq/work/observable_measurement_data.py +22 -17
- cirq/work/observable_measurement_data_test.py +4 -1
- cirq/work/observable_measurement_test.py +48 -29
- cirq/work/observable_readout_calibration.py +5 -2
- cirq/work/observable_readout_calibration_test.py +5 -2
- cirq/work/observable_settings.py +13 -22
- cirq/work/observable_settings_test.py +9 -7
- cirq/work/pauli_sum_collector.py +12 -10
- cirq/work/pauli_sum_collector_test.py +9 -9
- cirq/work/sampler.py +42 -43
- cirq/work/sampler_test.py +31 -24
- cirq/work/zeros_sampler.py +6 -4
- cirq/work/zeros_sampler_test.py +7 -5
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/METADATA +7 -8
- cirq_core-1.6.0.dist-info/RECORD +1241 -0
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/WHEEL +1 -1
- cirq_core-1.5.0.dev20250409225226.dist-info/RECORD +0 -1216
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/top_level.txt +0 -0
cirq/__init__.py
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
"""Cirq is a framework for creating, editing, and invoking quantum circuits."""
|
|
16
16
|
|
|
17
|
+
# ruff: noqa: F401
|
|
18
|
+
|
|
17
19
|
from cirq import _import
|
|
18
20
|
|
|
19
21
|
from cirq._compat import __cirq_debug__ as __cirq_debug__, with_debug as with_debug
|
|
@@ -121,20 +123,19 @@ from cirq.interop import (
|
|
|
121
123
|
)
|
|
122
124
|
|
|
123
125
|
from cirq.linalg import (
|
|
124
|
-
# pylint: disable=line-too-long
|
|
125
126
|
all_near_zero as all_near_zero,
|
|
126
127
|
all_near_zero_mod as all_near_zero_mod,
|
|
127
128
|
allclose_up_to_global_phase as allclose_up_to_global_phase,
|
|
128
129
|
apply_matrix_to_slices as apply_matrix_to_slices,
|
|
129
130
|
axis_angle as axis_angle,
|
|
130
131
|
AxisAngleDecomposition as AxisAngleDecomposition,
|
|
131
|
-
bidiagonalize_real_matrix_pair_with_symmetric_products as bidiagonalize_real_matrix_pair_with_symmetric_products,
|
|
132
|
-
bidiagonalize_unitary_with_special_orthogonals as bidiagonalize_unitary_with_special_orthogonals,
|
|
132
|
+
bidiagonalize_real_matrix_pair_with_symmetric_products as bidiagonalize_real_matrix_pair_with_symmetric_products, # noqa: E501
|
|
133
|
+
bidiagonalize_unitary_with_special_orthogonals as bidiagonalize_unitary_with_special_orthogonals, # noqa: E501
|
|
133
134
|
block_diag as block_diag,
|
|
134
135
|
CONTROL_TAG as CONTROL_TAG,
|
|
135
136
|
deconstruct_single_qubit_matrix_into_angles as deconstruct_single_qubit_matrix_into_angles,
|
|
136
137
|
density_matrix_kronecker_product as density_matrix_kronecker_product,
|
|
137
|
-
diagonalize_real_symmetric_and_sorted_diagonal_matrices as diagonalize_real_symmetric_and_sorted_diagonal_matrices,
|
|
138
|
+
diagonalize_real_symmetric_and_sorted_diagonal_matrices as diagonalize_real_symmetric_and_sorted_diagonal_matrices, # noqa: E501
|
|
138
139
|
diagonalize_real_symmetric_matrix as diagonalize_real_symmetric_matrix,
|
|
139
140
|
dot as dot,
|
|
140
141
|
expand_matrix_in_orthogonal_basis as expand_matrix_in_orthogonal_basis,
|
|
@@ -163,7 +164,7 @@ from cirq.linalg import (
|
|
|
163
164
|
partial_trace as partial_trace,
|
|
164
165
|
partial_trace_of_state_vector_as_mixture as partial_trace_of_state_vector_as_mixture,
|
|
165
166
|
PAULI_BASIS as PAULI_BASIS,
|
|
166
|
-
scatter_plot_normalized_kak_interaction_coefficients as scatter_plot_normalized_kak_interaction_coefficients,
|
|
167
|
+
scatter_plot_normalized_kak_interaction_coefficients as scatter_plot_normalized_kak_interaction_coefficients, # noqa: E501
|
|
167
168
|
pow_pauli_combination as pow_pauli_combination,
|
|
168
169
|
reflection_matrix_pow as reflection_matrix_pow,
|
|
169
170
|
slice_for_qubits_equal_to as slice_for_qubits_equal_to,
|
|
@@ -205,7 +206,9 @@ from cirq.ops import (
|
|
|
205
206
|
CSwapGate as CSwapGate,
|
|
206
207
|
CX as CX,
|
|
207
208
|
CXPowGate as CXPowGate,
|
|
209
|
+
CXSWAP as CXSWAP,
|
|
208
210
|
CZ as CZ,
|
|
211
|
+
CZSWAP as CZSWAP,
|
|
209
212
|
CZPowGate as CZPowGate,
|
|
210
213
|
DensePauliString as DensePauliString,
|
|
211
214
|
depolarize as depolarize,
|
|
@@ -340,20 +343,19 @@ from cirq.ops import (
|
|
|
340
343
|
|
|
341
344
|
|
|
342
345
|
from cirq.transformers import (
|
|
343
|
-
# pylint: disable=line-too-long
|
|
344
346
|
AbstractInitialMapper as AbstractInitialMapper,
|
|
345
347
|
add_dynamical_decoupling as add_dynamical_decoupling,
|
|
346
348
|
align_left as align_left,
|
|
347
349
|
align_right as align_right,
|
|
348
350
|
CompilationTargetGateset as CompilationTargetGateset,
|
|
349
351
|
CZTargetGateset as CZTargetGateset,
|
|
350
|
-
compute_cphase_exponents_for_fsim_decomposition as compute_cphase_exponents_for_fsim_decomposition,
|
|
352
|
+
compute_cphase_exponents_for_fsim_decomposition as compute_cphase_exponents_for_fsim_decomposition, # noqa: E501
|
|
351
353
|
create_transformer_with_kwargs as create_transformer_with_kwargs,
|
|
352
354
|
decompose_clifford_tableau_to_operations as decompose_clifford_tableau_to_operations,
|
|
353
355
|
decompose_cphase_into_two_fsim as decompose_cphase_into_two_fsim,
|
|
354
356
|
decompose_multi_controlled_x as decompose_multi_controlled_x,
|
|
355
357
|
decompose_multi_controlled_rotation as decompose_multi_controlled_rotation,
|
|
356
|
-
decompose_two_qubit_interaction_into_four_fsim_gates as decompose_two_qubit_interaction_into_four_fsim_gates,
|
|
358
|
+
decompose_two_qubit_interaction_into_four_fsim_gates as decompose_two_qubit_interaction_into_four_fsim_gates, # noqa: E501
|
|
357
359
|
defer_measurements as defer_measurements,
|
|
358
360
|
dephase_measurements as dephase_measurements,
|
|
359
361
|
drop_empty_moments as drop_empty_moments,
|
|
@@ -363,6 +365,7 @@ from cirq.transformers import (
|
|
|
363
365
|
eject_z as eject_z,
|
|
364
366
|
expand_composite as expand_composite,
|
|
365
367
|
HardCodedInitialMapper as HardCodedInitialMapper,
|
|
368
|
+
index_tags as index_tags,
|
|
366
369
|
is_negligible_turn as is_negligible_turn,
|
|
367
370
|
LineInitialMapper as LineInitialMapper,
|
|
368
371
|
MappingManager as MappingManager,
|
|
@@ -377,6 +380,7 @@ from cirq.transformers import (
|
|
|
377
380
|
merge_operations_to_circuit_op as merge_operations_to_circuit_op,
|
|
378
381
|
merge_single_qubit_gates_to_phased_x_and_z as merge_single_qubit_gates_to_phased_x_and_z,
|
|
379
382
|
merge_single_qubit_gates_to_phxz as merge_single_qubit_gates_to_phxz,
|
|
383
|
+
merge_single_qubit_gates_to_phxz_symbolized as merge_single_qubit_gates_to_phxz_symbolized,
|
|
380
384
|
merge_single_qubit_moments_to_phxz as merge_single_qubit_moments_to_phxz,
|
|
381
385
|
optimize_for_target_gateset as optimize_for_target_gateset,
|
|
382
386
|
parameterized_2q_op_to_sqrt_iswap_operations as parameterized_2q_op_to_sqrt_iswap_operations,
|
|
@@ -385,6 +389,7 @@ from cirq.transformers import (
|
|
|
385
389
|
prepare_two_qubit_state_using_sqrt_iswap as prepare_two_qubit_state_using_sqrt_iswap,
|
|
386
390
|
quantum_shannon_decomposition as quantum_shannon_decomposition,
|
|
387
391
|
RouteCQC as RouteCQC,
|
|
392
|
+
remove_tags as remove_tags,
|
|
388
393
|
routed_circuit_with_mapping as routed_circuit_with_mapping,
|
|
389
394
|
SqrtIswapTargetGateset as SqrtIswapTargetGateset,
|
|
390
395
|
single_qubit_matrix_to_gates as single_qubit_matrix_to_gates,
|
|
@@ -393,6 +398,7 @@ from cirq.transformers import (
|
|
|
393
398
|
single_qubit_matrix_to_phxz as single_qubit_matrix_to_phxz,
|
|
394
399
|
single_qubit_op_to_framed_phase_form as single_qubit_op_to_framed_phase_form,
|
|
395
400
|
stratified_circuit as stratified_circuit,
|
|
401
|
+
symbolize_single_qubit_gates_by_indexed_tags as symbolize_single_qubit_gates_by_indexed_tags,
|
|
396
402
|
synchronize_terminal_measurements as synchronize_terminal_measurements,
|
|
397
403
|
TRANSFORMER as TRANSFORMER,
|
|
398
404
|
TransformerContext as TransformerContext,
|
|
@@ -401,7 +407,7 @@ from cirq.transformers import (
|
|
|
401
407
|
transformer as transformer,
|
|
402
408
|
two_qubit_matrix_to_cz_isometry as two_qubit_matrix_to_cz_isometry,
|
|
403
409
|
two_qubit_matrix_to_cz_operations as two_qubit_matrix_to_cz_operations,
|
|
404
|
-
two_qubit_matrix_to_diagonal_and_cz_operations as two_qubit_matrix_to_diagonal_and_cz_operations,
|
|
410
|
+
two_qubit_matrix_to_diagonal_and_cz_operations as two_qubit_matrix_to_diagonal_and_cz_operations, # noqa: E501
|
|
405
411
|
two_qubit_matrix_to_ion_operations as two_qubit_matrix_to_ion_operations,
|
|
406
412
|
two_qubit_matrix_to_sqrt_iswap_operations as two_qubit_matrix_to_sqrt_iswap_operations,
|
|
407
413
|
two_qubit_gate_product_tabulation as two_qubit_gate_product_tabulation,
|
|
@@ -565,7 +571,6 @@ from cirq.value import (
|
|
|
565
571
|
ProductState as ProductState,
|
|
566
572
|
)
|
|
567
573
|
|
|
568
|
-
# pylint: disable=redefined-builtin
|
|
569
574
|
from cirq.protocols import (
|
|
570
575
|
act_on as act_on,
|
|
571
576
|
apply_channel as apply_channel,
|
|
@@ -687,14 +692,10 @@ from cirq.work import (
|
|
|
687
692
|
ZerosSampler as ZerosSampler,
|
|
688
693
|
)
|
|
689
694
|
|
|
690
|
-
# pylint: enable=redefined-builtin
|
|
691
695
|
|
|
692
696
|
# Unflattened sub-modules.
|
|
693
697
|
|
|
694
|
-
from cirq import testing
|
|
695
|
-
|
|
696
698
|
# Registers cirq-core's public classes for JSON serialization.
|
|
697
|
-
# pylint: disable=wrong-import-position
|
|
698
699
|
from cirq.protocols.json_serialization import _register_resolver
|
|
699
700
|
from cirq.json_resolver_cache import _class_resolver_dictionary
|
|
700
701
|
|
|
@@ -703,6 +704,4 @@ _register_resolver(_class_resolver_dictionary)
|
|
|
703
704
|
|
|
704
705
|
# contrib's json resolver cache depends on cirq.DEFAULT_RESOLVER
|
|
705
706
|
|
|
706
|
-
from cirq import contrib
|
|
707
|
-
|
|
708
|
-
# pylint: enable=wrong-import-position
|
|
707
|
+
from cirq import contrib # noqa: E402
|
cirq/_compat.py
CHANGED
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
"""Workarounds for compatibility issues between versions and libraries."""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
import contextlib
|
|
17
20
|
import contextvars
|
|
18
21
|
import dataclasses
|
|
@@ -25,7 +28,7 @@ import sys
|
|
|
25
28
|
import traceback
|
|
26
29
|
import warnings
|
|
27
30
|
from types import ModuleType
|
|
28
|
-
from typing import Any, Callable,
|
|
31
|
+
from typing import Any, Callable, Iterator, overload, TypeVar
|
|
29
32
|
|
|
30
33
|
import numpy as np
|
|
31
34
|
import pandas as pd
|
|
@@ -76,7 +79,7 @@ def cached_method(__func: TFunc) -> TFunc: ...
|
|
|
76
79
|
def cached_method(*, maxsize: int = 128) -> Callable[[TFunc], TFunc]: ...
|
|
77
80
|
|
|
78
81
|
|
|
79
|
-
def cached_method(method:
|
|
82
|
+
def cached_method(method: TFunc | None = None, *, maxsize: int = 128) -> Any:
|
|
80
83
|
"""Decorator that adds a per-instance LRU cache for a method.
|
|
81
84
|
|
|
82
85
|
Can be applied with or without parameters to customize the underlying cache:
|
|
@@ -192,7 +195,7 @@ def proper_repr(value: Any) -> str:
|
|
|
192
195
|
f'\n)'
|
|
193
196
|
)
|
|
194
197
|
|
|
195
|
-
if isinstance(value,
|
|
198
|
+
if isinstance(value, dict):
|
|
196
199
|
return '{' + ','.join(f"{proper_repr(k)}: {proper_repr(v)}" for k, v in value.items()) + '}'
|
|
197
200
|
|
|
198
201
|
if hasattr(value, "__qualname__"):
|
|
@@ -285,7 +288,7 @@ def _validate_deadline(deadline: str):
|
|
|
285
288
|
|
|
286
289
|
|
|
287
290
|
def deprecated(
|
|
288
|
-
*, deadline: str, fix: str, name:
|
|
291
|
+
*, deadline: str, fix: str, name: str | None = None
|
|
289
292
|
) -> Callable[[Callable], Callable]:
|
|
290
293
|
"""Marks a function as deprecated.
|
|
291
294
|
|
|
@@ -326,9 +329,7 @@ def deprecated(
|
|
|
326
329
|
return decorator
|
|
327
330
|
|
|
328
331
|
|
|
329
|
-
def deprecated_class(
|
|
330
|
-
*, deadline: str, fix: str, name: Optional[str] = None
|
|
331
|
-
) -> Callable[[Type], Type]:
|
|
332
|
+
def deprecated_class(*, deadline: str, fix: str, name: str | None = None) -> Callable[[type], type]:
|
|
332
333
|
"""Marks a class as deprecated.
|
|
333
334
|
|
|
334
335
|
Args:
|
|
@@ -345,7 +346,7 @@ def deprecated_class(
|
|
|
345
346
|
|
|
346
347
|
_validate_deadline(deadline)
|
|
347
348
|
|
|
348
|
-
def decorator(clazz:
|
|
349
|
+
def decorator(clazz: type) -> type:
|
|
349
350
|
clazz_new = clazz.__new__
|
|
350
351
|
|
|
351
352
|
def patched_new(cls, *args, **kwargs):
|
|
@@ -375,12 +376,12 @@ def deprecated_parameter(
|
|
|
375
376
|
*,
|
|
376
377
|
deadline: str,
|
|
377
378
|
fix: str,
|
|
378
|
-
func_name:
|
|
379
|
+
func_name: str | None = None,
|
|
379
380
|
parameter_desc: str,
|
|
380
|
-
match: Callable[[
|
|
381
|
-
rewrite:
|
|
382
|
-
Callable[[
|
|
383
|
-
|
|
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,
|
|
384
385
|
) -> Callable[[Callable], Callable]:
|
|
385
386
|
"""Marks a function parameter as deprecated.
|
|
386
387
|
|
|
@@ -444,7 +445,7 @@ def deprecated_parameter(
|
|
|
444
445
|
return decorator
|
|
445
446
|
|
|
446
447
|
|
|
447
|
-
def deprecate_attributes(module_name: str, deprecated_attributes:
|
|
448
|
+
def deprecate_attributes(module_name: str, deprecated_attributes: dict[str, tuple[str, str]]):
|
|
448
449
|
"""Replace module with a wrapper that gives warnings for deprecated attributes.
|
|
449
450
|
|
|
450
451
|
Args:
|
|
@@ -468,7 +469,7 @@ def deprecate_attributes(module_name: str, deprecated_attributes: Dict[str, Tupl
|
|
|
468
469
|
__dict__ = module.__dict__
|
|
469
470
|
|
|
470
471
|
# Workaround for: https://github.com/python/mypy/issues/8083
|
|
471
|
-
__spec__ = _make_proxy_spec_property(module)
|
|
472
|
+
__spec__ = _make_proxy_spec_property(module)
|
|
472
473
|
|
|
473
474
|
def __getattr__(self, name):
|
|
474
475
|
if name in deprecated_attributes:
|
|
@@ -534,7 +535,7 @@ class DeprecatedModuleLoader(importlib.abc.Loader):
|
|
|
534
535
|
sys.modules[self.old_module_name] = sys.modules[self.new_module_name]
|
|
535
536
|
return sys.modules[self.old_module_name]
|
|
536
537
|
method(self.new_module_name)
|
|
537
|
-
# https://docs.python.org/3.
|
|
538
|
+
# https://docs.python.org/3.11/library/importlib.html#importlib.abc.Loader.load_module
|
|
538
539
|
assert self.new_module_name in sys.modules, (
|
|
539
540
|
f"Wrapped loader {self.loader} was "
|
|
540
541
|
f"expected to insert "
|
|
@@ -583,7 +584,7 @@ def _is_internal(filename: str) -> bool:
|
|
|
583
584
|
return 'importlib' in filename and '_bootstrap' in filename
|
|
584
585
|
|
|
585
586
|
|
|
586
|
-
_warned:
|
|
587
|
+
_warned: set[str] = set()
|
|
587
588
|
|
|
588
589
|
|
|
589
590
|
def _called_from_test() -> bool:
|
|
@@ -632,7 +633,7 @@ class DeprecatedModuleFinder(importlib.abc.MetaPathFinder):
|
|
|
632
633
|
new_module_name: str,
|
|
633
634
|
old_module_name: str,
|
|
634
635
|
deadline: str,
|
|
635
|
-
broken_module_exception:
|
|
636
|
+
broken_module_exception: BaseException | None,
|
|
636
637
|
):
|
|
637
638
|
"""An aliasing module finder that uses existing module finders to find a python
|
|
638
639
|
module spec and intercept the execution of matching modules.
|
|
@@ -760,7 +761,7 @@ def _setup_deprecated_submodule_attribute(
|
|
|
760
761
|
old_parent: str,
|
|
761
762
|
old_child: str,
|
|
762
763
|
deadline: str,
|
|
763
|
-
new_module:
|
|
764
|
+
new_module: ModuleType | None,
|
|
764
765
|
):
|
|
765
766
|
parent_module = sys.modules[old_parent]
|
|
766
767
|
setattr(parent_module, old_child, new_module)
|
|
@@ -769,7 +770,7 @@ def _setup_deprecated_submodule_attribute(
|
|
|
769
770
|
__dict__ = parent_module.__dict__
|
|
770
771
|
|
|
771
772
|
# Workaround for: https://github.com/python/mypy/issues/8083
|
|
772
|
-
__spec__ = _make_proxy_spec_property(parent_module)
|
|
773
|
+
__spec__ = _make_proxy_spec_property(parent_module)
|
|
773
774
|
|
|
774
775
|
def __getattr__(self, name):
|
|
775
776
|
if name == old_child:
|
cirq/_compat_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 collections
|
|
15
18
|
import dataclasses
|
|
16
19
|
import importlib.metadata
|
|
@@ -24,7 +27,7 @@ import types
|
|
|
24
27
|
import warnings
|
|
25
28
|
from importlib.machinery import ModuleSpec
|
|
26
29
|
from types import ModuleType
|
|
27
|
-
from typing import Any, Callable
|
|
30
|
+
from typing import Any, Callable
|
|
28
31
|
from unittest import mock
|
|
29
32
|
|
|
30
33
|
import duet
|
|
@@ -199,13 +202,11 @@ def test_deprecated():
|
|
|
199
202
|
old_func(1, 2)
|
|
200
203
|
|
|
201
204
|
with pytest.raises(AssertionError, match='deadline should match vX.Y'):
|
|
202
|
-
|
|
205
|
+
|
|
203
206
|
@deprecated(deadline='invalid', fix='Roll some dice.')
|
|
204
207
|
def badly_deprecated_func(*args, **kwargs): # pragma: no cover
|
|
205
208
|
return new_func(*args, **kwargs)
|
|
206
209
|
|
|
207
|
-
# pylint: enable=unused-variable
|
|
208
|
-
|
|
209
210
|
|
|
210
211
|
def test_deprecated_parameter():
|
|
211
212
|
@deprecated_parameter(
|
|
@@ -231,20 +232,16 @@ def test_deprecated_parameter():
|
|
|
231
232
|
'Double it yourself.',
|
|
232
233
|
deadline='v1.2',
|
|
233
234
|
):
|
|
234
|
-
# pylint: disable=unexpected-keyword-arg
|
|
235
235
|
# pylint: disable=no-value-for-parameter
|
|
236
236
|
assert f(double_count=1) == 2
|
|
237
237
|
# pylint: enable=no-value-for-parameter
|
|
238
|
-
# pylint: enable=unexpected-keyword-arg
|
|
239
238
|
|
|
240
239
|
with pytest.raises(
|
|
241
240
|
ValueError, match='During testing using Cirq deprecated functionality is not allowed'
|
|
242
241
|
):
|
|
243
|
-
# pylint: disable=unexpected-keyword-arg
|
|
244
242
|
# pylint: disable=no-value-for-parameter
|
|
245
243
|
f(double_count=1)
|
|
246
244
|
# pylint: enable=no-value-for-parameter
|
|
247
|
-
# pylint: enable=unexpected-keyword-arg
|
|
248
245
|
|
|
249
246
|
with pytest.raises(AssertionError, match='deadline should match vX.Y'):
|
|
250
247
|
|
|
@@ -256,12 +253,9 @@ def test_deprecated_parameter():
|
|
|
256
253
|
match=lambda args, kwargs: 'double_count' in kwargs,
|
|
257
254
|
rewrite=lambda args, kwargs: (args, {'new_count': kwargs['double_count'] * 2}),
|
|
258
255
|
)
|
|
259
|
-
# pylint: disable=unused-variable
|
|
260
256
|
def f_with_badly_deprecated_param(new_count): # pragma: no cover
|
|
261
257
|
return new_count
|
|
262
258
|
|
|
263
|
-
# pylint: enable=unused-variable
|
|
264
|
-
|
|
265
259
|
|
|
266
260
|
@duet.sync
|
|
267
261
|
async def test_deprecated_parameter_async_function():
|
|
@@ -290,11 +284,9 @@ async def test_deprecated_parameter_async_function():
|
|
|
290
284
|
'Double it yourself.',
|
|
291
285
|
deadline='v1.2',
|
|
292
286
|
):
|
|
293
|
-
# pylint: disable=unexpected-keyword-arg
|
|
294
287
|
# pylint: disable=no-value-for-parameter
|
|
295
288
|
assert await f(double_count=1) == 2
|
|
296
289
|
# pylint: enable=no-value-for-parameter
|
|
297
|
-
# pylint: enable=unexpected-keyword-arg
|
|
298
290
|
|
|
299
291
|
|
|
300
292
|
def test_wrap_module():
|
|
@@ -402,13 +394,11 @@ def test_deprecated_class():
|
|
|
402
394
|
OldClass('1')
|
|
403
395
|
|
|
404
396
|
with pytest.raises(AssertionError, match='deadline should match vX.Y'):
|
|
405
|
-
|
|
397
|
+
|
|
406
398
|
@deprecated_class(deadline='invalid', fix='theFix', name='foo')
|
|
407
399
|
class BadlyDeprecatedClass(NewClass): # pragma: no cover
|
|
408
400
|
...
|
|
409
401
|
|
|
410
|
-
# pylint: enable=unused-variable
|
|
411
|
-
|
|
412
402
|
|
|
413
403
|
def _from_parent_import_deprecated():
|
|
414
404
|
from cirq.testing._compat_test_data import fake_a
|
|
@@ -574,8 +564,7 @@ def _import_top_level_deprecated():
|
|
|
574
564
|
def _repeated_import_path():
|
|
575
565
|
"""to ensure that the highly unlikely repeated subpath import doesn't interfere"""
|
|
576
566
|
|
|
577
|
-
#
|
|
578
|
-
from cirq.testing._compat_test_data.repeated_child.cirq.testing._compat_test_data.repeated_child import ( # type: ignore
|
|
567
|
+
from cirq.testing._compat_test_data.repeated_child.cirq.testing._compat_test_data.repeated_child import ( # type: ignore # noqa: E501
|
|
579
568
|
child,
|
|
580
569
|
)
|
|
581
570
|
|
|
@@ -584,7 +573,6 @@ def _repeated_import_path():
|
|
|
584
573
|
|
|
585
574
|
def _type_repr_in_deprecated_module():
|
|
586
575
|
# initialize the DeprecatedModuleFinders
|
|
587
|
-
# pylint: disable=unused-import
|
|
588
576
|
import cirq.testing._compat_test_data.fake_a as mod_a
|
|
589
577
|
|
|
590
578
|
expected_repr = "<class 'cirq.testing._compat_test_data.module_a.types.SampleType'>"
|
|
@@ -635,7 +623,7 @@ _repeated_child_deprecation_msg = [
|
|
|
635
623
|
] + _deprecation_origin
|
|
636
624
|
|
|
637
625
|
|
|
638
|
-
def _trace_unhandled_exceptions(*args, queue:
|
|
626
|
+
def _trace_unhandled_exceptions(*args, queue: multiprocessing.Queue, func: Callable):
|
|
639
627
|
try:
|
|
640
628
|
func(*args)
|
|
641
629
|
queue.put(None)
|
|
@@ -760,9 +748,6 @@ def test_metadata_search_path():
|
|
|
760
748
|
|
|
761
749
|
def _test_metadata_search_path_inner(): # pragma: no cover
|
|
762
750
|
# initialize the DeprecatedModuleFinders
|
|
763
|
-
# pylint: disable=unused-import
|
|
764
|
-
import cirq.testing._compat_test_data.module_a
|
|
765
|
-
|
|
766
751
|
assert importlib.metadata.metadata('numpy')
|
|
767
752
|
|
|
768
753
|
|
|
@@ -803,7 +788,6 @@ def test_type_repr_in_new_module():
|
|
|
803
788
|
|
|
804
789
|
def _test_type_repr_in_new_module_inner():
|
|
805
790
|
# initialize the DeprecatedModuleFinders
|
|
806
|
-
# pylint: disable=unused-import
|
|
807
791
|
import cirq.testing._compat_test_data.module_a as mod_a
|
|
808
792
|
|
|
809
793
|
expected_repr = "<class 'cirq.testing._compat_test_data.module_a.types.SampleType'>"
|
|
@@ -825,8 +809,7 @@ def _test_broken_module_1_inner():
|
|
|
825
809
|
with pytest.raises(
|
|
826
810
|
DeprecatedModuleImportError, match="missing_module cannot be imported. The typical reasons"
|
|
827
811
|
):
|
|
828
|
-
#
|
|
829
|
-
import cirq.testing._compat_test_data.broken_ref as br # type: ignore
|
|
812
|
+
import cirq.testing._compat_test_data.broken_ref as br # type: ignore # noqa: F401
|
|
830
813
|
|
|
831
814
|
|
|
832
815
|
def _test_broken_module_2_inner():
|
|
@@ -873,14 +856,11 @@ def test_new_module_is_top_level():
|
|
|
873
856
|
|
|
874
857
|
def _test_new_module_is_top_level_inner():
|
|
875
858
|
# sets up the DeprecationFinders
|
|
876
|
-
# pylint: disable=unused-import
|
|
877
859
|
import time
|
|
878
860
|
|
|
879
861
|
# imports a top level module that was also deprecated
|
|
880
862
|
from freezegun import api
|
|
881
863
|
|
|
882
|
-
import cirq.testing._compat_test_data
|
|
883
|
-
|
|
884
864
|
assert api.real_time == time.time
|
|
885
865
|
|
|
886
866
|
|
|
@@ -922,7 +902,7 @@ def test_loader_create_module():
|
|
|
922
902
|
fake_mod = ModuleType('hello')
|
|
923
903
|
|
|
924
904
|
class CreateModuleLoader(importlib.abc.Loader):
|
|
925
|
-
def create_module(self, spec: ModuleSpec) ->
|
|
905
|
+
def create_module(self, spec: ModuleSpec) -> ModuleType | None:
|
|
926
906
|
return fake_mod
|
|
927
907
|
|
|
928
908
|
assert (
|
|
@@ -1014,16 +994,16 @@ def test_block_overlapping_deprecation():
|
|
|
1014
994
|
|
|
1015
995
|
class Bar:
|
|
1016
996
|
def __init__(self) -> None:
|
|
1017
|
-
self.foo_calls:
|
|
1018
|
-
self.bar_calls:
|
|
997
|
+
self.foo_calls: dict[int, int] = collections.Counter()
|
|
998
|
+
self.bar_calls: dict[int, int] = collections.Counter()
|
|
1019
999
|
|
|
1020
1000
|
@cached_method
|
|
1021
|
-
def foo(self, n: int) ->
|
|
1001
|
+
def foo(self, n: int) -> tuple[int, int]:
|
|
1022
1002
|
self.foo_calls[n] += 1
|
|
1023
1003
|
return (id(self), n)
|
|
1024
1004
|
|
|
1025
1005
|
@cached_method(maxsize=1)
|
|
1026
|
-
def bar(self, n: int) ->
|
|
1006
|
+
def bar(self, n: int) -> tuple[int, int]:
|
|
1027
1007
|
self.bar_calls[n] += 1
|
|
1028
1008
|
return (id(self), 2 * n)
|
|
1029
1009
|
|
cirq/_doc.py
CHANGED
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
"""Workaround for associating docstrings with public constants."""
|
|
15
15
|
|
|
16
|
-
from
|
|
16
|
+
from __future__ import annotations
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
RECORDED_CONST_DOCS: dict[int, str] = {}
|
|
19
21
|
|
|
20
22
|
|
|
21
23
|
def document(value: Any, doc_string: str = ''):
|
cirq/_import.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 importlib
|
|
16
18
|
import sys
|
|
17
19
|
from contextlib import contextmanager
|
|
@@ -19,7 +21,7 @@ from importlib import abc
|
|
|
19
21
|
from importlib.abc import Loader
|
|
20
22
|
from importlib.machinery import ModuleSpec
|
|
21
23
|
from types import ModuleType
|
|
22
|
-
from typing import Any, Callable, cast
|
|
24
|
+
from typing import Any, Callable, cast
|
|
23
25
|
|
|
24
26
|
|
|
25
27
|
class InstrumentedFinder(abc.MetaPathFinder):
|
|
@@ -29,7 +31,7 @@ class InstrumentedFinder(abc.MetaPathFinder):
|
|
|
29
31
|
self,
|
|
30
32
|
finder: Any,
|
|
31
33
|
module_name: str,
|
|
32
|
-
wrap_module: Callable[[ModuleType],
|
|
34
|
+
wrap_module: Callable[[ModuleType], ModuleType | None],
|
|
33
35
|
after_exec: Callable[[ModuleType], None],
|
|
34
36
|
):
|
|
35
37
|
"""A module finder that uses an existing module finder to find a python
|
|
@@ -54,7 +56,7 @@ class InstrumentedFinder(abc.MetaPathFinder):
|
|
|
54
56
|
|
|
55
57
|
self.finder = finder
|
|
56
58
|
self.module_name = module_name
|
|
57
|
-
self.match_components:
|
|
59
|
+
self.match_components: list[str] = []
|
|
58
60
|
if self.module_name:
|
|
59
61
|
self.match_components = self.module_name.split('.')
|
|
60
62
|
self.wrap_module = wrap_module
|
|
@@ -80,7 +82,7 @@ class InstrumentedLoader(abc.Loader):
|
|
|
80
82
|
def __init__(
|
|
81
83
|
self,
|
|
82
84
|
loader: Any,
|
|
83
|
-
wrap_module: Callable[[ModuleType],
|
|
85
|
+
wrap_module: Callable[[ModuleType], ModuleType | None],
|
|
84
86
|
after_exec: Callable[[ModuleType], None],
|
|
85
87
|
):
|
|
86
88
|
"""A module loader that uses an existing module loader and intercepts
|
|
@@ -119,7 +121,7 @@ class InstrumentedLoader(abc.Loader):
|
|
|
119
121
|
@contextmanager
|
|
120
122
|
def wrap_module_executions(
|
|
121
123
|
module_name: str,
|
|
122
|
-
wrap_func: Callable[[ModuleType],
|
|
124
|
+
wrap_func: Callable[[ModuleType], ModuleType | None],
|
|
123
125
|
after_exec: Callable[[ModuleType], None] = lambda m: None,
|
|
124
126
|
assert_meta_path_unchanged: bool = True,
|
|
125
127
|
):
|
|
@@ -155,7 +157,7 @@ def delay_import(module_name: str):
|
|
|
155
157
|
delay = True
|
|
156
158
|
execute_list = []
|
|
157
159
|
|
|
158
|
-
def wrap_func(module: ModuleType) ->
|
|
160
|
+
def wrap_func(module: ModuleType) -> ModuleType | None:
|
|
159
161
|
if delay:
|
|
160
162
|
execute_list.append(module)
|
|
161
163
|
return None # Don't allow the module to be executed yet
|
cirq/_import_test.py
CHANGED
|
@@ -12,12 +12,14 @@
|
|
|
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
|
from cirq import _import
|
|
16
18
|
|
|
17
19
|
|
|
18
|
-
def test_lazy_loader():
|
|
20
|
+
def test_lazy_loader() -> None:
|
|
19
21
|
linalg = _import.LazyLoader("linalg", globals(), "scipy.linalg")
|
|
20
|
-
linalg.fun = 1
|
|
22
|
+
linalg.fun = 1 # type: ignore[attr-defined]
|
|
21
23
|
assert linalg._module is None
|
|
22
24
|
assert "linalg" not in linalg.__dict__
|
|
23
25
|
|
cirq/_version.py
CHANGED
|
@@ -13,19 +13,19 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
"""Define version number here, read it from setup.py automatically,
|
|
16
|
-
and warn users that the latest version of
|
|
16
|
+
and warn users that the latest version of Cirq uses Python 3.11+"""
|
|
17
17
|
|
|
18
18
|
import sys
|
|
19
19
|
|
|
20
|
-
if sys.version_info < (3,
|
|
20
|
+
if sys.version_info < (3, 11, 0): # pragma: no cover
|
|
21
21
|
raise SystemError(
|
|
22
|
-
"You installed the latest version of
|
|
22
|
+
"You installed the latest version of Cirq but aren't on Python 3.11+.\n"
|
|
23
23
|
'To fix this error, you need to either:\n'
|
|
24
24
|
'\n'
|
|
25
|
-
'A) Update to
|
|
25
|
+
'A) Update to Python 3.11 or later.\n'
|
|
26
26
|
'- OR -\n'
|
|
27
27
|
'B) Explicitly install an older deprecated-but-compatible version '
|
|
28
|
-
'of
|
|
28
|
+
'of Cirq (e.g. "python -m pip install cirq==1.5.0")'
|
|
29
29
|
)
|
|
30
30
|
|
|
31
|
-
__version__ = "1.
|
|
31
|
+
__version__ = "1.6.0"
|
cirq/_version_test.py
CHANGED
|
@@ -12,8 +12,9 @@
|
|
|
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 collections
|
|
16
|
-
from typing import Dict, List, Optional, Tuple
|
|
17
18
|
|
|
18
19
|
from cirq.circuits._box_drawing_character_data import box_draw_character, BoxDrawCharacterSet
|
|
19
20
|
|
|
@@ -55,7 +56,7 @@ class Block:
|
|
|
55
56
|
left: bool = False,
|
|
56
57
|
right: bool = False,
|
|
57
58
|
bottom: bool = False,
|
|
58
|
-
crossing_char:
|
|
59
|
+
crossing_char: str | None = None,
|
|
59
60
|
):
|
|
60
61
|
"""Draws lines in the box using the given character set.
|
|
61
62
|
|
|
@@ -105,7 +106,7 @@ class Block:
|
|
|
105
106
|
|
|
106
107
|
self._prev_curve_grid_chars = grid_characters
|
|
107
108
|
|
|
108
|
-
def render(self, width: int, height: int) ->
|
|
109
|
+
def render(self, width: int, height: int) -> list[str]:
|
|
109
110
|
"""Returns a list of text lines representing the block's contents.
|
|
110
111
|
|
|
111
112
|
Args:
|
|
@@ -157,9 +158,9 @@ class BlockDiagramDrawer:
|
|
|
157
158
|
"""Aligns text and curve data placed onto an abstract 2d grid of blocks."""
|
|
158
159
|
|
|
159
160
|
def __init__(self) -> None:
|
|
160
|
-
self._blocks:
|
|
161
|
-
self._min_widths:
|
|
162
|
-
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)
|
|
163
164
|
|
|
164
165
|
# Populate the origin.
|
|
165
166
|
_ = self._blocks[(0, 0)]
|
|
@@ -187,8 +188,8 @@ class BlockDiagramDrawer:
|
|
|
187
188
|
def render(
|
|
188
189
|
self,
|
|
189
190
|
*,
|
|
190
|
-
block_span_x:
|
|
191
|
-
block_span_y:
|
|
191
|
+
block_span_x: int | None = None,
|
|
192
|
+
block_span_y: int | None = None,
|
|
192
193
|
min_block_width: int = 0,
|
|
193
194
|
min_block_height: int = 0,
|
|
194
195
|
) -> str:
|
|
@@ -250,10 +251,10 @@ class BlockDiagramDrawer:
|
|
|
250
251
|
}
|
|
251
252
|
|
|
252
253
|
# Paste together all of the rows of rendered block content.
|
|
253
|
-
out_lines:
|
|
254
|
+
out_lines: list[str] = []
|
|
254
255
|
for y in range(block_span_y):
|
|
255
256
|
for by in range(heights[y]):
|
|
256
|
-
out_line_chunks:
|
|
257
|
+
out_line_chunks: list[str] = []
|
|
257
258
|
for x in range(block_span_x):
|
|
258
259
|
out_line_chunks.extend(block_renders[x, y][by])
|
|
259
260
|
out_lines.append(''.join(out_line_chunks).rstrip())
|