cirq-core 1.5.0.dev20250409222543__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.dev20250409222543.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.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/WHEEL +1 -1
- cirq_core-1.5.0.dev20250409222543.dist-info/RECORD +0 -1216
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/top_level.txt +0 -0
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
import numpy as np
|
|
15
18
|
import pytest
|
|
16
19
|
import sympy
|
|
@@ -18,7 +21,11 @@ import sympy
|
|
|
18
21
|
import cirq
|
|
19
22
|
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
class CustomTag:
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_circuit_diagram_info_value_wrapping() -> None:
|
|
22
29
|
single_info = cirq.CircuitDiagramInfo(('Single',))
|
|
23
30
|
|
|
24
31
|
class ReturnInfo:
|
|
@@ -67,20 +74,20 @@ def test_circuit_diagram_info_value_wrapping():
|
|
|
67
74
|
)
|
|
68
75
|
|
|
69
76
|
|
|
70
|
-
def test_circuit_diagram_info_init():
|
|
77
|
+
def test_circuit_diagram_info_init() -> None:
|
|
71
78
|
assert cirq.CircuitDiagramInfo(['a', 'b']).wire_symbols == ('a', 'b')
|
|
72
79
|
|
|
73
80
|
|
|
74
|
-
def test_circuit_diagram_info_validate():
|
|
81
|
+
def test_circuit_diagram_info_validate() -> None:
|
|
75
82
|
with pytest.raises(ValueError):
|
|
76
83
|
_ = cirq.CircuitDiagramInfo('X')
|
|
77
84
|
|
|
78
85
|
|
|
79
|
-
def test_circuit_diagram_info_repr():
|
|
86
|
+
def test_circuit_diagram_info_repr() -> None:
|
|
80
87
|
cirq.testing.assert_equivalent_repr(cirq.CircuitDiagramInfo(('X', 'Y'), 2))
|
|
81
88
|
|
|
82
89
|
|
|
83
|
-
def test_circuit_diagram_info_eq():
|
|
90
|
+
def test_circuit_diagram_info_eq() -> None:
|
|
84
91
|
eq = cirq.testing.EqualsTester()
|
|
85
92
|
eq.make_equality_group(lambda: cirq.CircuitDiagramInfo(('X',)))
|
|
86
93
|
eq.add_equality_group(
|
|
@@ -92,7 +99,7 @@ def test_circuit_diagram_info_eq():
|
|
|
92
99
|
eq.add_equality_group(cirq.CircuitDiagramInfo(('Z',), 3, auto_exponent_parens=False))
|
|
93
100
|
|
|
94
101
|
|
|
95
|
-
def test_circuit_diagram_info_pass_fail():
|
|
102
|
+
def test_circuit_diagram_info_pass_fail() -> None:
|
|
96
103
|
class C:
|
|
97
104
|
pass
|
|
98
105
|
|
|
@@ -115,7 +122,14 @@ def test_circuit_diagram_info_pass_fail():
|
|
|
115
122
|
assert cirq.circuit_diagram_info(E()) == cirq.CircuitDiagramInfo(('X',))
|
|
116
123
|
|
|
117
124
|
|
|
118
|
-
def
|
|
125
|
+
def test_controlled_1x1_matrixgate_diagram_error() -> None:
|
|
126
|
+
q = cirq.LineQubit(0)
|
|
127
|
+
g = cirq.MatrixGate(np.array([[1j]])).controlled()
|
|
128
|
+
c = cirq.Circuit(g(q))
|
|
129
|
+
assert str(c) == "0: ───C[[0.+1.j]]───"
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def test_circuit_diagram_info_args_eq() -> None:
|
|
119
133
|
eq = cirq.testing.EqualsTester()
|
|
120
134
|
eq.add_equality_group(cirq.CircuitDiagramInfoArgs.UNINFORMED_DEFAULT)
|
|
121
135
|
eq.add_equality_group(
|
|
@@ -164,6 +178,26 @@ def test_circuit_diagram_info_args_eq():
|
|
|
164
178
|
include_tags=False,
|
|
165
179
|
)
|
|
166
180
|
)
|
|
181
|
+
eq.add_equality_group(
|
|
182
|
+
cirq.CircuitDiagramInfoArgs(
|
|
183
|
+
known_qubits=cirq.LineQubit.range(2),
|
|
184
|
+
known_qubit_count=2,
|
|
185
|
+
use_unicode_characters=False,
|
|
186
|
+
precision=None,
|
|
187
|
+
label_map=None,
|
|
188
|
+
include_tags={str},
|
|
189
|
+
)
|
|
190
|
+
)
|
|
191
|
+
eq.add_equality_group(
|
|
192
|
+
cirq.CircuitDiagramInfoArgs(
|
|
193
|
+
known_qubits=cirq.LineQubit.range(2),
|
|
194
|
+
known_qubit_count=2,
|
|
195
|
+
use_unicode_characters=False,
|
|
196
|
+
precision=None,
|
|
197
|
+
label_map=None,
|
|
198
|
+
include_tags={CustomTag},
|
|
199
|
+
)
|
|
200
|
+
)
|
|
167
201
|
eq.add_equality_group(
|
|
168
202
|
cirq.CircuitDiagramInfoArgs(
|
|
169
203
|
known_qubits=cirq.LineQubit.range(2),
|
|
@@ -185,7 +219,7 @@ def test_circuit_diagram_info_args_eq():
|
|
|
185
219
|
)
|
|
186
220
|
|
|
187
221
|
|
|
188
|
-
def test_circuit_diagram_info_args_repr():
|
|
222
|
+
def test_circuit_diagram_info_args_repr() -> None:
|
|
189
223
|
cirq.testing.assert_equivalent_repr(
|
|
190
224
|
cirq.CircuitDiagramInfoArgs(
|
|
191
225
|
known_qubits=cirq.LineQubit.range(2),
|
|
@@ -198,8 +232,32 @@ def test_circuit_diagram_info_args_repr():
|
|
|
198
232
|
)
|
|
199
233
|
)
|
|
200
234
|
|
|
235
|
+
cirq.testing.assert_equivalent_repr(
|
|
236
|
+
cirq.CircuitDiagramInfoArgs(
|
|
237
|
+
known_qubits=cirq.LineQubit.range(1),
|
|
238
|
+
known_qubit_count=1,
|
|
239
|
+
use_unicode_characters=False,
|
|
240
|
+
precision=None,
|
|
241
|
+
label_map=None,
|
|
242
|
+
include_tags={str},
|
|
243
|
+
transpose=False,
|
|
244
|
+
)
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
cirq.testing.assert_equivalent_repr(
|
|
248
|
+
cirq.CircuitDiagramInfoArgs(
|
|
249
|
+
known_qubits=cirq.LineQubit.range(1),
|
|
250
|
+
known_qubit_count=1,
|
|
251
|
+
use_unicode_characters=False,
|
|
252
|
+
precision=None,
|
|
253
|
+
label_map=None,
|
|
254
|
+
include_tags={CustomTag},
|
|
255
|
+
transpose=False,
|
|
256
|
+
)
|
|
257
|
+
)
|
|
258
|
+
|
|
201
259
|
|
|
202
|
-
def test_format_real():
|
|
260
|
+
def test_format_real() -> None:
|
|
203
261
|
args = cirq.CircuitDiagramInfoArgs.UNINFORMED_DEFAULT.copy()
|
|
204
262
|
assert args.format_real(1) == '1'
|
|
205
263
|
assert args.format_real(1.1) == '1.1'
|
|
@@ -220,7 +278,7 @@ def test_format_real():
|
|
|
220
278
|
assert args.format_real(sympy.Symbol('t') * 2 + 1) == '2*t + 1'
|
|
221
279
|
|
|
222
280
|
|
|
223
|
-
def test_format_complex():
|
|
281
|
+
def test_format_complex() -> None:
|
|
224
282
|
args = cirq.CircuitDiagramInfoArgs.UNINFORMED_DEFAULT.copy()
|
|
225
283
|
assert args.format_complex(1) == '1+0i'
|
|
226
284
|
assert args.format_complex(1.1) == '1.1+0i'
|
|
@@ -243,7 +301,7 @@ def test_format_complex():
|
|
|
243
301
|
assert args.format_complex(sympy.Symbol('t') * 2 + 1) == '2*t + 1'
|
|
244
302
|
|
|
245
303
|
|
|
246
|
-
def test_format_radians_without_precision():
|
|
304
|
+
def test_format_radians_without_precision() -> None:
|
|
247
305
|
args = cirq.CircuitDiagramInfoArgs(
|
|
248
306
|
known_qubits=None,
|
|
249
307
|
known_qubit_count=None,
|
|
@@ -271,7 +329,7 @@ def test_format_radians_without_precision():
|
|
|
271
329
|
assert args.format_radians(sympy.Symbol('t') * 2 + 1) == '2*t + 1'
|
|
272
330
|
|
|
273
331
|
|
|
274
|
-
def test_format_radians_with_precision():
|
|
332
|
+
def test_format_radians_with_precision() -> None:
|
|
275
333
|
args = cirq.CircuitDiagramInfoArgs(
|
|
276
334
|
known_qubits=None,
|
|
277
335
|
known_qubit_count=None,
|
|
@@ -11,10 +11,13 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
14
15
|
"""Protocol for determining commutativity."""
|
|
15
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
from types import NotImplementedType
|
|
17
|
-
from typing import Any, overload, TypeVar
|
|
20
|
+
from typing import Any, overload, TypeVar
|
|
18
21
|
|
|
19
22
|
import numpy as np
|
|
20
23
|
from typing_extensions import Protocol
|
|
@@ -35,7 +38,7 @@ class SupportsCommutes(Protocol):
|
|
|
35
38
|
"""An object that can determine commutation relationships vs others."""
|
|
36
39
|
|
|
37
40
|
@doc_private
|
|
38
|
-
def _commutes_(self, other: Any, *, atol: float) ->
|
|
41
|
+
def _commutes_(self, other: Any, *, atol: float) -> None | bool | NotImplementedType:
|
|
39
42
|
r"""Determines if this object commutes with the other object.
|
|
40
43
|
|
|
41
44
|
Can return None to indicate the commutation relationship is
|
|
@@ -78,9 +81,7 @@ def commutes(v1: Any, v2: Any, *, atol: float = 1e-8) -> bool: ...
|
|
|
78
81
|
|
|
79
82
|
|
|
80
83
|
@overload
|
|
81
|
-
def commutes(
|
|
82
|
-
v1: Any, v2: Any, *, atol: float = 1e-8, default: TDefault
|
|
83
|
-
) -> Union[bool, TDefault]: ...
|
|
84
|
+
def commutes(v1: Any, v2: Any, *, atol: float = 1e-8, default: TDefault) -> bool | TDefault: ...
|
|
84
85
|
|
|
85
86
|
|
|
86
87
|
def commutes(
|
|
@@ -159,7 +160,7 @@ def definitely_commutes(v1: Any, v2: Any, *, atol: float = 1e-8) -> bool:
|
|
|
159
160
|
|
|
160
161
|
def _strat_commutes_from_commutes(
|
|
161
162
|
v1: Any, v2: Any, *, atol: float = 1e-8
|
|
162
|
-
) ->
|
|
163
|
+
) -> bool | NotImplementedType | None:
|
|
163
164
|
"""Attempts to determine commutativity via the objects' _commutes_
|
|
164
165
|
method."""
|
|
165
166
|
|
|
@@ -176,7 +177,7 @@ def _strat_commutes_from_commutes(
|
|
|
176
177
|
|
|
177
178
|
def _strat_commutes_from_matrix(
|
|
178
179
|
v1: Any, v2: Any, *, atol: float
|
|
179
|
-
) ->
|
|
180
|
+
) -> bool | NotImplementedType | None:
|
|
180
181
|
"""Attempts to determine commutativity of matrices."""
|
|
181
182
|
if not isinstance(v1, np.ndarray) or not isinstance(v2, np.ndarray):
|
|
182
183
|
return NotImplemented
|
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
"""Protocol for object that have control keys."""
|
|
15
15
|
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
16
18
|
from types import NotImplementedType
|
|
17
|
-
from typing import Any,
|
|
19
|
+
from typing import Any, TYPE_CHECKING
|
|
18
20
|
|
|
19
21
|
from typing_extensions import Protocol
|
|
20
22
|
|
|
@@ -35,7 +37,7 @@ class SupportsControlKey(Protocol):
|
|
|
35
37
|
"""
|
|
36
38
|
|
|
37
39
|
@doc_private
|
|
38
|
-
def _control_keys_(self) ->
|
|
40
|
+
def _control_keys_(self) -> frozenset[cirq.MeasurementKey] | NotImplementedType | None:
|
|
39
41
|
"""Return the keys for controls referenced by the receiving object.
|
|
40
42
|
|
|
41
43
|
Returns:
|
|
@@ -44,7 +46,7 @@ class SupportsControlKey(Protocol):
|
|
|
44
46
|
"""
|
|
45
47
|
|
|
46
48
|
|
|
47
|
-
def control_keys(val: Any) ->
|
|
49
|
+
def control_keys(val: Any) -> frozenset[cirq.MeasurementKey]:
|
|
48
50
|
"""Gets the keys that the value is classically controlled by.
|
|
49
51
|
|
|
50
52
|
Args:
|
|
@@ -62,7 +64,7 @@ def control_keys(val: Any) -> FrozenSet['cirq.MeasurementKey']:
|
|
|
62
64
|
return frozenset()
|
|
63
65
|
|
|
64
66
|
|
|
65
|
-
def measurement_keys_touched(val: Any) ->
|
|
67
|
+
def measurement_keys_touched(val: Any) -> frozenset[cirq.MeasurementKey]:
|
|
66
68
|
"""Returns all the measurement keys used by the value.
|
|
67
69
|
|
|
68
70
|
This would be the case if the value is or contains a measurement gate, or
|
|
@@ -12,10 +12,12 @@
|
|
|
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 cirq
|
|
16
18
|
|
|
17
19
|
|
|
18
|
-
def test_control_key():
|
|
20
|
+
def test_control_key() -> None:
|
|
19
21
|
class Named:
|
|
20
22
|
def _control_keys_(self):
|
|
21
23
|
return frozenset([cirq.MeasurementKey('key')])
|
|
@@ -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 dataclasses
|
|
15
18
|
import inspect
|
|
16
19
|
import itertools
|
|
@@ -19,14 +22,10 @@ from types import NotImplementedType
|
|
|
19
22
|
from typing import (
|
|
20
23
|
Any,
|
|
21
24
|
Callable,
|
|
22
|
-
Dict,
|
|
23
25
|
Iterable,
|
|
24
26
|
Iterator,
|
|
25
|
-
List,
|
|
26
|
-
Optional,
|
|
27
27
|
overload,
|
|
28
28
|
Sequence,
|
|
29
|
-
Tuple,
|
|
30
29
|
TYPE_CHECKING,
|
|
31
30
|
TypeVar,
|
|
32
31
|
Union,
|
|
@@ -55,11 +54,11 @@ _CONTEXT_COUNTER = itertools.count() # Use _reset_context_counter() to reset th
|
|
|
55
54
|
@runtime_checkable
|
|
56
55
|
class OpDecomposerWithContext(Protocol):
|
|
57
56
|
def __call__(
|
|
58
|
-
self, __op:
|
|
57
|
+
self, __op: cirq.Operation, *, context: cirq.DecompositionContext | None = None
|
|
59
58
|
) -> DecomposeResult: ...
|
|
60
59
|
|
|
61
60
|
|
|
62
|
-
OpDecomposer =
|
|
61
|
+
OpDecomposer = Callable[['cirq.Operation'], DecomposeResult] | OpDecomposerWithContext
|
|
63
62
|
|
|
64
63
|
DECOMPOSE_TARGET_GATESET = ops.Gateset(
|
|
65
64
|
ops.XPowGate,
|
|
@@ -71,7 +70,7 @@ DECOMPOSE_TARGET_GATESET = ops.Gateset(
|
|
|
71
70
|
)
|
|
72
71
|
|
|
73
72
|
|
|
74
|
-
def _value_error_describing_bad_operation(op:
|
|
73
|
+
def _value_error_describing_bad_operation(op: cirq.Operation) -> ValueError:
|
|
75
74
|
return ValueError(f"Operation doesn't satisfy the given `keep` but can't be decomposed: {op!r}")
|
|
76
75
|
|
|
77
76
|
|
|
@@ -82,9 +81,16 @@ class DecompositionContext:
|
|
|
82
81
|
Args:
|
|
83
82
|
qubit_manager: A `cirq.QubitManager` instance to allocate clean / dirty ancilla qubits as
|
|
84
83
|
part of the decompose protocol.
|
|
84
|
+
extract_global_phases: If set, will extract the global phases from
|
|
85
|
+
`DECOMPOSE_TARGET_GATESET` into independent global phase operations.
|
|
85
86
|
"""
|
|
86
87
|
|
|
87
|
-
qubit_manager:
|
|
88
|
+
qubit_manager: cirq.QubitManager
|
|
89
|
+
extract_global_phases: bool = False
|
|
90
|
+
|
|
91
|
+
def extracting_global_phases(self) -> DecompositionContext:
|
|
92
|
+
"""Returns a copy with the `extract_global_phases` field set."""
|
|
93
|
+
return dataclasses.replace(self, extract_global_phases=True)
|
|
88
94
|
|
|
89
95
|
|
|
90
96
|
class SupportsDecompose(Protocol):
|
|
@@ -127,7 +133,7 @@ class SupportsDecompose(Protocol):
|
|
|
127
133
|
pass
|
|
128
134
|
|
|
129
135
|
def _decompose_with_context_(
|
|
130
|
-
self, *, context:
|
|
136
|
+
self, *, context: DecompositionContext | None = None
|
|
131
137
|
) -> DecomposeResult:
|
|
132
138
|
pass
|
|
133
139
|
|
|
@@ -151,17 +157,17 @@ class SupportsDecomposeWithQubits(Protocol):
|
|
|
151
157
|
implements `SupportsDecomposeWithQubits`.
|
|
152
158
|
"""
|
|
153
159
|
|
|
154
|
-
def _decompose_(self, qubits:
|
|
160
|
+
def _decompose_(self, qubits: tuple[cirq.Qid, ...]) -> DecomposeResult:
|
|
155
161
|
pass
|
|
156
162
|
|
|
157
163
|
def _decompose_with_context_(
|
|
158
|
-
self, qubits:
|
|
164
|
+
self, qubits: tuple[cirq.Qid, ...], *, context: DecompositionContext | None = None
|
|
159
165
|
) -> DecomposeResult:
|
|
160
166
|
pass
|
|
161
167
|
|
|
162
168
|
|
|
163
169
|
def _try_op_decomposer(
|
|
164
|
-
val: Any, decomposer:
|
|
170
|
+
val: Any, decomposer: OpDecomposer | None, *, context: DecompositionContext | None = None
|
|
165
171
|
) -> DecomposeResult:
|
|
166
172
|
if decomposer is None or not isinstance(val, ops.Operation):
|
|
167
173
|
return None
|
|
@@ -174,15 +180,15 @@ def _try_op_decomposer(
|
|
|
174
180
|
|
|
175
181
|
@dataclasses.dataclass(frozen=True)
|
|
176
182
|
class _DecomposeArgs:
|
|
177
|
-
context:
|
|
178
|
-
intercepting_decomposer:
|
|
179
|
-
fallback_decomposer:
|
|
180
|
-
keep:
|
|
181
|
-
on_stuck_raise:
|
|
183
|
+
context: DecompositionContext | None
|
|
184
|
+
intercepting_decomposer: OpDecomposer | None
|
|
185
|
+
fallback_decomposer: OpDecomposer | None
|
|
186
|
+
keep: Callable[[cirq.Operation], bool] | None
|
|
187
|
+
on_stuck_raise: None | Exception | Callable[[cirq.Operation], Exception | None]
|
|
182
188
|
preserve_structure: bool
|
|
183
189
|
|
|
184
190
|
|
|
185
|
-
def _decompose_dfs(item: Any, args: _DecomposeArgs) -> Iterator[
|
|
191
|
+
def _decompose_dfs(item: Any, args: _DecomposeArgs) -> Iterator[cirq.Operation]:
|
|
186
192
|
from cirq.circuits import CircuitOperation, FrozenCircuit
|
|
187
193
|
|
|
188
194
|
if isinstance(item, ops.Operation):
|
|
@@ -224,15 +230,15 @@ def _decompose_dfs(item: Any, args: _DecomposeArgs) -> Iterator['cirq.Operation'
|
|
|
224
230
|
def decompose(
|
|
225
231
|
val: Any,
|
|
226
232
|
*,
|
|
227
|
-
intercepting_decomposer:
|
|
228
|
-
fallback_decomposer:
|
|
229
|
-
keep:
|
|
230
|
-
on_stuck_raise:
|
|
231
|
-
None
|
|
232
|
-
|
|
233
|
+
intercepting_decomposer: OpDecomposer | None = None,
|
|
234
|
+
fallback_decomposer: OpDecomposer | None = None,
|
|
235
|
+
keep: Callable[[cirq.Operation], bool] | None = None,
|
|
236
|
+
on_stuck_raise: (
|
|
237
|
+
None | Exception | Callable[[cirq.Operation], Exception | None]
|
|
238
|
+
) = _value_error_describing_bad_operation,
|
|
233
239
|
preserve_structure: bool = False,
|
|
234
|
-
context:
|
|
235
|
-
) ->
|
|
240
|
+
context: DecompositionContext | None = None,
|
|
241
|
+
) -> list[cirq.Operation]:
|
|
236
242
|
"""Recursively decomposes a value into `cirq.Operation`s meeting a criteria.
|
|
237
243
|
|
|
238
244
|
Args:
|
|
@@ -309,18 +315,15 @@ def decompose(
|
|
|
309
315
|
return [*_decompose_dfs(val, args)]
|
|
310
316
|
|
|
311
317
|
|
|
312
|
-
# pylint: disable=function-redefined
|
|
313
|
-
|
|
314
|
-
|
|
315
318
|
@overload
|
|
316
|
-
def decompose_once(val: Any, **kwargs) ->
|
|
319
|
+
def decompose_once(val: Any, **kwargs) -> list[cirq.Operation]:
|
|
317
320
|
pass
|
|
318
321
|
|
|
319
322
|
|
|
320
323
|
@overload
|
|
321
324
|
def decompose_once(
|
|
322
325
|
val: Any, default: TDefault, *args, flatten: bool = True, **kwargs
|
|
323
|
-
) ->
|
|
326
|
+
) -> TDefault | list[cirq.Operation]:
|
|
324
327
|
pass
|
|
325
328
|
|
|
326
329
|
|
|
@@ -329,7 +332,7 @@ def decompose_once(
|
|
|
329
332
|
default=RaiseTypeErrorIfNotProvided,
|
|
330
333
|
*args,
|
|
331
334
|
flatten: bool = True,
|
|
332
|
-
context:
|
|
335
|
+
context: DecompositionContext | None = None,
|
|
333
336
|
**kwargs,
|
|
334
337
|
):
|
|
335
338
|
"""Decomposes a value into operations, if possible.
|
|
@@ -370,7 +373,7 @@ def decompose_once(
|
|
|
370
373
|
|
|
371
374
|
method = getattr(val, '_decompose_with_context_', None)
|
|
372
375
|
decomposed = NotImplemented if method is None else method(*args, **kwargs, context=context)
|
|
373
|
-
if decomposed is NotImplemented or None:
|
|
376
|
+
if decomposed is NotImplemented or decomposed is None:
|
|
374
377
|
method = getattr(val, '_decompose_', None)
|
|
375
378
|
decomposed = NotImplemented if method is None else method(*args, **kwargs)
|
|
376
379
|
|
|
@@ -386,39 +389,40 @@ def decompose_once(
|
|
|
386
389
|
)
|
|
387
390
|
raise TypeError(
|
|
388
391
|
f"object of type {type(val)} does have a _decompose_ method, "
|
|
389
|
-
"but it returned NotImplemented or None."
|
|
392
|
+
"but it returned NotImplemented or None. The value is not "
|
|
393
|
+
"convertible to simpler operations."
|
|
390
394
|
)
|
|
391
395
|
|
|
392
396
|
|
|
393
397
|
@overload
|
|
394
398
|
def decompose_once_with_qubits(
|
|
395
399
|
val: Any,
|
|
396
|
-
qubits: Iterable[
|
|
400
|
+
qubits: Iterable[cirq.Qid],
|
|
397
401
|
*,
|
|
398
402
|
flatten: bool = True,
|
|
399
|
-
context:
|
|
400
|
-
) ->
|
|
403
|
+
context: DecompositionContext | None = None,
|
|
404
|
+
) -> list[cirq.Operation]:
|
|
401
405
|
pass
|
|
402
406
|
|
|
403
407
|
|
|
404
408
|
@overload
|
|
405
409
|
def decompose_once_with_qubits(
|
|
406
410
|
val: Any,
|
|
407
|
-
qubits: Iterable[
|
|
408
|
-
default:
|
|
411
|
+
qubits: Iterable[cirq.Qid],
|
|
412
|
+
default: TDefault | None,
|
|
409
413
|
*,
|
|
410
414
|
flatten: bool = True,
|
|
411
|
-
context:
|
|
412
|
-
) ->
|
|
415
|
+
context: DecompositionContext | None = None,
|
|
416
|
+
) -> TDefault | list[cirq.Operation]:
|
|
413
417
|
pass
|
|
414
418
|
|
|
415
419
|
|
|
416
420
|
def decompose_once_with_qubits(
|
|
417
421
|
val: Any,
|
|
418
|
-
qubits: Iterable[
|
|
422
|
+
qubits: Iterable[cirq.Qid],
|
|
419
423
|
default=RaiseTypeErrorIfNotProvided,
|
|
420
424
|
flatten: bool = True,
|
|
421
|
-
context:
|
|
425
|
+
context: DecompositionContext | None = None,
|
|
422
426
|
):
|
|
423
427
|
"""Decomposes a value into operations on the given qubits.
|
|
424
428
|
|
|
@@ -452,12 +456,9 @@ def decompose_once_with_qubits(
|
|
|
452
456
|
return decompose_once(val, default, tuple(qubits), flatten=flatten, context=context)
|
|
453
457
|
|
|
454
458
|
|
|
455
|
-
# pylint: enable=function-redefined
|
|
456
|
-
|
|
457
|
-
|
|
458
459
|
def _try_decompose_into_operations_and_qubits(
|
|
459
460
|
val: Any,
|
|
460
|
-
) ->
|
|
461
|
+
) -> tuple[list[cirq.Operation] | None, Sequence[cirq.Qid], tuple[int, ...]]:
|
|
461
462
|
"""Returns the value's decomposition (if any) and the qubits it applies to."""
|
|
462
463
|
|
|
463
464
|
if isinstance(val, ops.Gate):
|
|
@@ -473,7 +474,7 @@ def _try_decompose_into_operations_and_qubits(
|
|
|
473
474
|
result = decompose_once(val, None)
|
|
474
475
|
if result is not None:
|
|
475
476
|
qubit_set = set()
|
|
476
|
-
qid_shape_dict:
|
|
477
|
+
qid_shape_dict: dict[cirq.Qid, int] = defaultdict(lambda: 1)
|
|
477
478
|
for op in result:
|
|
478
479
|
for level, q in zip(qid_shape_protocol.qid_shape(op), op.qubits):
|
|
479
480
|
qubit_set.add(q)
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
import itertools
|
|
15
|
-
from typing import Optional
|
|
16
18
|
from unittest import mock
|
|
17
19
|
|
|
18
20
|
import pytest
|
|
@@ -61,7 +63,7 @@ class DecomposeQuditGate:
|
|
|
61
63
|
yield cirq.identity_each(*qids)
|
|
62
64
|
|
|
63
65
|
|
|
64
|
-
def test_decompose_once():
|
|
66
|
+
def test_decompose_once() -> None:
|
|
65
67
|
# No default value results in descriptive error.
|
|
66
68
|
with pytest.raises(TypeError, match='no _decompose_with_context_ or _decompose_ method'):
|
|
67
69
|
_ = cirq.decompose_once(NoMethod())
|
|
@@ -88,7 +90,7 @@ def test_decompose_once():
|
|
|
88
90
|
]
|
|
89
91
|
|
|
90
92
|
|
|
91
|
-
def test_decompose_once_with_qubits():
|
|
93
|
+
def test_decompose_once_with_qubits() -> None:
|
|
92
94
|
qs = cirq.LineQubit.range(3)
|
|
93
95
|
|
|
94
96
|
# No default value results in descriptive error.
|
|
@@ -134,7 +136,7 @@ def test_decompose_once_with_qubits():
|
|
|
134
136
|
) == list(cirq.X.on_each(*qs)) + list(cirq.Y.on_each(*qs))
|
|
135
137
|
|
|
136
138
|
|
|
137
|
-
def test_decompose_general():
|
|
139
|
+
def test_decompose_general() -> None:
|
|
138
140
|
a, b, c = cirq.LineQubit.range(3)
|
|
139
141
|
no_method = NoMethod()
|
|
140
142
|
assert cirq.decompose(no_method) == [no_method]
|
|
@@ -149,7 +151,7 @@ def test_decompose_general():
|
|
|
149
151
|
)
|
|
150
152
|
|
|
151
153
|
|
|
152
|
-
def test_decompose_keep():
|
|
154
|
+
def test_decompose_keep() -> None:
|
|
153
155
|
a, b = cirq.LineQubit.range(2)
|
|
154
156
|
|
|
155
157
|
# Recursion can be stopped.
|
|
@@ -177,7 +179,7 @@ def test_decompose_keep():
|
|
|
177
179
|
assert cirq.decompose([[[cirq.SWAP(a, b)]]], keep=lambda _: True) == [cirq.SWAP(a, b)]
|
|
178
180
|
|
|
179
181
|
|
|
180
|
-
def test_decompose_on_stuck_raise():
|
|
182
|
+
def test_decompose_on_stuck_raise() -> None:
|
|
181
183
|
a, b = cirq.LineQubit.range(2)
|
|
182
184
|
no_method = NoMethod()
|
|
183
185
|
|
|
@@ -207,7 +209,7 @@ def test_decompose_on_stuck_raise():
|
|
|
207
209
|
assert cirq.decompose([], on_stuck_raise=TypeError('x'))
|
|
208
210
|
|
|
209
211
|
|
|
210
|
-
def test_decompose_intercept():
|
|
212
|
+
def test_decompose_intercept() -> None:
|
|
211
213
|
a = cirq.NamedQubit('a')
|
|
212
214
|
b = cirq.NamedQubit('b')
|
|
213
215
|
|
|
@@ -228,7 +230,7 @@ def test_decompose_intercept():
|
|
|
228
230
|
|
|
229
231
|
# Accepts a context, when provided.
|
|
230
232
|
def _intercept_with_context(
|
|
231
|
-
op: cirq.Operation, context:
|
|
233
|
+
op: cirq.Operation, context: cirq.DecompositionContext | None = None
|
|
232
234
|
):
|
|
233
235
|
assert context is not None
|
|
234
236
|
if op.gate == cirq.SWAP:
|
|
@@ -244,7 +246,7 @@ def test_decompose_intercept():
|
|
|
244
246
|
assert actual == [cirq.X(a), cirq.X(cirq.ops.CleanQubit(0)), cirq.X(b)]
|
|
245
247
|
|
|
246
248
|
|
|
247
|
-
def test_decompose_preserving_structure():
|
|
249
|
+
def test_decompose_preserving_structure() -> None:
|
|
248
250
|
a, b = cirq.LineQubit.range(2)
|
|
249
251
|
fc1 = cirq.FrozenCircuit(cirq.SWAP(a, b), cirq.FSimGate(0.1, 0.2).on(a, b))
|
|
250
252
|
cop1_1 = cirq.CircuitOperation(fc1).with_tags('test_tag')
|
|
@@ -272,7 +274,7 @@ def test_decompose_preserving_structure():
|
|
|
272
274
|
|
|
273
275
|
# Test both intercepting and fallback decomposers.
|
|
274
276
|
@pytest.mark.parametrize('decompose_mode', ['intercept', 'fallback'])
|
|
275
|
-
def test_decompose_preserving_structure_forwards_args(decompose_mode):
|
|
277
|
+
def test_decompose_preserving_structure_forwards_args(decompose_mode) -> None:
|
|
276
278
|
a, b = cirq.LineQubit.range(2)
|
|
277
279
|
fc1 = cirq.FrozenCircuit(cirq.SWAP(a, b), cirq.FSimGate(0.1, 0.2).on(a, b))
|
|
278
280
|
cop1_1 = cirq.CircuitOperation(fc1).with_tags('test_tag')
|
|
@@ -282,11 +284,11 @@ def test_decompose_preserving_structure_forwards_args(decompose_mode):
|
|
|
282
284
|
|
|
283
285
|
circuit = cirq.Circuit(cop2, cirq.measure(a, b, key='m'))
|
|
284
286
|
|
|
285
|
-
def keep_func(op:
|
|
287
|
+
def keep_func(op: cirq.Operation):
|
|
286
288
|
# Only decompose SWAP and X.
|
|
287
289
|
return not isinstance(op.gate, (cirq.SwapPowGate, cirq.XPowGate))
|
|
288
290
|
|
|
289
|
-
def x_to_hzh(op:
|
|
291
|
+
def x_to_hzh(op: cirq.Operation):
|
|
290
292
|
if isinstance(op.gate, cirq.XPowGate) and op.gate.exponent == 1:
|
|
291
293
|
return [cirq.H(*op.qubits), cirq.Z(*op.qubits), cirq.H(*op.qubits)]
|
|
292
294
|
|
|
@@ -319,7 +321,7 @@ def test_decompose_preserving_structure_forwards_args(decompose_mode):
|
|
|
319
321
|
assert actual == expected
|
|
320
322
|
|
|
321
323
|
|
|
322
|
-
def test_decompose_tagged_operation():
|
|
324
|
+
def test_decompose_tagged_operation() -> None:
|
|
323
325
|
op = cirq.TaggedOperation(
|
|
324
326
|
cirq.CircuitOperation(
|
|
325
327
|
circuit=cirq.FrozenCircuit(
|
|
@@ -374,7 +376,7 @@ class RecursiveDecompose(cirq.Gate):
|
|
|
374
376
|
|
|
375
377
|
|
|
376
378
|
@pytest.mark.parametrize('with_context', [True, False])
|
|
377
|
-
def test_decompose_recursive_dfs(with_context: bool):
|
|
379
|
+
def test_decompose_recursive_dfs(with_context: bool) -> None:
|
|
378
380
|
expected_calls = [
|
|
379
381
|
mock.call.qalloc(True),
|
|
380
382
|
mock.call.qalloc(False),
|
|
@@ -423,7 +425,7 @@ class G2(cirq.Gate):
|
|
|
423
425
|
|
|
424
426
|
|
|
425
427
|
@mock.patch('cirq.protocols.decompose_protocol._CONTEXT_COUNTER', itertools.count())
|
|
426
|
-
def test_successive_decompose_once_succeed():
|
|
428
|
+
def test_successive_decompose_once_succeed() -> None:
|
|
427
429
|
op = G2()(cirq.NamedQubit('q'))
|
|
428
430
|
d1 = cirq.decompose_once(op)
|
|
429
431
|
d2 = cirq.decompose_once(d1[0])
|
|
@@ -435,7 +437,7 @@ def test_successive_decompose_once_succeed():
|
|
|
435
437
|
]
|
|
436
438
|
|
|
437
439
|
|
|
438
|
-
def test_decompose_without_context_succeed():
|
|
440
|
+
def test_decompose_without_context_succeed() -> None:
|
|
439
441
|
op = G2()(cirq.NamedQubit('q'))
|
|
440
442
|
assert cirq.decompose(op, keep=lambda op: op.gate is cirq.CNOT) == [
|
|
441
443
|
cirq.CNOT(
|
|
@@ -443,3 +445,12 @@ def test_decompose_without_context_succeed():
|
|
|
443
445
|
cirq.ops.CleanQubit(1, prefix='_decompose_protocol'),
|
|
444
446
|
)
|
|
445
447
|
]
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def test_extracting_global_phases() -> None:
|
|
451
|
+
qm = cirq.SimpleQubitManager()
|
|
452
|
+
context = cirq.DecompositionContext(qm)
|
|
453
|
+
new_context = context.extracting_global_phases()
|
|
454
|
+
assert not context.extract_global_phases
|
|
455
|
+
assert new_context.extract_global_phases
|
|
456
|
+
assert new_context.qubit_manager is qm
|