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/common_gates.py
CHANGED
|
@@ -25,19 +25,10 @@ Each of these are implemented as EigenGates, which means that they can be
|
|
|
25
25
|
raised to a power (i.e. cirq.H**0.5). See the definition in EigenGate.
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
28
30
|
from types import NotImplementedType
|
|
29
|
-
from typing import
|
|
30
|
-
Any,
|
|
31
|
-
cast,
|
|
32
|
-
Collection,
|
|
33
|
-
Dict,
|
|
34
|
-
List,
|
|
35
|
-
Optional,
|
|
36
|
-
Sequence,
|
|
37
|
-
Tuple,
|
|
38
|
-
TYPE_CHECKING,
|
|
39
|
-
Union,
|
|
40
|
-
)
|
|
31
|
+
from typing import Any, cast, Collection, Sequence
|
|
41
32
|
|
|
42
33
|
import numpy as np
|
|
43
34
|
import sympy
|
|
@@ -46,13 +37,17 @@ import cirq
|
|
|
46
37
|
from cirq import protocols, value
|
|
47
38
|
from cirq._compat import proper_repr
|
|
48
39
|
from cirq._doc import document
|
|
49
|
-
from cirq.ops import
|
|
40
|
+
from cirq.ops import (
|
|
41
|
+
control_values as cv,
|
|
42
|
+
controlled_gate,
|
|
43
|
+
eigen_gate,
|
|
44
|
+
gate_features,
|
|
45
|
+
global_phase_op,
|
|
46
|
+
raw_types,
|
|
47
|
+
)
|
|
50
48
|
from cirq.ops.measurement_gate import MeasurementGate
|
|
51
49
|
from cirq.ops.swap_gates import ISWAP, ISwapPowGate, SWAP, SwapPowGate
|
|
52
50
|
|
|
53
|
-
if TYPE_CHECKING:
|
|
54
|
-
import cirq
|
|
55
|
-
|
|
56
51
|
assert all(
|
|
57
52
|
[ISWAP, SWAP, ISwapPowGate, SwapPowGate, MeasurementGate]
|
|
58
53
|
), """
|
|
@@ -87,7 +82,7 @@ class XPowGate(eigen_gate.EigenGate):
|
|
|
87
82
|
`cirq.X`, the Pauli X gate, is an instance of this gate at `exponent=1`.
|
|
88
83
|
"""
|
|
89
84
|
|
|
90
|
-
_eigencomponents:
|
|
85
|
+
_eigencomponents: dict[int, list[tuple[float, np.ndarray]]] = {}
|
|
91
86
|
|
|
92
87
|
def __init__(
|
|
93
88
|
self, *, exponent: value.TParamVal = 1.0, global_shift: float = 0.0, dimension: int = 2
|
|
@@ -126,7 +121,7 @@ class XPowGate(eigen_gate.EigenGate):
|
|
|
126
121
|
def _num_qubits_(self) -> int:
|
|
127
122
|
return 1
|
|
128
123
|
|
|
129
|
-
def _apply_unitary_(self, args:
|
|
124
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
130
125
|
if self._exponent != 1 or self._dimension != 2:
|
|
131
126
|
return NotImplemented
|
|
132
127
|
zero = args.subspace_index(0)
|
|
@@ -138,18 +133,18 @@ class XPowGate(eigen_gate.EigenGate):
|
|
|
138
133
|
args.available_buffer *= p
|
|
139
134
|
return args.available_buffer
|
|
140
135
|
|
|
141
|
-
def in_su2(self) ->
|
|
136
|
+
def in_su2(self) -> Rx:
|
|
142
137
|
"""Returns an equal-up-global-phase gate from the group SU2."""
|
|
143
138
|
return Rx(rads=self._exponent * _pi(self._exponent))
|
|
144
139
|
|
|
145
|
-
def with_canonical_global_phase(self) ->
|
|
140
|
+
def with_canonical_global_phase(self) -> XPowGate:
|
|
146
141
|
"""Returns an equal-up-global-phase standardized form of the gate."""
|
|
147
142
|
return XPowGate(exponent=self._exponent, dimension=self._dimension)
|
|
148
143
|
|
|
149
|
-
def _qid_shape_(self) ->
|
|
144
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
150
145
|
return (self._dimension,)
|
|
151
146
|
|
|
152
|
-
def _eigen_components(self) ->
|
|
147
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
153
148
|
if self._dimension not in XPowGate._eigencomponents:
|
|
154
149
|
components = []
|
|
155
150
|
root = 1j ** (4 / self._dimension)
|
|
@@ -161,7 +156,7 @@ class XPowGate(eigen_gate.EigenGate):
|
|
|
161
156
|
XPowGate._eigencomponents[self._dimension] = components
|
|
162
157
|
return XPowGate._eigencomponents[self._dimension]
|
|
163
158
|
|
|
164
|
-
def _with_exponent(self, exponent:
|
|
159
|
+
def _with_exponent(self, exponent: cirq.TParamVal) -> cirq.XPowGate:
|
|
165
160
|
return XPowGate(
|
|
166
161
|
exponent=exponent, global_shift=self._global_shift, dimension=self._dimension
|
|
167
162
|
)
|
|
@@ -179,18 +174,16 @@ class XPowGate(eigen_gate.EigenGate):
|
|
|
179
174
|
return SingleQubitCliffordGate.X_nsqrt.on(*qubits)
|
|
180
175
|
return NotImplemented # pragma: no cover
|
|
181
176
|
|
|
182
|
-
def _trace_distance_bound_(self) ->
|
|
177
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
183
178
|
if self._is_parameterized_() or self._dimension != 2:
|
|
184
179
|
return None
|
|
185
180
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
186
181
|
|
|
187
182
|
def controlled(
|
|
188
183
|
self,
|
|
189
|
-
num_controls:
|
|
190
|
-
control_values:
|
|
191
|
-
|
|
192
|
-
] = None,
|
|
193
|
-
control_qid_shape: Optional[Tuple[int, ...]] = None,
|
|
184
|
+
num_controls: int | None = None,
|
|
185
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
186
|
+
control_qid_shape: tuple[int, ...] | None = None,
|
|
194
187
|
) -> raw_types.Gate:
|
|
195
188
|
"""Returns a controlled `XPowGate`, using a `CXPowGate` where possible.
|
|
196
189
|
|
|
@@ -236,27 +229,24 @@ class XPowGate(eigen_gate.EigenGate):
|
|
|
236
229
|
A `cirq.ControlledGate` (or `cirq.CXPowGate` if possible) representing
|
|
237
230
|
`self` controlled by the given control values and qubits.
|
|
238
231
|
"""
|
|
239
|
-
if control_values and not isinstance(control_values, cv.AbstractControlValues):
|
|
240
|
-
control_values = cv.ProductOfSums(
|
|
241
|
-
tuple(
|
|
242
|
-
(val,) if isinstance(val, int) else tuple(sorted(val)) for val in control_values
|
|
243
|
-
)
|
|
244
|
-
)
|
|
245
232
|
result = super().controlled(num_controls, control_values, control_qid_shape)
|
|
246
233
|
if (
|
|
247
234
|
self._global_shift == 0
|
|
248
235
|
and isinstance(result, controlled_gate.ControlledGate)
|
|
249
236
|
and isinstance(result.control_values, cv.ProductOfSums)
|
|
250
|
-
and result.control_values
|
|
251
|
-
and result.control_qid_shape[-1] == 2
|
|
237
|
+
and result.control_values.is_trivial
|
|
252
238
|
):
|
|
253
|
-
|
|
254
|
-
exponent=self._exponent
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
)
|
|
239
|
+
if result.control_qid_shape == (2,):
|
|
240
|
+
return cirq.CXPowGate(exponent=self._exponent)
|
|
241
|
+
if result.control_qid_shape == (2, 2):
|
|
242
|
+
return cirq.CCXPowGate(exponent=self._exponent)
|
|
258
243
|
return result
|
|
259
244
|
|
|
245
|
+
def _decompose_with_context_(
|
|
246
|
+
self, qubits: tuple[cirq.Qid, ...], context: cirq.DecompositionContext
|
|
247
|
+
) -> list[cirq.Operation] | NotImplementedType:
|
|
248
|
+
return _extract_phase(self, XPowGate, qubits, context)
|
|
249
|
+
|
|
260
250
|
def _pauli_expansion_(self) -> value.LinearDict[str]:
|
|
261
251
|
if self._dimension != 2:
|
|
262
252
|
return NotImplemented # pragma: no cover
|
|
@@ -266,13 +256,13 @@ class XPowGate(eigen_gate.EigenGate):
|
|
|
266
256
|
return value.LinearDict({'I': phase * lib.cos(angle), 'X': -1j * phase * lib.sin(angle)})
|
|
267
257
|
|
|
268
258
|
def _circuit_diagram_info_(
|
|
269
|
-
self, args:
|
|
270
|
-
) ->
|
|
259
|
+
self, args: cirq.CircuitDiagramInfoArgs
|
|
260
|
+
) -> str | protocols.CircuitDiagramInfo:
|
|
271
261
|
return protocols.CircuitDiagramInfo(
|
|
272
262
|
wire_symbols=('X',), exponent=self._diagram_exponent(args)
|
|
273
263
|
)
|
|
274
264
|
|
|
275
|
-
def _qasm_(self, args:
|
|
265
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
276
266
|
args.validate_version('2.0', '3.0')
|
|
277
267
|
if self._global_shift == 0:
|
|
278
268
|
if self._exponent == 1:
|
|
@@ -291,7 +281,7 @@ class XPowGate(eigen_gate.EigenGate):
|
|
|
291
281
|
"""See `cirq.SupportsPhase`."""
|
|
292
282
|
return _phased_x_or_pauli_gate(exponent=self._exponent, phase_exponent=phase_turns * 2)
|
|
293
283
|
|
|
294
|
-
def _has_stabilizer_effect_(self) ->
|
|
284
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
295
285
|
if self._is_parameterized_() or self._dimension != 2:
|
|
296
286
|
return None
|
|
297
287
|
return self.exponent % 0.5 == 0
|
|
@@ -318,7 +308,7 @@ class XPowGate(eigen_gate.EigenGate):
|
|
|
318
308
|
all_args = ', '.join(args)
|
|
319
309
|
return f'cirq.XPowGate({all_args})'
|
|
320
310
|
|
|
321
|
-
def _json_dict_(self) ->
|
|
311
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
322
312
|
d = protocols.obj_to_dict_helper(self, ['exponent', 'global_shift'])
|
|
323
313
|
if self.dimension != 2:
|
|
324
314
|
d['dimension'] = self.dimension
|
|
@@ -349,12 +339,12 @@ class Rx(XPowGate):
|
|
|
349
339
|
self._rads = rads
|
|
350
340
|
super().__init__(exponent=rads / _pi(rads), global_shift=-0.5)
|
|
351
341
|
|
|
352
|
-
def _with_exponent(self, exponent: value.TParamVal) ->
|
|
342
|
+
def _with_exponent(self, exponent: value.TParamVal) -> Rx:
|
|
353
343
|
return Rx(rads=exponent * _pi(exponent))
|
|
354
344
|
|
|
355
345
|
def _circuit_diagram_info_(
|
|
356
|
-
self, args:
|
|
357
|
-
) ->
|
|
346
|
+
self, args: cirq.CircuitDiagramInfoArgs
|
|
347
|
+
) -> str | protocols.CircuitDiagramInfo:
|
|
358
348
|
angle_str = self._format_exponent_as_angle(args)
|
|
359
349
|
return f'Rx({angle_str})'
|
|
360
350
|
|
|
@@ -366,15 +356,15 @@ class Rx(XPowGate):
|
|
|
366
356
|
def __repr__(self) -> str:
|
|
367
357
|
return f'cirq.Rx(rads={proper_repr(self._rads)})'
|
|
368
358
|
|
|
369
|
-
def _qasm_(self, args:
|
|
359
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
370
360
|
args.validate_version('2.0', '3.0')
|
|
371
361
|
return args.format('rx({0:half_turns}) {1};\n', self._exponent, qubits[0])
|
|
372
362
|
|
|
373
|
-
def _json_dict_(self) ->
|
|
363
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
374
364
|
return {'rads': self._rads}
|
|
375
365
|
|
|
376
366
|
@classmethod
|
|
377
|
-
def _from_json_dict_(cls, rads, **kwargs) ->
|
|
367
|
+
def _from_json_dict_(cls, rads, **kwargs) -> Rx:
|
|
378
368
|
return cls(rads=rads)
|
|
379
369
|
|
|
380
370
|
|
|
@@ -412,7 +402,7 @@ class YPowGate(eigen_gate.EigenGate):
|
|
|
412
402
|
def _num_qubits_(self) -> int:
|
|
413
403
|
return 1
|
|
414
404
|
|
|
415
|
-
def _apply_unitary_(self, args:
|
|
405
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
416
406
|
if self._exponent != 1:
|
|
417
407
|
return NotImplemented
|
|
418
408
|
zero = args.subspace_index(0)
|
|
@@ -424,11 +414,11 @@ class YPowGate(eigen_gate.EigenGate):
|
|
|
424
414
|
args.available_buffer *= p
|
|
425
415
|
return args.available_buffer
|
|
426
416
|
|
|
427
|
-
def in_su2(self) ->
|
|
417
|
+
def in_su2(self) -> Ry:
|
|
428
418
|
"""Returns an equal-up-global-phase gate from the group SU2."""
|
|
429
419
|
return Ry(rads=self._exponent * _pi(self._exponent))
|
|
430
420
|
|
|
431
|
-
def with_canonical_global_phase(self) ->
|
|
421
|
+
def with_canonical_global_phase(self) -> YPowGate:
|
|
432
422
|
"""Returns an equal-up-global-phase standardized form of the gate."""
|
|
433
423
|
return YPowGate(exponent=self._exponent)
|
|
434
424
|
|
|
@@ -445,13 +435,13 @@ class YPowGate(eigen_gate.EigenGate):
|
|
|
445
435
|
return SingleQubitCliffordGate.Y_nsqrt.on(*qubits)
|
|
446
436
|
return NotImplemented # pragma: no cover
|
|
447
437
|
|
|
448
|
-
def _eigen_components(self) ->
|
|
438
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
449
439
|
return [
|
|
450
440
|
(0, np.array([[0.5, -0.5j], [0.5j, 0.5]])),
|
|
451
441
|
(1, np.array([[0.5, 0.5j], [-0.5j, 0.5]])),
|
|
452
442
|
]
|
|
453
443
|
|
|
454
|
-
def _trace_distance_bound_(self) ->
|
|
444
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
455
445
|
if self._is_parameterized_():
|
|
456
446
|
return None
|
|
457
447
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
@@ -463,13 +453,13 @@ class YPowGate(eigen_gate.EigenGate):
|
|
|
463
453
|
return value.LinearDict({'I': phase * lib.cos(angle), 'Y': -1j * phase * lib.sin(angle)})
|
|
464
454
|
|
|
465
455
|
def _circuit_diagram_info_(
|
|
466
|
-
self, args:
|
|
467
|
-
) ->
|
|
456
|
+
self, args: cirq.CircuitDiagramInfoArgs
|
|
457
|
+
) -> str | protocols.CircuitDiagramInfo:
|
|
468
458
|
return protocols.CircuitDiagramInfo(
|
|
469
459
|
wire_symbols=('Y',), exponent=self._diagram_exponent(args)
|
|
470
460
|
)
|
|
471
461
|
|
|
472
|
-
def _qasm_(self, args:
|
|
462
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
473
463
|
args.validate_version('2.0', '3.0')
|
|
474
464
|
if self._exponent == 1 and self.global_shift != -0.5:
|
|
475
465
|
return args.format('y {0};\n', qubits[0])
|
|
@@ -486,7 +476,7 @@ class YPowGate(eigen_gate.EigenGate):
|
|
|
486
476
|
exponent=self._exponent, phase_exponent=0.5 + phase_turns * 2
|
|
487
477
|
)
|
|
488
478
|
|
|
489
|
-
def _has_stabilizer_effect_(self) ->
|
|
479
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
490
480
|
if self._is_parameterized_():
|
|
491
481
|
return None
|
|
492
482
|
return self.exponent % 0.5 == 0
|
|
@@ -509,6 +499,11 @@ class YPowGate(eigen_gate.EigenGate):
|
|
|
509
499
|
f'global_shift={self._global_shift!r})'
|
|
510
500
|
)
|
|
511
501
|
|
|
502
|
+
def _decompose_with_context_(
|
|
503
|
+
self, qubits: tuple[cirq.Qid, ...], context: cirq.DecompositionContext
|
|
504
|
+
) -> list[cirq.Operation] | NotImplementedType:
|
|
505
|
+
return _extract_phase(self, YPowGate, qubits, context)
|
|
506
|
+
|
|
512
507
|
|
|
513
508
|
class Ry(YPowGate):
|
|
514
509
|
r"""A gate with matrix $e^{-i Y t/2}$ that rotates around the Y axis of the Bloch sphere by $t$.
|
|
@@ -534,12 +529,12 @@ class Ry(YPowGate):
|
|
|
534
529
|
self._rads = rads
|
|
535
530
|
super().__init__(exponent=rads / _pi(rads), global_shift=-0.5)
|
|
536
531
|
|
|
537
|
-
def _with_exponent(self, exponent: value.TParamVal) ->
|
|
532
|
+
def _with_exponent(self, exponent: value.TParamVal) -> Ry:
|
|
538
533
|
return Ry(rads=exponent * _pi(exponent))
|
|
539
534
|
|
|
540
535
|
def _circuit_diagram_info_(
|
|
541
|
-
self, args:
|
|
542
|
-
) ->
|
|
536
|
+
self, args: cirq.CircuitDiagramInfoArgs
|
|
537
|
+
) -> str | protocols.CircuitDiagramInfo:
|
|
543
538
|
angle_str = self._format_exponent_as_angle(args)
|
|
544
539
|
return f'Ry({angle_str})'
|
|
545
540
|
|
|
@@ -551,15 +546,15 @@ class Ry(YPowGate):
|
|
|
551
546
|
def __repr__(self) -> str:
|
|
552
547
|
return f'cirq.Ry(rads={proper_repr(self._rads)})'
|
|
553
548
|
|
|
554
|
-
def _qasm_(self, args:
|
|
549
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
555
550
|
args.validate_version('2.0', '3.0')
|
|
556
551
|
return args.format('ry({0:half_turns}) {1};\n', self._exponent, qubits[0])
|
|
557
552
|
|
|
558
|
-
def _json_dict_(self) ->
|
|
553
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
559
554
|
return {'rads': self._rads}
|
|
560
555
|
|
|
561
556
|
@classmethod
|
|
562
|
-
def _from_json_dict_(cls, rads, **kwargs) ->
|
|
557
|
+
def _from_json_dict_(cls, rads, **kwargs) -> Ry:
|
|
563
558
|
return cls(rads=rads)
|
|
564
559
|
|
|
565
560
|
|
|
@@ -585,7 +580,7 @@ class ZPowGate(eigen_gate.EigenGate):
|
|
|
585
580
|
`cirq.Z`, the Pauli Z gate, is an instance of this gate at `exponent=1`.
|
|
586
581
|
"""
|
|
587
582
|
|
|
588
|
-
_eigencomponents:
|
|
583
|
+
_eigencomponents: dict[int, list[tuple[float, np.ndarray]]] = {}
|
|
589
584
|
|
|
590
585
|
def __init__(
|
|
591
586
|
self, *, exponent: value.TParamVal = 1.0, global_shift: float = 0.0, dimension: int = 2
|
|
@@ -624,7 +619,7 @@ class ZPowGate(eigen_gate.EigenGate):
|
|
|
624
619
|
def _num_qubits_(self) -> int:
|
|
625
620
|
return 1
|
|
626
621
|
|
|
627
|
-
def _apply_unitary_(self, args:
|
|
622
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
628
623
|
if protocols.is_parameterized(self):
|
|
629
624
|
return None
|
|
630
625
|
|
|
@@ -650,21 +645,19 @@ class ZPowGate(eigen_gate.EigenGate):
|
|
|
650
645
|
return SingleQubitCliffordGate.Z_nsqrt.on(*qubits)
|
|
651
646
|
return NotImplemented # pragma: no cover
|
|
652
647
|
|
|
653
|
-
def in_su2(self) ->
|
|
648
|
+
def in_su2(self) -> Rz:
|
|
654
649
|
"""Returns an equal-up-global-phase gate from the group SU2."""
|
|
655
650
|
return Rz(rads=self._exponent * _pi(self._exponent))
|
|
656
651
|
|
|
657
|
-
def with_canonical_global_phase(self) ->
|
|
652
|
+
def with_canonical_global_phase(self) -> ZPowGate:
|
|
658
653
|
"""Returns an equal-up-global-phase standardized form of the gate."""
|
|
659
654
|
return ZPowGate(exponent=self._exponent, dimension=self._dimension)
|
|
660
655
|
|
|
661
656
|
def controlled(
|
|
662
657
|
self,
|
|
663
|
-
num_controls:
|
|
664
|
-
control_values:
|
|
665
|
-
|
|
666
|
-
] = None,
|
|
667
|
-
control_qid_shape: Optional[Tuple[int, ...]] = None,
|
|
658
|
+
num_controls: int | None = None,
|
|
659
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
660
|
+
control_qid_shape: tuple[int, ...] | None = None,
|
|
668
661
|
) -> raw_types.Gate:
|
|
669
662
|
"""Returns a controlled `ZPowGate`, using a `CZPowGate` where possible.
|
|
670
663
|
|
|
@@ -710,31 +703,28 @@ class ZPowGate(eigen_gate.EigenGate):
|
|
|
710
703
|
A `cirq.ControlledGate` (or `cirq.CZPowGate` if possible) representing
|
|
711
704
|
`self` controlled by the given control values and qubits.
|
|
712
705
|
"""
|
|
713
|
-
if control_values and not isinstance(control_values, cv.AbstractControlValues):
|
|
714
|
-
control_values = cv.ProductOfSums(
|
|
715
|
-
tuple(
|
|
716
|
-
(val,) if isinstance(val, int) else tuple(sorted(val)) for val in control_values
|
|
717
|
-
)
|
|
718
|
-
)
|
|
719
706
|
result = super().controlled(num_controls, control_values, control_qid_shape)
|
|
720
707
|
if (
|
|
721
708
|
self._global_shift == 0
|
|
722
709
|
and isinstance(result, controlled_gate.ControlledGate)
|
|
723
710
|
and isinstance(result.control_values, cv.ProductOfSums)
|
|
724
|
-
and result.control_values
|
|
725
|
-
and result.control_qid_shape[-1] == 2
|
|
711
|
+
and result.control_values.is_trivial
|
|
726
712
|
):
|
|
727
|
-
|
|
728
|
-
exponent=self._exponent
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
)
|
|
713
|
+
if result.control_qid_shape == (2,):
|
|
714
|
+
return cirq.CZPowGate(exponent=self._exponent)
|
|
715
|
+
if result.control_qid_shape == (2, 2):
|
|
716
|
+
return cirq.CCZPowGate(exponent=self._exponent)
|
|
732
717
|
return result
|
|
733
718
|
|
|
734
|
-
def
|
|
719
|
+
def _decompose_with_context_(
|
|
720
|
+
self, qubits: tuple[cirq.Qid, ...], context: cirq.DecompositionContext
|
|
721
|
+
) -> list[cirq.Operation] | NotImplementedType:
|
|
722
|
+
return _extract_phase(self, ZPowGate, qubits, context)
|
|
723
|
+
|
|
724
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
735
725
|
return (self._dimension,)
|
|
736
726
|
|
|
737
|
-
def _eigen_components(self) ->
|
|
727
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
738
728
|
if self._dimension not in ZPowGate._eigencomponents:
|
|
739
729
|
components = []
|
|
740
730
|
for i in range(self._dimension):
|
|
@@ -745,12 +735,12 @@ class ZPowGate(eigen_gate.EigenGate):
|
|
|
745
735
|
ZPowGate._eigencomponents[self._dimension] = components
|
|
746
736
|
return ZPowGate._eigencomponents[self._dimension]
|
|
747
737
|
|
|
748
|
-
def _with_exponent(self, exponent:
|
|
738
|
+
def _with_exponent(self, exponent: cirq.TParamVal) -> cirq.ZPowGate:
|
|
749
739
|
return ZPowGate(
|
|
750
740
|
exponent=exponent, global_shift=self._global_shift, dimension=self._dimension
|
|
751
741
|
)
|
|
752
742
|
|
|
753
|
-
def _trace_distance_bound_(self) ->
|
|
743
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
754
744
|
if self._is_parameterized_() or self._dimension != 2:
|
|
755
745
|
return None
|
|
756
746
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
@@ -766,14 +756,14 @@ class ZPowGate(eigen_gate.EigenGate):
|
|
|
766
756
|
def _phase_by_(self, phase_turns: float, qubit_index: int):
|
|
767
757
|
return self
|
|
768
758
|
|
|
769
|
-
def _has_stabilizer_effect_(self) ->
|
|
759
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
770
760
|
if self._is_parameterized_() or self._dimension != 2:
|
|
771
761
|
return None
|
|
772
762
|
return self.exponent % 0.5 == 0
|
|
773
763
|
|
|
774
764
|
def _circuit_diagram_info_(
|
|
775
|
-
self, args:
|
|
776
|
-
) ->
|
|
765
|
+
self, args: cirq.CircuitDiagramInfoArgs
|
|
766
|
+
) -> str | protocols.CircuitDiagramInfo:
|
|
777
767
|
e = self._diagram_exponent(args)
|
|
778
768
|
if e in [-0.25, 0.25]:
|
|
779
769
|
return protocols.CircuitDiagramInfo(wire_symbols=('T',), exponent=cast(float, e) * 4)
|
|
@@ -783,7 +773,7 @@ class ZPowGate(eigen_gate.EigenGate):
|
|
|
783
773
|
|
|
784
774
|
return protocols.CircuitDiagramInfo(wire_symbols=('Z',), exponent=e)
|
|
785
775
|
|
|
786
|
-
def _qasm_(self, args:
|
|
776
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
787
777
|
args.validate_version('2.0', '3.0')
|
|
788
778
|
|
|
789
779
|
if self.global_shift == 0:
|
|
@@ -838,8 +828,8 @@ class ZPowGate(eigen_gate.EigenGate):
|
|
|
838
828
|
return f'cirq.ZPowGate({all_args})'
|
|
839
829
|
|
|
840
830
|
def _commutes_on_qids_(
|
|
841
|
-
self, qids:
|
|
842
|
-
) ->
|
|
831
|
+
self, qids: Sequence[cirq.Qid], other: Any, *, atol: float = 1e-8
|
|
832
|
+
) -> bool | NotImplementedType | None:
|
|
843
833
|
from cirq.ops.parity_gates import ZZPowGate
|
|
844
834
|
|
|
845
835
|
if not isinstance(other, raw_types.Operation):
|
|
@@ -848,7 +838,7 @@ class ZPowGate(eigen_gate.EigenGate):
|
|
|
848
838
|
return NotImplemented
|
|
849
839
|
return True
|
|
850
840
|
|
|
851
|
-
def _json_dict_(self) ->
|
|
841
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
852
842
|
d = protocols.obj_to_dict_helper(self, ['exponent', 'global_shift'])
|
|
853
843
|
if self.dimension != 2:
|
|
854
844
|
d['dimension'] = self.dimension
|
|
@@ -879,12 +869,12 @@ class Rz(ZPowGate):
|
|
|
879
869
|
self._rads = rads
|
|
880
870
|
super().__init__(exponent=rads / _pi(rads), global_shift=-0.5)
|
|
881
871
|
|
|
882
|
-
def _with_exponent(self, exponent: value.TParamVal) ->
|
|
872
|
+
def _with_exponent(self, exponent: value.TParamVal) -> Rz:
|
|
883
873
|
return Rz(rads=exponent * _pi(exponent))
|
|
884
874
|
|
|
885
875
|
def _circuit_diagram_info_(
|
|
886
|
-
self, args:
|
|
887
|
-
) ->
|
|
876
|
+
self, args: cirq.CircuitDiagramInfoArgs
|
|
877
|
+
) -> str | protocols.CircuitDiagramInfo:
|
|
888
878
|
angle_str = self._format_exponent_as_angle(args)
|
|
889
879
|
return f'Rz({angle_str})'
|
|
890
880
|
|
|
@@ -896,15 +886,15 @@ class Rz(ZPowGate):
|
|
|
896
886
|
def __repr__(self) -> str:
|
|
897
887
|
return f'cirq.Rz(rads={proper_repr(self._rads)})'
|
|
898
888
|
|
|
899
|
-
def _qasm_(self, args:
|
|
889
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
900
890
|
args.validate_version('2.0', '3.0')
|
|
901
891
|
return args.format('rz({0:half_turns}) {1};\n', self._exponent, qubits[0])
|
|
902
892
|
|
|
903
|
-
def _json_dict_(self) ->
|
|
893
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
904
894
|
return {'rads': self._rads}
|
|
905
895
|
|
|
906
896
|
@classmethod
|
|
907
|
-
def _from_json_dict_(cls, rads, **kwargs) ->
|
|
897
|
+
def _from_json_dict_(cls, rads, **kwargs) -> Rz:
|
|
908
898
|
return cls(rads=rads)
|
|
909
899
|
|
|
910
900
|
|
|
@@ -931,7 +921,7 @@ class HPowGate(eigen_gate.EigenGate):
|
|
|
931
921
|
`cirq.H`, the Hadamard gate, is an instance of this gate at `exponent=1`.
|
|
932
922
|
"""
|
|
933
923
|
|
|
934
|
-
def _eigen_components(self) ->
|
|
924
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
935
925
|
s = np.sqrt(2)
|
|
936
926
|
|
|
937
927
|
component0 = np.array([[3 + 2 * s, 1 + s], [1 + s, 1]]) / (4 + 2 * s)
|
|
@@ -943,7 +933,7 @@ class HPowGate(eigen_gate.EigenGate):
|
|
|
943
933
|
def _num_qubits_(self) -> int:
|
|
944
934
|
return 1
|
|
945
935
|
|
|
946
|
-
def _trace_distance_bound_(self) ->
|
|
936
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
947
937
|
if self._is_parameterized_():
|
|
948
938
|
return None
|
|
949
939
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
@@ -970,7 +960,7 @@ class HPowGate(eigen_gate.EigenGate):
|
|
|
970
960
|
return []
|
|
971
961
|
return NotImplemented # pragma: no cover
|
|
972
962
|
|
|
973
|
-
def _apply_unitary_(self, args:
|
|
963
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
974
964
|
if self._exponent != 1:
|
|
975
965
|
return NotImplemented
|
|
976
966
|
|
|
@@ -995,14 +985,12 @@ class HPowGate(eigen_gate.EigenGate):
|
|
|
995
985
|
yield XPowGate(exponent=self._exponent, global_shift=self.global_shift).on(q)
|
|
996
986
|
yield YPowGate(exponent=-0.25).on(q)
|
|
997
987
|
|
|
998
|
-
def _circuit_diagram_info_(
|
|
999
|
-
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
1000
|
-
) -> 'cirq.CircuitDiagramInfo':
|
|
988
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
1001
989
|
return protocols.CircuitDiagramInfo(
|
|
1002
990
|
wire_symbols=('H',), exponent=self._diagram_exponent(args)
|
|
1003
991
|
)
|
|
1004
992
|
|
|
1005
|
-
def _qasm_(self, args:
|
|
993
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
1006
994
|
args.validate_version('2.0', '3.0')
|
|
1007
995
|
if self._exponent == 0:
|
|
1008
996
|
return args.format('id {0};\n', qubits[0])
|
|
@@ -1017,7 +1005,7 @@ class HPowGate(eigen_gate.EigenGate):
|
|
|
1017
1005
|
qubits[0],
|
|
1018
1006
|
)
|
|
1019
1007
|
|
|
1020
|
-
def _has_stabilizer_effect_(self) ->
|
|
1008
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
1021
1009
|
if self._is_parameterized_():
|
|
1022
1010
|
return None
|
|
1023
1011
|
return self.exponent % 1 == 0
|
|
@@ -1068,17 +1056,15 @@ class CZPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
|
|
|
1068
1056
|
return []
|
|
1069
1057
|
return NotImplemented # pragma: no cover
|
|
1070
1058
|
|
|
1071
|
-
def _eigen_components(self) ->
|
|
1059
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
1072
1060
|
return [(0, np.diag([1, 1, 1, 0])), (1, np.diag([0, 0, 0, 1]))]
|
|
1073
1061
|
|
|
1074
|
-
def _trace_distance_bound_(self) ->
|
|
1062
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
1075
1063
|
if self._is_parameterized_():
|
|
1076
1064
|
return None
|
|
1077
1065
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
1078
1066
|
|
|
1079
|
-
def _apply_unitary_(
|
|
1080
|
-
self, args: 'protocols.ApplyUnitaryArgs'
|
|
1081
|
-
) -> Union[np.ndarray, NotImplementedType]:
|
|
1067
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | NotImplementedType:
|
|
1082
1068
|
if protocols.is_parameterized(self):
|
|
1083
1069
|
return NotImplemented
|
|
1084
1070
|
|
|
@@ -1110,11 +1096,9 @@ class CZPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
|
|
|
1110
1096
|
|
|
1111
1097
|
def controlled(
|
|
1112
1098
|
self,
|
|
1113
|
-
num_controls:
|
|
1114
|
-
control_values:
|
|
1115
|
-
|
|
1116
|
-
] = None,
|
|
1117
|
-
control_qid_shape: Optional[Tuple[int, ...]] = None,
|
|
1099
|
+
num_controls: int | None = None,
|
|
1100
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
1101
|
+
control_qid_shape: tuple[int, ...] | None = None,
|
|
1118
1102
|
) -> raw_types.Gate:
|
|
1119
1103
|
"""Returns a controlled `CZPowGate`, using a `CCZPowGate` where possible.
|
|
1120
1104
|
|
|
@@ -1160,41 +1144,32 @@ class CZPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate):
|
|
|
1160
1144
|
A `cirq.ControlledGate` (or `cirq.CCZPowGate` if possible) representing
|
|
1161
1145
|
`self` controlled by the given control values and qubits.
|
|
1162
1146
|
"""
|
|
1163
|
-
if control_values and not isinstance(control_values, cv.AbstractControlValues):
|
|
1164
|
-
control_values = cv.ProductOfSums(
|
|
1165
|
-
tuple(
|
|
1166
|
-
(val,) if isinstance(val, int) else tuple(sorted(val)) for val in control_values
|
|
1167
|
-
)
|
|
1168
|
-
)
|
|
1169
1147
|
result = super().controlled(num_controls, control_values, control_qid_shape)
|
|
1170
|
-
if (
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
)
|
|
1177
|
-
return cirq.CCZPowGate(
|
|
1178
|
-
exponent=self._exponent, global_shift=self._global_shift
|
|
1179
|
-
).controlled(
|
|
1180
|
-
result.num_controls() - 1, result.control_values[:-1], result.control_qid_shape[:-1]
|
|
1181
|
-
)
|
|
1182
|
-
return result
|
|
1148
|
+
if self._global_shift != 0 or not isinstance(result, controlled_gate.ControlledGate):
|
|
1149
|
+
return result
|
|
1150
|
+
return ZPowGate(exponent=self.exponent).controlled(
|
|
1151
|
+
num_controls=result.num_controls() + 1,
|
|
1152
|
+
control_values=result.control_values & cv.ProductOfSums([1]),
|
|
1153
|
+
control_qid_shape=result.control_qid_shape + (2,),
|
|
1154
|
+
)
|
|
1183
1155
|
|
|
1184
|
-
def
|
|
1185
|
-
self,
|
|
1186
|
-
) ->
|
|
1156
|
+
def _decompose_with_context_(
|
|
1157
|
+
self, qubits: tuple[cirq.Qid, ...], context: cirq.DecompositionContext
|
|
1158
|
+
) -> list[cirq.Operation] | NotImplementedType:
|
|
1159
|
+
return _extract_phase(self, CZPowGate, qubits, context)
|
|
1160
|
+
|
|
1161
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
1187
1162
|
return protocols.CircuitDiagramInfo(
|
|
1188
1163
|
wire_symbols=('@', '@'), exponent=self._diagram_exponent(args)
|
|
1189
1164
|
)
|
|
1190
1165
|
|
|
1191
|
-
def _qasm_(self, args:
|
|
1166
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
1192
1167
|
if self._exponent != 1:
|
|
1193
1168
|
return None # Don't have an equivalent gate in QASM
|
|
1194
1169
|
args.validate_version('2.0', '3.0')
|
|
1195
1170
|
return args.format('cz {0},{1};\n', qubits[0], qubits[1])
|
|
1196
1171
|
|
|
1197
|
-
def _has_stabilizer_effect_(self) ->
|
|
1172
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
1198
1173
|
if self._is_parameterized_():
|
|
1199
1174
|
return None
|
|
1200
1175
|
return self.exponent % 1 == 0
|
|
@@ -1269,25 +1244,23 @@ class CXPowGate(eigen_gate.EigenGate):
|
|
|
1269
1244
|
yield cirq.CZPowGate(exponent=self._exponent, global_shift=self.global_shift).on(c, t)
|
|
1270
1245
|
yield YPowGate(exponent=0.5).on(t)
|
|
1271
1246
|
|
|
1272
|
-
def _eigen_components(self) ->
|
|
1247
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
1273
1248
|
return [
|
|
1274
1249
|
(0, np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0.5, 0.5], [0, 0, 0.5, 0.5]])),
|
|
1275
1250
|
(1, np.array([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0.5, -0.5], [0, 0, -0.5, 0.5]])),
|
|
1276
1251
|
]
|
|
1277
1252
|
|
|
1278
|
-
def _trace_distance_bound_(self) ->
|
|
1253
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
1279
1254
|
if self._is_parameterized_():
|
|
1280
1255
|
return None
|
|
1281
1256
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
1282
1257
|
|
|
1283
|
-
def _circuit_diagram_info_(
|
|
1284
|
-
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
1285
|
-
) -> 'cirq.CircuitDiagramInfo':
|
|
1258
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
1286
1259
|
return protocols.CircuitDiagramInfo(
|
|
1287
1260
|
wire_symbols=('@', 'X'), exponent=self._diagram_exponent(args), exponent_qubit_index=1
|
|
1288
1261
|
)
|
|
1289
1262
|
|
|
1290
|
-
def _apply_unitary_(self, args:
|
|
1263
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
1291
1264
|
if self._exponent != 1:
|
|
1292
1265
|
return NotImplemented
|
|
1293
1266
|
|
|
@@ -1318,11 +1291,9 @@ class CXPowGate(eigen_gate.EigenGate):
|
|
|
1318
1291
|
|
|
1319
1292
|
def controlled(
|
|
1320
1293
|
self,
|
|
1321
|
-
num_controls:
|
|
1322
|
-
control_values:
|
|
1323
|
-
|
|
1324
|
-
] = None,
|
|
1325
|
-
control_qid_shape: Optional[Tuple[int, ...]] = None,
|
|
1294
|
+
num_controls: int | None = None,
|
|
1295
|
+
control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
|
|
1296
|
+
control_qid_shape: tuple[int, ...] | None = None,
|
|
1326
1297
|
) -> raw_types.Gate:
|
|
1327
1298
|
"""Returns a controlled `CXPowGate`, using a `CCXPowGate` where possible.
|
|
1328
1299
|
|
|
@@ -1368,34 +1339,22 @@ class CXPowGate(eigen_gate.EigenGate):
|
|
|
1368
1339
|
A `cirq.ControlledGate` (or `cirq.CCXPowGate` if possible) representing
|
|
1369
1340
|
`self` controlled by the given control values and qubits.
|
|
1370
1341
|
"""
|
|
1371
|
-
if control_values and not isinstance(control_values, cv.AbstractControlValues):
|
|
1372
|
-
control_values = cv.ProductOfSums(
|
|
1373
|
-
tuple(
|
|
1374
|
-
(val,) if isinstance(val, int) else tuple(sorted(val)) for val in control_values
|
|
1375
|
-
)
|
|
1376
|
-
)
|
|
1377
1342
|
result = super().controlled(num_controls, control_values, control_qid_shape)
|
|
1378
|
-
if (
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
)
|
|
1385
|
-
return cirq.CCXPowGate(
|
|
1386
|
-
exponent=self._exponent, global_shift=self._global_shift
|
|
1387
|
-
).controlled(
|
|
1388
|
-
result.num_controls() - 1, result.control_values[:-1], result.control_qid_shape[:-1]
|
|
1389
|
-
)
|
|
1390
|
-
return result
|
|
1343
|
+
if self._global_shift != 0 or not isinstance(result, controlled_gate.ControlledGate):
|
|
1344
|
+
return result
|
|
1345
|
+
return XPowGate(exponent=self.exponent).controlled(
|
|
1346
|
+
num_controls=result.num_controls() + 1,
|
|
1347
|
+
control_values=result.control_values & cv.ProductOfSums([1]),
|
|
1348
|
+
control_qid_shape=result.control_qid_shape + (2,),
|
|
1349
|
+
)
|
|
1391
1350
|
|
|
1392
|
-
def _qasm_(self, args:
|
|
1351
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
1393
1352
|
if self._exponent != 1:
|
|
1394
1353
|
return None # Don't have an equivalent gate in QASM
|
|
1395
1354
|
args.validate_version('2.0', '3.0')
|
|
1396
1355
|
return args.format('cx {0},{1};\n', qubits[0], qubits[1])
|
|
1397
1356
|
|
|
1398
|
-
def _has_stabilizer_effect_(self) ->
|
|
1357
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
1399
1358
|
if self._is_parameterized_():
|
|
1400
1359
|
return None
|
|
1401
1360
|
return self.exponent % 1 == 0
|
|
@@ -1543,8 +1502,8 @@ document(
|
|
|
1543
1502
|
|
|
1544
1503
|
|
|
1545
1504
|
def _phased_x_or_pauli_gate(
|
|
1546
|
-
exponent:
|
|
1547
|
-
) ->
|
|
1505
|
+
exponent: float | sympy.Expr, phase_exponent: float | sympy.Expr
|
|
1506
|
+
) -> cirq.PhasedXPowGate | cirq.XPowGate | cirq.YPowGate:
|
|
1548
1507
|
"""Return PhasedXPowGate or X or Y gate if equivalent at the given phase_exponent."""
|
|
1549
1508
|
if not isinstance(phase_exponent, sympy.Expr) or phase_exponent.is_constant():
|
|
1550
1509
|
half_turns = value.canonicalize_half_turns(float(phase_exponent))
|
|
@@ -1554,3 +1513,25 @@ def _phased_x_or_pauli_gate(
|
|
|
1554
1513
|
case 0.5:
|
|
1555
1514
|
return YPowGate(exponent=exponent)
|
|
1556
1515
|
return cirq.ops.PhasedXPowGate(exponent=exponent, phase_exponent=phase_exponent)
|
|
1516
|
+
|
|
1517
|
+
|
|
1518
|
+
def _extract_phase(
|
|
1519
|
+
gate: cirq.EigenGate,
|
|
1520
|
+
gate_class: type,
|
|
1521
|
+
qubits: tuple[cirq.Qid, ...],
|
|
1522
|
+
context: cirq.DecompositionContext,
|
|
1523
|
+
) -> list[cirq.Operation] | NotImplementedType:
|
|
1524
|
+
"""Extracts the global phase field to its own gate, or absorbs it if it has no effect.
|
|
1525
|
+
|
|
1526
|
+
This is for use within the decompose handlers, and will return `NotImplemented` if there is no
|
|
1527
|
+
global phase, implying it is already in its simplest form. It will return a list, with the
|
|
1528
|
+
original op minus any global phase first, and the global phase op second. If the resulting
|
|
1529
|
+
global phase is empty (can happen for example in `XPowGate(global_phase=2/3)**3`), then it is
|
|
1530
|
+
excluded from the return value."""
|
|
1531
|
+
if not context.extract_global_phases or gate.global_shift == 0:
|
|
1532
|
+
return NotImplemented
|
|
1533
|
+
result = [gate_class(exponent=gate.exponent).on(*qubits)]
|
|
1534
|
+
phase_gate = global_phase_op.from_phase_and_exponent(gate.global_shift, gate.exponent)
|
|
1535
|
+
if not phase_gate.is_identity():
|
|
1536
|
+
result.append(phase_gate())
|
|
1537
|
+
return result
|