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
cirq/ops/fsim_gate.py
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
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
|
"""Defines the fermionic simulation gate.
|
|
15
16
|
|
|
16
17
|
This is the family of two-qubit gates that preserve excitations (number of ON
|
|
@@ -21,9 +22,11 @@ context of chemistry the electron count is conserved over time. This property
|
|
|
21
22
|
applies more generally to fermions, thus the name of the gate.
|
|
22
23
|
"""
|
|
23
24
|
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
24
27
|
import cmath
|
|
25
28
|
import math
|
|
26
|
-
from typing import AbstractSet, Any,
|
|
29
|
+
from typing import AbstractSet, Any, Iterator
|
|
27
30
|
|
|
28
31
|
import numpy as np
|
|
29
32
|
import sympy
|
|
@@ -34,7 +37,7 @@ from cirq._compat import proper_repr
|
|
|
34
37
|
from cirq.ops import gate_features, raw_types
|
|
35
38
|
|
|
36
39
|
|
|
37
|
-
def _canonicalize(value:
|
|
40
|
+
def _canonicalize(value: cirq.TParamVal) -> cirq.TParamVal:
|
|
38
41
|
"""Assumes value is 2π-periodic and shifts it into [-π, π)."""
|
|
39
42
|
if protocols.is_parameterized(value):
|
|
40
43
|
return value
|
|
@@ -42,12 +45,12 @@ def _canonicalize(value: 'cirq.TParamVal') -> 'cirq.TParamVal':
|
|
|
42
45
|
return value - period * np.floor((value + np.pi) / period)
|
|
43
46
|
|
|
44
47
|
|
|
45
|
-
def _zero_mod_pi(param:
|
|
48
|
+
def _zero_mod_pi(param: cirq.TParamVal) -> bool:
|
|
46
49
|
"""Returns True iff param, assumed to be in [-pi, pi), is 0 (mod pi)."""
|
|
47
50
|
return param in (0.0, -np.pi, -sympy.pi)
|
|
48
51
|
|
|
49
52
|
|
|
50
|
-
def _half_pi_mod_pi(param:
|
|
53
|
+
def _half_pi_mod_pi(param: cirq.TParamVal) -> bool:
|
|
51
54
|
"""Returns True iff param, assumed to be in [-pi, pi), is pi/2 (mod pi)."""
|
|
52
55
|
return param in (-np.pi / 2, np.pi / 2, -sympy.pi / 2, sympy.pi / 2)
|
|
53
56
|
|
|
@@ -90,7 +93,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
90
93
|
FSimGate(θ, φ) = ISWAP**(-2θ/π) CZPowGate(exponent=-φ/π)
|
|
91
94
|
"""
|
|
92
95
|
|
|
93
|
-
def __init__(self, theta:
|
|
96
|
+
def __init__(self, theta: cirq.TParamVal, phi: cirq.TParamVal) -> None:
|
|
94
97
|
"""Inits FSimGate.
|
|
95
98
|
|
|
96
99
|
Args:
|
|
@@ -106,11 +109,11 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
106
109
|
self._phi = _canonicalize(phi)
|
|
107
110
|
|
|
108
111
|
@property
|
|
109
|
-
def theta(self) ->
|
|
112
|
+
def theta(self) -> cirq.TParamVal:
|
|
110
113
|
return self._theta
|
|
111
114
|
|
|
112
115
|
@property
|
|
113
|
-
def phi(self) ->
|
|
116
|
+
def phi(self) -> cirq.TParamVal:
|
|
114
117
|
return self._phi
|
|
115
118
|
|
|
116
119
|
def _num_qubits_(self) -> int:
|
|
@@ -128,7 +131,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
128
131
|
def _has_unitary_(self):
|
|
129
132
|
return not self._is_parameterized_()
|
|
130
133
|
|
|
131
|
-
def _unitary_(self) ->
|
|
134
|
+
def _unitary_(self) -> np.ndarray | None:
|
|
132
135
|
if self._is_parameterized_():
|
|
133
136
|
return None
|
|
134
137
|
a = math.cos(self.theta)
|
|
@@ -162,15 +165,13 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
162
165
|
}
|
|
163
166
|
)
|
|
164
167
|
|
|
165
|
-
def _resolve_parameters_(
|
|
166
|
-
self, resolver: 'cirq.ParamResolver', recursive: bool
|
|
167
|
-
) -> 'cirq.FSimGate':
|
|
168
|
+
def _resolve_parameters_(self, resolver: cirq.ParamResolver, recursive: bool) -> cirq.FSimGate:
|
|
168
169
|
return FSimGate(
|
|
169
170
|
protocols.resolve_parameters(self.theta, resolver, recursive),
|
|
170
171
|
protocols.resolve_parameters(self.phi, resolver, recursive),
|
|
171
172
|
)
|
|
172
173
|
|
|
173
|
-
def _apply_unitary_(self, args:
|
|
174
|
+
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
174
175
|
if cirq.is_parameterized(self):
|
|
175
176
|
return None
|
|
176
177
|
if self.theta != 0:
|
|
@@ -187,7 +188,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
187
188
|
out[ii] *= cmath.exp(-1j * self.phi)
|
|
188
189
|
return out
|
|
189
190
|
|
|
190
|
-
def _decompose_(self, qubits) -> Iterator[
|
|
191
|
+
def _decompose_(self, qubits) -> Iterator[cirq.OP_TREE]:
|
|
191
192
|
a, b = qubits
|
|
192
193
|
xx = cirq.XXPowGate(exponent=self.theta / np.pi, global_shift=-0.5)
|
|
193
194
|
yy = cirq.YYPowGate(exponent=self.theta / np.pi, global_shift=-0.5)
|
|
@@ -195,12 +196,12 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
195
196
|
yield yy(a, b)
|
|
196
197
|
yield cirq.CZ(a, b) ** (-self.phi / np.pi)
|
|
197
198
|
|
|
198
|
-
def _circuit_diagram_info_(self, args:
|
|
199
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> tuple[str, ...]:
|
|
199
200
|
t = args.format_radians(self.theta)
|
|
200
201
|
p = args.format_radians(self.phi)
|
|
201
202
|
return f'FSim({t}, {p})', f'FSim({t}, {p})'
|
|
202
203
|
|
|
203
|
-
def __pow__(self, power) ->
|
|
204
|
+
def __pow__(self, power) -> FSimGate:
|
|
204
205
|
return FSimGate(cirq.mul(self.theta, power), cirq.mul(self.phi, power))
|
|
205
206
|
|
|
206
207
|
def __repr__(self) -> str:
|
|
@@ -208,7 +209,7 @@ class FSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
208
209
|
p = proper_repr(self.phi)
|
|
209
210
|
return f'cirq.FSimGate(theta={t}, phi={p})'
|
|
210
211
|
|
|
211
|
-
def _json_dict_(self) ->
|
|
212
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
212
213
|
return protocols.obj_to_dict_helper(self, ['theta', 'phi'])
|
|
213
214
|
|
|
214
215
|
|
|
@@ -275,11 +276,11 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
275
276
|
|
|
276
277
|
def __init__(
|
|
277
278
|
self,
|
|
278
|
-
theta:
|
|
279
|
-
zeta:
|
|
280
|
-
chi:
|
|
281
|
-
gamma:
|
|
282
|
-
phi:
|
|
279
|
+
theta: cirq.TParamVal,
|
|
280
|
+
zeta: cirq.TParamVal = 0.0,
|
|
281
|
+
chi: cirq.TParamVal = 0.0,
|
|
282
|
+
gamma: cirq.TParamVal = 0.0,
|
|
283
|
+
phi: cirq.TParamVal = 0.0,
|
|
283
284
|
) -> None:
|
|
284
285
|
"""Inits PhasedFSimGate.
|
|
285
286
|
|
|
@@ -302,32 +303,32 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
302
303
|
self._phi = _canonicalize(phi)
|
|
303
304
|
|
|
304
305
|
@property
|
|
305
|
-
def theta(self) ->
|
|
306
|
+
def theta(self) -> cirq.TParamVal:
|
|
306
307
|
return self._theta
|
|
307
308
|
|
|
308
309
|
@property
|
|
309
|
-
def zeta(self) ->
|
|
310
|
+
def zeta(self) -> cirq.TParamVal:
|
|
310
311
|
return self._zeta
|
|
311
312
|
|
|
312
313
|
@property
|
|
313
|
-
def chi(self) ->
|
|
314
|
+
def chi(self) -> cirq.TParamVal:
|
|
314
315
|
return self._chi
|
|
315
316
|
|
|
316
317
|
@property
|
|
317
|
-
def gamma(self) ->
|
|
318
|
+
def gamma(self) -> cirq.TParamVal:
|
|
318
319
|
return self._gamma
|
|
319
320
|
|
|
320
321
|
@property
|
|
321
|
-
def phi(self) ->
|
|
322
|
+
def phi(self) -> cirq.TParamVal:
|
|
322
323
|
return self._phi
|
|
323
324
|
|
|
324
325
|
@staticmethod
|
|
325
326
|
def from_fsim_rz(
|
|
326
|
-
theta:
|
|
327
|
-
phi:
|
|
328
|
-
rz_angles_before:
|
|
329
|
-
rz_angles_after:
|
|
330
|
-
) ->
|
|
327
|
+
theta: cirq.TParamVal,
|
|
328
|
+
phi: cirq.TParamVal,
|
|
329
|
+
rz_angles_before: tuple[cirq.TParamVal, cirq.TParamVal],
|
|
330
|
+
rz_angles_after: tuple[cirq.TParamVal, cirq.TParamVal],
|
|
331
|
+
) -> PhasedFSimGate:
|
|
331
332
|
"""Creates PhasedFSimGate using an alternate parametrization.
|
|
332
333
|
|
|
333
334
|
Args:
|
|
@@ -348,7 +349,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
348
349
|
return PhasedFSimGate(theta, zeta, chi, gamma, phi)
|
|
349
350
|
|
|
350
351
|
@staticmethod
|
|
351
|
-
def from_matrix(u: np.ndarray) ->
|
|
352
|
+
def from_matrix(u: np.ndarray) -> PhasedFSimGate | None:
|
|
352
353
|
"""Contruct a PhasedFSimGate from unitary.
|
|
353
354
|
|
|
354
355
|
Args:
|
|
@@ -387,14 +388,14 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
387
388
|
return None
|
|
388
389
|
|
|
389
390
|
@property
|
|
390
|
-
def rz_angles_before(self) ->
|
|
391
|
+
def rz_angles_before(self) -> tuple[cirq.TParamVal, cirq.TParamVal]:
|
|
391
392
|
"""Returns 2-tuple of phase angles applied to qubits before FSimGate."""
|
|
392
393
|
b0 = (-self.gamma + self.zeta + self.chi) / 2.0
|
|
393
394
|
b1 = (-self.gamma - self.zeta - self.chi) / 2.0
|
|
394
395
|
return b0, b1
|
|
395
396
|
|
|
396
397
|
@property
|
|
397
|
-
def rz_angles_after(self) ->
|
|
398
|
+
def rz_angles_after(self) -> tuple[cirq.TParamVal, cirq.TParamVal]:
|
|
398
399
|
"""Returns 2-tuple of phase angles applied to qubits after FSimGate."""
|
|
399
400
|
a0 = (-self.gamma + self.zeta - self.chi) / 2.0
|
|
400
401
|
a1 = (-self.gamma - self.zeta + self.chi) / 2.0
|
|
@@ -433,7 +434,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
433
434
|
def _has_unitary_(self):
|
|
434
435
|
return not self._is_parameterized_()
|
|
435
436
|
|
|
436
|
-
def _unitary_(self) ->
|
|
437
|
+
def _unitary_(self) -> np.ndarray | None:
|
|
437
438
|
if self._is_parameterized_():
|
|
438
439
|
return None
|
|
439
440
|
a = math.cos(self.theta)
|
|
@@ -456,8 +457,8 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
456
457
|
# fmt: on
|
|
457
458
|
|
|
458
459
|
def _resolve_parameters_(
|
|
459
|
-
self, resolver:
|
|
460
|
-
) ->
|
|
460
|
+
self, resolver: cirq.ParamResolver, recursive: bool
|
|
461
|
+
) -> cirq.PhasedFSimGate:
|
|
461
462
|
return PhasedFSimGate(
|
|
462
463
|
protocols.resolve_parameters(self.theta, resolver, recursive),
|
|
463
464
|
protocols.resolve_parameters(self.zeta, resolver, recursive),
|
|
@@ -466,7 +467,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
466
467
|
protocols.resolve_parameters(self.phi, resolver, recursive),
|
|
467
468
|
)
|
|
468
469
|
|
|
469
|
-
def _apply_unitary_(self, args:
|
|
470
|
+
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
470
471
|
if cirq.is_parameterized(self):
|
|
471
472
|
return None
|
|
472
473
|
oi = args.subspace_index(0b01)
|
|
@@ -491,7 +492,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
491
492
|
out[ii] *= f * f
|
|
492
493
|
return out
|
|
493
494
|
|
|
494
|
-
def _decompose_(self, qubits) -> Iterator[
|
|
495
|
+
def _decompose_(self, qubits) -> Iterator[cirq.OP_TREE]:
|
|
495
496
|
"""Decomposes self into Z rotations and FSimGate.
|
|
496
497
|
|
|
497
498
|
Note that Z rotations returned by this method have unusual global phase
|
|
@@ -500,7 +501,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
500
501
|
makes the top left element of the matrix equal to 1.
|
|
501
502
|
"""
|
|
502
503
|
|
|
503
|
-
def to_exponent(angle_rads:
|
|
504
|
+
def to_exponent(angle_rads: cirq.TParamVal) -> cirq.TParamVal:
|
|
504
505
|
"""Divides angle_rads by symbolic or numerical pi."""
|
|
505
506
|
pi = sympy.pi if protocols.is_parameterized(angle_rads) else np.pi
|
|
506
507
|
return angle_rads / pi
|
|
@@ -514,7 +515,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
514
515
|
yield cirq.Z(q0) ** to_exponent(after[0])
|
|
515
516
|
yield cirq.Z(q1) ** to_exponent(after[1])
|
|
516
517
|
|
|
517
|
-
def _circuit_diagram_info_(self, args:
|
|
518
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> tuple[str, ...]:
|
|
518
519
|
theta = args.format_radians(self.theta)
|
|
519
520
|
zeta = args.format_radians(self.zeta)
|
|
520
521
|
chi = args.format_radians(self.chi)
|
|
@@ -536,7 +537,7 @@ class PhasedFSimGate(gate_features.InterchangeableQubitsGate, raw_types.Gate):
|
|
|
536
537
|
f'gamma={gamma}, phi={phi})'
|
|
537
538
|
)
|
|
538
539
|
|
|
539
|
-
def _json_dict_(self) ->
|
|
540
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
540
541
|
return protocols.obj_to_dict_helper(self, ['theta', 'zeta', 'chi', 'gamma', 'phi'])
|
|
541
542
|
|
|
542
543
|
def _num_qubits_(self) -> int:
|
cirq/ops/fsim_gate_test.py
CHANGED
|
@@ -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
|
|
@@ -19,7 +21,7 @@ import sympy
|
|
|
19
21
|
import cirq
|
|
20
22
|
|
|
21
23
|
|
|
22
|
-
def test_fsim_init():
|
|
24
|
+
def test_fsim_init() -> None:
|
|
23
25
|
f = cirq.FSimGate(1, 2)
|
|
24
26
|
assert f.theta == 1
|
|
25
27
|
assert f.phi == 2
|
|
@@ -33,7 +35,7 @@ def test_fsim_init():
|
|
|
33
35
|
assert f3.phi == -5 + 2 * np.pi
|
|
34
36
|
|
|
35
37
|
|
|
36
|
-
def test_fsim_eq():
|
|
38
|
+
def test_fsim_eq() -> None:
|
|
37
39
|
eq = cirq.testing.EqualsTester()
|
|
38
40
|
a, b = cirq.LineQubit.range(2)
|
|
39
41
|
|
|
@@ -45,7 +47,7 @@ def test_fsim_eq():
|
|
|
45
47
|
eq.add_equality_group(cirq.FSimGate(np.pi, np.pi), cirq.FSimGate(-np.pi, -np.pi))
|
|
46
48
|
|
|
47
49
|
|
|
48
|
-
def test_fsim_approx_eq():
|
|
50
|
+
def test_fsim_approx_eq() -> None:
|
|
49
51
|
assert cirq.approx_eq(cirq.FSimGate(1, 2), cirq.FSimGate(1.00001, 2.00001), atol=0.01)
|
|
50
52
|
|
|
51
53
|
|
|
@@ -60,12 +62,12 @@ def test_fsim_approx_eq():
|
|
|
60
62
|
(np.pi / 2, 0.5),
|
|
61
63
|
],
|
|
62
64
|
)
|
|
63
|
-
def test_fsim_consistent(theta, phi):
|
|
65
|
+
def test_fsim_consistent(theta, phi) -> None:
|
|
64
66
|
gate = cirq.FSimGate(theta=theta, phi=phi)
|
|
65
67
|
cirq.testing.assert_implements_consistent_protocols(gate)
|
|
66
68
|
|
|
67
69
|
|
|
68
|
-
def test_fsim_circuit():
|
|
70
|
+
def test_fsim_circuit() -> None:
|
|
69
71
|
a, b = cirq.LineQubit.range(2)
|
|
70
72
|
c = cirq.Circuit(
|
|
71
73
|
cirq.FSimGate(np.pi / 2, np.pi).on(a, b), cirq.FSimGate(-np.pi, np.pi / 2).on(a, b)
|
|
@@ -109,7 +111,7 @@ def test_fsim_circuit():
|
|
|
109
111
|
|
|
110
112
|
|
|
111
113
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
112
|
-
def test_fsim_resolve(resolve_fn):
|
|
114
|
+
def test_fsim_resolve(resolve_fn) -> None:
|
|
113
115
|
f = cirq.FSimGate(sympy.Symbol('a'), sympy.Symbol('b'))
|
|
114
116
|
assert cirq.is_parameterized(f)
|
|
115
117
|
|
|
@@ -122,7 +124,7 @@ def test_fsim_resolve(resolve_fn):
|
|
|
122
124
|
assert not cirq.is_parameterized(f)
|
|
123
125
|
|
|
124
126
|
|
|
125
|
-
def test_fsim_unitary():
|
|
127
|
+
def test_fsim_unitary() -> None:
|
|
126
128
|
# fmt: off
|
|
127
129
|
np.testing.assert_allclose(
|
|
128
130
|
cirq.unitary(cirq.FSimGate(theta=0, phi=0)),
|
|
@@ -265,7 +267,7 @@ def test_fsim_unitary():
|
|
|
265
267
|
(3.5 * np.pi, 4 * np.pi),
|
|
266
268
|
),
|
|
267
269
|
)
|
|
268
|
-
def test_fsim_iswap_cphase(theta, phi):
|
|
270
|
+
def test_fsim_iswap_cphase(theta, phi) -> None:
|
|
269
271
|
q0, q1 = cirq.NamedQubit('q0'), cirq.NamedQubit('q1')
|
|
270
272
|
iswap = cirq.ISWAP ** (-theta * 2 / np.pi)
|
|
271
273
|
cphase = cirq.CZPowGate(exponent=-phi / np.pi)
|
|
@@ -274,16 +276,16 @@ def test_fsim_iswap_cphase(theta, phi):
|
|
|
274
276
|
assert np.allclose(cirq.unitary(iswap_cphase), cirq.unitary(fsim))
|
|
275
277
|
|
|
276
278
|
|
|
277
|
-
def test_fsim_repr():
|
|
279
|
+
def test_fsim_repr() -> None:
|
|
278
280
|
f = cirq.FSimGate(sympy.Symbol('a'), sympy.Symbol('b'))
|
|
279
281
|
cirq.testing.assert_equivalent_repr(f)
|
|
280
282
|
|
|
281
283
|
|
|
282
|
-
def test_fsim_json_dict():
|
|
284
|
+
def test_fsim_json_dict() -> None:
|
|
283
285
|
assert cirq.FSimGate(theta=0.123, phi=0.456)._json_dict_() == {'theta': 0.123, 'phi': 0.456}
|
|
284
286
|
|
|
285
287
|
|
|
286
|
-
def test_phased_fsim_init():
|
|
288
|
+
def test_phased_fsim_init() -> None:
|
|
287
289
|
f = cirq.PhasedFSimGate(1, 2, 3, 4, 5)
|
|
288
290
|
assert f.theta == 1
|
|
289
291
|
assert f.zeta == 2
|
|
@@ -307,7 +309,7 @@ def test_phased_fsim_init():
|
|
|
307
309
|
(np.pi / 5, np.pi / 6, (0.1, 0.2), (0.3, 0.5)),
|
|
308
310
|
),
|
|
309
311
|
)
|
|
310
|
-
def test_phased_fsim_from_fsim_rz(theta, phi, rz_angles_before, rz_angles_after):
|
|
312
|
+
def test_phased_fsim_from_fsim_rz(theta, phi, rz_angles_before, rz_angles_after) -> None:
|
|
311
313
|
f = cirq.PhasedFSimGate.from_fsim_rz(theta, phi, rz_angles_before, rz_angles_after)
|
|
312
314
|
q0, q1 = cirq.LineQubit.range(2)
|
|
313
315
|
c = cirq.Circuit(
|
|
@@ -330,7 +332,7 @@ def test_phased_fsim_from_fsim_rz(theta, phi, rz_angles_before, rz_angles_after)
|
|
|
330
332
|
((np.pi / 5, -np.pi / 3), (0, np.pi / 2)),
|
|
331
333
|
),
|
|
332
334
|
)
|
|
333
|
-
def test_phased_fsim_recreate_from_phase_angles(rz_angles_before, rz_angles_after):
|
|
335
|
+
def test_phased_fsim_recreate_from_phase_angles(rz_angles_before, rz_angles_after) -> None:
|
|
334
336
|
f = cirq.PhasedFSimGate.from_fsim_rz(np.pi / 3, np.pi / 5, rz_angles_before, rz_angles_after)
|
|
335
337
|
f2 = cirq.PhasedFSimGate.from_fsim_rz(f.theta, f.phi, f.rz_angles_before, f.rz_angles_after)
|
|
336
338
|
assert cirq.approx_eq(f, f2)
|
|
@@ -346,7 +348,7 @@ def test_phased_fsim_recreate_from_phase_angles(rz_angles_before, rz_angles_afte
|
|
|
346
348
|
((np.pi, np.pi / 6), (-np.pi / 2, 0)),
|
|
347
349
|
),
|
|
348
350
|
)
|
|
349
|
-
def test_phased_fsim_phase_angle_symmetry(rz_angles_before, rz_angles_after):
|
|
351
|
+
def test_phased_fsim_phase_angle_symmetry(rz_angles_before, rz_angles_after) -> None:
|
|
350
352
|
f = cirq.PhasedFSimGate.from_fsim_rz(np.pi / 3, np.pi / 5, rz_angles_before, rz_angles_after)
|
|
351
353
|
for d in (-10, -7, -2 * np.pi, -0.2, 0, 0.1, 0.2, np.pi, 8, 20):
|
|
352
354
|
rz_angles_before2 = (rz_angles_before[0] + d, rz_angles_before[1] + d)
|
|
@@ -357,7 +359,7 @@ def test_phased_fsim_phase_angle_symmetry(rz_angles_before, rz_angles_after):
|
|
|
357
359
|
assert cirq.approx_eq(f, f2)
|
|
358
360
|
|
|
359
361
|
|
|
360
|
-
def test_phased_fsim_eq():
|
|
362
|
+
def test_phased_fsim_eq() -> None:
|
|
361
363
|
eq = cirq.testing.EqualsTester()
|
|
362
364
|
a, b = cirq.LineQubit.range(2)
|
|
363
365
|
r, s = sympy.Symbol('r'), sympy.Symbol('s')
|
|
@@ -435,7 +437,7 @@ def test_phased_fsim_eq():
|
|
|
435
437
|
(cirq.PhasedFSimGate(1, np.pi / 2, 0, 4, 5), False),
|
|
436
438
|
),
|
|
437
439
|
)
|
|
438
|
-
def test_qubit_interchangeability(gate, interchangeable):
|
|
440
|
+
def test_qubit_interchangeability(gate, interchangeable) -> None:
|
|
439
441
|
a, b = cirq.LineQubit.range(2)
|
|
440
442
|
c1 = cirq.Circuit(gate.on(a, b))
|
|
441
443
|
c2 = cirq.Circuit(cirq.SWAP(a, b), gate.on(a, b), cirq.SWAP(a, b))
|
|
@@ -444,7 +446,7 @@ def test_qubit_interchangeability(gate, interchangeable):
|
|
|
444
446
|
assert np.all(u1 == u2) == interchangeable
|
|
445
447
|
|
|
446
448
|
|
|
447
|
-
def test_phased_fsim_approx_eq():
|
|
449
|
+
def test_phased_fsim_approx_eq() -> None:
|
|
448
450
|
assert cirq.approx_eq(
|
|
449
451
|
cirq.PhasedFSimGate(1, 2, 3, 4, 5),
|
|
450
452
|
cirq.PhasedFSimGate(1.00001, 2.00001, 3.00001, 4.00004, 5.00005),
|
|
@@ -469,12 +471,12 @@ def test_phased_fsim_approx_eq():
|
|
|
469
471
|
(np.pi, 0, 0, sympy.Symbol('a'), 0),
|
|
470
472
|
],
|
|
471
473
|
)
|
|
472
|
-
def test_phased_fsim_consistent(theta, zeta, chi, gamma, phi):
|
|
474
|
+
def test_phased_fsim_consistent(theta, zeta, chi, gamma, phi) -> None:
|
|
473
475
|
gate = cirq.PhasedFSimGate(theta=theta, zeta=zeta, chi=chi, gamma=gamma, phi=phi)
|
|
474
476
|
cirq.testing.assert_implements_consistent_protocols(gate)
|
|
475
477
|
|
|
476
478
|
|
|
477
|
-
def test_phased_fsim_circuit():
|
|
479
|
+
def test_phased_fsim_circuit() -> None:
|
|
478
480
|
a, b = cirq.LineQubit.range(2)
|
|
479
481
|
c = cirq.Circuit(
|
|
480
482
|
cirq.PhasedFSimGate(np.pi / 2, np.pi, np.pi / 2, 0, -np.pi / 4).on(a, b),
|
|
@@ -488,7 +490,6 @@ def test_phased_fsim_circuit():
|
|
|
488
490
|
1: ───PhFSim(0.5π, -π, 0.5π, 0, -0.25π)───PhFSim(-π, 0.5π, 0.1π, 0.2π, 0.3π)───
|
|
489
491
|
""",
|
|
490
492
|
)
|
|
491
|
-
# pylint: disable=line-too-long
|
|
492
493
|
cirq.testing.assert_has_diagram(
|
|
493
494
|
c,
|
|
494
495
|
"""
|
|
@@ -504,11 +505,10 @@ def test_phased_fsim_circuit():
|
|
|
504
505
|
0: ---PhFSim(1.5707963267948966, -pi, 1.5707963267948966, 0, -0.7853981633974483)---PhFSim(-pi, 1.5707963267948966, 0.3141592653589793, 0.6283185307179586, 0.9424777960769379)---
|
|
505
506
|
| |
|
|
506
507
|
1: ---PhFSim(1.5707963267948966, -pi, 1.5707963267948966, 0, -0.7853981633974483)---PhFSim(-pi, 1.5707963267948966, 0.3141592653589793, 0.6283185307179586, 0.9424777960769379)---
|
|
507
|
-
""",
|
|
508
|
+
""", # noqa: E501
|
|
508
509
|
use_unicode_characters=False,
|
|
509
510
|
precision=None,
|
|
510
511
|
)
|
|
511
|
-
# pylint: enable=line-too-long
|
|
512
512
|
c = cirq.Circuit(
|
|
513
513
|
cirq.PhasedFSimGate(
|
|
514
514
|
sympy.Symbol('a') + sympy.Symbol('b'),
|
|
@@ -529,7 +529,7 @@ def test_phased_fsim_circuit():
|
|
|
529
529
|
|
|
530
530
|
|
|
531
531
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
532
|
-
def test_phased_fsim_resolve(resolve_fn):
|
|
532
|
+
def test_phased_fsim_resolve(resolve_fn) -> None:
|
|
533
533
|
f = cirq.PhasedFSimGate(
|
|
534
534
|
sympy.Symbol('a'),
|
|
535
535
|
sympy.Symbol('b'),
|
|
@@ -562,7 +562,7 @@ def test_phased_fsim_resolve(resolve_fn):
|
|
|
562
562
|
assert not cirq.is_parameterized(f)
|
|
563
563
|
|
|
564
564
|
|
|
565
|
-
def test_phased_fsim_unitary():
|
|
565
|
+
def test_phased_fsim_unitary() -> None:
|
|
566
566
|
# fmt: off
|
|
567
567
|
np.testing.assert_allclose(
|
|
568
568
|
cirq.unitary(cirq.PhasedFSimGate(theta=0, phi=0)),
|
|
@@ -776,13 +776,13 @@ def test_phased_fsim_unitary():
|
|
|
776
776
|
(3.5 * np.pi, 4 * np.pi),
|
|
777
777
|
),
|
|
778
778
|
)
|
|
779
|
-
def test_phased_fsim_vs_fsim(theta, phi):
|
|
779
|
+
def test_phased_fsim_vs_fsim(theta, phi) -> None:
|
|
780
780
|
g1 = cirq.FSimGate(theta, phi)
|
|
781
781
|
g2 = cirq.PhasedFSimGate(theta, 0, 0, 0, phi)
|
|
782
782
|
assert np.allclose(cirq.unitary(g1), cirq.unitary(g2))
|
|
783
783
|
|
|
784
784
|
|
|
785
|
-
def test_phased_fsim_repr():
|
|
785
|
+
def test_phased_fsim_repr() -> None:
|
|
786
786
|
f = cirq.PhasedFSimGate(
|
|
787
787
|
sympy.Symbol('a'),
|
|
788
788
|
sympy.Symbol('b'),
|
|
@@ -793,7 +793,7 @@ def test_phased_fsim_repr():
|
|
|
793
793
|
cirq.testing.assert_equivalent_repr(f)
|
|
794
794
|
|
|
795
795
|
|
|
796
|
-
def test_phased_fsim_json_dict():
|
|
796
|
+
def test_phased_fsim_json_dict() -> None:
|
|
797
797
|
assert cirq.PhasedFSimGate(
|
|
798
798
|
theta=0.12, zeta=0.34, chi=0.56, gamma=0.78, phi=0.9
|
|
799
799
|
)._json_dict_() == {'theta': 0.12, 'zeta': 0.34, 'chi': 0.56, 'gamma': 0.78, 'phi': 0.9}
|
|
@@ -811,10 +811,10 @@ def test_phased_fsim_json_dict():
|
|
|
811
811
|
cirq.CZ**0.2,
|
|
812
812
|
],
|
|
813
813
|
)
|
|
814
|
-
def test_phase_fsim_from_matrix(gate):
|
|
814
|
+
def test_phase_fsim_from_matrix(gate) -> None:
|
|
815
815
|
u = cirq.unitary(gate)
|
|
816
816
|
np.testing.assert_allclose(cirq.unitary(cirq.PhasedFSimGate.from_matrix(u)), u, atol=1e-8)
|
|
817
817
|
|
|
818
818
|
|
|
819
|
-
def test_phase_fsim_from_matrix_not_fsim_returns_none():
|
|
819
|
+
def test_phase_fsim_from_matrix_not_fsim_returns_none() -> None:
|
|
820
820
|
assert cirq.PhasedFSimGate.from_matrix(np.ones((4, 4))) is None
|
cirq/ops/gate_features.py
CHANGED
cirq/ops/gate_features_test.py
CHANGED
|
@@ -12,12 +12,14 @@
|
|
|
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 pytest
|
|
16
18
|
|
|
17
19
|
import cirq
|
|
18
20
|
|
|
19
21
|
|
|
20
|
-
def test_qasm_output_args_validate():
|
|
22
|
+
def test_qasm_output_args_validate() -> None:
|
|
21
23
|
args = cirq.QasmArgs(version='2.0')
|
|
22
24
|
args.validate_version('2.0')
|
|
23
25
|
|
|
@@ -25,7 +27,7 @@ def test_qasm_output_args_validate():
|
|
|
25
27
|
args.validate_version('2.1')
|
|
26
28
|
|
|
27
29
|
|
|
28
|
-
def test_qasm_output_args_format():
|
|
30
|
+
def test_qasm_output_args_format() -> None:
|
|
29
31
|
a = cirq.NamedQubit('a')
|
|
30
32
|
b = cirq.NamedQubit('b')
|
|
31
33
|
m_a = cirq.measure(a, key='meas_a')
|
|
@@ -52,7 +54,7 @@ def test_qasm_output_args_format():
|
|
|
52
54
|
assert args.format('_{0}_', 'other') == '_other_'
|
|
53
55
|
|
|
54
56
|
|
|
55
|
-
def test_multi_qubit_gate_validate():
|
|
57
|
+
def test_multi_qubit_gate_validate() -> None:
|
|
56
58
|
class Example(cirq.Gate):
|
|
57
59
|
def _num_qubits_(self) -> int:
|
|
58
60
|
return self._num_qubits
|