cirq-core 1.5.0.dev20250409222543__py3-none-any.whl → 1.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cirq-core might be problematic. Click here for more details.
- cirq/__init__.py +16 -17
- cirq/_compat.py +21 -20
- cirq/_compat_test.py +14 -34
- cirq/_doc.py +4 -2
- cirq/_import.py +8 -6
- cirq/_import_test.py +4 -2
- cirq/_version.py +6 -6
- cirq/_version_test.py +2 -2
- cirq/circuits/_block_diagram_drawer.py +11 -10
- cirq/circuits/_block_diagram_drawer_test.py +8 -6
- cirq/circuits/_box_drawing_character_data.py +8 -8
- cirq/circuits/_box_drawing_character_data_test.py +3 -1
- cirq/circuits/_bucket_priority_queue.py +9 -7
- cirq/circuits/_bucket_priority_queue_test.py +22 -20
- cirq/circuits/circuit.py +248 -172
- cirq/circuits/circuit_operation.py +73 -83
- cirq/circuits/circuit_operation_test.py +128 -90
- cirq/circuits/circuit_test.py +211 -151
- cirq/circuits/frozen_circuit.py +23 -60
- cirq/circuits/frozen_circuit_test.py +31 -8
- cirq/circuits/insert_strategy.py +7 -5
- cirq/circuits/insert_strategy_test.py +4 -2
- cirq/circuits/moment.py +88 -40
- cirq/circuits/moment_test.py +128 -51
- cirq/circuits/optimization_pass.py +5 -5
- cirq/circuits/optimization_pass_test.py +10 -10
- cirq/circuits/qasm_output.py +11 -11
- cirq/circuits/qasm_output_test.py +25 -22
- cirq/circuits/text_diagram_drawer.py +23 -38
- cirq/circuits/text_diagram_drawer_test.py +19 -17
- cirq/conftest.py +4 -3
- cirq/contrib/__init__.py +4 -4
- cirq/contrib/acquaintance/__init__.py +1 -1
- cirq/contrib/acquaintance/bipartite.py +5 -8
- cirq/contrib/acquaintance/bipartite_test.py +18 -13
- cirq/contrib/acquaintance/devices.py +2 -2
- cirq/contrib/acquaintance/devices_test.py +5 -3
- cirq/contrib/acquaintance/executor.py +5 -5
- cirq/contrib/acquaintance/executor_test.py +13 -9
- cirq/contrib/acquaintance/gates.py +18 -28
- cirq/contrib/acquaintance/gates_test.py +24 -20
- cirq/contrib/acquaintance/inspection_utils.py +8 -4
- cirq/contrib/acquaintance/inspection_utils_test.py +4 -2
- cirq/contrib/acquaintance/mutation_utils.py +4 -4
- cirq/contrib/acquaintance/mutation_utils_test.py +4 -2
- cirq/contrib/acquaintance/optimizers.py +4 -4
- cirq/contrib/acquaintance/optimizers_test.py +4 -1
- cirq/contrib/acquaintance/permutation.py +15 -27
- cirq/contrib/acquaintance/permutation_test.py +26 -17
- cirq/contrib/acquaintance/shift.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network_test.py +9 -6
- cirq/contrib/acquaintance/shift_test.py +8 -6
- cirq/contrib/acquaintance/strategies/cubic.py +2 -2
- cirq/contrib/acquaintance/strategies/cubic_test.py +4 -2
- cirq/contrib/acquaintance/strategies/quartic_paired.py +6 -6
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +10 -6
- cirq/contrib/acquaintance/testing.py +2 -0
- cirq/contrib/acquaintance/topological_sort.py +2 -2
- cirq/contrib/acquaintance/topological_sort_test.py +3 -1
- cirq/contrib/bayesian_network/bayesian_network_gate.py +9 -10
- cirq/contrib/bayesian_network/bayesian_network_gate_test.py +14 -9
- cirq/contrib/circuitdag/circuit_dag.py +4 -4
- cirq/contrib/circuitdag/circuit_dag_test.py +17 -15
- cirq/contrib/custom_simulators/custom_state_simulator.py +5 -5
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +22 -17
- cirq/contrib/graph_device/graph_device.py +12 -11
- cirq/contrib/graph_device/graph_device_test.py +18 -14
- cirq/contrib/graph_device/hypergraph.py +16 -14
- cirq/contrib/graph_device/hypergraph_test.py +13 -11
- cirq/contrib/graph_device/uniform_graph_device.py +6 -4
- cirq/contrib/graph_device/uniform_graph_device_test.py +11 -3
- cirq/contrib/hacks/disable_validation.py +6 -1
- cirq/contrib/hacks/disable_validation_test.py +3 -1
- cirq/contrib/json.py +31 -5
- cirq/contrib/json_test.py +6 -3
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.json +6 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.json +5 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/__init__.py +17 -0
- cirq/contrib/json_test_data/spec.py +32 -0
- cirq/contrib/noise_models/noise_models.py +119 -5
- cirq/contrib/noise_models/noise_models_test.py +37 -9
- cirq/contrib/paulistring/clifford_optimize.py +6 -4
- cirq/contrib/paulistring/clifford_optimize_test.py +6 -5
- cirq/contrib/paulistring/clifford_target_gateset.py +10 -10
- cirq/contrib/paulistring/clifford_target_gateset_test.py +13 -11
- cirq/contrib/paulistring/optimize.py +2 -0
- cirq/contrib/paulistring/optimize_test.py +4 -3
- cirq/contrib/paulistring/pauli_string_dag.py +2 -0
- cirq/contrib/paulistring/pauli_string_dag_test.py +3 -1
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +255 -120
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +398 -19
- cirq/contrib/paulistring/pauli_string_optimize.py +7 -1
- cirq/contrib/paulistring/pauli_string_optimize_test.py +5 -3
- cirq/contrib/paulistring/recombine.py +6 -4
- cirq/contrib/paulistring/recombine_test.py +3 -1
- cirq/contrib/paulistring/separate.py +9 -6
- cirq/contrib/paulistring/separate_test.py +3 -1
- cirq/contrib/qasm_import/_lexer.py +3 -2
- cirq/contrib/qasm_import/_lexer_test.py +49 -13
- cirq/contrib/qasm_import/_parser.py +547 -83
- cirq/contrib/qasm_import/_parser_test.py +988 -97
- cirq/contrib/qasm_import/exception.py +2 -0
- cirq/contrib/qasm_import/qasm.py +8 -2
- cirq/contrib/qasm_import/qasm_test.py +7 -4
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +5 -5
- cirq/contrib/qcircuit/qcircuit_diagram_info_test.py +4 -1
- cirq/contrib/qcircuit/qcircuit_pdf.py +7 -3
- cirq/contrib/qcircuit/qcircuit_pdf_test.py +3 -1
- cirq/contrib/qcircuit/qcircuit_test.py +10 -8
- cirq/contrib/quantum_volume/quantum_volume.py +31 -27
- cirq/contrib/quantum_volume/quantum_volume_test.py +19 -16
- cirq/contrib/quimb/density_matrix.py +15 -14
- cirq/contrib/quimb/density_matrix_test.py +10 -7
- cirq/contrib/quimb/grid_circuits.py +5 -2
- cirq/contrib/quimb/grid_circuits_test.py +3 -0
- cirq/contrib/quimb/mps_simulator.py +20 -20
- cirq/contrib/quimb/mps_simulator_test.py +3 -0
- cirq/contrib/quimb/state_vector.py +12 -11
- cirq/contrib/quimb/state_vector_test.py +3 -0
- cirq/contrib/quirk/export_to_quirk.py +5 -3
- cirq/contrib/quirk/export_to_quirk_test.py +18 -16
- cirq/contrib/quirk/linearize_circuit.py +2 -0
- cirq/contrib/quirk/quirk_gate.py +18 -17
- cirq/contrib/routing/device.py +5 -3
- cirq/contrib/routing/device_test.py +2 -0
- cirq/contrib/routing/greedy.py +10 -21
- cirq/contrib/routing/greedy_test.py +4 -2
- cirq/contrib/routing/initialization.py +2 -2
- cirq/contrib/routing/initialization_test.py +5 -3
- cirq/contrib/routing/router.py +9 -5
- cirq/contrib/routing/router_test.py +2 -0
- cirq/contrib/routing/swap_network.py +3 -3
- cirq/contrib/routing/swap_network_test.py +3 -1
- cirq/contrib/routing/utils.py +2 -2
- cirq/contrib/routing/utils_test.py +3 -0
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +15 -9
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +3 -0
- cirq/contrib/svg/svg.py +3 -3
- cirq/contrib/svg/svg_test.py +8 -5
- cirq/devices/device.py +4 -4
- cirq/devices/device_test.py +7 -4
- cirq/devices/grid_device_metadata.py +10 -10
- cirq/devices/grid_device_metadata_test.py +3 -0
- cirq/devices/grid_qubit.py +29 -21
- cirq/devices/grid_qubit_test.py +3 -0
- cirq/devices/insertion_noise_model.py +7 -7
- cirq/devices/insertion_noise_model_test.py +7 -5
- cirq/devices/line_qubit.py +13 -13
- cirq/devices/line_qubit_test.py +2 -0
- cirq/devices/named_topologies.py +18 -29
- cirq/devices/named_topologies_test.py +13 -10
- cirq/devices/noise_model.py +3 -3
- cirq/devices/noise_model_test.py +19 -15
- cirq/devices/noise_properties.py +15 -6
- cirq/devices/noise_properties_test.py +34 -3
- cirq/devices/noise_utils.py +11 -9
- cirq/devices/noise_utils_test.py +2 -0
- cirq/devices/superconducting_qubits_noise_properties.py +23 -22
- cirq/devices/superconducting_qubits_noise_properties_test.py +6 -6
- cirq/devices/thermal_noise_model.py +107 -37
- cirq/devices/thermal_noise_model_test.py +21 -0
- cirq/devices/unconstrained_device.py +5 -3
- cirq/devices/unconstrained_device_test.py +2 -0
- cirq/experiments/__init__.py +4 -2
- cirq/experiments/benchmarking/__init__.py +17 -0
- cirq/experiments/benchmarking/parallel_xeb.py +677 -0
- cirq/experiments/benchmarking/parallel_xeb_test.py +447 -0
- cirq/experiments/fidelity_estimation.py +14 -8
- cirq/experiments/fidelity_estimation_test.py +3 -0
- cirq/experiments/n_qubit_tomography.py +17 -16
- cirq/experiments/n_qubit_tomography_test.py +8 -5
- cirq/experiments/purity_estimation.py +2 -0
- cirq/experiments/purity_estimation_test.py +2 -0
- cirq/experiments/qubit_characterizations.py +207 -103
- cirq/experiments/qubit_characterizations_test.py +40 -12
- cirq/experiments/random_quantum_circuit_generation.py +56 -70
- cirq/experiments/random_quantum_circuit_generation_test.py +11 -8
- cirq/experiments/readout_confusion_matrix.py +24 -22
- cirq/experiments/readout_confusion_matrix_test.py +2 -0
- cirq/experiments/single_qubit_readout_calibration.py +30 -15
- cirq/experiments/single_qubit_readout_calibration_test.py +5 -2
- cirq/experiments/t1_decay_experiment.py +9 -7
- cirq/experiments/t1_decay_experiment_test.py +13 -11
- cirq/experiments/t2_decay_experiment.py +16 -13
- cirq/experiments/t2_decay_experiment_test.py +2 -0
- cirq/experiments/two_qubit_xeb.py +64 -57
- cirq/experiments/two_qubit_xeb_test.py +10 -6
- cirq/experiments/xeb_fitting.py +39 -35
- cirq/experiments/xeb_sampling.py +37 -44
- cirq/experiments/xeb_sampling_test.py +3 -0
- cirq/experiments/xeb_simulation.py +14 -10
- cirq/experiments/xeb_simulation_test.py +5 -5
- cirq/experiments/z_phase_calibration.py +32 -29
- cirq/experiments/z_phase_calibration_test.py +3 -4
- cirq/interop/quirk/cells/__init__.py +1 -1
- cirq/interop/quirk/cells/all_cells.py +7 -2
- cirq/interop/quirk/cells/arithmetic_cells.py +29 -41
- cirq/interop/quirk/cells/arithmetic_cells_test.py +17 -14
- cirq/interop/quirk/cells/cell.py +19 -28
- cirq/interop/quirk/cells/cell_test.py +3 -0
- cirq/interop/quirk/cells/composite_cell.py +13 -28
- cirq/interop/quirk/cells/composite_cell_test.py +2 -0
- cirq/interop/quirk/cells/control_cells.py +15 -15
- cirq/interop/quirk/cells/control_cells_test.py +7 -5
- cirq/interop/quirk/cells/frequency_space_cells.py +4 -3
- cirq/interop/quirk/cells/frequency_space_cells_test.py +3 -1
- cirq/interop/quirk/cells/ignored_cells.py +3 -0
- cirq/interop/quirk/cells/ignored_cells_test.py +3 -1
- cirq/interop/quirk/cells/input_cells.py +7 -5
- cirq/interop/quirk/cells/input_cells_test.py +7 -5
- cirq/interop/quirk/cells/input_rotation_cells.py +15 -13
- cirq/interop/quirk/cells/input_rotation_cells_test.py +9 -7
- cirq/interop/quirk/cells/measurement_cells.py +5 -2
- cirq/interop/quirk/cells/measurement_cells_test.py +3 -1
- cirq/interop/quirk/cells/parse.py +22 -23
- cirq/interop/quirk/cells/parse_test.py +12 -10
- cirq/interop/quirk/cells/qubit_permutation_cells.py +5 -3
- cirq/interop/quirk/cells/qubit_permutation_cells_test.py +9 -7
- cirq/interop/quirk/cells/scalar_cells.py +4 -1
- cirq/interop/quirk/cells/scalar_cells_test.py +3 -1
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +5 -2
- cirq/interop/quirk/cells/single_qubit_rotation_cells_test.py +5 -3
- cirq/interop/quirk/cells/swap_cell.py +8 -6
- cirq/interop/quirk/cells/swap_cell_test.py +6 -4
- cirq/interop/quirk/cells/testing.py +6 -6
- cirq/interop/quirk/cells/testing_test.py +8 -6
- cirq/interop/quirk/cells/unsupported_cells.py +3 -0
- cirq/interop/quirk/cells/unsupported_cells_test.py +4 -2
- cirq/interop/quirk/url_to_circuit.py +23 -36
- cirq/interop/quirk/url_to_circuit_test.py +4 -1
- cirq/json_resolver_cache.py +14 -12
- cirq/linalg/__init__.py +4 -6
- cirq/linalg/combinators.py +7 -5
- cirq/linalg/combinators_test.py +10 -7
- cirq/linalg/decompositions.py +24 -35
- cirq/linalg/decompositions_test.py +3 -1
- cirq/linalg/diagonalize.py +6 -4
- cirq/linalg/diagonalize_test.py +15 -14
- cirq/linalg/operator_spaces.py +14 -14
- cirq/linalg/operator_spaces_test.py +13 -11
- cirq/linalg/predicates.py +18 -9
- cirq/linalg/predicates_test.py +5 -0
- cirq/linalg/tolerance.py +6 -3
- cirq/linalg/tolerance_test.py +6 -4
- cirq/linalg/transformations.py +23 -20
- cirq/linalg/transformations_test.py +73 -43
- cirq/neutral_atoms/convert_to_neutral_atom_gates.py +9 -3
- cirq/neutral_atoms/convert_to_neutral_atom_gates_test.py +3 -1
- cirq/neutral_atoms/neutral_atom_devices.py +2 -0
- cirq/ops/__init__.py +2 -0
- cirq/ops/arithmetic_operation.py +21 -21
- cirq/ops/arithmetic_operation_test.py +7 -8
- cirq/ops/boolean_hamiltonian.py +23 -22
- cirq/ops/boolean_hamiltonian_test.py +12 -9
- cirq/ops/classically_controlled_operation.py +31 -36
- cirq/ops/classically_controlled_operation_test.py +121 -117
- cirq/ops/clifford_gate.py +98 -81
- cirq/ops/clifford_gate_test.py +72 -57
- cirq/ops/common_channels.py +44 -44
- cirq/ops/common_channels_test.py +83 -81
- cirq/ops/common_gate_families.py +9 -7
- cirq/ops/common_gate_families_test.py +11 -7
- cirq/ops/common_gates.py +164 -183
- cirq/ops/common_gates_test.py +135 -95
- cirq/ops/control_values.py +23 -26
- cirq/ops/control_values_test.py +22 -20
- cirq/ops/controlled_gate.py +64 -112
- cirq/ops/controlled_gate_test.py +130 -35
- cirq/ops/controlled_operation.py +24 -35
- cirq/ops/controlled_operation_test.py +8 -6
- cirq/ops/dense_pauli_string.py +38 -49
- cirq/ops/dense_pauli_string_test.py +4 -2
- cirq/ops/diagonal_gate.py +18 -31
- cirq/ops/diagonal_gate_test.py +13 -13
- cirq/ops/eigen_gate.py +29 -29
- cirq/ops/eigen_gate_test.py +45 -28
- cirq/ops/fourier_transform.py +14 -20
- cirq/ops/fourier_transform_test.py +15 -12
- cirq/ops/fsim_gate.py +43 -42
- cirq/ops/fsim_gate_test.py +29 -29
- cirq/ops/gate_features.py +2 -0
- cirq/ops/gate_features_test.py +5 -3
- cirq/ops/gate_operation.py +43 -65
- cirq/ops/gate_operation_test.py +46 -42
- cirq/ops/gateset.py +28 -40
- cirq/ops/gateset_test.py +4 -2
- cirq/ops/global_phase_op.py +45 -20
- cirq/ops/global_phase_op_test.py +44 -20
- cirq/ops/greedy_qubit_manager.py +10 -8
- cirq/ops/greedy_qubit_manager_test.py +5 -3
- cirq/ops/identity.py +14 -12
- cirq/ops/identity_test.py +24 -20
- cirq/ops/kraus_channel.py +11 -8
- cirq/ops/kraus_channel_test.py +14 -11
- cirq/ops/linear_combinations.py +65 -77
- cirq/ops/linear_combinations_test.py +14 -9
- cirq/ops/matrix_gates.py +21 -18
- cirq/ops/matrix_gates_test.py +16 -0
- cirq/ops/measure_util.py +15 -20
- cirq/ops/measure_util_test.py +2 -0
- cirq/ops/measurement_gate.py +26 -37
- cirq/ops/measurement_gate_test.py +2 -0
- cirq/ops/mixed_unitary_channel.py +12 -9
- cirq/ops/mixed_unitary_channel_test.py +14 -11
- cirq/ops/named_qubit.py +16 -13
- cirq/ops/named_qubit_test.py +15 -13
- cirq/ops/op_tree.py +9 -7
- cirq/ops/op_tree_test.py +22 -19
- cirq/ops/parallel_gate.py +15 -17
- cirq/ops/parallel_gate_test.py +18 -16
- cirq/ops/parity_gates.py +23 -25
- cirq/ops/parity_gates_test.py +36 -32
- cirq/ops/pauli_gates.py +22 -21
- cirq/ops/pauli_gates_test.py +29 -20
- cirq/ops/pauli_interaction_gate.py +15 -19
- cirq/ops/pauli_interaction_gate_test.py +10 -8
- cirq/ops/pauli_measurement_gate.py +23 -35
- cirq/ops/pauli_measurement_gate_test.py +2 -0
- cirq/ops/pauli_string.py +92 -120
- cirq/ops/pauli_string_phasor.py +52 -45
- cirq/ops/pauli_string_phasor_test.py +4 -5
- cirq/ops/pauli_string_raw_types.py +9 -7
- cirq/ops/pauli_string_raw_types_test.py +2 -0
- cirq/ops/pauli_string_test.py +31 -154
- cirq/ops/pauli_sum_exponential.py +12 -12
- cirq/ops/pauli_sum_exponential_test.py +12 -10
- cirq/ops/permutation_gate.py +8 -6
- cirq/ops/permutation_gate_test.py +10 -8
- cirq/ops/phased_iswap_gate.py +16 -16
- cirq/ops/phased_iswap_gate_test.py +17 -15
- cirq/ops/phased_x_gate.py +16 -17
- cirq/ops/phased_x_gate_test.py +18 -16
- cirq/ops/phased_x_z_gate.py +24 -22
- cirq/ops/phased_x_z_gate_test.py +17 -11
- cirq/ops/projector.py +16 -11
- cirq/ops/projector_test.py +19 -16
- cirq/ops/qid_util.py +7 -5
- cirq/ops/qid_util_test.py +2 -0
- cirq/ops/qubit_manager.py +11 -9
- cirq/ops/qubit_manager_test.py +6 -4
- cirq/ops/qubit_order.py +11 -14
- cirq/ops/qubit_order_or_list.py +4 -2
- cirq/ops/qubit_order_test.py +12 -10
- cirq/ops/random_gate_channel.py +12 -10
- cirq/ops/random_gate_channel_test.py +14 -11
- cirq/ops/raw_types.py +109 -129
- cirq/ops/raw_types_test.py +63 -57
- cirq/ops/state_preparation_channel.py +7 -7
- cirq/ops/state_preparation_channel_test.py +11 -9
- cirq/ops/swap_gates.py +13 -15
- cirq/ops/swap_gates_test.py +19 -17
- cirq/ops/tags.py +5 -3
- cirq/ops/tags_test.py +4 -2
- cirq/ops/three_qubit_gates.py +43 -76
- cirq/ops/three_qubit_gates_test.py +19 -17
- cirq/ops/two_qubit_diagonal_gate.py +13 -13
- cirq/ops/two_qubit_diagonal_gate_test.py +10 -8
- cirq/ops/uniform_superposition_gate.py +5 -3
- cirq/ops/uniform_superposition_gate_test.py +5 -3
- cirq/ops/wait_gate.py +17 -14
- cirq/ops/wait_gate_test.py +9 -6
- cirq/protocols/__init__.py +0 -3
- cirq/protocols/act_on_protocol.py +8 -6
- cirq/protocols/act_on_protocol_test.py +15 -12
- cirq/protocols/apply_channel_protocol.py +10 -14
- cirq/protocols/apply_channel_protocol_test.py +2 -0
- cirq/protocols/apply_mixture_protocol.py +13 -42
- cirq/protocols/apply_mixture_protocol_test.py +7 -5
- cirq/protocols/apply_unitary_protocol.py +39 -34
- cirq/protocols/apply_unitary_protocol_test.py +4 -1
- cirq/protocols/approximate_equality_protocol.py +2 -0
- cirq/protocols/approximate_equality_protocol_test.py +2 -0
- cirq/protocols/circuit_diagram_info_protocol.py +58 -42
- cirq/protocols/circuit_diagram_info_protocol_test.py +70 -12
- cirq/protocols/commutes_protocol.py +8 -7
- cirq/protocols/commutes_protocol_test.py +2 -0
- cirq/protocols/control_key_protocol.py +6 -4
- cirq/protocols/control_key_protocol_test.py +3 -1
- cirq/protocols/decompose_protocol.py +49 -48
- cirq/protocols/decompose_protocol_test.py +27 -16
- cirq/protocols/equal_up_to_global_phase_protocol.py +2 -0
- cirq/protocols/equal_up_to_global_phase_protocol_test.py +9 -6
- cirq/protocols/has_stabilizer_effect_protocol.py +7 -5
- cirq/protocols/has_stabilizer_effect_protocol_test.py +7 -5
- cirq/protocols/has_unitary_protocol.py +10 -6
- cirq/protocols/has_unitary_protocol_test.py +13 -8
- cirq/protocols/hash_from_pickle_test.py +2 -11
- cirq/protocols/inverse_protocol.py +13 -16
- cirq/protocols/inverse_protocol_test.py +5 -3
- cirq/protocols/json_serialization.py +35 -54
- cirq/protocols/json_serialization_test.py +14 -21
- cirq/protocols/json_test_data/CXSWAP.json +46 -0
- cirq/protocols/json_test_data/CXSWAP.repr +13 -0
- cirq/protocols/json_test_data/CZSWAP.json +46 -0
- cirq/protocols/json_test_data/CZSWAP.repr +13 -0
- cirq/protocols/json_test_data/CircuitOperation.json +6 -3
- cirq/protocols/json_test_data/CircuitOperation.repr_inward +4 -2
- cirq/protocols/json_test_data/Moment.json +24 -1
- cirq/protocols/json_test_data/Moment.repr +6 -1
- cirq/protocols/json_test_data/ThermalNoiseModel.json +32 -0
- cirq/protocols/json_test_data/ThermalNoiseModel.repr +1 -0
- cirq/protocols/json_test_data/spec.py +6 -2
- cirq/protocols/kraus_protocol.py +47 -7
- cirq/protocols/kraus_protocol_test.py +86 -12
- cirq/protocols/measurement_key_protocol.py +15 -16
- cirq/protocols/measurement_key_protocol_test.py +13 -11
- cirq/protocols/mixture_protocol.py +7 -5
- cirq/protocols/mixture_protocol_test.py +4 -2
- cirq/protocols/mul_protocol.py +2 -3
- cirq/protocols/mul_protocol_test.py +2 -0
- cirq/protocols/pauli_expansion_protocol.py +6 -3
- cirq/protocols/pauli_expansion_protocol_test.py +5 -3
- cirq/protocols/phase_protocol.py +2 -0
- cirq/protocols/phase_protocol_test.py +3 -1
- cirq/protocols/pow_protocol.py +11 -16
- cirq/protocols/pow_protocol_test.py +2 -0
- cirq/protocols/qasm.py +14 -20
- cirq/protocols/qasm_test.py +6 -3
- cirq/protocols/qid_shape_protocol.py +8 -8
- cirq/protocols/qid_shape_protocol_test.py +3 -1
- cirq/protocols/resolve_parameters.py +5 -3
- cirq/protocols/resolve_parameters_test.py +8 -7
- cirq/protocols/trace_distance_bound.py +6 -4
- cirq/protocols/trace_distance_bound_test.py +3 -1
- cirq/protocols/unitary_protocol.py +17 -7
- cirq/protocols/unitary_protocol_test.py +12 -2
- cirq/qis/channels.py +6 -2
- cirq/qis/channels_test.py +20 -16
- cirq/qis/clifford_tableau.py +21 -19
- cirq/qis/clifford_tableau_test.py +2 -2
- cirq/qis/entropy.py +14 -3
- cirq/qis/entropy_test.py +3 -1
- cirq/qis/measures.py +13 -13
- cirq/qis/measures_test.py +20 -14
- cirq/qis/noise_utils.py +2 -0
- cirq/qis/noise_utils_test.py +9 -7
- cirq/qis/quantum_state_representation.py +7 -8
- cirq/qis/states.py +58 -56
- cirq/qis/states_test.py +2 -0
- cirq/sim/classical_simulator.py +23 -22
- cirq/sim/classical_simulator_test.py +2 -0
- cirq/sim/clifford/clifford_simulator.py +23 -21
- cirq/sim/clifford/clifford_simulator_test.py +7 -4
- cirq/sim/clifford/clifford_tableau_simulation_state.py +10 -7
- cirq/sim/clifford/clifford_tableau_simulation_state_test.py +5 -5
- cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +8 -6
- cirq/sim/clifford/stabilizer_ch_form_simulation_state_test.py +8 -6
- cirq/sim/clifford/stabilizer_sampler.py +9 -7
- cirq/sim/clifford/stabilizer_sampler_test.py +4 -2
- cirq/sim/clifford/stabilizer_simulation_state.py +14 -13
- cirq/sim/clifford/stabilizer_simulation_state_test.py +6 -4
- cirq/sim/clifford/stabilizer_state_ch_form.py +13 -11
- cirq/sim/clifford/stabilizer_state_ch_form_test.py +4 -2
- cirq/sim/density_matrix_simulation_state.py +26 -27
- cirq/sim/density_matrix_simulation_state_test.py +10 -8
- cirq/sim/density_matrix_simulator.py +30 -28
- cirq/sim/density_matrix_simulator_test.py +48 -48
- cirq/sim/density_matrix_utils.py +13 -11
- cirq/sim/density_matrix_utils_test.py +38 -36
- cirq/sim/mux.py +33 -31
- cirq/sim/mux_test.py +3 -0
- cirq/sim/simulation_product_state.py +15 -15
- cirq/sim/simulation_product_state_test.py +29 -26
- cirq/sim/simulation_state.py +29 -38
- cirq/sim/simulation_state_base.py +21 -32
- cirq/sim/simulation_state_test.py +15 -13
- cirq/sim/simulation_utils.py +5 -2
- cirq/sim/simulation_utils_test.py +5 -2
- cirq/sim/simulator.py +90 -106
- cirq/sim/simulator_base.py +33 -45
- cirq/sim/simulator_base_test.py +20 -15
- cirq/sim/simulator_test.py +23 -14
- cirq/sim/sparse_simulator.py +19 -17
- cirq/sim/sparse_simulator_test.py +41 -40
- cirq/sim/state_vector.py +15 -12
- cirq/sim/state_vector_simulation_state.py +31 -31
- cirq/sim/state_vector_simulation_state_test.py +16 -14
- cirq/sim/state_vector_simulator.py +17 -14
- cirq/sim/state_vector_simulator_test.py +2 -0
- cirq/sim/state_vector_test.py +6 -3
- cirq/study/flatten_expressions.py +16 -15
- cirq/study/flatten_expressions_test.py +13 -11
- cirq/study/resolver.py +18 -17
- cirq/study/resolver_test.py +22 -20
- cirq/study/result.py +17 -27
- cirq/study/result_test.py +2 -0
- cirq/study/sweepable.py +12 -10
- cirq/study/sweepable_test.py +3 -0
- cirq/study/sweeps.py +42 -61
- cirq/study/sweeps_test.py +33 -0
- cirq/testing/__init__.py +7 -11
- cirq/testing/_compat_test_data/module_a/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/module_b/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/sub/__init__.py +1 -0
- cirq/testing/circuit_compare.py +8 -17
- cirq/testing/circuit_compare_test.py +2 -0
- cirq/testing/consistent_act_on.py +13 -11
- cirq/testing/consistent_act_on_test.py +5 -3
- cirq/testing/consistent_channels.py +2 -0
- cirq/testing/consistent_channels_test.py +10 -8
- cirq/testing/consistent_controlled_gate_op.py +5 -5
- cirq/testing/consistent_controlled_gate_op_test.py +18 -18
- cirq/testing/consistent_decomposition.py +2 -2
- cirq/testing/consistent_decomposition_test.py +4 -2
- cirq/testing/consistent_pauli_expansion.py +2 -0
- cirq/testing/consistent_pauli_expansion_test.py +3 -1
- cirq/testing/consistent_phase_by.py +2 -0
- cirq/testing/consistent_phase_by_test.py +3 -1
- cirq/testing/consistent_protocols.py +14 -20
- cirq/testing/consistent_protocols_test.py +13 -11
- cirq/testing/consistent_qasm.py +6 -4
- cirq/testing/consistent_qasm_test.py +7 -7
- cirq/testing/consistent_resolve_parameters.py +2 -0
- cirq/testing/consistent_specified_has_unitary.py +2 -2
- cirq/testing/consistent_specified_has_unitary_test.py +6 -4
- cirq/testing/consistent_unitary.py +1 -0
- cirq/testing/consistent_unitary_test.py +4 -2
- cirq/testing/deprecation.py +5 -2
- cirq/testing/deprecation_test.py +5 -2
- cirq/testing/devices.py +7 -4
- cirq/testing/devices_test.py +7 -4
- cirq/testing/equals_tester.py +4 -2
- cirq/testing/equals_tester_test.py +21 -17
- cirq/testing/equivalent_basis_map.py +6 -4
- cirq/testing/equivalent_basis_map_test.py +6 -4
- cirq/testing/equivalent_repr_eval.py +6 -4
- cirq/testing/equivalent_repr_eval_test.py +5 -3
- cirq/testing/gate_features.py +2 -0
- cirq/testing/gate_features_test.py +7 -5
- cirq/testing/json.py +19 -15
- cirq/testing/json_test.py +5 -3
- cirq/testing/lin_alg_utils.py +10 -11
- cirq/testing/lin_alg_utils_test.py +14 -12
- cirq/testing/logs.py +7 -6
- cirq/testing/logs_test.py +9 -7
- cirq/testing/no_identifier_qubit.py +4 -2
- cirq/testing/no_identifier_qubit_test.py +5 -3
- cirq/testing/op_tree.py +2 -0
- cirq/testing/op_tree_test.py +4 -1
- cirq/testing/order_tester.py +2 -0
- cirq/testing/order_tester_test.py +8 -6
- cirq/testing/pytest_utils.py +2 -0
- cirq/testing/pytest_utils_test.py +4 -2
- cirq/testing/random_circuit.py +21 -20
- cirq/testing/random_circuit_test.py +12 -9
- cirq/testing/repr_pretty_tester.py +1 -0
- cirq/testing/repr_pretty_tester_test.py +5 -3
- cirq/testing/routing_devices.py +4 -1
- cirq/testing/routing_devices_test.py +9 -6
- cirq/testing/sample_circuits.py +4 -1
- cirq/testing/sample_circuits_test.py +3 -1
- cirq/testing/sample_gates.py +3 -0
- cirq/testing/sample_gates_test.py +5 -2
- cirq/transformers/__init__.py +11 -4
- cirq/transformers/align.py +9 -7
- cirq/transformers/align_test.py +2 -0
- cirq/transformers/analytical_decompositions/__init__.py +3 -6
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +18 -16
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +19 -16
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +11 -9
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition_test.py +5 -3
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +141 -44
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +35 -1
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +8 -7
- cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +2 -0
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +7 -4
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +3 -0
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +11 -19
- cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py +8 -33
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +9 -11
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +2 -0
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +91 -27
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +36 -7
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +20 -21
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py +8 -6
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +13 -15
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +3 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +39 -41
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +2 -0
- cirq/transformers/drop_empty_moments.py +5 -3
- cirq/transformers/drop_empty_moments_test.py +4 -2
- cirq/transformers/drop_negligible_operations.py +7 -5
- cirq/transformers/drop_negligible_operations_test.py +2 -0
- cirq/transformers/dynamical_decoupling.py +49 -42
- cirq/transformers/dynamical_decoupling_test.py +223 -205
- cirq/transformers/eject_phased_paulis.py +28 -26
- cirq/transformers/eject_phased_paulis_test.py +12 -9
- cirq/transformers/eject_z.py +12 -12
- cirq/transformers/eject_z_test.py +2 -2
- cirq/transformers/expand_composite.py +6 -4
- cirq/transformers/expand_composite_test.py +3 -1
- cirq/transformers/gauge_compiling/__init__.py +3 -1
- cirq/transformers/gauge_compiling/cphase_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cphase_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling.py +45 -41
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +2 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils_test.py +5 -1
- cirq/transformers/gauge_compiling/iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/iswap_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge.py +2 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +7 -6
- cirq/transformers/gauge_compiling/sqrt_cz_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge_test.py +2 -0
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +6 -3
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +3 -0
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +12 -9
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation_test.py +9 -7
- cirq/transformers/insertion_sort.py +8 -6
- cirq/transformers/insertion_sort_test.py +3 -1
- cirq/transformers/measurement_transformers.py +29 -29
- cirq/transformers/measurement_transformers_test.py +2 -0
- cirq/transformers/merge_k_qubit_gates.py +12 -10
- cirq/transformers/merge_k_qubit_gates_test.py +18 -18
- cirq/transformers/merge_single_qubit_gates.py +197 -20
- cirq/transformers/merge_single_qubit_gates_test.py +177 -5
- cirq/transformers/noise_adding.py +5 -3
- cirq/transformers/noise_adding_test.py +2 -0
- cirq/transformers/optimize_for_target_gateset.py +19 -17
- cirq/transformers/optimize_for_target_gateset_test.py +11 -8
- cirq/transformers/qubit_management_transformers.py +13 -11
- cirq/transformers/qubit_management_transformers_test.py +5 -3
- cirq/transformers/randomized_measurements.py +16 -14
- cirq/transformers/randomized_measurements_test.py +10 -4
- cirq/transformers/routing/initial_mapper.py +6 -4
- cirq/transformers/routing/initial_mapper_test.py +2 -0
- cirq/transformers/routing/line_initial_mapper.py +16 -14
- cirq/transformers/routing/line_initial_mapper_test.py +9 -7
- cirq/transformers/routing/mapping_manager.py +10 -10
- cirq/transformers/routing/mapping_manager_test.py +2 -0
- cirq/transformers/routing/route_circuit_cqc.py +33 -31
- cirq/transformers/routing/route_circuit_cqc_test.py +15 -13
- cirq/transformers/routing/visualize_routed_circuit.py +8 -7
- cirq/transformers/routing/visualize_routed_circuit_test.py +4 -2
- cirq/transformers/stratify.py +17 -15
- cirq/transformers/stratify_test.py +3 -0
- cirq/transformers/symbolize.py +103 -0
- cirq/transformers/symbolize_test.py +62 -0
- cirq/transformers/synchronize_terminal_measurements.py +10 -10
- cirq/transformers/synchronize_terminal_measurements_test.py +12 -10
- cirq/transformers/tag_transformers.py +97 -0
- cirq/transformers/tag_transformers_test.py +103 -0
- cirq/transformers/target_gatesets/compilation_target_gateset.py +21 -19
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +20 -16
- cirq/transformers/target_gatesets/cz_gateset.py +7 -5
- cirq/transformers/target_gatesets/cz_gateset_test.py +21 -19
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +9 -7
- cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +25 -25
- cirq/transformers/transformer_api.py +34 -47
- cirq/transformers/transformer_api_test.py +9 -8
- cirq/transformers/transformer_primitives.py +39 -49
- cirq/transformers/transformer_primitives_test.py +10 -17
- cirq/value/abc_alt.py +6 -4
- cirq/value/abc_alt_test.py +5 -3
- cirq/value/angle.py +11 -12
- cirq/value/angle_test.py +5 -3
- cirq/value/classical_data.py +27 -27
- cirq/value/classical_data_test.py +11 -8
- cirq/value/condition.py +26 -24
- cirq/value/condition_test.py +2 -0
- cirq/value/digits.py +14 -11
- cirq/value/digits_test.py +2 -0
- cirq/value/duration.py +23 -20
- cirq/value/duration_test.py +2 -0
- cirq/value/linear_dict.py +25 -30
- cirq/value/linear_dict_test.py +10 -8
- cirq/value/measurement_key.py +12 -12
- cirq/value/measurement_key_test.py +2 -0
- cirq/value/periodic_value.py +4 -4
- cirq/value/periodic_value_test.py +11 -7
- cirq/value/probability.py +3 -1
- cirq/value/probability_test.py +4 -2
- cirq/value/product_state.py +15 -13
- cirq/value/product_state_test.py +4 -1
- cirq/value/random_state.py +2 -0
- cirq/value/random_state_test.py +5 -3
- cirq/value/timestamp.py +11 -7
- cirq/value/timestamp_test.py +14 -12
- cirq/value/type_alias.py +4 -4
- cirq/value/value_equality_attr.py +8 -9
- cirq/value/value_equality_attr_test.py +14 -11
- cirq/vis/density_matrix.py +3 -3
- cirq/vis/density_matrix_test.py +20 -17
- cirq/vis/heatmap.py +24 -37
- cirq/vis/heatmap_test.py +3 -0
- cirq/vis/histogram.py +9 -6
- cirq/vis/histogram_test.py +5 -2
- cirq/vis/state_histogram.py +10 -8
- cirq/vis/state_histogram_test.py +7 -5
- cirq/vis/vis_utils.py +4 -1
- cirq/vis/vis_utils_test.py +4 -1
- cirq/work/collector.py +12 -18
- cirq/work/collector_test.py +15 -10
- cirq/work/observable_grouping.py +6 -7
- cirq/work/observable_grouping_test.py +10 -9
- cirq/work/observable_measurement.py +47 -45
- cirq/work/observable_measurement_data.py +22 -17
- cirq/work/observable_measurement_data_test.py +4 -1
- cirq/work/observable_measurement_test.py +48 -29
- cirq/work/observable_readout_calibration.py +5 -2
- cirq/work/observable_readout_calibration_test.py +5 -2
- cirq/work/observable_settings.py +13 -22
- cirq/work/observable_settings_test.py +9 -7
- cirq/work/pauli_sum_collector.py +12 -10
- cirq/work/pauli_sum_collector_test.py +9 -9
- cirq/work/sampler.py +42 -43
- cirq/work/sampler_test.py +31 -24
- cirq/work/zeros_sampler.py +6 -4
- cirq/work/zeros_sampler_test.py +7 -5
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/METADATA +7 -8
- cirq_core-1.6.0.dist-info/RECORD +1241 -0
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/WHEEL +1 -1
- cirq_core-1.5.0.dev20250409222543.dist-info/RECORD +0 -1216
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/top_level.txt +0 -0
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import numpy as np
|
|
16
18
|
import pytest
|
|
17
19
|
import sympy
|
|
@@ -22,12 +24,12 @@ import cirq.testing
|
|
|
22
24
|
q0, q1, q2, q3 = cirq.LineQubit.range(4)
|
|
23
25
|
|
|
24
26
|
|
|
25
|
-
def test_raises_for_non_commuting_paulis():
|
|
27
|
+
def test_raises_for_non_commuting_paulis() -> None:
|
|
26
28
|
with pytest.raises(ValueError, match='commuting'):
|
|
27
29
|
cirq.PauliSumExponential(cirq.X(q0) + cirq.Z(q0), np.pi / 2)
|
|
28
30
|
|
|
29
31
|
|
|
30
|
-
def test_raises_for_non_hermitian_pauli():
|
|
32
|
+
def test_raises_for_non_hermitian_pauli() -> None:
|
|
31
33
|
with pytest.raises(ValueError, match='hermitian'):
|
|
32
34
|
cirq.PauliSumExponential(cirq.X(q0) + 1j * cirq.Z(q1), np.pi / 2)
|
|
33
35
|
|
|
@@ -46,7 +48,7 @@ def test_raises_for_non_hermitian_pauli():
|
|
|
46
48
|
),
|
|
47
49
|
),
|
|
48
50
|
)
|
|
49
|
-
def test_pauli_sum_exponential_qubits(psum_exp, expected_qubits):
|
|
51
|
+
def test_pauli_sum_exponential_qubits(psum_exp, expected_qubits) -> None:
|
|
50
52
|
assert psum_exp.qubits == expected_qubits
|
|
51
53
|
|
|
52
54
|
|
|
@@ -67,7 +69,7 @@ def test_pauli_sum_exponential_qubits(psum_exp, expected_qubits):
|
|
|
67
69
|
),
|
|
68
70
|
),
|
|
69
71
|
)
|
|
70
|
-
def test_pauli_sum_exponential_with_qubits(psum_exp, expected_psum_exp):
|
|
72
|
+
def test_pauli_sum_exponential_with_qubits(psum_exp, expected_psum_exp) -> None:
|
|
71
73
|
assert psum_exp.with_qubits(*expected_psum_exp.qubits) == expected_psum_exp
|
|
72
74
|
|
|
73
75
|
|
|
@@ -79,7 +81,7 @@ def test_pauli_sum_exponential_with_qubits(psum_exp, expected_psum_exp):
|
|
|
79
81
|
(cirq.X(q0) * cirq.Y(q1) + cirq.Y(q1) * cirq.Z(q3), np.pi),
|
|
80
82
|
),
|
|
81
83
|
)
|
|
82
|
-
def test_with_parameters_resolved_by(psum, exp):
|
|
84
|
+
def test_with_parameters_resolved_by(psum, exp) -> None:
|
|
83
85
|
psum_exp = cirq.PauliSumExponential(psum, sympy.Symbol("theta"))
|
|
84
86
|
resolver = cirq.ParamResolver({"theta": exp})
|
|
85
87
|
actual = cirq.resolve_parameters(psum_exp, resolver)
|
|
@@ -87,7 +89,7 @@ def test_with_parameters_resolved_by(psum, exp):
|
|
|
87
89
|
assert actual == expected
|
|
88
90
|
|
|
89
91
|
|
|
90
|
-
def test_pauli_sum_exponential_parameterized_matrix_raises():
|
|
92
|
+
def test_pauli_sum_exponential_parameterized_matrix_raises() -> None:
|
|
91
93
|
with pytest.raises(ValueError, match='parameterized'):
|
|
92
94
|
cirq.PauliSumExponential(cirq.X(q0) + cirq.Z(q1), sympy.Symbol("theta")).matrix()
|
|
93
95
|
|
|
@@ -102,7 +104,7 @@ def test_pauli_sum_exponential_parameterized_matrix_raises():
|
|
|
102
104
|
),
|
|
103
105
|
),
|
|
104
106
|
)
|
|
105
|
-
def test_pauli_sum_exponential_has_correct_unitary(psum_exp, expected_unitary):
|
|
107
|
+
def test_pauli_sum_exponential_has_correct_unitary(psum_exp, expected_unitary) -> None:
|
|
106
108
|
assert cirq.has_unitary(psum_exp)
|
|
107
109
|
assert np.allclose(cirq.unitary(psum_exp), expected_unitary)
|
|
108
110
|
|
|
@@ -127,7 +129,7 @@ def test_pauli_sum_exponential_has_correct_unitary(psum_exp, expected_unitary):
|
|
|
127
129
|
),
|
|
128
130
|
),
|
|
129
131
|
)
|
|
130
|
-
def test_pauli_sum_exponential_pow(psum_exp, power, expected_psum):
|
|
132
|
+
def test_pauli_sum_exponential_pow(psum_exp, power, expected_psum) -> None:
|
|
131
133
|
assert psum_exp**power == expected_psum
|
|
132
134
|
|
|
133
135
|
|
|
@@ -138,7 +140,7 @@ def test_pauli_sum_exponential_pow(psum_exp, power, expected_psum):
|
|
|
138
140
|
(cirq.PauliSumExponential(2j * cirq.X(q0) + 3j * cirq.Z(q1), np.pi / 2)),
|
|
139
141
|
),
|
|
140
142
|
)
|
|
141
|
-
def test_pauli_sum_exponential_repr(psum_exp):
|
|
143
|
+
def test_pauli_sum_exponential_repr(psum_exp) -> None:
|
|
142
144
|
cirq.testing.assert_equivalent_repr(psum_exp)
|
|
143
145
|
|
|
144
146
|
|
|
@@ -156,5 +158,5 @@ def test_pauli_sum_exponential_repr(psum_exp):
|
|
|
156
158
|
),
|
|
157
159
|
),
|
|
158
160
|
)
|
|
159
|
-
def test_pauli_sum_exponential_formatting(psum_exp, expected_str):
|
|
161
|
+
def test_pauli_sum_exponential_formatting(psum_exp, expected_str) -> None:
|
|
160
162
|
assert str(psum_exp) == expected_str
|
cirq/ops/permutation_gate.py
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import Any, Iterator, Sequence, TYPE_CHECKING
|
|
16
18
|
|
|
17
19
|
from cirq import protocols, value
|
|
18
20
|
from cirq.ops import raw_types, swap_gates
|
|
@@ -61,7 +63,7 @@ class QubitPermutationGate(raw_types.Gate):
|
|
|
61
63
|
self._permutation = tuple(permutation)
|
|
62
64
|
|
|
63
65
|
@property
|
|
64
|
-
def permutation(self) ->
|
|
66
|
+
def permutation(self) -> tuple[int, ...]:
|
|
65
67
|
return self._permutation
|
|
66
68
|
|
|
67
69
|
def _value_equality_values_(self):
|
|
@@ -73,7 +75,7 @@ class QubitPermutationGate(raw_types.Gate):
|
|
|
73
75
|
def _has_unitary_(self):
|
|
74
76
|
return True
|
|
75
77
|
|
|
76
|
-
def _decompose_(self, qubits: Sequence[
|
|
78
|
+
def _decompose_(self, qubits: Sequence[cirq.Qid]) -> Iterator[cirq.OP_TREE]:
|
|
77
79
|
permutation = [p for p in self.permutation]
|
|
78
80
|
|
|
79
81
|
for i in range(len(permutation)):
|
|
@@ -90,7 +92,7 @@ class QubitPermutationGate(raw_types.Gate):
|
|
|
90
92
|
for idx in cycle[1:]:
|
|
91
93
|
yield swap_gates.SWAP(qubits[cycle[0]], qubits[idx])
|
|
92
94
|
|
|
93
|
-
def _apply_unitary_(self, args:
|
|
95
|
+
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs):
|
|
94
96
|
# Compute the permutation index list.
|
|
95
97
|
permuted_axes = list(range(len(args.target_tensor.shape)))
|
|
96
98
|
for i in range(len(args.axes)):
|
|
@@ -104,13 +106,13 @@ class QubitPermutationGate(raw_types.Gate):
|
|
|
104
106
|
args.available_buffer[...] = args.target_tensor.transpose(permuted_axes)
|
|
105
107
|
return args.available_buffer
|
|
106
108
|
|
|
107
|
-
def _circuit_diagram_info_(self, args:
|
|
109
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> tuple[str, ...]:
|
|
108
110
|
return tuple(f'[{i}>{self.permutation[i]}]' for i in range(len(self.permutation)))
|
|
109
111
|
|
|
110
112
|
def __repr__(self) -> str:
|
|
111
113
|
return f'cirq.QubitPermutationGate(permutation={self.permutation!r})'
|
|
112
114
|
|
|
113
|
-
def _json_dict_(self) ->
|
|
115
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
114
116
|
return protocols.obj_to_dict_helper(self, attribute_names=['permutation'])
|
|
115
117
|
|
|
116
118
|
@classmethod
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import numpy as np
|
|
16
18
|
import pytest
|
|
17
19
|
|
|
@@ -19,7 +21,7 @@ import cirq
|
|
|
19
21
|
from cirq.ops import QubitPermutationGate
|
|
20
22
|
|
|
21
23
|
|
|
22
|
-
def test_permutation_gate_equality():
|
|
24
|
+
def test_permutation_gate_equality() -> None:
|
|
23
25
|
eq = cirq.testing.EqualsTester()
|
|
24
26
|
eq.make_equality_group(
|
|
25
27
|
lambda: QubitPermutationGate([0, 1]), lambda: QubitPermutationGate((0, 1))
|
|
@@ -27,7 +29,7 @@ def test_permutation_gate_equality():
|
|
|
27
29
|
eq.add_equality_group(QubitPermutationGate([1, 0]), QubitPermutationGate((1, 0)))
|
|
28
30
|
|
|
29
31
|
|
|
30
|
-
def test_permutation_gate_repr():
|
|
32
|
+
def test_permutation_gate_repr() -> None:
|
|
31
33
|
cirq.testing.assert_equivalent_repr(QubitPermutationGate([0, 1]))
|
|
32
34
|
|
|
33
35
|
|
|
@@ -35,26 +37,26 @@ rs = np.random.RandomState(seed=1234)
|
|
|
35
37
|
|
|
36
38
|
|
|
37
39
|
@pytest.mark.parametrize('permutation', [rs.permutation(i) for i in range(3, 7)])
|
|
38
|
-
def test_permutation_gate_consistent_protocols(permutation):
|
|
40
|
+
def test_permutation_gate_consistent_protocols(permutation) -> None:
|
|
39
41
|
gate = QubitPermutationGate(list(permutation))
|
|
40
42
|
cirq.testing.assert_implements_consistent_protocols(gate)
|
|
41
43
|
|
|
42
44
|
|
|
43
|
-
def test_permutation_gate_invalid_indices():
|
|
45
|
+
def test_permutation_gate_invalid_indices() -> None:
|
|
44
46
|
with pytest.raises(ValueError, match="Invalid indices"):
|
|
45
47
|
QubitPermutationGate([1, 0, 2, 4])
|
|
46
48
|
with pytest.raises(ValueError, match="Invalid indices"):
|
|
47
49
|
QubitPermutationGate([-1])
|
|
48
50
|
|
|
49
51
|
|
|
50
|
-
def test_permutation_gate_invalid_permutation():
|
|
52
|
+
def test_permutation_gate_invalid_permutation() -> None:
|
|
51
53
|
with pytest.raises(ValueError, match="Invalid permutation"):
|
|
52
54
|
QubitPermutationGate([1, 1])
|
|
53
55
|
with pytest.raises(ValueError, match="Invalid permutation"):
|
|
54
56
|
QubitPermutationGate([])
|
|
55
57
|
|
|
56
58
|
|
|
57
|
-
def test_permutation_gate_diagram():
|
|
59
|
+
def test_permutation_gate_diagram() -> None:
|
|
58
60
|
q = cirq.LineQubit.range(6)
|
|
59
61
|
cirq.testing.assert_has_diagram(
|
|
60
62
|
cirq.Circuit(cirq.X(q[0]), cirq.X(q[5]), QubitPermutationGate([3, 2, 1, 0]).on(*q[1:5])),
|
|
@@ -74,7 +76,7 @@ def test_permutation_gate_diagram():
|
|
|
74
76
|
)
|
|
75
77
|
|
|
76
78
|
|
|
77
|
-
def test_permutation_gate_json_dict():
|
|
79
|
+
def test_permutation_gate_json_dict() -> None:
|
|
78
80
|
assert cirq.QubitPermutationGate([0, 1, 2])._json_dict_() == {'permutation': (0, 1, 2)}
|
|
79
81
|
|
|
80
82
|
|
|
@@ -96,7 +98,7 @@ def test_permutation_gate_json_dict():
|
|
|
96
98
|
],
|
|
97
99
|
],
|
|
98
100
|
)
|
|
99
|
-
def test_permutation_gate_maps(maps, permutation):
|
|
101
|
+
def test_permutation_gate_maps(maps, permutation) -> None:
|
|
100
102
|
qs = cirq.LineQubit.range(len(permutation))
|
|
101
103
|
permutationOp = cirq.QubitPermutationGate(permutation).on(*qs)
|
|
102
104
|
circuit = cirq.Circuit(permutationOp)
|
cirq/ops/phased_iswap_gate.py
CHANGED
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
"""ISWAPPowGate conjugated by tensor product Rz(phi) and Rz(-phi)."""
|
|
15
15
|
|
|
16
|
-
from
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from typing import AbstractSet, Any, cast, Iterator, Sequence
|
|
17
19
|
|
|
18
20
|
import numpy as np
|
|
19
21
|
import sympy
|
|
@@ -60,8 +62,8 @@ class PhasedISwapPowGate(eigen_gate.EigenGate):
|
|
|
60
62
|
def __init__(
|
|
61
63
|
self,
|
|
62
64
|
*,
|
|
63
|
-
phase_exponent:
|
|
64
|
-
exponent:
|
|
65
|
+
phase_exponent: float | sympy.Expr = 0.25,
|
|
66
|
+
exponent: float | sympy.Expr = 1.0,
|
|
65
67
|
global_shift: float = 0.0,
|
|
66
68
|
):
|
|
67
69
|
"""Inits PhasedISwapPowGate.
|
|
@@ -79,13 +81,13 @@ class PhasedISwapPowGate(eigen_gate.EigenGate):
|
|
|
79
81
|
super().__init__(exponent=exponent, global_shift=global_shift)
|
|
80
82
|
|
|
81
83
|
@property
|
|
82
|
-
def phase_exponent(self) ->
|
|
84
|
+
def phase_exponent(self) -> float | sympy.Expr:
|
|
83
85
|
return self._phase_exponent
|
|
84
86
|
|
|
85
87
|
def _num_qubits_(self) -> int:
|
|
86
88
|
return 2
|
|
87
89
|
|
|
88
|
-
def _json_dict_(self) ->
|
|
90
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
89
91
|
return {
|
|
90
92
|
'phase_exponent': self._phase_exponent,
|
|
91
93
|
'exponent': self._exponent,
|
|
@@ -112,32 +114,32 @@ class PhasedISwapPowGate(eigen_gate.EigenGate):
|
|
|
112
114
|
)
|
|
113
115
|
|
|
114
116
|
def _resolve_parameters_(
|
|
115
|
-
self, resolver:
|
|
116
|
-
) ->
|
|
117
|
+
self, resolver: cirq.ParamResolver, recursive: bool
|
|
118
|
+
) -> PhasedISwapPowGate:
|
|
117
119
|
return self.__class__(
|
|
118
120
|
phase_exponent=protocols.resolve_parameters(self.phase_exponent, resolver, recursive),
|
|
119
121
|
exponent=protocols.resolve_parameters(self.exponent, resolver, recursive),
|
|
120
122
|
)
|
|
121
123
|
|
|
122
|
-
def _with_exponent(self, exponent: value.type_alias.TParamVal) ->
|
|
124
|
+
def _with_exponent(self, exponent: value.type_alias.TParamVal) -> PhasedISwapPowGate:
|
|
123
125
|
return PhasedISwapPowGate(
|
|
124
126
|
phase_exponent=self.phase_exponent, exponent=exponent, global_shift=self.global_shift
|
|
125
127
|
)
|
|
126
128
|
|
|
127
|
-
def _eigen_shifts(self) ->
|
|
129
|
+
def _eigen_shifts(self) -> list[float]:
|
|
128
130
|
return [0.0, +0.5, -0.5]
|
|
129
131
|
|
|
130
|
-
def _eigen_components(self) ->
|
|
132
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
131
133
|
phase = np.exp(1j * np.pi * self.phase_exponent)
|
|
132
134
|
phase_matrix = np.diag([1, phase, phase.conjugate(), 1])
|
|
133
135
|
inverse_phase_matrix = np.conjugate(phase_matrix)
|
|
134
|
-
eigen_components:
|
|
136
|
+
eigen_components: list[tuple[float, np.ndarray]] = []
|
|
135
137
|
for eigenvalue, projector in self._iswap._eigen_components():
|
|
136
138
|
new_projector = phase_matrix @ projector @ inverse_phase_matrix
|
|
137
139
|
eigen_components.append((eigenvalue, new_projector))
|
|
138
140
|
return eigen_components
|
|
139
141
|
|
|
140
|
-
def _apply_unitary_(self, args:
|
|
142
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
141
143
|
if protocols.is_parameterized(self):
|
|
142
144
|
return NotImplemented
|
|
143
145
|
|
|
@@ -156,7 +158,7 @@ class PhasedISwapPowGate(eigen_gate.EigenGate):
|
|
|
156
158
|
)
|
|
157
159
|
return args.available_buffer
|
|
158
160
|
|
|
159
|
-
def _decompose_(self, qubits: Sequence[
|
|
161
|
+
def _decompose_(self, qubits: Sequence[cirq.Qid]) -> Iterator[cirq.OP_TREE]:
|
|
160
162
|
if len(qubits) != 2:
|
|
161
163
|
raise ValueError(f'Expected two qubits, got {len(qubits)}')
|
|
162
164
|
a, b = qubits
|
|
@@ -189,9 +191,7 @@ class PhasedISwapPowGate(eigen_gate.EigenGate):
|
|
|
189
191
|
}
|
|
190
192
|
)
|
|
191
193
|
|
|
192
|
-
def _circuit_diagram_info_(
|
|
193
|
-
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
194
|
-
) -> 'cirq.CircuitDiagramInfo':
|
|
194
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
195
195
|
s = f'PhISwap({args.format_real(self._phase_exponent)})'
|
|
196
196
|
return protocols.CircuitDiagramInfo(
|
|
197
197
|
wire_symbols=(s, s), exponent=self._diagram_exponent(args)
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import numpy as np
|
|
16
18
|
import pytest
|
|
17
19
|
import scipy
|
|
@@ -22,7 +24,7 @@ import cirq
|
|
|
22
24
|
np.set_printoptions(linewidth=300)
|
|
23
25
|
|
|
24
26
|
|
|
25
|
-
def test_phased_iswap_init():
|
|
27
|
+
def test_phased_iswap_init() -> None:
|
|
26
28
|
p = -0.25
|
|
27
29
|
t = 0.75
|
|
28
30
|
s = 0.5
|
|
@@ -32,7 +34,7 @@ def test_phased_iswap_init():
|
|
|
32
34
|
assert gate.global_shift == s
|
|
33
35
|
|
|
34
36
|
|
|
35
|
-
def test_phased_iswap_equality():
|
|
37
|
+
def test_phased_iswap_equality() -> None:
|
|
36
38
|
eq = cirq.testing.EqualsTester()
|
|
37
39
|
eq.add_equality_group(cirq.PhasedISwapPowGate(phase_exponent=0, exponent=0.4))
|
|
38
40
|
eq.add_equality_group(cirq.ISWAP**0.4)
|
|
@@ -40,7 +42,7 @@ def test_phased_iswap_equality():
|
|
|
40
42
|
eq.add_equality_group(cirq.ISwapPowGate(global_shift=0.3) ** 0.4)
|
|
41
43
|
|
|
42
44
|
|
|
43
|
-
def test_repr():
|
|
45
|
+
def test_repr() -> None:
|
|
44
46
|
p = -0.25
|
|
45
47
|
t = 0.75
|
|
46
48
|
s = 0.3
|
|
@@ -48,7 +50,7 @@ def test_repr():
|
|
|
48
50
|
cirq.testing.assert_equivalent_repr(gate)
|
|
49
51
|
|
|
50
52
|
|
|
51
|
-
def test_phased_iswap_unitary():
|
|
53
|
+
def test_phased_iswap_unitary() -> None:
|
|
52
54
|
p = 0.3
|
|
53
55
|
t = 0.4
|
|
54
56
|
actual = cirq.unitary(cirq.PhasedISwapPowGate(phase_exponent=p, exponent=t))
|
|
@@ -64,7 +66,7 @@ def test_phased_iswap_unitary():
|
|
|
64
66
|
assert np.allclose(actual, expected)
|
|
65
67
|
|
|
66
68
|
|
|
67
|
-
def test_phased_iswap_equivalent_circuit():
|
|
69
|
+
def test_phased_iswap_equivalent_circuit() -> None:
|
|
68
70
|
p = 0.7
|
|
69
71
|
t = -0.4
|
|
70
72
|
gate = cirq.PhasedISwapPowGate(phase_exponent=p, exponent=t)
|
|
@@ -81,7 +83,7 @@ def test_phased_iswap_equivalent_circuit():
|
|
|
81
83
|
assert np.allclose(cirq.unitary(gate), cirq.unitary(equivalent_circuit))
|
|
82
84
|
|
|
83
85
|
|
|
84
|
-
def test_phased_iswap_str():
|
|
86
|
+
def test_phased_iswap_str() -> None:
|
|
85
87
|
assert str(cirq.PhasedISwapPowGate(exponent=1)) == 'PhasedISWAP'
|
|
86
88
|
assert str(cirq.PhasedISwapPowGate(exponent=0.5)) == 'PhasedISWAP**0.5'
|
|
87
89
|
assert (
|
|
@@ -90,7 +92,7 @@ def test_phased_iswap_str():
|
|
|
90
92
|
)
|
|
91
93
|
|
|
92
94
|
|
|
93
|
-
def test_phased_iswap_pow():
|
|
95
|
+
def test_phased_iswap_pow() -> None:
|
|
94
96
|
gate1 = cirq.PhasedISwapPowGate(phase_exponent=0.1, exponent=0.25)
|
|
95
97
|
gate2 = cirq.PhasedISwapPowGate(phase_exponent=0.1, exponent=0.5)
|
|
96
98
|
assert gate1**2 == gate2
|
|
@@ -108,7 +110,7 @@ def test_phased_iswap_pow():
|
|
|
108
110
|
assert np.allclose(u1 @ u1, u2)
|
|
109
111
|
|
|
110
112
|
|
|
111
|
-
def test_decompose_invalid_qubits():
|
|
113
|
+
def test_decompose_invalid_qubits() -> None:
|
|
112
114
|
qs = cirq.LineQubit.range(3)
|
|
113
115
|
with pytest.raises(ValueError):
|
|
114
116
|
cirq.protocols.decompose_once_with_qubits(cirq.PhasedISwapPowGate(), qs)
|
|
@@ -134,7 +136,7 @@ def test_decompose_invalid_qubits():
|
|
|
134
136
|
(sympy.Symbol('t'), sympy.Symbol('p'), 1),
|
|
135
137
|
],
|
|
136
138
|
)
|
|
137
|
-
def test_phased_iswap_has_consistent_protocols(phase_exponent, exponent, global_shift):
|
|
139
|
+
def test_phased_iswap_has_consistent_protocols(phase_exponent, exponent, global_shift) -> None:
|
|
138
140
|
cirq.testing.assert_implements_consistent_protocols(
|
|
139
141
|
cirq.PhasedISwapPowGate(
|
|
140
142
|
phase_exponent=phase_exponent, exponent=exponent, global_shift=global_shift
|
|
@@ -142,7 +144,7 @@ def test_phased_iswap_has_consistent_protocols(phase_exponent, exponent, global_
|
|
|
142
144
|
)
|
|
143
145
|
|
|
144
146
|
|
|
145
|
-
def test_diagram():
|
|
147
|
+
def test_diagram() -> None:
|
|
146
148
|
q0, q1 = cirq.LineQubit.range(2)
|
|
147
149
|
c = cirq.Circuit(
|
|
148
150
|
cirq.PhasedISwapPowGate(phase_exponent=sympy.Symbol('p'), exponent=sympy.Symbol('t')).on(
|
|
@@ -165,7 +167,7 @@ def test_diagram():
|
|
|
165
167
|
|
|
166
168
|
|
|
167
169
|
@pytest.mark.parametrize('angle_rads', (-np.pi, -np.pi / 3, -0.1, np.pi / 5))
|
|
168
|
-
def test_givens_rotation_unitary(angle_rads):
|
|
170
|
+
def test_givens_rotation_unitary(angle_rads) -> None:
|
|
169
171
|
actual = cirq.unitary(cirq.givens(angle_rads))
|
|
170
172
|
c = np.cos(angle_rads)
|
|
171
173
|
s = np.sin(angle_rads)
|
|
@@ -179,7 +181,7 @@ def test_givens_rotation_unitary(angle_rads):
|
|
|
179
181
|
|
|
180
182
|
|
|
181
183
|
@pytest.mark.parametrize('angle_rads', (-2 * np.pi / 3, -0.2, 0.4, np.pi / 4))
|
|
182
|
-
def test_givens_rotation_hamiltonian(angle_rads):
|
|
184
|
+
def test_givens_rotation_hamiltonian(angle_rads) -> None:
|
|
183
185
|
actual = cirq.unitary(cirq.givens(angle_rads))
|
|
184
186
|
x = np.array([[0, 1], [1, 0]])
|
|
185
187
|
y = np.array([[0, -1j], [1j, 0]])
|
|
@@ -189,7 +191,7 @@ def test_givens_rotation_hamiltonian(angle_rads):
|
|
|
189
191
|
assert np.allclose(actual, expected)
|
|
190
192
|
|
|
191
193
|
|
|
192
|
-
def test_givens_rotation_equivalent_circuit():
|
|
194
|
+
def test_givens_rotation_equivalent_circuit() -> None:
|
|
193
195
|
angle_rads = 3 * np.pi / 7
|
|
194
196
|
t = 2 * angle_rads / np.pi
|
|
195
197
|
gate = cirq.givens(angle_rads)
|
|
@@ -201,11 +203,11 @@ def test_givens_rotation_equivalent_circuit():
|
|
|
201
203
|
|
|
202
204
|
|
|
203
205
|
@pytest.mark.parametrize('angle_rads', (-np.pi / 5, 0.4, 2, np.pi))
|
|
204
|
-
def test_givens_rotation_has_consistent_protocols(angle_rads):
|
|
206
|
+
def test_givens_rotation_has_consistent_protocols(angle_rads) -> None:
|
|
205
207
|
cirq.testing.assert_implements_consistent_protocols(cirq.givens(angle_rads))
|
|
206
208
|
|
|
207
209
|
|
|
208
|
-
def test_approx_eq():
|
|
210
|
+
def test_approx_eq() -> None:
|
|
209
211
|
gate0 = cirq.PhasedISwapPowGate(phase_exponent=0)
|
|
210
212
|
gate1 = cirq.PhasedISwapPowGate(phase_exponent=1e-12)
|
|
211
213
|
gate2 = cirq.PhasedISwapPowGate(phase_exponent=2e-12)
|
cirq/ops/phased_x_gate.py
CHANGED
|
@@ -11,12 +11,15 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
14
15
|
"""An `XPowGate` conjugated by `ZPowGate`s."""
|
|
15
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
16
19
|
import math
|
|
17
20
|
import numbers
|
|
18
21
|
from types import NotImplementedType
|
|
19
|
-
from typing import AbstractSet, Any, cast,
|
|
22
|
+
from typing import AbstractSet, Any, cast, Sequence
|
|
20
23
|
|
|
21
24
|
import numpy as np
|
|
22
25
|
import sympy
|
|
@@ -48,8 +51,8 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
48
51
|
def __init__(
|
|
49
52
|
self,
|
|
50
53
|
*,
|
|
51
|
-
phase_exponent:
|
|
52
|
-
exponent:
|
|
54
|
+
phase_exponent: float | sympy.Expr,
|
|
55
|
+
exponent: float | sympy.Expr = 1.0,
|
|
53
56
|
global_shift: float = 0.0,
|
|
54
57
|
) -> None:
|
|
55
58
|
"""Inits PhasedXPowGate.
|
|
@@ -64,7 +67,7 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
64
67
|
self._exponent = exponent
|
|
65
68
|
self._global_shift = global_shift
|
|
66
69
|
|
|
67
|
-
def _qasm_(self, args:
|
|
70
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
68
71
|
if cirq.is_parameterized(self):
|
|
69
72
|
return None
|
|
70
73
|
|
|
@@ -92,7 +95,7 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
92
95
|
qubits[0],
|
|
93
96
|
)
|
|
94
97
|
|
|
95
|
-
def _decompose_(self, qubits: Sequence[
|
|
98
|
+
def _decompose_(self, qubits: Sequence[cirq.Qid]) -> cirq.OP_TREE:
|
|
96
99
|
assert len(qubits) == 1
|
|
97
100
|
q = qubits[0]
|
|
98
101
|
z = cirq.Z(q) ** self._phase_exponent
|
|
@@ -100,12 +103,12 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
100
103
|
return z**-1, x, z
|
|
101
104
|
|
|
102
105
|
@property
|
|
103
|
-
def exponent(self) ->
|
|
106
|
+
def exponent(self) -> float | sympy.Expr:
|
|
104
107
|
"""The exponent on the central X gate conjugated by the Z gates."""
|
|
105
108
|
return self._exponent
|
|
106
109
|
|
|
107
110
|
@property
|
|
108
|
-
def phase_exponent(self) ->
|
|
111
|
+
def phase_exponent(self) -> float | sympy.Expr:
|
|
109
112
|
"""The exponent on the Z gates conjugating the X gate."""
|
|
110
113
|
return self._phase_exponent
|
|
111
114
|
|
|
@@ -113,7 +116,7 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
113
116
|
def global_shift(self) -> float:
|
|
114
117
|
return self._global_shift
|
|
115
118
|
|
|
116
|
-
def __pow__(self, exponent:
|
|
119
|
+
def __pow__(self, exponent: float | sympy.Expr) -> PhasedXPowGate:
|
|
117
120
|
new_exponent = protocols.mul(self._exponent, exponent, NotImplemented)
|
|
118
121
|
if new_exponent is NotImplemented:
|
|
119
122
|
return NotImplemented # pragma: no cover
|
|
@@ -123,7 +126,7 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
123
126
|
global_shift=self._global_shift,
|
|
124
127
|
)
|
|
125
128
|
|
|
126
|
-
def _trace_distance_bound_(self) ->
|
|
129
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
127
130
|
if self._is_parameterized_():
|
|
128
131
|
return None
|
|
129
132
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
@@ -131,7 +134,7 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
131
134
|
def _has_unitary_(self):
|
|
132
135
|
return not self._is_parameterized_()
|
|
133
136
|
|
|
134
|
-
def _unitary_(self) ->
|
|
137
|
+
def _unitary_(self) -> np.ndarray | NotImplementedType | None:
|
|
135
138
|
"""See `cirq.SupportsUnitary`."""
|
|
136
139
|
if self._is_parameterized_():
|
|
137
140
|
return None
|
|
@@ -169,9 +172,7 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
169
172
|
self._phase_exponent
|
|
170
173
|
)
|
|
171
174
|
|
|
172
|
-
def _resolve_parameters_(
|
|
173
|
-
self, resolver: 'cirq.ParamResolver', recursive: bool
|
|
174
|
-
) -> 'PhasedXPowGate':
|
|
175
|
+
def _resolve_parameters_(self, resolver: cirq.ParamResolver, recursive: bool) -> PhasedXPowGate:
|
|
175
176
|
"""See `cirq.SupportsParameterization`."""
|
|
176
177
|
phase_exponent = resolver.value_of(self._phase_exponent, recursive)
|
|
177
178
|
exponent = resolver.value_of(self._exponent, recursive)
|
|
@@ -198,9 +199,7 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
198
199
|
global_shift=self._global_shift,
|
|
199
200
|
)
|
|
200
201
|
|
|
201
|
-
def _circuit_diagram_info_(
|
|
202
|
-
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
203
|
-
) -> 'cirq.CircuitDiagramInfo':
|
|
202
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
204
203
|
"""See `cirq.SupportsCircuitDiagramInfo`."""
|
|
205
204
|
|
|
206
205
|
return protocols.CircuitDiagramInfo(
|
|
@@ -244,5 +243,5 @@ class PhasedXPowGate(raw_types.Gate):
|
|
|
244
243
|
def _value_equality_values_(self):
|
|
245
244
|
return self.phase_exponent, self._canonical_exponent, self._global_shift
|
|
246
245
|
|
|
247
|
-
def _json_dict_(self) ->
|
|
246
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
248
247
|
return protocols.obj_to_dict_helper(self, ['phase_exponent', 'exponent', 'global_shift'])
|