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/gate_operation.py
CHANGED
|
@@ -14,33 +14,21 @@
|
|
|
14
14
|
|
|
15
15
|
"""Basic types defining qubits, gates, and operations."""
|
|
16
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
17
19
|
import re
|
|
18
20
|
import warnings
|
|
19
21
|
from types import NotImplementedType
|
|
20
|
-
from typing import
|
|
21
|
-
|
|
22
|
-
Any,
|
|
23
|
-
cast,
|
|
24
|
-
Collection,
|
|
25
|
-
Dict,
|
|
26
|
-
FrozenSet,
|
|
27
|
-
List,
|
|
28
|
-
Mapping,
|
|
29
|
-
Optional,
|
|
30
|
-
Sequence,
|
|
31
|
-
Tuple,
|
|
32
|
-
TYPE_CHECKING,
|
|
33
|
-
TypeVar,
|
|
34
|
-
Union,
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
import numpy as np
|
|
22
|
+
from typing import AbstractSet, Any, cast, Collection, Mapping, Sequence, TYPE_CHECKING, TypeVar
|
|
23
|
+
|
|
38
24
|
from typing_extensions import Self
|
|
39
25
|
|
|
40
26
|
from cirq import ops, protocols, value
|
|
41
27
|
from cirq.ops import control_values as cv, gate_features, raw_types
|
|
42
28
|
|
|
43
29
|
if TYPE_CHECKING:
|
|
30
|
+
import numpy as np
|
|
31
|
+
|
|
44
32
|
import cirq
|
|
45
33
|
|
|
46
34
|
|
|
@@ -51,7 +39,7 @@ class GateOperation(raw_types.Operation):
|
|
|
51
39
|
Objects of this type are immutable.
|
|
52
40
|
"""
|
|
53
41
|
|
|
54
|
-
def __init__(self, gate:
|
|
42
|
+
def __init__(self, gate: cirq.Gate, qubits: Sequence[cirq.Qid]) -> None:
|
|
55
43
|
"""Inits GateOperation.
|
|
56
44
|
|
|
57
45
|
Args:
|
|
@@ -63,19 +51,19 @@ class GateOperation(raw_types.Operation):
|
|
|
63
51
|
self._qubits = tuple(qubits)
|
|
64
52
|
|
|
65
53
|
@property
|
|
66
|
-
def gate(self) ->
|
|
54
|
+
def gate(self) -> cirq.Gate:
|
|
67
55
|
"""The gate applied by the operation."""
|
|
68
56
|
return self._gate
|
|
69
57
|
|
|
70
58
|
@property
|
|
71
|
-
def qubits(self) ->
|
|
59
|
+
def qubits(self) -> tuple[cirq.Qid, ...]:
|
|
72
60
|
"""The qubits targeted by the operation."""
|
|
73
61
|
return self._qubits
|
|
74
62
|
|
|
75
|
-
def with_qubits(self, *new_qubits:
|
|
63
|
+
def with_qubits(self, *new_qubits: cirq.Qid) -> Self:
|
|
76
64
|
return cast(Self, self.gate.on(*new_qubits))
|
|
77
65
|
|
|
78
|
-
def with_gate(self, new_gate:
|
|
66
|
+
def with_gate(self, new_gate: cirq.Gate) -> cirq.Operation:
|
|
79
67
|
if self.gate is new_gate:
|
|
80
68
|
# As GateOperation is immutable, this can return the original.
|
|
81
69
|
return self
|
|
@@ -90,7 +78,7 @@ class GateOperation(raw_types.Operation):
|
|
|
90
78
|
return self
|
|
91
79
|
return new_gate.on(*self.qubits)
|
|
92
80
|
|
|
93
|
-
def _with_key_path_(self, path:
|
|
81
|
+
def _with_key_path_(self, path: tuple[str, ...]):
|
|
94
82
|
new_gate = protocols.with_key_path(self.gate, path)
|
|
95
83
|
if new_gate is NotImplemented:
|
|
96
84
|
return NotImplemented
|
|
@@ -99,7 +87,7 @@ class GateOperation(raw_types.Operation):
|
|
|
99
87
|
return self
|
|
100
88
|
return new_gate.on(*self.qubits)
|
|
101
89
|
|
|
102
|
-
def _with_key_path_prefix_(self, prefix:
|
|
90
|
+
def _with_key_path_prefix_(self, prefix: tuple[str, ...]):
|
|
103
91
|
new_gate = protocols.with_key_path_prefix(self.gate, prefix)
|
|
104
92
|
if new_gate is NotImplemented:
|
|
105
93
|
return NotImplemented
|
|
@@ -109,7 +97,7 @@ class GateOperation(raw_types.Operation):
|
|
|
109
97
|
return new_gate.on(*self.qubits)
|
|
110
98
|
|
|
111
99
|
def _with_rescoped_keys_(
|
|
112
|
-
self, path:
|
|
100
|
+
self, path: tuple[str, ...], bindable_keys: frozenset[cirq.MeasurementKey]
|
|
113
101
|
):
|
|
114
102
|
new_gate = protocols.with_rescoped_keys(self.gate, path, bindable_keys)
|
|
115
103
|
if new_gate is self.gate:
|
|
@@ -137,15 +125,15 @@ class GateOperation(raw_types.Operation):
|
|
|
137
125
|
qubits = ', '.join(str(e) for e in self.qubits)
|
|
138
126
|
return f'{self.gate}({qubits})' if qubits else str(self.gate)
|
|
139
127
|
|
|
140
|
-
def _json_dict_(self) ->
|
|
128
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
141
129
|
return protocols.obj_to_dict_helper(self, ['gate', 'qubits'])
|
|
142
130
|
|
|
143
131
|
def _group_interchangeable_qubits(
|
|
144
132
|
self,
|
|
145
|
-
) ->
|
|
133
|
+
) -> tuple[cirq.Qid | tuple[int, frozenset[cirq.Qid]], ...]:
|
|
146
134
|
if not isinstance(self.gate, gate_features.InterchangeableQubitsGate):
|
|
147
135
|
return self.qubits
|
|
148
|
-
groups:
|
|
136
|
+
groups: dict[int, list[cirq.Qid]] = {}
|
|
149
137
|
for i, q in enumerate(self.qubits):
|
|
150
138
|
k = self.gate.qubit_index_to_equivalence_group_key(i)
|
|
151
139
|
groups.setdefault(k, []).append(q)
|
|
@@ -160,12 +148,12 @@ class GateOperation(raw_types.Operation):
|
|
|
160
148
|
def _num_qubits_(self):
|
|
161
149
|
return len(self._qubits)
|
|
162
150
|
|
|
163
|
-
def _decompose_(self) ->
|
|
151
|
+
def _decompose_(self) -> cirq.OP_TREE:
|
|
164
152
|
return self._decompose_with_context_()
|
|
165
153
|
|
|
166
154
|
def _decompose_with_context_(
|
|
167
|
-
self, context:
|
|
168
|
-
) ->
|
|
155
|
+
self, context: cirq.DecompositionContext | None = None
|
|
156
|
+
) -> cirq.OP_TREE:
|
|
169
157
|
return protocols.decompose_once_with_qubits(
|
|
170
158
|
self.gate, self.qubits, NotImplemented, flatten=False, context=context
|
|
171
159
|
)
|
|
@@ -177,8 +165,8 @@ class GateOperation(raw_types.Operation):
|
|
|
177
165
|
return NotImplemented
|
|
178
166
|
|
|
179
167
|
def _apply_unitary_(
|
|
180
|
-
self, args:
|
|
181
|
-
) ->
|
|
168
|
+
self, args: protocols.ApplyUnitaryArgs
|
|
169
|
+
) -> np.ndarray | None | NotImplementedType:
|
|
182
170
|
getter = getattr(self.gate, '_apply_unitary_', None)
|
|
183
171
|
if getter is not None:
|
|
184
172
|
return getter(args)
|
|
@@ -190,15 +178,13 @@ class GateOperation(raw_types.Operation):
|
|
|
190
178
|
return getter()
|
|
191
179
|
return NotImplemented
|
|
192
180
|
|
|
193
|
-
def _unitary_(self) ->
|
|
181
|
+
def _unitary_(self) -> np.ndarray | NotImplementedType:
|
|
194
182
|
getter = getattr(self.gate, '_unitary_', None)
|
|
195
183
|
if getter is not None:
|
|
196
184
|
return getter()
|
|
197
185
|
return NotImplemented
|
|
198
186
|
|
|
199
|
-
def _commutes_(
|
|
200
|
-
self, other: Any, *, atol: float = 1e-8
|
|
201
|
-
) -> Union[bool, NotImplementedType, None]:
|
|
187
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> bool | NotImplementedType | None:
|
|
202
188
|
commutes = self.gate._commutes_on_qids_(self.qubits, other, atol=atol)
|
|
203
189
|
if commutes is not NotImplemented:
|
|
204
190
|
return commutes
|
|
@@ -211,15 +197,15 @@ class GateOperation(raw_types.Operation):
|
|
|
211
197
|
return getter()
|
|
212
198
|
return NotImplemented
|
|
213
199
|
|
|
214
|
-
def _mixture_(self) -> Sequence[
|
|
200
|
+
def _mixture_(self) -> Sequence[tuple[float, Any]]:
|
|
215
201
|
getter = getattr(self.gate, '_mixture_', None)
|
|
216
202
|
if getter is not None:
|
|
217
203
|
return getter()
|
|
218
204
|
return NotImplemented
|
|
219
205
|
|
|
220
206
|
def _apply_channel_(
|
|
221
|
-
self, args:
|
|
222
|
-
) ->
|
|
207
|
+
self, args: protocols.ApplyChannelArgs
|
|
208
|
+
) -> np.ndarray | None | NotImplementedType:
|
|
223
209
|
getter = getattr(self.gate, '_apply_channel_', None)
|
|
224
210
|
if getter is not None:
|
|
225
211
|
return getter(args)
|
|
@@ -231,46 +217,44 @@ class GateOperation(raw_types.Operation):
|
|
|
231
217
|
return getter()
|
|
232
218
|
return NotImplemented
|
|
233
219
|
|
|
234
|
-
def _kraus_(self) ->
|
|
220
|
+
def _kraus_(self) -> tuple[np.ndarray] | NotImplementedType:
|
|
235
221
|
getter = getattr(self.gate, '_kraus_', None)
|
|
236
222
|
if getter is not None:
|
|
237
223
|
return getter()
|
|
238
224
|
return NotImplemented
|
|
239
225
|
|
|
240
|
-
def _is_measurement_(self) ->
|
|
226
|
+
def _is_measurement_(self) -> bool | None:
|
|
241
227
|
getter = getattr(self.gate, '_is_measurement_', None)
|
|
242
228
|
if getter is not None:
|
|
243
229
|
return getter()
|
|
244
230
|
# Let the protocol handle the fallback.
|
|
245
231
|
return NotImplemented
|
|
246
232
|
|
|
247
|
-
def _measurement_key_name_(self) ->
|
|
233
|
+
def _measurement_key_name_(self) -> str | None:
|
|
248
234
|
getter = getattr(self.gate, '_measurement_key_name_', None)
|
|
249
235
|
if getter is not None:
|
|
250
236
|
return getter()
|
|
251
237
|
return NotImplemented
|
|
252
238
|
|
|
253
|
-
def _measurement_key_names_(self) ->
|
|
239
|
+
def _measurement_key_names_(self) -> frozenset[str] | NotImplementedType | None:
|
|
254
240
|
getter = getattr(self.gate, '_measurement_key_names_', None)
|
|
255
241
|
if getter is not None:
|
|
256
242
|
return getter()
|
|
257
243
|
return NotImplemented
|
|
258
244
|
|
|
259
|
-
def _measurement_key_obj_(self) ->
|
|
245
|
+
def _measurement_key_obj_(self) -> cirq.MeasurementKey | None:
|
|
260
246
|
getter = getattr(self.gate, '_measurement_key_obj_', None)
|
|
261
247
|
if getter is not None:
|
|
262
248
|
return getter()
|
|
263
249
|
return NotImplemented
|
|
264
250
|
|
|
265
|
-
def _measurement_key_objs_(
|
|
266
|
-
self,
|
|
267
|
-
) -> Union[FrozenSet['cirq.MeasurementKey'], NotImplementedType, None]:
|
|
251
|
+
def _measurement_key_objs_(self) -> frozenset[cirq.MeasurementKey] | NotImplementedType | None:
|
|
268
252
|
getter = getattr(self.gate, '_measurement_key_objs_', None)
|
|
269
253
|
if getter is not None:
|
|
270
254
|
return getter()
|
|
271
255
|
return NotImplemented
|
|
272
256
|
|
|
273
|
-
def _act_on_(self, sim_state:
|
|
257
|
+
def _act_on_(self, sim_state: cirq.SimulationStateBase):
|
|
274
258
|
getter = getattr(self.gate, '_act_on_', None)
|
|
275
259
|
if getter is not None:
|
|
276
260
|
return getter(sim_state, self.qubits)
|
|
@@ -288,15 +272,11 @@ class GateOperation(raw_types.Operation):
|
|
|
288
272
|
return getter()
|
|
289
273
|
return NotImplemented
|
|
290
274
|
|
|
291
|
-
def _resolve_parameters_(
|
|
292
|
-
self, resolver: 'cirq.ParamResolver', recursive: bool
|
|
293
|
-
) -> 'cirq.Operation':
|
|
275
|
+
def _resolve_parameters_(self, resolver: cirq.ParamResolver, recursive: bool) -> cirq.Operation:
|
|
294
276
|
resolved_gate = protocols.resolve_parameters(self.gate, resolver, recursive)
|
|
295
277
|
return self.with_gate(resolved_gate)
|
|
296
278
|
|
|
297
|
-
def _circuit_diagram_info_(
|
|
298
|
-
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
299
|
-
) -> 'cirq.CircuitDiagramInfo':
|
|
279
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
300
280
|
return protocols.circuit_diagram_info(self.gate, args, NotImplemented)
|
|
301
281
|
|
|
302
282
|
def _decompose_into_clifford_(self):
|
|
@@ -311,13 +291,13 @@ class GateOperation(raw_types.Operation):
|
|
|
311
291
|
return getter()
|
|
312
292
|
return NotImplemented
|
|
313
293
|
|
|
314
|
-
def _phase_by_(self, phase_turns: float, qubit_index: int) ->
|
|
294
|
+
def _phase_by_(self, phase_turns: float, qubit_index: int) -> GateOperation:
|
|
315
295
|
phased_gate = protocols.phase_by(self.gate, phase_turns, qubit_index, default=None)
|
|
316
296
|
if phased_gate is None:
|
|
317
297
|
return NotImplemented
|
|
318
298
|
return GateOperation(phased_gate, self._qubits)
|
|
319
299
|
|
|
320
|
-
def __pow__(self, exponent: Any) ->
|
|
300
|
+
def __pow__(self, exponent: Any) -> cirq.Operation:
|
|
321
301
|
"""Raise gate to a power, then reapply to the same qubits.
|
|
322
302
|
|
|
323
303
|
Only works if the gate implements cirq.ExtrapolatableEffect.
|
|
@@ -348,7 +328,7 @@ class GateOperation(raw_types.Operation):
|
|
|
348
328
|
def __rmul__(self, other: Any) -> Any:
|
|
349
329
|
return self.gate._rmul_with_qubits(self._qubits, other)
|
|
350
330
|
|
|
351
|
-
def _qasm_(self, args:
|
|
331
|
+
def _qasm_(self, args: protocols.QasmArgs) -> str | None:
|
|
352
332
|
if isinstance(self.gate, ops.GlobalPhaseGate):
|
|
353
333
|
warnings.warn(
|
|
354
334
|
"OpenQASM 2.0 does not support global phase."
|
|
@@ -361,7 +341,7 @@ class GateOperation(raw_types.Operation):
|
|
|
361
341
|
|
|
362
342
|
def _equal_up_to_global_phase_(
|
|
363
343
|
self, other: Any, atol: float = 1e-8
|
|
364
|
-
) ->
|
|
344
|
+
) -> NotImplementedType | bool:
|
|
365
345
|
if not isinstance(other, type(self)):
|
|
366
346
|
return NotImplemented
|
|
367
347
|
if self._group_interchangeable_qubits() != other._group_interchangeable_qubits():
|
|
@@ -370,11 +350,9 @@ class GateOperation(raw_types.Operation):
|
|
|
370
350
|
|
|
371
351
|
def controlled_by(
|
|
372
352
|
self,
|
|
373
|
-
*control_qubits:
|
|
374
|
-
control_values:
|
|
375
|
-
|
|
376
|
-
] = None,
|
|
377
|
-
) -> 'cirq.Operation':
|
|
353
|
+
*control_qubits: cirq.Qid,
|
|
354
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
355
|
+
) -> cirq.Operation:
|
|
378
356
|
if len(control_qubits) == 0:
|
|
379
357
|
return self
|
|
380
358
|
qubits = tuple(control_qubits)
|
cirq/ops/gate_operation_test.py
CHANGED
|
@@ -11,8 +11,12 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
import collections.abc
|
|
15
18
|
import pathlib
|
|
19
|
+
from typing import cast
|
|
16
20
|
|
|
17
21
|
import numpy as np
|
|
18
22
|
import pytest
|
|
@@ -22,7 +26,7 @@ import cirq
|
|
|
22
26
|
import cirq.testing
|
|
23
27
|
|
|
24
28
|
|
|
25
|
-
def test_gate_operation_init():
|
|
29
|
+
def test_gate_operation_init() -> None:
|
|
26
30
|
q = cirq.NamedQubit('q')
|
|
27
31
|
g = cirq.testing.SingleQubitGate()
|
|
28
32
|
v = cirq.GateOperation(g, (q,))
|
|
@@ -30,14 +34,14 @@ def test_gate_operation_init():
|
|
|
30
34
|
assert v.qubits == (q,)
|
|
31
35
|
|
|
32
36
|
|
|
33
|
-
def test_invalid_gate_operation():
|
|
37
|
+
def test_invalid_gate_operation() -> None:
|
|
34
38
|
three_qubit_gate = cirq.testing.ThreeQubitGate()
|
|
35
39
|
single_qubit = [cirq.GridQubit(0, 0)]
|
|
36
40
|
with pytest.raises(ValueError, match="number of qubits"):
|
|
37
41
|
cirq.GateOperation(three_qubit_gate, single_qubit)
|
|
38
42
|
|
|
39
43
|
|
|
40
|
-
def test_immutable():
|
|
44
|
+
def test_immutable() -> None:
|
|
41
45
|
a, b = cirq.LineQubit.range(2)
|
|
42
46
|
op = cirq.X(a)
|
|
43
47
|
|
|
@@ -57,7 +61,7 @@ def test_immutable():
|
|
|
57
61
|
op.qubits = [b]
|
|
58
62
|
|
|
59
63
|
|
|
60
|
-
def test_gate_operation_eq():
|
|
64
|
+
def test_gate_operation_eq() -> None:
|
|
61
65
|
g1 = cirq.testing.SingleQubitGate()
|
|
62
66
|
g2 = cirq.testing.SingleQubitGate()
|
|
63
67
|
g3 = cirq.testing.TwoQubitGate()
|
|
@@ -102,7 +106,7 @@ def test_gate_operation_eq():
|
|
|
102
106
|
eq.add_equality_group(p(b0, a1, a0, b1, c0))
|
|
103
107
|
|
|
104
108
|
|
|
105
|
-
def test_gate_operation_approx_eq():
|
|
109
|
+
def test_gate_operation_approx_eq() -> None:
|
|
106
110
|
a = [cirq.NamedQubit('r1')]
|
|
107
111
|
b = [cirq.NamedQubit('r2')]
|
|
108
112
|
|
|
@@ -128,7 +132,7 @@ def test_gate_operation_approx_eq():
|
|
|
128
132
|
)
|
|
129
133
|
|
|
130
134
|
|
|
131
|
-
def test_gate_operation_qid_shape():
|
|
135
|
+
def test_gate_operation_qid_shape() -> None:
|
|
132
136
|
class ShapeGate(cirq.Gate):
|
|
133
137
|
def _qid_shape_(self):
|
|
134
138
|
return (1, 2, 3, 4)
|
|
@@ -138,7 +142,7 @@ def test_gate_operation_qid_shape():
|
|
|
138
142
|
assert cirq.num_qubits(op) == 4
|
|
139
143
|
|
|
140
144
|
|
|
141
|
-
def test_gate_operation_num_qubits():
|
|
145
|
+
def test_gate_operation_num_qubits() -> None:
|
|
142
146
|
class NumQubitsGate(cirq.Gate):
|
|
143
147
|
def _num_qubits_(self):
|
|
144
148
|
return 4
|
|
@@ -148,25 +152,25 @@ def test_gate_operation_num_qubits():
|
|
|
148
152
|
assert cirq.num_qubits(op) == 4
|
|
149
153
|
|
|
150
154
|
|
|
151
|
-
def test_gate_operation_pow():
|
|
155
|
+
def test_gate_operation_pow() -> None:
|
|
152
156
|
Y = cirq.Y
|
|
153
157
|
q = cirq.NamedQubit('q')
|
|
154
158
|
assert (Y**0.5)(q) == Y(q) ** 0.5
|
|
155
159
|
|
|
156
160
|
|
|
157
|
-
def test_with_qubits_and_transform_qubits():
|
|
161
|
+
def test_with_qubits_and_transform_qubits() -> None:
|
|
158
162
|
g = cirq.testing.ThreeQubitGate()
|
|
159
163
|
g = cirq.testing.ThreeQubitGate()
|
|
160
164
|
op = cirq.GateOperation(g, cirq.LineQubit.range(3))
|
|
161
165
|
assert op.with_qubits(*cirq.LineQubit.range(3, 0, -1)) == cirq.GateOperation(
|
|
162
166
|
g, cirq.LineQubit.range(3, 0, -1)
|
|
163
167
|
)
|
|
164
|
-
assert op.transform_qubits(
|
|
165
|
-
|
|
166
|
-
)
|
|
168
|
+
assert op.transform_qubits(
|
|
169
|
+
lambda e: cirq.LineQubit(-cast(cirq.LineQubit, e).x)
|
|
170
|
+
) == cirq.GateOperation(g, [cirq.LineQubit(0), cirq.LineQubit(-1), cirq.LineQubit(-2)])
|
|
167
171
|
|
|
168
172
|
|
|
169
|
-
def test_extrapolate():
|
|
173
|
+
def test_extrapolate() -> None:
|
|
170
174
|
q = cirq.NamedQubit('q')
|
|
171
175
|
|
|
172
176
|
# If the gate isn't extrapolatable, you get a type error.
|
|
@@ -179,7 +183,7 @@ def test_extrapolate():
|
|
|
179
183
|
assert (cirq.Y**0.5).on(q) == cirq.Y(q) ** 0.5
|
|
180
184
|
|
|
181
185
|
|
|
182
|
-
def test_inverse():
|
|
186
|
+
def test_inverse() -> None:
|
|
183
187
|
q = cirq.NamedQubit('q')
|
|
184
188
|
|
|
185
189
|
# If the gate isn't reversible, you get a type error.
|
|
@@ -191,7 +195,7 @@ def test_inverse():
|
|
|
191
195
|
assert cirq.inverse(cirq.S).on(q) == cirq.inverse(cirq.S.on(q))
|
|
192
196
|
|
|
193
197
|
|
|
194
|
-
def test_text_diagrammable():
|
|
198
|
+
def test_text_diagrammable() -> None:
|
|
195
199
|
q = cirq.NamedQubit('q')
|
|
196
200
|
|
|
197
201
|
# If the gate isn't diagrammable, you get a type error.
|
|
@@ -205,7 +209,7 @@ def test_text_diagrammable():
|
|
|
205
209
|
assert actual == expected
|
|
206
210
|
|
|
207
211
|
|
|
208
|
-
def test_bounded_effect():
|
|
212
|
+
def test_bounded_effect() -> None:
|
|
209
213
|
q = cirq.NamedQubit('q')
|
|
210
214
|
|
|
211
215
|
# If the gate isn't bounded, you get a type error.
|
|
@@ -217,7 +221,7 @@ def test_bounded_effect():
|
|
|
217
221
|
|
|
218
222
|
|
|
219
223
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
220
|
-
def test_parameterizable_effect(resolve_fn):
|
|
224
|
+
def test_parameterizable_effect(resolve_fn) -> None:
|
|
221
225
|
q = cirq.NamedQubit('q')
|
|
222
226
|
r = cirq.ParamResolver({'a': 0.5})
|
|
223
227
|
|
|
@@ -228,7 +232,7 @@ def test_parameterizable_effect(resolve_fn):
|
|
|
228
232
|
assert op2 == cirq.S.on(q)
|
|
229
233
|
|
|
230
234
|
|
|
231
|
-
def test_pauli_expansion():
|
|
235
|
+
def test_pauli_expansion() -> None:
|
|
232
236
|
a = cirq.NamedQubit('a')
|
|
233
237
|
b = cirq.NamedQubit('b')
|
|
234
238
|
|
|
@@ -250,7 +254,7 @@ def test_pauli_expansion():
|
|
|
250
254
|
assert cirq.pauli_expansion(Yes().on(a)) == cirq.LinearDict({'X': 0.5})
|
|
251
255
|
|
|
252
256
|
|
|
253
|
-
def test_unitary():
|
|
257
|
+
def test_unitary() -> None:
|
|
254
258
|
a = cirq.NamedQubit('a')
|
|
255
259
|
b = cirq.NamedQubit('b')
|
|
256
260
|
|
|
@@ -260,7 +264,7 @@ def test_unitary():
|
|
|
260
264
|
np.testing.assert_allclose(cirq.unitary(cirq.CNOT(a, b)), cirq.unitary(cirq.CNOT), atol=1e-8)
|
|
261
265
|
|
|
262
266
|
|
|
263
|
-
def test_channel():
|
|
267
|
+
def test_channel() -> None:
|
|
264
268
|
a = cirq.NamedQubit('a')
|
|
265
269
|
op = cirq.bit_flip(0.5).on(a)
|
|
266
270
|
np.testing.assert_allclose(cirq.kraus(op), cirq.kraus(op.gate))
|
|
@@ -270,19 +274,19 @@ def test_channel():
|
|
|
270
274
|
assert not cirq.has_kraus(cirq.testing.SingleQubitGate()(a))
|
|
271
275
|
|
|
272
276
|
|
|
273
|
-
def test_measurement_key():
|
|
277
|
+
def test_measurement_key() -> None:
|
|
274
278
|
a = cirq.NamedQubit('a')
|
|
275
279
|
assert cirq.measurement_key_name(cirq.measure(a, key='lock')) == 'lock'
|
|
276
280
|
|
|
277
281
|
|
|
278
|
-
def assert_mixtures_equal(actual, expected):
|
|
282
|
+
def assert_mixtures_equal(actual, expected) -> None:
|
|
279
283
|
"""Assert equal for tuple of mixed scalar and array types."""
|
|
280
284
|
for a, e in zip(actual, expected):
|
|
281
285
|
np.testing.assert_almost_equal(a[0], e[0])
|
|
282
286
|
np.testing.assert_almost_equal(a[1], e[1])
|
|
283
287
|
|
|
284
288
|
|
|
285
|
-
def test_mixture():
|
|
289
|
+
def test_mixture() -> None:
|
|
286
290
|
a = cirq.NamedQubit('a')
|
|
287
291
|
op = cirq.bit_flip(0.5).on(a)
|
|
288
292
|
assert_mixtures_equal(cirq.mixture(op), cirq.mixture(op.gate))
|
|
@@ -295,7 +299,7 @@ def test_mixture():
|
|
|
295
299
|
np.testing.assert_allclose(m[0][1], cirq.unitary(cirq.X))
|
|
296
300
|
|
|
297
301
|
|
|
298
|
-
def test_repr():
|
|
302
|
+
def test_repr() -> None:
|
|
299
303
|
a, b = cirq.LineQubit.range(2)
|
|
300
304
|
assert (
|
|
301
305
|
repr(cirq.GateOperation(cirq.CZ, (a, b))) == 'cirq.CZ(cirq.LineQubit(0), cirq.LineQubit(1))'
|
|
@@ -324,7 +328,7 @@ def test_repr():
|
|
|
324
328
|
(cirq.Z ** sympy.Symbol('e'), cirq.Z ** sympy.Symbol('f'), False),
|
|
325
329
|
],
|
|
326
330
|
)
|
|
327
|
-
def test_equal_up_to_global_phase_on_gates(gate1, gate2, eq_up_to_global_phase):
|
|
331
|
+
def test_equal_up_to_global_phase_on_gates(gate1, gate2, eq_up_to_global_phase) -> None:
|
|
328
332
|
num_qubits1, num_qubits2 = (cirq.num_qubits(g) for g in (gate1, gate2))
|
|
329
333
|
qubits = cirq.LineQubit.range(max(num_qubits1, num_qubits2) + 1)
|
|
330
334
|
op1, op2 = gate1(*qubits[:num_qubits1]), gate2(*qubits[:num_qubits2])
|
|
@@ -333,12 +337,12 @@ def test_equal_up_to_global_phase_on_gates(gate1, gate2, eq_up_to_global_phase):
|
|
|
333
337
|
assert not cirq.equal_up_to_global_phase(op1, op2_on_diff_qubits)
|
|
334
338
|
|
|
335
339
|
|
|
336
|
-
def test_equal_up_to_global_phase_on_diff_types():
|
|
340
|
+
def test_equal_up_to_global_phase_on_diff_types() -> None:
|
|
337
341
|
op = cirq.X(cirq.LineQubit(0))
|
|
338
342
|
assert not cirq.equal_up_to_global_phase(op, 3)
|
|
339
343
|
|
|
340
344
|
|
|
341
|
-
def test_gate_on_operation_besides_gate_operation():
|
|
345
|
+
def test_gate_on_operation_besides_gate_operation() -> None:
|
|
342
346
|
a, b = cirq.LineQubit.range(2)
|
|
343
347
|
|
|
344
348
|
op = -1j * cirq.X(a) * cirq.Y(b)
|
|
@@ -347,7 +351,7 @@ def test_gate_on_operation_besides_gate_operation():
|
|
|
347
351
|
assert not isinstance(op.gate, cirq.XPowGate)
|
|
348
352
|
|
|
349
353
|
|
|
350
|
-
def test_mul():
|
|
354
|
+
def test_mul() -> None:
|
|
351
355
|
class GateRMul(cirq.Gate):
|
|
352
356
|
def num_qubits(self) -> int:
|
|
353
357
|
return 1
|
|
@@ -373,29 +377,29 @@ def test_mul():
|
|
|
373
377
|
# Delegates right multiplication.
|
|
374
378
|
q = cirq.LineQubit(0)
|
|
375
379
|
r = GateRMul().on(q)
|
|
376
|
-
assert 2 * r == 3
|
|
380
|
+
assert 2 * r == 3 # type: ignore[operator]
|
|
377
381
|
with pytest.raises(TypeError):
|
|
378
|
-
_ = r * 2
|
|
382
|
+
_ = r * 2 # type: ignore[operator]
|
|
379
383
|
|
|
380
384
|
# Delegates left multiplication.
|
|
381
385
|
m = GateMul().on(q)
|
|
382
|
-
assert m * 2 == 5
|
|
386
|
+
assert m * 2 == 5 # type: ignore[operator]
|
|
383
387
|
with pytest.raises(TypeError):
|
|
384
|
-
_ = 2 * m
|
|
388
|
+
_ = 2 * m # type: ignore[operator]
|
|
385
389
|
|
|
386
390
|
# Handles the symmetric type case correctly.
|
|
387
|
-
assert m * m == 6
|
|
388
|
-
assert r * r == 4
|
|
391
|
+
assert m * m == 6 # type: ignore[operator]
|
|
392
|
+
assert r * r == 4 # type: ignore[operator]
|
|
389
393
|
|
|
390
394
|
|
|
391
|
-
def test_with_gate():
|
|
395
|
+
def test_with_gate() -> None:
|
|
392
396
|
g1 = cirq.GateOperation(cirq.X, cirq.LineQubit.range(1))
|
|
393
397
|
g2 = cirq.GateOperation(cirq.Y, cirq.LineQubit.range(1))
|
|
394
398
|
assert g1.with_gate(cirq.X) is g1
|
|
395
399
|
assert g1.with_gate(cirq.Y) == g2
|
|
396
400
|
|
|
397
401
|
|
|
398
|
-
def test_with_measurement_key_mapping():
|
|
402
|
+
def test_with_measurement_key_mapping() -> None:
|
|
399
403
|
a = cirq.LineQubit(0)
|
|
400
404
|
op = cirq.measure(a, key='m')
|
|
401
405
|
|
|
@@ -404,7 +408,7 @@ def test_with_measurement_key_mapping():
|
|
|
404
408
|
assert cirq.with_measurement_key_mapping(op, {'x': 'k'}) is op
|
|
405
409
|
|
|
406
410
|
|
|
407
|
-
def test_with_key_path():
|
|
411
|
+
def test_with_key_path() -> None:
|
|
408
412
|
a = cirq.LineQubit(0)
|
|
409
413
|
op = cirq.measure(a, key='m')
|
|
410
414
|
|
|
@@ -417,7 +421,7 @@ def test_with_key_path():
|
|
|
417
421
|
assert cirq.with_key_path(cirq.X(a), ('a', 'b')) is NotImplemented
|
|
418
422
|
|
|
419
423
|
|
|
420
|
-
def test_with_key_path_prefix():
|
|
424
|
+
def test_with_key_path_prefix() -> None:
|
|
421
425
|
a = cirq.LineQubit(0)
|
|
422
426
|
op = cirq.measure(a, key='m')
|
|
423
427
|
remap_op = cirq.with_key_path_prefix(op, ('a', 'b'))
|
|
@@ -427,14 +431,14 @@ def test_with_key_path_prefix():
|
|
|
427
431
|
assert cirq.with_key_path_prefix(cirq.X(a), ('a', 'b')) is NotImplemented
|
|
428
432
|
|
|
429
433
|
|
|
430
|
-
def test_cannot_remap_non_measurement_gate():
|
|
434
|
+
def test_cannot_remap_non_measurement_gate() -> None:
|
|
431
435
|
a = cirq.LineQubit(0)
|
|
432
436
|
op = cirq.X(a)
|
|
433
437
|
|
|
434
438
|
assert cirq.with_measurement_key_mapping(op, {'m': 'k'}) is NotImplemented
|
|
435
439
|
|
|
436
440
|
|
|
437
|
-
def test_is_parameterized():
|
|
441
|
+
def test_is_parameterized() -> None:
|
|
438
442
|
class No1(cirq.testing.SingleQubitGate):
|
|
439
443
|
def num_qubits(self) -> int:
|
|
440
444
|
return 1
|
|
@@ -460,7 +464,7 @@ def test_is_parameterized():
|
|
|
460
464
|
assert cirq.is_parameterized(Yes().on(q))
|
|
461
465
|
|
|
462
466
|
|
|
463
|
-
def test_group_interchangeable_qubits_creates_tuples_with_unique_keys():
|
|
467
|
+
def test_group_interchangeable_qubits_creates_tuples_with_unique_keys() -> None:
|
|
464
468
|
class MyGate(cirq.Gate, cirq.InterchangeableQubitsGate):
|
|
465
469
|
def __init__(self, num_qubits) -> None:
|
|
466
470
|
self._num_qubits = num_qubits
|
|
@@ -481,7 +485,7 @@ def test_group_interchangeable_qubits_creates_tuples_with_unique_keys():
|
|
|
481
485
|
)
|
|
482
486
|
|
|
483
487
|
|
|
484
|
-
def test_gate_to_operation_to_gate_round_trips():
|
|
488
|
+
def test_gate_to_operation_to_gate_round_trips() -> None:
|
|
485
489
|
def all_subclasses(cls):
|
|
486
490
|
return set(cls.__subclasses__()).union(
|
|
487
491
|
[s for c in cls.__subclasses__() for s in all_subclasses(c)]
|