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/ops/raw_types.py
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
"""Basic types defining qubits, gates, and operations."""
|
|
16
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
17
19
|
import abc
|
|
18
20
|
import functools
|
|
19
21
|
from types import NotImplementedType
|
|
@@ -23,27 +25,19 @@ from typing import (
|
|
|
23
25
|
Callable,
|
|
24
26
|
cast,
|
|
25
27
|
Collection,
|
|
26
|
-
Dict,
|
|
27
|
-
FrozenSet,
|
|
28
28
|
Hashable,
|
|
29
29
|
Iterable,
|
|
30
|
-
List,
|
|
31
30
|
Mapping,
|
|
32
|
-
Optional,
|
|
33
31
|
Sequence,
|
|
34
|
-
Tuple,
|
|
35
32
|
TYPE_CHECKING,
|
|
36
|
-
Union,
|
|
37
33
|
)
|
|
38
34
|
|
|
39
35
|
import numpy as np
|
|
40
|
-
import sympy
|
|
41
36
|
from typing_extensions import Self
|
|
42
37
|
|
|
43
38
|
from cirq import protocols, value
|
|
44
39
|
from cirq._compat import __cirq_debug__, _method_cache_name, cached_method
|
|
45
40
|
from cirq._import import LazyLoader
|
|
46
|
-
from cirq.ops import control_values as cv
|
|
47
41
|
|
|
48
42
|
# Lazy imports to break circular dependencies.
|
|
49
43
|
ops = LazyLoader("ops", globals(), "cirq.ops")
|
|
@@ -51,7 +45,10 @@ line_qubit = LazyLoader("line_qubit", globals(), "cirq.devices.line_qubit")
|
|
|
51
45
|
|
|
52
46
|
|
|
53
47
|
if TYPE_CHECKING:
|
|
48
|
+
import sympy
|
|
49
|
+
|
|
54
50
|
import cirq
|
|
51
|
+
from cirq.ops import control_values as cv
|
|
55
52
|
|
|
56
53
|
|
|
57
54
|
class Qid(metaclass=abc.ABCMeta):
|
|
@@ -96,7 +93,7 @@ class Qid(metaclass=abc.ABCMeta):
|
|
|
96
93
|
f'Wrong qid dimension. Expected a positive integer but got {dimension}.'
|
|
97
94
|
)
|
|
98
95
|
|
|
99
|
-
def with_dimension(self, dimension: int) ->
|
|
96
|
+
def with_dimension(self, dimension: int) -> Qid:
|
|
100
97
|
"""Returns a new qid with a different dimension.
|
|
101
98
|
|
|
102
99
|
Child classes can override. Wraps the qubit object by default.
|
|
@@ -115,7 +112,7 @@ class Qid(metaclass=abc.ABCMeta):
|
|
|
115
112
|
def __hash__(self) -> int:
|
|
116
113
|
return hash((Qid, self._comparison_key()))
|
|
117
114
|
|
|
118
|
-
def __getstate__(self) ->
|
|
115
|
+
def __getstate__(self) -> dict[str, Any]:
|
|
119
116
|
# clear cached hash value when pickling, see #6674
|
|
120
117
|
state = self.__dict__
|
|
121
118
|
hash_attr = _method_cache_name(self.__hash__)
|
|
@@ -154,9 +151,7 @@ class Qid(metaclass=abc.ABCMeta):
|
|
|
154
151
|
return NotImplemented
|
|
155
152
|
return self._cmp_tuple() >= other._cmp_tuple()
|
|
156
153
|
|
|
157
|
-
def _circuit_diagram_info_(
|
|
158
|
-
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
159
|
-
) -> 'cirq.CircuitDiagramInfo':
|
|
154
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
160
155
|
"""Circuit symbol for qids defaults to the string representation."""
|
|
161
156
|
return protocols.CircuitDiagramInfo(wire_symbols=(str(self),))
|
|
162
157
|
|
|
@@ -190,7 +185,7 @@ class _QubitAsQid(Qid):
|
|
|
190
185
|
def __str__(self) -> str:
|
|
191
186
|
return f'{self.qubit!s} (d={self.dimension})'
|
|
192
187
|
|
|
193
|
-
def _json_dict_(self) ->
|
|
188
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
194
189
|
return protocols.obj_to_dict_helper(self, ['qubit', 'dimension'])
|
|
195
190
|
|
|
196
191
|
|
|
@@ -203,14 +198,16 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
203
198
|
to create an Operation on q1 and q2 is equivalent to MyGate(q1,q2).
|
|
204
199
|
|
|
205
200
|
Gates operate on a certain number of qubits. All implementations of gate
|
|
206
|
-
must implement
|
|
207
|
-
|
|
201
|
+
must implement a method to declare the number of qubits (if a gate acting
|
|
202
|
+
on qubits) or the qid shape (if acting on qudits). In general, this means
|
|
203
|
+
that a Gate subclass should implement only `_qid_shape_` if it can act on
|
|
204
|
+
qudits, otherwise it should define only `_num_qubits_`.
|
|
208
205
|
|
|
209
206
|
Linear combinations of gates can be created by adding gates together and
|
|
210
207
|
multiplying them by scalars.
|
|
211
208
|
"""
|
|
212
209
|
|
|
213
|
-
def validate_args(self, qubits: Sequence[
|
|
210
|
+
def validate_args(self, qubits: Sequence[cirq.Qid]) -> None:
|
|
214
211
|
"""Checks if this gate can be applied to the given qubits.
|
|
215
212
|
|
|
216
213
|
By default checks that:
|
|
@@ -230,7 +227,7 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
230
227
|
if __cirq_debug__.get():
|
|
231
228
|
_validate_qid_shape(self, qubits)
|
|
232
229
|
|
|
233
|
-
def on(self, *qubits: Qid) ->
|
|
230
|
+
def on(self, *qubits: Qid) -> cirq.Operation:
|
|
234
231
|
"""Returns an application of this gate to the given qubits.
|
|
235
232
|
|
|
236
233
|
Args:
|
|
@@ -241,7 +238,7 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
241
238
|
"""
|
|
242
239
|
return ops.gate_operation.GateOperation(self, qubits)
|
|
243
240
|
|
|
244
|
-
def on_each(self, *targets:
|
|
241
|
+
def on_each(self, *targets: Qid | Iterable[Any]) -> list[cirq.Operation]:
|
|
245
242
|
"""Returns a list of operations applying the gate to all targets.
|
|
246
243
|
|
|
247
244
|
Args:
|
|
@@ -259,7 +256,7 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
259
256
|
If the gate qubit number is incompatible.
|
|
260
257
|
TypeError: If a single target is supplied and it is not iterable.
|
|
261
258
|
"""
|
|
262
|
-
operations:
|
|
259
|
+
operations: list[cirq.Operation] = []
|
|
263
260
|
if self._num_qubits_() > 1:
|
|
264
261
|
iterator: Iterable = targets
|
|
265
262
|
if len(targets) == 1:
|
|
@@ -306,8 +303,8 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
306
303
|
return operations
|
|
307
304
|
|
|
308
305
|
def wrap_in_linear_combination(
|
|
309
|
-
self, coefficient:
|
|
310
|
-
) ->
|
|
306
|
+
self, coefficient: cirq.TParamValComplex = 1
|
|
307
|
+
) -> cirq.LinearCombinationOfGates:
|
|
311
308
|
"""Returns a LinearCombinationOfGates with this gate.
|
|
312
309
|
|
|
313
310
|
Args:
|
|
@@ -320,30 +317,26 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
320
317
|
"""
|
|
321
318
|
return ops.linear_combinations.LinearCombinationOfGates({self: coefficient})
|
|
322
319
|
|
|
323
|
-
def __add__(
|
|
324
|
-
self, other: Union['Gate', 'cirq.LinearCombinationOfGates']
|
|
325
|
-
) -> 'cirq.LinearCombinationOfGates':
|
|
320
|
+
def __add__(self, other: Gate | cirq.LinearCombinationOfGates) -> cirq.LinearCombinationOfGates:
|
|
326
321
|
if isinstance(other, Gate):
|
|
327
322
|
return self.wrap_in_linear_combination() + other.wrap_in_linear_combination()
|
|
328
323
|
return self.wrap_in_linear_combination() + other
|
|
329
324
|
|
|
330
|
-
def __sub__(
|
|
331
|
-
self, other: Union['Gate', 'cirq.LinearCombinationOfGates']
|
|
332
|
-
) -> 'cirq.LinearCombinationOfGates':
|
|
325
|
+
def __sub__(self, other: Gate | cirq.LinearCombinationOfGates) -> cirq.LinearCombinationOfGates:
|
|
333
326
|
if isinstance(other, Gate):
|
|
334
327
|
return self.wrap_in_linear_combination() - other.wrap_in_linear_combination()
|
|
335
328
|
return self.wrap_in_linear_combination() - other
|
|
336
329
|
|
|
337
|
-
def __neg__(self) ->
|
|
330
|
+
def __neg__(self) -> cirq.LinearCombinationOfGates:
|
|
338
331
|
return self.wrap_in_linear_combination(coefficient=-1)
|
|
339
332
|
|
|
340
|
-
def __mul__(self, other: complex) ->
|
|
333
|
+
def __mul__(self, other: complex) -> cirq.LinearCombinationOfGates:
|
|
341
334
|
return self.wrap_in_linear_combination(coefficient=other)
|
|
342
335
|
|
|
343
|
-
def __rmul__(self, other: complex) ->
|
|
336
|
+
def __rmul__(self, other: complex) -> cirq.LinearCombinationOfGates:
|
|
344
337
|
return self.wrap_in_linear_combination(coefficient=other)
|
|
345
338
|
|
|
346
|
-
def __truediv__(self, other: complex) ->
|
|
339
|
+
def __truediv__(self, other: complex) -> cirq.LinearCombinationOfGates:
|
|
347
340
|
return self.wrap_in_linear_combination(coefficient=1 / other)
|
|
348
341
|
|
|
349
342
|
def __pow__(self, power):
|
|
@@ -368,7 +361,7 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
368
361
|
def __call__(self, *qubits: Qid, **kwargs):
|
|
369
362
|
return self.on(*qubits)
|
|
370
363
|
|
|
371
|
-
def with_probability(self, probability:
|
|
364
|
+
def with_probability(self, probability: cirq.TParamVal) -> cirq.Gate:
|
|
372
365
|
"""Creates a probabilistic channel with this gate.
|
|
373
366
|
|
|
374
367
|
Args:
|
|
@@ -385,12 +378,10 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
385
378
|
|
|
386
379
|
def controlled(
|
|
387
380
|
self,
|
|
388
|
-
num_controls:
|
|
389
|
-
control_values:
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
control_qid_shape: Optional[Tuple[int, ...]] = None,
|
|
393
|
-
) -> 'Gate':
|
|
381
|
+
num_controls: int | None = None,
|
|
382
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
383
|
+
control_qid_shape: tuple[int, ...] | None = None,
|
|
384
|
+
) -> Gate:
|
|
394
385
|
"""Returns a controlled version of this gate. If no arguments are
|
|
395
386
|
specified, defaults to a single qubit control.
|
|
396
387
|
|
|
@@ -427,7 +418,7 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
427
418
|
def _backwards_compatibility_num_qubits(self) -> int:
|
|
428
419
|
return protocols.num_qubits(self)
|
|
429
420
|
|
|
430
|
-
def _has_stabilizer_effect_(self) ->
|
|
421
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
431
422
|
return NotImplemented
|
|
432
423
|
|
|
433
424
|
@value.alternative(requires='_num_qubits_', implementation=_backwards_compatibility_num_qubits)
|
|
@@ -450,15 +441,15 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
450
441
|
"""The number of qubits this gate acts on."""
|
|
451
442
|
raise NotImplementedError
|
|
452
443
|
|
|
453
|
-
def _default_shape_from_num_qubits(self) ->
|
|
444
|
+
def _default_shape_from_num_qubits(self) -> tuple[int, ...]:
|
|
454
445
|
num_qubits = self._num_qubits_()
|
|
455
446
|
if num_qubits is NotImplemented:
|
|
456
447
|
return NotImplemented
|
|
457
448
|
return (2,) * num_qubits
|
|
458
449
|
|
|
459
450
|
@value.alternative(requires='_num_qubits_', implementation=_default_shape_from_num_qubits)
|
|
460
|
-
def _qid_shape_(self) ->
|
|
461
|
-
"""Returns a
|
|
451
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
452
|
+
"""Returns a tuple containing the number of quantum levels of each qid
|
|
462
453
|
the gate acts on. E.g. (2, 2, 2) for the three-qubit CCZ gate and
|
|
463
454
|
(3, 3) for a 2-qutrit ternary gate.
|
|
464
455
|
"""
|
|
@@ -466,7 +457,7 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
466
457
|
|
|
467
458
|
def _equal_up_to_global_phase_(
|
|
468
459
|
self, other: Any, atol: float = 1e-8
|
|
469
|
-
) ->
|
|
460
|
+
) -> NotImplementedType | bool:
|
|
470
461
|
"""Default fallback for gates that do not implement this protocol."""
|
|
471
462
|
try:
|
|
472
463
|
return protocols.equal_up_to_global_phase(
|
|
@@ -477,13 +468,11 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
477
468
|
return NotImplemented
|
|
478
469
|
|
|
479
470
|
def _commutes_on_qids_(
|
|
480
|
-
self, qids:
|
|
481
|
-
) ->
|
|
471
|
+
self, qids: Sequence[cirq.Qid], other: Any, *, atol: float = 1e-8
|
|
472
|
+
) -> bool | NotImplementedType | None:
|
|
482
473
|
return NotImplemented
|
|
483
474
|
|
|
484
|
-
def _commutes_(
|
|
485
|
-
self, other: Any, *, atol: float = 1e-8
|
|
486
|
-
) -> Union[None, NotImplementedType, bool]:
|
|
475
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> None | NotImplementedType | bool:
|
|
487
476
|
if not isinstance(other, Gate):
|
|
488
477
|
return NotImplemented
|
|
489
478
|
if protocols.qid_shape(self) != protocols.qid_shape(other):
|
|
@@ -492,15 +481,15 @@ class Gate(metaclass=value.ABCMetaImplementAnyOneOf):
|
|
|
492
481
|
qs = line_qubit.LineQid.for_qid_shape(protocols.qid_shape(self))
|
|
493
482
|
return protocols.commutes(self(*qs), other(*qs))
|
|
494
483
|
|
|
495
|
-
def _mul_with_qubits(self, qubits:
|
|
484
|
+
def _mul_with_qubits(self, qubits: tuple[cirq.Qid, ...], other):
|
|
496
485
|
"""cirq.GateOperation.__mul__ delegates to this method."""
|
|
497
486
|
return NotImplemented
|
|
498
487
|
|
|
499
|
-
def _rmul_with_qubits(self, qubits:
|
|
488
|
+
def _rmul_with_qubits(self, qubits: tuple[cirq.Qid, ...], other):
|
|
500
489
|
"""cirq.GateOperation.__rmul__ delegates to this method."""
|
|
501
490
|
return NotImplemented
|
|
502
491
|
|
|
503
|
-
def _json_dict_(self) ->
|
|
492
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
504
493
|
return protocols.obj_to_dict_helper(self, attribute_names=[])
|
|
505
494
|
|
|
506
495
|
|
|
@@ -512,12 +501,12 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
512
501
|
"""
|
|
513
502
|
|
|
514
503
|
@property
|
|
515
|
-
def gate(self) ->
|
|
504
|
+
def gate(self) -> cirq.Gate | None:
|
|
516
505
|
return None
|
|
517
506
|
|
|
518
507
|
@property
|
|
519
508
|
@abc.abstractmethod
|
|
520
|
-
def qubits(self) ->
|
|
509
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
521
510
|
raise NotImplementedError()
|
|
522
511
|
|
|
523
512
|
def _num_qubits_(self) -> int:
|
|
@@ -528,11 +517,11 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
528
517
|
return len(self.qubits)
|
|
529
518
|
|
|
530
519
|
@cached_method
|
|
531
|
-
def _qid_shape_(self) ->
|
|
520
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
532
521
|
return protocols.qid_shape(self.qubits)
|
|
533
522
|
|
|
534
523
|
@abc.abstractmethod
|
|
535
|
-
def with_qubits(self, *new_qubits:
|
|
524
|
+
def with_qubits(self, *new_qubits: cirq.Qid) -> Self:
|
|
536
525
|
"""Returns the same operation, but applied to different qubits.
|
|
537
526
|
|
|
538
527
|
Args:
|
|
@@ -542,16 +531,16 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
542
531
|
"""
|
|
543
532
|
|
|
544
533
|
@property
|
|
545
|
-
def tags(self) ->
|
|
534
|
+
def tags(self) -> tuple[Hashable, ...]:
|
|
546
535
|
"""Returns a tuple of the operation's tags."""
|
|
547
536
|
return ()
|
|
548
537
|
|
|
549
538
|
@property
|
|
550
|
-
def untagged(self) ->
|
|
539
|
+
def untagged(self) -> cirq.Operation:
|
|
551
540
|
"""Returns the underlying operation without any tags."""
|
|
552
541
|
return self
|
|
553
542
|
|
|
554
|
-
def with_tags(self, *new_tags: Hashable) ->
|
|
543
|
+
def with_tags(self, *new_tags: Hashable) -> cirq.Operation:
|
|
555
544
|
"""Creates a new TaggedOperation, with this op and the specified tags.
|
|
556
545
|
|
|
557
546
|
This method can be used to attach meta-data to specific operations
|
|
@@ -577,7 +566,7 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
577
566
|
return TaggedOperation(self, *new_tags)
|
|
578
567
|
|
|
579
568
|
def transform_qubits(
|
|
580
|
-
self, qubit_map:
|
|
569
|
+
self, qubit_map: dict[cirq.Qid, cirq.Qid] | Callable[[cirq.Qid], cirq.Qid]
|
|
581
570
|
) -> Self:
|
|
582
571
|
"""Returns the same operation, but with different qubits.
|
|
583
572
|
|
|
@@ -622,11 +611,9 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
622
611
|
|
|
623
612
|
def controlled_by(
|
|
624
613
|
self,
|
|
625
|
-
*control_qubits:
|
|
626
|
-
control_values:
|
|
627
|
-
|
|
628
|
-
] = None,
|
|
629
|
-
) -> 'cirq.Operation':
|
|
614
|
+
*control_qubits: cirq.Qid,
|
|
615
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
616
|
+
) -> cirq.Operation:
|
|
630
617
|
"""Returns a controlled version of this operation. If no control_qubits
|
|
631
618
|
are specified, returns self.
|
|
632
619
|
|
|
@@ -644,7 +631,7 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
644
631
|
return self
|
|
645
632
|
return ops.controlled_operation.ControlledOperation(control_qubits, self, control_values)
|
|
646
633
|
|
|
647
|
-
def with_probability(self, probability:
|
|
634
|
+
def with_probability(self, probability: cirq.TParamVal) -> cirq.Operation:
|
|
648
635
|
"""Creates a probabilistic channel with this operation.
|
|
649
636
|
|
|
650
637
|
Args:
|
|
@@ -667,7 +654,7 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
667
654
|
*self.qubits
|
|
668
655
|
)
|
|
669
656
|
|
|
670
|
-
def validate_args(self, qubits: Sequence[
|
|
657
|
+
def validate_args(self, qubits: Sequence[cirq.Qid]) -> None:
|
|
671
658
|
"""Raises an exception if the `qubits` don't match this operation's qid
|
|
672
659
|
shape.
|
|
673
660
|
|
|
@@ -682,22 +669,20 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
682
669
|
if __cirq_debug__.get():
|
|
683
670
|
_validate_qid_shape(self, qubits)
|
|
684
671
|
|
|
685
|
-
def _commutes_(
|
|
686
|
-
self, other: Any, *, atol: float = 1e-8
|
|
687
|
-
) -> Union[bool, NotImplementedType, None]:
|
|
672
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> bool | NotImplementedType | None:
|
|
688
673
|
"""Determine if this Operation commutes with the object"""
|
|
689
674
|
if not isinstance(other, Operation):
|
|
690
675
|
return NotImplemented
|
|
691
676
|
return _operations_commutes_impl([self], [other], atol=atol)
|
|
692
677
|
|
|
693
678
|
@property
|
|
694
|
-
def classical_controls(self) ->
|
|
679
|
+
def classical_controls(self) -> frozenset[cirq.Condition]:
|
|
695
680
|
"""The classical controls gating this operation."""
|
|
696
681
|
return frozenset()
|
|
697
682
|
|
|
698
683
|
def with_classical_controls(
|
|
699
|
-
self, *conditions:
|
|
700
|
-
) ->
|
|
684
|
+
self, *conditions: str | cirq.MeasurementKey | cirq.Condition | sympy.Expr
|
|
685
|
+
) -> cirq.Operation:
|
|
701
686
|
"""Returns a classically controlled version of this operation.
|
|
702
687
|
|
|
703
688
|
An operation that is classically controlled is executed iff all
|
|
@@ -728,7 +713,7 @@ class Operation(metaclass=abc.ABCMeta):
|
|
|
728
713
|
return self
|
|
729
714
|
return ClassicallyControlledOperation(self, conditions)
|
|
730
715
|
|
|
731
|
-
def without_classical_controls(self) ->
|
|
716
|
+
def without_classical_controls(self) -> cirq.Operation:
|
|
732
717
|
"""Removes all classical controls from the operation.
|
|
733
718
|
|
|
734
719
|
This function removes all classical controls gating the operation. It
|
|
@@ -766,25 +751,25 @@ class TaggedOperation(Operation):
|
|
|
766
751
|
See `Operation.with_tags()` for more information on intended usage.
|
|
767
752
|
"""
|
|
768
753
|
|
|
769
|
-
def __init__(self, sub_operation:
|
|
754
|
+
def __init__(self, sub_operation: cirq.Operation, *tags: Hashable):
|
|
770
755
|
self._sub_operation = sub_operation
|
|
771
756
|
self._tags = tuple(tags)
|
|
772
757
|
if any(isinstance(tag, type) for tag in tags):
|
|
773
758
|
raise ValueError('Tags cannot be types. Did you forget to instantiate the tag type?')
|
|
774
759
|
|
|
775
760
|
@property
|
|
776
|
-
def sub_operation(self) ->
|
|
761
|
+
def sub_operation(self) -> cirq.Operation:
|
|
777
762
|
return self._sub_operation
|
|
778
763
|
|
|
779
764
|
@property
|
|
780
|
-
def qubits(self) ->
|
|
765
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
781
766
|
return self.sub_operation.qubits
|
|
782
767
|
|
|
783
768
|
@property
|
|
784
|
-
def gate(self) ->
|
|
769
|
+
def gate(self) -> cirq.Gate | None:
|
|
785
770
|
return self.sub_operation.gate
|
|
786
771
|
|
|
787
|
-
def with_qubits(self, *new_qubits:
|
|
772
|
+
def with_qubits(self, *new_qubits: cirq.Qid):
|
|
788
773
|
return TaggedOperation(self.sub_operation.with_qubits(*new_qubits), *self._tags)
|
|
789
774
|
|
|
790
775
|
def _with_measurement_key_mapping_(self, key_map: Mapping[str, str]):
|
|
@@ -795,26 +780,24 @@ class TaggedOperation(Operation):
|
|
|
795
780
|
|
|
796
781
|
def controlled_by(
|
|
797
782
|
self,
|
|
798
|
-
*control_qubits:
|
|
799
|
-
control_values:
|
|
800
|
-
|
|
801
|
-
] = None,
|
|
802
|
-
) -> 'cirq.Operation':
|
|
783
|
+
*control_qubits: cirq.Qid,
|
|
784
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
785
|
+
) -> cirq.Operation:
|
|
803
786
|
if len(control_qubits) == 0:
|
|
804
787
|
return self
|
|
805
788
|
return self.sub_operation.controlled_by(*control_qubits, control_values=control_values)
|
|
806
789
|
|
|
807
790
|
@property
|
|
808
|
-
def tags(self) ->
|
|
791
|
+
def tags(self) -> tuple[Hashable, ...]:
|
|
809
792
|
"""Returns a tuple of the operation's tags."""
|
|
810
793
|
return self._tags
|
|
811
794
|
|
|
812
795
|
@property
|
|
813
|
-
def untagged(self) ->
|
|
796
|
+
def untagged(self) -> cirq.Operation:
|
|
814
797
|
"""Returns the underlying operation without any tags."""
|
|
815
798
|
return self.sub_operation
|
|
816
799
|
|
|
817
|
-
def with_tags(self, *new_tags: Hashable) ->
|
|
800
|
+
def with_tags(self, *new_tags: Hashable) -> cirq.TaggedOperation:
|
|
818
801
|
"""Creates a new TaggedOperation with combined tags.
|
|
819
802
|
|
|
820
803
|
Overloads Operation.with_tags to create a new TaggedOperation
|
|
@@ -842,15 +825,15 @@ class TaggedOperation(Operation):
|
|
|
842
825
|
def _from_json_dict_(cls, sub_operation, tags, **kwargs):
|
|
843
826
|
return cls(sub_operation, *tags)
|
|
844
827
|
|
|
845
|
-
def _json_dict_(self) ->
|
|
828
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
846
829
|
return protocols.obj_to_dict_helper(self, ['sub_operation', 'tags'])
|
|
847
830
|
|
|
848
|
-
def _decompose_(self) ->
|
|
831
|
+
def _decompose_(self) -> cirq.OP_TREE:
|
|
849
832
|
return self._decompose_with_context_()
|
|
850
833
|
|
|
851
834
|
def _decompose_with_context_(
|
|
852
|
-
self, context:
|
|
853
|
-
) ->
|
|
835
|
+
self, context: cirq.DecompositionContext | None = None
|
|
836
|
+
) -> cirq.OP_TREE:
|
|
854
837
|
return protocols.decompose_once(
|
|
855
838
|
self.sub_operation, default=None, flatten=False, context=context
|
|
856
839
|
)
|
|
@@ -859,42 +842,40 @@ class TaggedOperation(Operation):
|
|
|
859
842
|
return protocols.pauli_expansion(self.sub_operation)
|
|
860
843
|
|
|
861
844
|
def _apply_unitary_(
|
|
862
|
-
self, args:
|
|
863
|
-
) ->
|
|
845
|
+
self, args: protocols.ApplyUnitaryArgs
|
|
846
|
+
) -> np.ndarray | None | NotImplementedType:
|
|
864
847
|
return protocols.apply_unitary(self.sub_operation, args, default=None)
|
|
865
848
|
|
|
866
849
|
@cached_method
|
|
867
850
|
def _has_unitary_(self) -> bool:
|
|
868
851
|
return protocols.has_unitary(self.sub_operation)
|
|
869
852
|
|
|
870
|
-
def _unitary_(self) ->
|
|
853
|
+
def _unitary_(self) -> np.ndarray | NotImplementedType:
|
|
871
854
|
return protocols.unitary(self.sub_operation, NotImplemented)
|
|
872
855
|
|
|
873
|
-
def _commutes_(
|
|
874
|
-
self, other: Any, *, atol: float = 1e-8
|
|
875
|
-
) -> Union[bool, NotImplementedType, None]:
|
|
856
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> bool | NotImplementedType | None:
|
|
876
857
|
return protocols.commutes(self.sub_operation, other, atol=atol)
|
|
877
858
|
|
|
878
859
|
@cached_method
|
|
879
860
|
def _has_mixture_(self) -> bool:
|
|
880
861
|
return protocols.has_mixture(self.sub_operation)
|
|
881
862
|
|
|
882
|
-
def _mixture_(self) -> Sequence[
|
|
863
|
+
def _mixture_(self) -> Sequence[tuple[float, Any]]:
|
|
883
864
|
return protocols.mixture(self.sub_operation, NotImplemented)
|
|
884
865
|
|
|
885
866
|
@cached_method
|
|
886
867
|
def _has_kraus_(self) -> bool:
|
|
887
868
|
return protocols.has_kraus(self.sub_operation)
|
|
888
869
|
|
|
889
|
-
def _kraus_(self) ->
|
|
870
|
+
def _kraus_(self) -> tuple[np.ndarray, ...] | NotImplementedType:
|
|
890
871
|
return protocols.kraus(self.sub_operation, NotImplemented)
|
|
891
872
|
|
|
892
873
|
@cached_method
|
|
893
|
-
def _measurement_key_names_(self) ->
|
|
874
|
+
def _measurement_key_names_(self) -> frozenset[str]:
|
|
894
875
|
return protocols.measurement_key_names(self.sub_operation)
|
|
895
876
|
|
|
896
877
|
@cached_method
|
|
897
|
-
def _measurement_key_objs_(self) ->
|
|
878
|
+
def _measurement_key_objs_(self) -> frozenset[cirq.MeasurementKey]:
|
|
898
879
|
return protocols.measurement_key_objs(self.sub_operation)
|
|
899
880
|
|
|
900
881
|
@cached_method
|
|
@@ -910,7 +891,7 @@ class TaggedOperation(Operation):
|
|
|
910
891
|
protocols.is_parameterized(tag) for tag in self.tags
|
|
911
892
|
)
|
|
912
893
|
|
|
913
|
-
def _act_on_(self, sim_state:
|
|
894
|
+
def _act_on_(self, sim_state: cirq.SimulationStateBase) -> bool:
|
|
914
895
|
sub = getattr(self.sub_operation, "_act_on_", None)
|
|
915
896
|
if sub is not None:
|
|
916
897
|
return sub(sim_state)
|
|
@@ -922,35 +903,34 @@ class TaggedOperation(Operation):
|
|
|
922
903
|
return protocols.parameter_names(self.sub_operation) | tag_params
|
|
923
904
|
|
|
924
905
|
def _resolve_parameters_(
|
|
925
|
-
self, resolver:
|
|
926
|
-
) ->
|
|
906
|
+
self, resolver: cirq.ParamResolver, recursive: bool
|
|
907
|
+
) -> TaggedOperation:
|
|
927
908
|
resolved_op = protocols.resolve_parameters(self.sub_operation, resolver, recursive)
|
|
928
909
|
resolved_tags = (
|
|
929
910
|
protocols.resolve_parameters(tag, resolver, recursive) for tag in self._tags
|
|
930
911
|
)
|
|
931
912
|
return TaggedOperation(resolved_op, *resolved_tags)
|
|
932
913
|
|
|
933
|
-
def _circuit_diagram_info_(
|
|
934
|
-
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
935
|
-
) -> 'cirq.CircuitDiagramInfo':
|
|
914
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
936
915
|
sub_op_info = protocols.circuit_diagram_info(self.sub_operation, args, NotImplemented)
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
sub_op_info.wire_symbols
|
|
941
|
-
|
|
916
|
+
if sub_op_info is not NotImplemented and sub_op_info.wire_symbols:
|
|
917
|
+
visible_tags = args.tags_to_include(self._tags)
|
|
918
|
+
if visible_tags:
|
|
919
|
+
sub_op_info.wire_symbols = (
|
|
920
|
+
sub_op_info.wire_symbols[0] + f"[{', '.join(map(str, visible_tags))}]",
|
|
921
|
+
) + sub_op_info.wire_symbols[1:]
|
|
942
922
|
return sub_op_info
|
|
943
923
|
|
|
944
924
|
@cached_method
|
|
945
925
|
def _trace_distance_bound_(self) -> float:
|
|
946
926
|
return protocols.trace_distance_bound(self.sub_operation)
|
|
947
927
|
|
|
948
|
-
def _phase_by_(self, phase_turns: float, qubit_index: int) ->
|
|
928
|
+
def _phase_by_(self, phase_turns: float, qubit_index: int) -> cirq.Operation:
|
|
949
929
|
return protocols.phase_by(
|
|
950
930
|
self.sub_operation, phase_turns, qubit_index, default=NotImplemented
|
|
951
931
|
)
|
|
952
932
|
|
|
953
|
-
def __pow__(self, exponent: Any) ->
|
|
933
|
+
def __pow__(self, exponent: Any) -> cirq.Operation:
|
|
954
934
|
return self.sub_operation**exponent
|
|
955
935
|
|
|
956
936
|
def __mul__(self, other: Any) -> Any:
|
|
@@ -959,30 +939,30 @@ class TaggedOperation(Operation):
|
|
|
959
939
|
def __rmul__(self, other: Any) -> Any:
|
|
960
940
|
return other * self.sub_operation
|
|
961
941
|
|
|
962
|
-
def _qasm_(self, args:
|
|
942
|
+
def _qasm_(self, args: protocols.QasmArgs) -> str | None:
|
|
963
943
|
return protocols.qasm(self.sub_operation, args=args, default=None)
|
|
964
944
|
|
|
965
945
|
def _equal_up_to_global_phase_(
|
|
966
946
|
self, other: Any, atol: float = 1e-8
|
|
967
|
-
) ->
|
|
947
|
+
) -> NotImplementedType | bool:
|
|
968
948
|
return protocols.equal_up_to_global_phase(self.sub_operation, other, atol=atol)
|
|
969
949
|
|
|
970
950
|
@property
|
|
971
|
-
def classical_controls(self) ->
|
|
951
|
+
def classical_controls(self) -> frozenset[cirq.Condition]:
|
|
972
952
|
return self.sub_operation.classical_controls
|
|
973
953
|
|
|
974
|
-
def without_classical_controls(self) ->
|
|
954
|
+
def without_classical_controls(self) -> cirq.Operation:
|
|
975
955
|
new_sub_operation = self.sub_operation.without_classical_controls()
|
|
976
956
|
return self if new_sub_operation is self.sub_operation else new_sub_operation
|
|
977
957
|
|
|
978
958
|
def with_classical_controls(
|
|
979
|
-
self, *conditions:
|
|
980
|
-
) ->
|
|
959
|
+
self, *conditions: str | cirq.MeasurementKey | cirq.Condition | sympy.Expr
|
|
960
|
+
) -> cirq.Operation:
|
|
981
961
|
if not conditions:
|
|
982
962
|
return self
|
|
983
963
|
return self.sub_operation.with_classical_controls(*conditions)
|
|
984
964
|
|
|
985
|
-
def _control_keys_(self) ->
|
|
965
|
+
def _control_keys_(self) -> frozenset[cirq.MeasurementKey]:
|
|
986
966
|
return protocols.control_keys(self.sub_operation)
|
|
987
967
|
|
|
988
968
|
|
|
@@ -1007,8 +987,8 @@ class _InverseCompositeGate(Gate):
|
|
|
1007
987
|
return self._decompose_with_context_(qubits)
|
|
1008
988
|
|
|
1009
989
|
def _decompose_with_context_(
|
|
1010
|
-
self, qubits: Sequence[
|
|
1011
|
-
) ->
|
|
990
|
+
self, qubits: Sequence[cirq.Qid], context: cirq.DecompositionContext | None = None
|
|
991
|
+
) -> cirq.OP_TREE:
|
|
1012
992
|
return protocols.inverse(
|
|
1013
993
|
protocols.decompose_once_with_qubits(self._original, qubits, context=context)
|
|
1014
994
|
)
|
|
@@ -1031,8 +1011,8 @@ class _InverseCompositeGate(Gate):
|
|
|
1031
1011
|
return protocols.parameter_names(self._original)
|
|
1032
1012
|
|
|
1033
1013
|
def _resolve_parameters_(
|
|
1034
|
-
self, resolver:
|
|
1035
|
-
) ->
|
|
1014
|
+
self, resolver: cirq.ParamResolver, recursive: bool
|
|
1015
|
+
) -> _InverseCompositeGate:
|
|
1036
1016
|
return _InverseCompositeGate(
|
|
1037
1017
|
protocols.resolve_parameters(self._original, resolver, recursive)
|
|
1038
1018
|
)
|
|
@@ -1040,7 +1020,7 @@ class _InverseCompositeGate(Gate):
|
|
|
1040
1020
|
def _value_equality_values_(self):
|
|
1041
1021
|
return self._original
|
|
1042
1022
|
|
|
1043
|
-
def _circuit_diagram_info_(self, args:
|
|
1023
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs):
|
|
1044
1024
|
sub_info = protocols.circuit_diagram_info(self._original, args, default=NotImplemented)
|
|
1045
1025
|
if sub_info is NotImplemented:
|
|
1046
1026
|
return NotImplemented
|
|
@@ -1053,11 +1033,11 @@ class _InverseCompositeGate(Gate):
|
|
|
1053
1033
|
def __str__(self) -> str:
|
|
1054
1034
|
return f'{self._original!s}†'
|
|
1055
1035
|
|
|
1056
|
-
def _json_dict_(self) ->
|
|
1036
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
1057
1037
|
return {'original': self._original}
|
|
1058
1038
|
|
|
1059
1039
|
|
|
1060
|
-
def _validate_qid_shape(val: Any, qubits: Sequence[
|
|
1040
|
+
def _validate_qid_shape(val: Any, qubits: Sequence[cirq.Qid]) -> None:
|
|
1061
1041
|
"""Helper function to validate qubits for gates and operations.
|
|
1062
1042
|
|
|
1063
1043
|
Raises:
|
|
@@ -1082,7 +1062,7 @@ def _validate_qid_shape(val: Any, qubits: Sequence['cirq.Qid']) -> None:
|
|
|
1082
1062
|
|
|
1083
1063
|
def _operations_commutes_impl(
|
|
1084
1064
|
ops1: Collection[Operation], ops2: Collection[Operation], *, atol: float
|
|
1085
|
-
) ->
|
|
1065
|
+
) -> bool | NotImplementedType:
|
|
1086
1066
|
"""Determine if two collections of non-overlapping Operations commute.
|
|
1087
1067
|
|
|
1088
1068
|
This function implements the commutes protocol for the Operation and Moment classes
|