cirq-core 1.5.0.dev20250409225226__py3-none-any.whl → 1.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cirq-core might be problematic. Click here for more details.
- cirq/__init__.py +16 -17
- cirq/_compat.py +21 -20
- cirq/_compat_test.py +14 -34
- cirq/_doc.py +4 -2
- cirq/_import.py +8 -6
- cirq/_import_test.py +4 -2
- cirq/_version.py +6 -6
- cirq/_version_test.py +2 -2
- cirq/circuits/_block_diagram_drawer.py +11 -10
- cirq/circuits/_block_diagram_drawer_test.py +8 -6
- cirq/circuits/_box_drawing_character_data.py +8 -8
- cirq/circuits/_box_drawing_character_data_test.py +3 -1
- cirq/circuits/_bucket_priority_queue.py +9 -7
- cirq/circuits/_bucket_priority_queue_test.py +22 -20
- cirq/circuits/circuit.py +248 -172
- cirq/circuits/circuit_operation.py +73 -83
- cirq/circuits/circuit_operation_test.py +128 -90
- cirq/circuits/circuit_test.py +211 -151
- cirq/circuits/frozen_circuit.py +23 -60
- cirq/circuits/frozen_circuit_test.py +31 -8
- cirq/circuits/insert_strategy.py +7 -5
- cirq/circuits/insert_strategy_test.py +4 -2
- cirq/circuits/moment.py +88 -40
- cirq/circuits/moment_test.py +128 -51
- cirq/circuits/optimization_pass.py +5 -5
- cirq/circuits/optimization_pass_test.py +10 -10
- cirq/circuits/qasm_output.py +11 -11
- cirq/circuits/qasm_output_test.py +25 -22
- cirq/circuits/text_diagram_drawer.py +23 -38
- cirq/circuits/text_diagram_drawer_test.py +19 -17
- cirq/conftest.py +4 -3
- cirq/contrib/__init__.py +4 -4
- cirq/contrib/acquaintance/__init__.py +1 -1
- cirq/contrib/acquaintance/bipartite.py +5 -8
- cirq/contrib/acquaintance/bipartite_test.py +18 -13
- cirq/contrib/acquaintance/devices.py +2 -2
- cirq/contrib/acquaintance/devices_test.py +5 -3
- cirq/contrib/acquaintance/executor.py +5 -5
- cirq/contrib/acquaintance/executor_test.py +13 -9
- cirq/contrib/acquaintance/gates.py +18 -28
- cirq/contrib/acquaintance/gates_test.py +24 -20
- cirq/contrib/acquaintance/inspection_utils.py +8 -4
- cirq/contrib/acquaintance/inspection_utils_test.py +4 -2
- cirq/contrib/acquaintance/mutation_utils.py +4 -4
- cirq/contrib/acquaintance/mutation_utils_test.py +4 -2
- cirq/contrib/acquaintance/optimizers.py +4 -4
- cirq/contrib/acquaintance/optimizers_test.py +4 -1
- cirq/contrib/acquaintance/permutation.py +15 -27
- cirq/contrib/acquaintance/permutation_test.py +26 -17
- cirq/contrib/acquaintance/shift.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network_test.py +9 -6
- cirq/contrib/acquaintance/shift_test.py +8 -6
- cirq/contrib/acquaintance/strategies/cubic.py +2 -2
- cirq/contrib/acquaintance/strategies/cubic_test.py +4 -2
- cirq/contrib/acquaintance/strategies/quartic_paired.py +6 -6
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +10 -6
- cirq/contrib/acquaintance/testing.py +2 -0
- cirq/contrib/acquaintance/topological_sort.py +2 -2
- cirq/contrib/acquaintance/topological_sort_test.py +3 -1
- cirq/contrib/bayesian_network/bayesian_network_gate.py +9 -10
- cirq/contrib/bayesian_network/bayesian_network_gate_test.py +14 -9
- cirq/contrib/circuitdag/circuit_dag.py +4 -4
- cirq/contrib/circuitdag/circuit_dag_test.py +17 -15
- cirq/contrib/custom_simulators/custom_state_simulator.py +5 -5
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +22 -17
- cirq/contrib/graph_device/graph_device.py +12 -11
- cirq/contrib/graph_device/graph_device_test.py +18 -14
- cirq/contrib/graph_device/hypergraph.py +16 -14
- cirq/contrib/graph_device/hypergraph_test.py +13 -11
- cirq/contrib/graph_device/uniform_graph_device.py +6 -4
- cirq/contrib/graph_device/uniform_graph_device_test.py +11 -3
- cirq/contrib/hacks/disable_validation.py +6 -1
- cirq/contrib/hacks/disable_validation_test.py +3 -1
- cirq/contrib/json.py +31 -5
- cirq/contrib/json_test.py +6 -3
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.json +6 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.json +5 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/__init__.py +17 -0
- cirq/contrib/json_test_data/spec.py +32 -0
- cirq/contrib/noise_models/noise_models.py +119 -5
- cirq/contrib/noise_models/noise_models_test.py +37 -9
- cirq/contrib/paulistring/clifford_optimize.py +6 -4
- cirq/contrib/paulistring/clifford_optimize_test.py +6 -5
- cirq/contrib/paulistring/clifford_target_gateset.py +10 -10
- cirq/contrib/paulistring/clifford_target_gateset_test.py +13 -11
- cirq/contrib/paulistring/optimize.py +2 -0
- cirq/contrib/paulistring/optimize_test.py +4 -3
- cirq/contrib/paulistring/pauli_string_dag.py +2 -0
- cirq/contrib/paulistring/pauli_string_dag_test.py +3 -1
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +255 -120
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +398 -19
- cirq/contrib/paulistring/pauli_string_optimize.py +7 -1
- cirq/contrib/paulistring/pauli_string_optimize_test.py +5 -3
- cirq/contrib/paulistring/recombine.py +6 -4
- cirq/contrib/paulistring/recombine_test.py +3 -1
- cirq/contrib/paulistring/separate.py +9 -6
- cirq/contrib/paulistring/separate_test.py +3 -1
- cirq/contrib/qasm_import/_lexer.py +3 -2
- cirq/contrib/qasm_import/_lexer_test.py +49 -13
- cirq/contrib/qasm_import/_parser.py +547 -83
- cirq/contrib/qasm_import/_parser_test.py +988 -97
- cirq/contrib/qasm_import/exception.py +2 -0
- cirq/contrib/qasm_import/qasm.py +8 -2
- cirq/contrib/qasm_import/qasm_test.py +7 -4
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +5 -5
- cirq/contrib/qcircuit/qcircuit_diagram_info_test.py +4 -1
- cirq/contrib/qcircuit/qcircuit_pdf.py +7 -3
- cirq/contrib/qcircuit/qcircuit_pdf_test.py +3 -1
- cirq/contrib/qcircuit/qcircuit_test.py +10 -8
- cirq/contrib/quantum_volume/quantum_volume.py +31 -27
- cirq/contrib/quantum_volume/quantum_volume_test.py +19 -16
- cirq/contrib/quimb/density_matrix.py +15 -14
- cirq/contrib/quimb/density_matrix_test.py +10 -7
- cirq/contrib/quimb/grid_circuits.py +5 -2
- cirq/contrib/quimb/grid_circuits_test.py +3 -0
- cirq/contrib/quimb/mps_simulator.py +20 -20
- cirq/contrib/quimb/mps_simulator_test.py +3 -0
- cirq/contrib/quimb/state_vector.py +12 -11
- cirq/contrib/quimb/state_vector_test.py +3 -0
- cirq/contrib/quirk/export_to_quirk.py +5 -3
- cirq/contrib/quirk/export_to_quirk_test.py +18 -16
- cirq/contrib/quirk/linearize_circuit.py +2 -0
- cirq/contrib/quirk/quirk_gate.py +18 -17
- cirq/contrib/routing/device.py +5 -3
- cirq/contrib/routing/device_test.py +2 -0
- cirq/contrib/routing/greedy.py +10 -21
- cirq/contrib/routing/greedy_test.py +4 -2
- cirq/contrib/routing/initialization.py +2 -2
- cirq/contrib/routing/initialization_test.py +5 -3
- cirq/contrib/routing/router.py +9 -5
- cirq/contrib/routing/router_test.py +2 -0
- cirq/contrib/routing/swap_network.py +3 -3
- cirq/contrib/routing/swap_network_test.py +3 -1
- cirq/contrib/routing/utils.py +2 -2
- cirq/contrib/routing/utils_test.py +3 -0
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +15 -9
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +3 -0
- cirq/contrib/svg/svg.py +3 -3
- cirq/contrib/svg/svg_test.py +8 -5
- cirq/devices/device.py +4 -4
- cirq/devices/device_test.py +7 -4
- cirq/devices/grid_device_metadata.py +10 -10
- cirq/devices/grid_device_metadata_test.py +3 -0
- cirq/devices/grid_qubit.py +29 -21
- cirq/devices/grid_qubit_test.py +3 -0
- cirq/devices/insertion_noise_model.py +7 -7
- cirq/devices/insertion_noise_model_test.py +7 -5
- cirq/devices/line_qubit.py +13 -13
- cirq/devices/line_qubit_test.py +2 -0
- cirq/devices/named_topologies.py +18 -29
- cirq/devices/named_topologies_test.py +13 -10
- cirq/devices/noise_model.py +3 -3
- cirq/devices/noise_model_test.py +19 -15
- cirq/devices/noise_properties.py +15 -6
- cirq/devices/noise_properties_test.py +34 -3
- cirq/devices/noise_utils.py +11 -9
- cirq/devices/noise_utils_test.py +2 -0
- cirq/devices/superconducting_qubits_noise_properties.py +23 -22
- cirq/devices/superconducting_qubits_noise_properties_test.py +6 -6
- cirq/devices/thermal_noise_model.py +107 -37
- cirq/devices/thermal_noise_model_test.py +21 -0
- cirq/devices/unconstrained_device.py +5 -3
- cirq/devices/unconstrained_device_test.py +2 -0
- cirq/experiments/__init__.py +4 -2
- cirq/experiments/benchmarking/__init__.py +17 -0
- cirq/experiments/benchmarking/parallel_xeb.py +677 -0
- cirq/experiments/benchmarking/parallel_xeb_test.py +447 -0
- cirq/experiments/fidelity_estimation.py +14 -8
- cirq/experiments/fidelity_estimation_test.py +3 -0
- cirq/experiments/n_qubit_tomography.py +17 -16
- cirq/experiments/n_qubit_tomography_test.py +8 -5
- cirq/experiments/purity_estimation.py +2 -0
- cirq/experiments/purity_estimation_test.py +2 -0
- cirq/experiments/qubit_characterizations.py +207 -103
- cirq/experiments/qubit_characterizations_test.py +40 -12
- cirq/experiments/random_quantum_circuit_generation.py +56 -70
- cirq/experiments/random_quantum_circuit_generation_test.py +11 -8
- cirq/experiments/readout_confusion_matrix.py +24 -22
- cirq/experiments/readout_confusion_matrix_test.py +2 -0
- cirq/experiments/single_qubit_readout_calibration.py +30 -15
- cirq/experiments/single_qubit_readout_calibration_test.py +5 -2
- cirq/experiments/t1_decay_experiment.py +9 -7
- cirq/experiments/t1_decay_experiment_test.py +13 -11
- cirq/experiments/t2_decay_experiment.py +16 -13
- cirq/experiments/t2_decay_experiment_test.py +2 -0
- cirq/experiments/two_qubit_xeb.py +64 -57
- cirq/experiments/two_qubit_xeb_test.py +10 -6
- cirq/experiments/xeb_fitting.py +39 -35
- cirq/experiments/xeb_sampling.py +37 -44
- cirq/experiments/xeb_sampling_test.py +3 -0
- cirq/experiments/xeb_simulation.py +14 -10
- cirq/experiments/xeb_simulation_test.py +5 -5
- cirq/experiments/z_phase_calibration.py +32 -29
- cirq/experiments/z_phase_calibration_test.py +3 -4
- cirq/interop/quirk/cells/__init__.py +1 -1
- cirq/interop/quirk/cells/all_cells.py +7 -2
- cirq/interop/quirk/cells/arithmetic_cells.py +29 -41
- cirq/interop/quirk/cells/arithmetic_cells_test.py +17 -14
- cirq/interop/quirk/cells/cell.py +19 -28
- cirq/interop/quirk/cells/cell_test.py +3 -0
- cirq/interop/quirk/cells/composite_cell.py +13 -28
- cirq/interop/quirk/cells/composite_cell_test.py +2 -0
- cirq/interop/quirk/cells/control_cells.py +15 -15
- cirq/interop/quirk/cells/control_cells_test.py +7 -5
- cirq/interop/quirk/cells/frequency_space_cells.py +4 -3
- cirq/interop/quirk/cells/frequency_space_cells_test.py +3 -1
- cirq/interop/quirk/cells/ignored_cells.py +3 -0
- cirq/interop/quirk/cells/ignored_cells_test.py +3 -1
- cirq/interop/quirk/cells/input_cells.py +7 -5
- cirq/interop/quirk/cells/input_cells_test.py +7 -5
- cirq/interop/quirk/cells/input_rotation_cells.py +15 -13
- cirq/interop/quirk/cells/input_rotation_cells_test.py +9 -7
- cirq/interop/quirk/cells/measurement_cells.py +5 -2
- cirq/interop/quirk/cells/measurement_cells_test.py +3 -1
- cirq/interop/quirk/cells/parse.py +22 -23
- cirq/interop/quirk/cells/parse_test.py +12 -10
- cirq/interop/quirk/cells/qubit_permutation_cells.py +5 -3
- cirq/interop/quirk/cells/qubit_permutation_cells_test.py +9 -7
- cirq/interop/quirk/cells/scalar_cells.py +4 -1
- cirq/interop/quirk/cells/scalar_cells_test.py +3 -1
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +5 -2
- cirq/interop/quirk/cells/single_qubit_rotation_cells_test.py +5 -3
- cirq/interop/quirk/cells/swap_cell.py +8 -6
- cirq/interop/quirk/cells/swap_cell_test.py +6 -4
- cirq/interop/quirk/cells/testing.py +6 -6
- cirq/interop/quirk/cells/testing_test.py +8 -6
- cirq/interop/quirk/cells/unsupported_cells.py +3 -0
- cirq/interop/quirk/cells/unsupported_cells_test.py +4 -2
- cirq/interop/quirk/url_to_circuit.py +23 -36
- cirq/interop/quirk/url_to_circuit_test.py +4 -1
- cirq/json_resolver_cache.py +14 -12
- cirq/linalg/__init__.py +4 -6
- cirq/linalg/combinators.py +7 -5
- cirq/linalg/combinators_test.py +10 -7
- cirq/linalg/decompositions.py +24 -35
- cirq/linalg/decompositions_test.py +3 -1
- cirq/linalg/diagonalize.py +6 -4
- cirq/linalg/diagonalize_test.py +15 -14
- cirq/linalg/operator_spaces.py +14 -14
- cirq/linalg/operator_spaces_test.py +13 -11
- cirq/linalg/predicates.py +18 -9
- cirq/linalg/predicates_test.py +5 -0
- cirq/linalg/tolerance.py +6 -3
- cirq/linalg/tolerance_test.py +6 -4
- cirq/linalg/transformations.py +23 -20
- cirq/linalg/transformations_test.py +73 -43
- cirq/neutral_atoms/convert_to_neutral_atom_gates.py +9 -3
- cirq/neutral_atoms/convert_to_neutral_atom_gates_test.py +3 -1
- cirq/neutral_atoms/neutral_atom_devices.py +2 -0
- cirq/ops/__init__.py +2 -0
- cirq/ops/arithmetic_operation.py +21 -21
- cirq/ops/arithmetic_operation_test.py +7 -8
- cirq/ops/boolean_hamiltonian.py +23 -22
- cirq/ops/boolean_hamiltonian_test.py +12 -9
- cirq/ops/classically_controlled_operation.py +31 -36
- cirq/ops/classically_controlled_operation_test.py +121 -117
- cirq/ops/clifford_gate.py +98 -81
- cirq/ops/clifford_gate_test.py +72 -57
- cirq/ops/common_channels.py +44 -44
- cirq/ops/common_channels_test.py +83 -81
- cirq/ops/common_gate_families.py +9 -7
- cirq/ops/common_gate_families_test.py +11 -7
- cirq/ops/common_gates.py +164 -183
- cirq/ops/common_gates_test.py +135 -95
- cirq/ops/control_values.py +23 -26
- cirq/ops/control_values_test.py +22 -20
- cirq/ops/controlled_gate.py +64 -112
- cirq/ops/controlled_gate_test.py +130 -35
- cirq/ops/controlled_operation.py +24 -35
- cirq/ops/controlled_operation_test.py +8 -6
- cirq/ops/dense_pauli_string.py +38 -49
- cirq/ops/dense_pauli_string_test.py +4 -2
- cirq/ops/diagonal_gate.py +18 -31
- cirq/ops/diagonal_gate_test.py +13 -13
- cirq/ops/eigen_gate.py +29 -29
- cirq/ops/eigen_gate_test.py +45 -28
- cirq/ops/fourier_transform.py +14 -20
- cirq/ops/fourier_transform_test.py +15 -12
- cirq/ops/fsim_gate.py +43 -42
- cirq/ops/fsim_gate_test.py +29 -29
- cirq/ops/gate_features.py +2 -0
- cirq/ops/gate_features_test.py +5 -3
- cirq/ops/gate_operation.py +43 -65
- cirq/ops/gate_operation_test.py +46 -42
- cirq/ops/gateset.py +28 -40
- cirq/ops/gateset_test.py +4 -2
- cirq/ops/global_phase_op.py +45 -20
- cirq/ops/global_phase_op_test.py +44 -20
- cirq/ops/greedy_qubit_manager.py +10 -8
- cirq/ops/greedy_qubit_manager_test.py +5 -3
- cirq/ops/identity.py +14 -12
- cirq/ops/identity_test.py +24 -20
- cirq/ops/kraus_channel.py +11 -8
- cirq/ops/kraus_channel_test.py +14 -11
- cirq/ops/linear_combinations.py +65 -77
- cirq/ops/linear_combinations_test.py +14 -9
- cirq/ops/matrix_gates.py +21 -18
- cirq/ops/matrix_gates_test.py +16 -0
- cirq/ops/measure_util.py +15 -20
- cirq/ops/measure_util_test.py +2 -0
- cirq/ops/measurement_gate.py +26 -37
- cirq/ops/measurement_gate_test.py +2 -0
- cirq/ops/mixed_unitary_channel.py +12 -9
- cirq/ops/mixed_unitary_channel_test.py +14 -11
- cirq/ops/named_qubit.py +16 -13
- cirq/ops/named_qubit_test.py +15 -13
- cirq/ops/op_tree.py +9 -7
- cirq/ops/op_tree_test.py +22 -19
- cirq/ops/parallel_gate.py +15 -17
- cirq/ops/parallel_gate_test.py +18 -16
- cirq/ops/parity_gates.py +23 -25
- cirq/ops/parity_gates_test.py +36 -32
- cirq/ops/pauli_gates.py +22 -21
- cirq/ops/pauli_gates_test.py +29 -20
- cirq/ops/pauli_interaction_gate.py +15 -19
- cirq/ops/pauli_interaction_gate_test.py +10 -8
- cirq/ops/pauli_measurement_gate.py +23 -35
- cirq/ops/pauli_measurement_gate_test.py +2 -0
- cirq/ops/pauli_string.py +92 -120
- cirq/ops/pauli_string_phasor.py +52 -45
- cirq/ops/pauli_string_phasor_test.py +4 -5
- cirq/ops/pauli_string_raw_types.py +9 -7
- cirq/ops/pauli_string_raw_types_test.py +2 -0
- cirq/ops/pauli_string_test.py +31 -154
- cirq/ops/pauli_sum_exponential.py +12 -12
- cirq/ops/pauli_sum_exponential_test.py +12 -10
- cirq/ops/permutation_gate.py +8 -6
- cirq/ops/permutation_gate_test.py +10 -8
- cirq/ops/phased_iswap_gate.py +16 -16
- cirq/ops/phased_iswap_gate_test.py +17 -15
- cirq/ops/phased_x_gate.py +16 -17
- cirq/ops/phased_x_gate_test.py +18 -16
- cirq/ops/phased_x_z_gate.py +24 -22
- cirq/ops/phased_x_z_gate_test.py +17 -11
- cirq/ops/projector.py +16 -11
- cirq/ops/projector_test.py +19 -16
- cirq/ops/qid_util.py +7 -5
- cirq/ops/qid_util_test.py +2 -0
- cirq/ops/qubit_manager.py +11 -9
- cirq/ops/qubit_manager_test.py +6 -4
- cirq/ops/qubit_order.py +11 -14
- cirq/ops/qubit_order_or_list.py +4 -2
- cirq/ops/qubit_order_test.py +12 -10
- cirq/ops/random_gate_channel.py +12 -10
- cirq/ops/random_gate_channel_test.py +14 -11
- cirq/ops/raw_types.py +109 -129
- cirq/ops/raw_types_test.py +63 -57
- cirq/ops/state_preparation_channel.py +7 -7
- cirq/ops/state_preparation_channel_test.py +11 -9
- cirq/ops/swap_gates.py +13 -15
- cirq/ops/swap_gates_test.py +19 -17
- cirq/ops/tags.py +5 -3
- cirq/ops/tags_test.py +4 -2
- cirq/ops/three_qubit_gates.py +43 -76
- cirq/ops/three_qubit_gates_test.py +19 -17
- cirq/ops/two_qubit_diagonal_gate.py +13 -13
- cirq/ops/two_qubit_diagonal_gate_test.py +10 -8
- cirq/ops/uniform_superposition_gate.py +5 -3
- cirq/ops/uniform_superposition_gate_test.py +5 -3
- cirq/ops/wait_gate.py +17 -14
- cirq/ops/wait_gate_test.py +9 -6
- cirq/protocols/__init__.py +0 -3
- cirq/protocols/act_on_protocol.py +8 -6
- cirq/protocols/act_on_protocol_test.py +15 -12
- cirq/protocols/apply_channel_protocol.py +10 -14
- cirq/protocols/apply_channel_protocol_test.py +2 -0
- cirq/protocols/apply_mixture_protocol.py +13 -42
- cirq/protocols/apply_mixture_protocol_test.py +7 -5
- cirq/protocols/apply_unitary_protocol.py +39 -34
- cirq/protocols/apply_unitary_protocol_test.py +4 -1
- cirq/protocols/approximate_equality_protocol.py +2 -0
- cirq/protocols/approximate_equality_protocol_test.py +2 -0
- cirq/protocols/circuit_diagram_info_protocol.py +58 -42
- cirq/protocols/circuit_diagram_info_protocol_test.py +70 -12
- cirq/protocols/commutes_protocol.py +8 -7
- cirq/protocols/commutes_protocol_test.py +2 -0
- cirq/protocols/control_key_protocol.py +6 -4
- cirq/protocols/control_key_protocol_test.py +3 -1
- cirq/protocols/decompose_protocol.py +49 -48
- cirq/protocols/decompose_protocol_test.py +27 -16
- cirq/protocols/equal_up_to_global_phase_protocol.py +2 -0
- cirq/protocols/equal_up_to_global_phase_protocol_test.py +9 -6
- cirq/protocols/has_stabilizer_effect_protocol.py +7 -5
- cirq/protocols/has_stabilizer_effect_protocol_test.py +7 -5
- cirq/protocols/has_unitary_protocol.py +10 -6
- cirq/protocols/has_unitary_protocol_test.py +13 -8
- cirq/protocols/hash_from_pickle_test.py +2 -11
- cirq/protocols/inverse_protocol.py +13 -16
- cirq/protocols/inverse_protocol_test.py +5 -3
- cirq/protocols/json_serialization.py +35 -54
- cirq/protocols/json_serialization_test.py +14 -21
- cirq/protocols/json_test_data/CXSWAP.json +46 -0
- cirq/protocols/json_test_data/CXSWAP.repr +13 -0
- cirq/protocols/json_test_data/CZSWAP.json +46 -0
- cirq/protocols/json_test_data/CZSWAP.repr +13 -0
- cirq/protocols/json_test_data/CircuitOperation.json +6 -3
- cirq/protocols/json_test_data/CircuitOperation.repr_inward +4 -2
- cirq/protocols/json_test_data/Moment.json +24 -1
- cirq/protocols/json_test_data/Moment.repr +6 -1
- cirq/protocols/json_test_data/ThermalNoiseModel.json +32 -0
- cirq/protocols/json_test_data/ThermalNoiseModel.repr +1 -0
- cirq/protocols/json_test_data/spec.py +6 -2
- cirq/protocols/kraus_protocol.py +47 -7
- cirq/protocols/kraus_protocol_test.py +86 -12
- cirq/protocols/measurement_key_protocol.py +15 -16
- cirq/protocols/measurement_key_protocol_test.py +13 -11
- cirq/protocols/mixture_protocol.py +7 -5
- cirq/protocols/mixture_protocol_test.py +4 -2
- cirq/protocols/mul_protocol.py +2 -3
- cirq/protocols/mul_protocol_test.py +2 -0
- cirq/protocols/pauli_expansion_protocol.py +6 -3
- cirq/protocols/pauli_expansion_protocol_test.py +5 -3
- cirq/protocols/phase_protocol.py +2 -0
- cirq/protocols/phase_protocol_test.py +3 -1
- cirq/protocols/pow_protocol.py +11 -16
- cirq/protocols/pow_protocol_test.py +2 -0
- cirq/protocols/qasm.py +14 -20
- cirq/protocols/qasm_test.py +6 -3
- cirq/protocols/qid_shape_protocol.py +8 -8
- cirq/protocols/qid_shape_protocol_test.py +3 -1
- cirq/protocols/resolve_parameters.py +5 -3
- cirq/protocols/resolve_parameters_test.py +8 -7
- cirq/protocols/trace_distance_bound.py +6 -4
- cirq/protocols/trace_distance_bound_test.py +3 -1
- cirq/protocols/unitary_protocol.py +17 -7
- cirq/protocols/unitary_protocol_test.py +12 -2
- cirq/qis/channels.py +6 -2
- cirq/qis/channels_test.py +20 -16
- cirq/qis/clifford_tableau.py +21 -19
- cirq/qis/clifford_tableau_test.py +2 -2
- cirq/qis/entropy.py +14 -3
- cirq/qis/entropy_test.py +3 -1
- cirq/qis/measures.py +13 -13
- cirq/qis/measures_test.py +20 -14
- cirq/qis/noise_utils.py +2 -0
- cirq/qis/noise_utils_test.py +9 -7
- cirq/qis/quantum_state_representation.py +7 -8
- cirq/qis/states.py +58 -56
- cirq/qis/states_test.py +2 -0
- cirq/sim/classical_simulator.py +23 -22
- cirq/sim/classical_simulator_test.py +2 -0
- cirq/sim/clifford/clifford_simulator.py +23 -21
- cirq/sim/clifford/clifford_simulator_test.py +7 -4
- cirq/sim/clifford/clifford_tableau_simulation_state.py +10 -7
- cirq/sim/clifford/clifford_tableau_simulation_state_test.py +5 -5
- cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +8 -6
- cirq/sim/clifford/stabilizer_ch_form_simulation_state_test.py +8 -6
- cirq/sim/clifford/stabilizer_sampler.py +9 -7
- cirq/sim/clifford/stabilizer_sampler_test.py +4 -2
- cirq/sim/clifford/stabilizer_simulation_state.py +14 -13
- cirq/sim/clifford/stabilizer_simulation_state_test.py +6 -4
- cirq/sim/clifford/stabilizer_state_ch_form.py +13 -11
- cirq/sim/clifford/stabilizer_state_ch_form_test.py +4 -2
- cirq/sim/density_matrix_simulation_state.py +26 -27
- cirq/sim/density_matrix_simulation_state_test.py +10 -8
- cirq/sim/density_matrix_simulator.py +30 -28
- cirq/sim/density_matrix_simulator_test.py +48 -48
- cirq/sim/density_matrix_utils.py +13 -11
- cirq/sim/density_matrix_utils_test.py +38 -36
- cirq/sim/mux.py +33 -31
- cirq/sim/mux_test.py +3 -0
- cirq/sim/simulation_product_state.py +15 -15
- cirq/sim/simulation_product_state_test.py +29 -26
- cirq/sim/simulation_state.py +29 -38
- cirq/sim/simulation_state_base.py +21 -32
- cirq/sim/simulation_state_test.py +15 -13
- cirq/sim/simulation_utils.py +5 -2
- cirq/sim/simulation_utils_test.py +5 -2
- cirq/sim/simulator.py +90 -106
- cirq/sim/simulator_base.py +33 -45
- cirq/sim/simulator_base_test.py +20 -15
- cirq/sim/simulator_test.py +23 -14
- cirq/sim/sparse_simulator.py +19 -17
- cirq/sim/sparse_simulator_test.py +41 -40
- cirq/sim/state_vector.py +15 -12
- cirq/sim/state_vector_simulation_state.py +31 -31
- cirq/sim/state_vector_simulation_state_test.py +16 -14
- cirq/sim/state_vector_simulator.py +17 -14
- cirq/sim/state_vector_simulator_test.py +2 -0
- cirq/sim/state_vector_test.py +6 -3
- cirq/study/flatten_expressions.py +16 -15
- cirq/study/flatten_expressions_test.py +13 -11
- cirq/study/resolver.py +18 -17
- cirq/study/resolver_test.py +22 -20
- cirq/study/result.py +17 -27
- cirq/study/result_test.py +2 -0
- cirq/study/sweepable.py +12 -10
- cirq/study/sweepable_test.py +3 -0
- cirq/study/sweeps.py +42 -61
- cirq/study/sweeps_test.py +33 -0
- cirq/testing/__init__.py +7 -11
- cirq/testing/_compat_test_data/module_a/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/module_b/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/sub/__init__.py +1 -0
- cirq/testing/circuit_compare.py +8 -17
- cirq/testing/circuit_compare_test.py +2 -0
- cirq/testing/consistent_act_on.py +13 -11
- cirq/testing/consistent_act_on_test.py +5 -3
- cirq/testing/consistent_channels.py +2 -0
- cirq/testing/consistent_channels_test.py +10 -8
- cirq/testing/consistent_controlled_gate_op.py +5 -5
- cirq/testing/consistent_controlled_gate_op_test.py +18 -18
- cirq/testing/consistent_decomposition.py +2 -2
- cirq/testing/consistent_decomposition_test.py +4 -2
- cirq/testing/consistent_pauli_expansion.py +2 -0
- cirq/testing/consistent_pauli_expansion_test.py +3 -1
- cirq/testing/consistent_phase_by.py +2 -0
- cirq/testing/consistent_phase_by_test.py +3 -1
- cirq/testing/consistent_protocols.py +14 -20
- cirq/testing/consistent_protocols_test.py +13 -11
- cirq/testing/consistent_qasm.py +6 -4
- cirq/testing/consistent_qasm_test.py +7 -7
- cirq/testing/consistent_resolve_parameters.py +2 -0
- cirq/testing/consistent_specified_has_unitary.py +2 -2
- cirq/testing/consistent_specified_has_unitary_test.py +6 -4
- cirq/testing/consistent_unitary.py +1 -0
- cirq/testing/consistent_unitary_test.py +4 -2
- cirq/testing/deprecation.py +5 -2
- cirq/testing/deprecation_test.py +5 -2
- cirq/testing/devices.py +7 -4
- cirq/testing/devices_test.py +7 -4
- cirq/testing/equals_tester.py +4 -2
- cirq/testing/equals_tester_test.py +21 -17
- cirq/testing/equivalent_basis_map.py +6 -4
- cirq/testing/equivalent_basis_map_test.py +6 -4
- cirq/testing/equivalent_repr_eval.py +6 -4
- cirq/testing/equivalent_repr_eval_test.py +5 -3
- cirq/testing/gate_features.py +2 -0
- cirq/testing/gate_features_test.py +7 -5
- cirq/testing/json.py +19 -15
- cirq/testing/json_test.py +5 -3
- cirq/testing/lin_alg_utils.py +10 -11
- cirq/testing/lin_alg_utils_test.py +14 -12
- cirq/testing/logs.py +7 -6
- cirq/testing/logs_test.py +9 -7
- cirq/testing/no_identifier_qubit.py +4 -2
- cirq/testing/no_identifier_qubit_test.py +5 -3
- cirq/testing/op_tree.py +2 -0
- cirq/testing/op_tree_test.py +4 -1
- cirq/testing/order_tester.py +2 -0
- cirq/testing/order_tester_test.py +8 -6
- cirq/testing/pytest_utils.py +2 -0
- cirq/testing/pytest_utils_test.py +4 -2
- cirq/testing/random_circuit.py +21 -20
- cirq/testing/random_circuit_test.py +12 -9
- cirq/testing/repr_pretty_tester.py +1 -0
- cirq/testing/repr_pretty_tester_test.py +5 -3
- cirq/testing/routing_devices.py +4 -1
- cirq/testing/routing_devices_test.py +9 -6
- cirq/testing/sample_circuits.py +4 -1
- cirq/testing/sample_circuits_test.py +3 -1
- cirq/testing/sample_gates.py +3 -0
- cirq/testing/sample_gates_test.py +5 -2
- cirq/transformers/__init__.py +11 -4
- cirq/transformers/align.py +9 -7
- cirq/transformers/align_test.py +2 -0
- cirq/transformers/analytical_decompositions/__init__.py +3 -6
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +18 -16
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +19 -16
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +11 -9
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition_test.py +5 -3
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +141 -44
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +35 -1
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +8 -7
- cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +2 -0
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +7 -4
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +3 -0
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +11 -19
- cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py +8 -33
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +9 -11
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +2 -0
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +91 -27
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +36 -7
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +20 -21
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py +8 -6
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +13 -15
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +3 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +39 -41
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +2 -0
- cirq/transformers/drop_empty_moments.py +5 -3
- cirq/transformers/drop_empty_moments_test.py +4 -2
- cirq/transformers/drop_negligible_operations.py +7 -5
- cirq/transformers/drop_negligible_operations_test.py +2 -0
- cirq/transformers/dynamical_decoupling.py +49 -42
- cirq/transformers/dynamical_decoupling_test.py +223 -205
- cirq/transformers/eject_phased_paulis.py +28 -26
- cirq/transformers/eject_phased_paulis_test.py +12 -9
- cirq/transformers/eject_z.py +12 -12
- cirq/transformers/eject_z_test.py +2 -2
- cirq/transformers/expand_composite.py +6 -4
- cirq/transformers/expand_composite_test.py +3 -1
- cirq/transformers/gauge_compiling/__init__.py +3 -1
- cirq/transformers/gauge_compiling/cphase_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cphase_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling.py +45 -41
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +2 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils_test.py +5 -1
- cirq/transformers/gauge_compiling/iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/iswap_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge.py +2 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +7 -6
- cirq/transformers/gauge_compiling/sqrt_cz_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge_test.py +2 -0
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +6 -3
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +3 -0
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +12 -9
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation_test.py +9 -7
- cirq/transformers/insertion_sort.py +8 -6
- cirq/transformers/insertion_sort_test.py +3 -1
- cirq/transformers/measurement_transformers.py +29 -29
- cirq/transformers/measurement_transformers_test.py +2 -0
- cirq/transformers/merge_k_qubit_gates.py +12 -10
- cirq/transformers/merge_k_qubit_gates_test.py +18 -18
- cirq/transformers/merge_single_qubit_gates.py +197 -20
- cirq/transformers/merge_single_qubit_gates_test.py +177 -5
- cirq/transformers/noise_adding.py +5 -3
- cirq/transformers/noise_adding_test.py +2 -0
- cirq/transformers/optimize_for_target_gateset.py +19 -17
- cirq/transformers/optimize_for_target_gateset_test.py +11 -8
- cirq/transformers/qubit_management_transformers.py +13 -11
- cirq/transformers/qubit_management_transformers_test.py +5 -3
- cirq/transformers/randomized_measurements.py +16 -14
- cirq/transformers/randomized_measurements_test.py +10 -4
- cirq/transformers/routing/initial_mapper.py +6 -4
- cirq/transformers/routing/initial_mapper_test.py +2 -0
- cirq/transformers/routing/line_initial_mapper.py +16 -14
- cirq/transformers/routing/line_initial_mapper_test.py +9 -7
- cirq/transformers/routing/mapping_manager.py +10 -10
- cirq/transformers/routing/mapping_manager_test.py +2 -0
- cirq/transformers/routing/route_circuit_cqc.py +33 -31
- cirq/transformers/routing/route_circuit_cqc_test.py +15 -13
- cirq/transformers/routing/visualize_routed_circuit.py +8 -7
- cirq/transformers/routing/visualize_routed_circuit_test.py +4 -2
- cirq/transformers/stratify.py +17 -15
- cirq/transformers/stratify_test.py +3 -0
- cirq/transformers/symbolize.py +103 -0
- cirq/transformers/symbolize_test.py +62 -0
- cirq/transformers/synchronize_terminal_measurements.py +10 -10
- cirq/transformers/synchronize_terminal_measurements_test.py +12 -10
- cirq/transformers/tag_transformers.py +97 -0
- cirq/transformers/tag_transformers_test.py +103 -0
- cirq/transformers/target_gatesets/compilation_target_gateset.py +21 -19
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +20 -16
- cirq/transformers/target_gatesets/cz_gateset.py +7 -5
- cirq/transformers/target_gatesets/cz_gateset_test.py +21 -19
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +9 -7
- cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +25 -25
- cirq/transformers/transformer_api.py +34 -47
- cirq/transformers/transformer_api_test.py +9 -8
- cirq/transformers/transformer_primitives.py +39 -49
- cirq/transformers/transformer_primitives_test.py +10 -17
- cirq/value/abc_alt.py +6 -4
- cirq/value/abc_alt_test.py +5 -3
- cirq/value/angle.py +11 -12
- cirq/value/angle_test.py +5 -3
- cirq/value/classical_data.py +27 -27
- cirq/value/classical_data_test.py +11 -8
- cirq/value/condition.py +26 -24
- cirq/value/condition_test.py +2 -0
- cirq/value/digits.py +14 -11
- cirq/value/digits_test.py +2 -0
- cirq/value/duration.py +23 -20
- cirq/value/duration_test.py +2 -0
- cirq/value/linear_dict.py +25 -30
- cirq/value/linear_dict_test.py +10 -8
- cirq/value/measurement_key.py +12 -12
- cirq/value/measurement_key_test.py +2 -0
- cirq/value/periodic_value.py +4 -4
- cirq/value/periodic_value_test.py +11 -7
- cirq/value/probability.py +3 -1
- cirq/value/probability_test.py +4 -2
- cirq/value/product_state.py +15 -13
- cirq/value/product_state_test.py +4 -1
- cirq/value/random_state.py +2 -0
- cirq/value/random_state_test.py +5 -3
- cirq/value/timestamp.py +11 -7
- cirq/value/timestamp_test.py +14 -12
- cirq/value/type_alias.py +4 -4
- cirq/value/value_equality_attr.py +8 -9
- cirq/value/value_equality_attr_test.py +14 -11
- cirq/vis/density_matrix.py +3 -3
- cirq/vis/density_matrix_test.py +20 -17
- cirq/vis/heatmap.py +24 -37
- cirq/vis/heatmap_test.py +3 -0
- cirq/vis/histogram.py +9 -6
- cirq/vis/histogram_test.py +5 -2
- cirq/vis/state_histogram.py +10 -8
- cirq/vis/state_histogram_test.py +7 -5
- cirq/vis/vis_utils.py +4 -1
- cirq/vis/vis_utils_test.py +4 -1
- cirq/work/collector.py +12 -18
- cirq/work/collector_test.py +15 -10
- cirq/work/observable_grouping.py +6 -7
- cirq/work/observable_grouping_test.py +10 -9
- cirq/work/observable_measurement.py +47 -45
- cirq/work/observable_measurement_data.py +22 -17
- cirq/work/observable_measurement_data_test.py +4 -1
- cirq/work/observable_measurement_test.py +48 -29
- cirq/work/observable_readout_calibration.py +5 -2
- cirq/work/observable_readout_calibration_test.py +5 -2
- cirq/work/observable_settings.py +13 -22
- cirq/work/observable_settings_test.py +9 -7
- cirq/work/pauli_sum_collector.py +12 -10
- cirq/work/pauli_sum_collector_test.py +9 -9
- cirq/work/sampler.py +42 -43
- cirq/work/sampler_test.py +31 -24
- cirq/work/zeros_sampler.py +6 -4
- cirq/work/zeros_sampler_test.py +7 -5
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/METADATA +7 -8
- cirq_core-1.6.0.dist-info/RECORD +1241 -0
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/WHEEL +1 -1
- cirq_core-1.5.0.dev20250409225226.dist-info/RECORD +0 -1216
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.5.0.dev20250409225226.dist-info → cirq_core-1.6.0.dist-info}/top_level.txt +0 -0
cirq/ops/common_gates_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
|
|
@@ -27,23 +29,23 @@ QFT2 = np.array([[1, 1, 1, 1], [1, 1j, -1, -1j], [1, -1, 1, -1], [1, -1j, -1, 1j
|
|
|
27
29
|
@pytest.mark.parametrize(
|
|
28
30
|
'eigen_gate_type', [cirq.CZPowGate, cirq.XPowGate, cirq.YPowGate, cirq.ZPowGate]
|
|
29
31
|
)
|
|
30
|
-
def test_phase_insensitive_eigen_gates_consistent_protocols(eigen_gate_type):
|
|
32
|
+
def test_phase_insensitive_eigen_gates_consistent_protocols(eigen_gate_type) -> None:
|
|
31
33
|
cirq.testing.assert_eigengate_implements_consistent_protocols(eigen_gate_type)
|
|
32
34
|
|
|
33
35
|
|
|
34
36
|
@pytest.mark.parametrize('eigen_gate_type', [cirq.CNotPowGate, cirq.HPowGate])
|
|
35
|
-
def test_phase_sensitive_eigen_gates_consistent_protocols(eigen_gate_type):
|
|
37
|
+
def test_phase_sensitive_eigen_gates_consistent_protocols(eigen_gate_type) -> None:
|
|
36
38
|
cirq.testing.assert_eigengate_implements_consistent_protocols(eigen_gate_type)
|
|
37
39
|
|
|
38
40
|
|
|
39
|
-
def test_cz_init():
|
|
41
|
+
def test_cz_init() -> None:
|
|
40
42
|
assert cirq.CZPowGate(exponent=0.5).exponent == 0.5
|
|
41
43
|
assert cirq.CZPowGate(exponent=5).exponent == 5
|
|
42
44
|
assert (cirq.CZ**0.5).exponent == 0.5
|
|
43
45
|
|
|
44
46
|
|
|
45
47
|
@pytest.mark.parametrize('theta,pi', [(0.4, np.pi), (sympy.Symbol("theta"), sympy.pi)])
|
|
46
|
-
def test_transformations(theta, pi):
|
|
48
|
+
def test_transformations(theta, pi) -> None:
|
|
47
49
|
initialRx = cirq.rx(theta)
|
|
48
50
|
expectedPowx = cirq.X ** (theta / pi)
|
|
49
51
|
receivedPowx = initialRx.with_canonical_global_phase()
|
|
@@ -64,19 +66,19 @@ def test_transformations(theta, pi):
|
|
|
64
66
|
assert backToRz == initialRz
|
|
65
67
|
|
|
66
68
|
|
|
67
|
-
def test_cz_str():
|
|
69
|
+
def test_cz_str() -> None:
|
|
68
70
|
assert str(cirq.CZ) == 'CZ'
|
|
69
71
|
assert str(cirq.CZ**0.5) == 'CZ**0.5'
|
|
70
72
|
assert str(cirq.CZ**-0.25) == 'CZ**-0.25'
|
|
71
73
|
|
|
72
74
|
|
|
73
|
-
def test_cz_repr():
|
|
75
|
+
def test_cz_repr() -> None:
|
|
74
76
|
assert repr(cirq.CZ) == 'cirq.CZ'
|
|
75
77
|
assert repr(cirq.CZ**0.5) == '(cirq.CZ**0.5)'
|
|
76
78
|
assert repr(cirq.CZ**-0.25) == '(cirq.CZ**-0.25)'
|
|
77
79
|
|
|
78
80
|
|
|
79
|
-
def test_cz_unitary():
|
|
81
|
+
def test_cz_unitary() -> None:
|
|
80
82
|
assert np.allclose(
|
|
81
83
|
cirq.unitary(cirq.CZ), np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, -1]])
|
|
82
84
|
)
|
|
@@ -96,7 +98,7 @@ def test_cz_unitary():
|
|
|
96
98
|
)
|
|
97
99
|
|
|
98
100
|
|
|
99
|
-
def test_z_init():
|
|
101
|
+
def test_z_init() -> None:
|
|
100
102
|
z = cirq.ZPowGate(exponent=5)
|
|
101
103
|
assert z.exponent == 5
|
|
102
104
|
|
|
@@ -107,19 +109,19 @@ def test_z_init():
|
|
|
107
109
|
|
|
108
110
|
|
|
109
111
|
@pytest.mark.parametrize(
|
|
110
|
-
'input_gate, specialized_output',
|
|
112
|
+
'input_gate, specialized_output, base_gate',
|
|
111
113
|
[
|
|
112
|
-
(cirq.Z, cirq.CZ),
|
|
113
|
-
(cirq.CZ, cirq.CCZ),
|
|
114
|
-
(cirq.X, cirq.CX),
|
|
115
|
-
(cirq.CX, cirq.CCX),
|
|
116
|
-
(cirq.ZPowGate(exponent=0.5), cirq.CZPowGate(exponent=0.5)),
|
|
117
|
-
(cirq.CZPowGate(exponent=0.5), cirq.CCZPowGate(exponent=0.5)),
|
|
118
|
-
(cirq.XPowGate(exponent=0.5), cirq.CXPowGate(exponent=0.5)),
|
|
119
|
-
(cirq.CXPowGate(exponent=0.5), cirq.CCXPowGate(exponent=0.5)),
|
|
114
|
+
(cirq.Z, cirq.CZ, cirq.Z),
|
|
115
|
+
(cirq.CZ, cirq.CCZ, cirq.Z),
|
|
116
|
+
(cirq.X, cirq.CX, cirq.X),
|
|
117
|
+
(cirq.CX, cirq.CCX, cirq.X),
|
|
118
|
+
(cirq.ZPowGate(exponent=0.5), cirq.CZPowGate(exponent=0.5), cirq.S),
|
|
119
|
+
(cirq.CZPowGate(exponent=0.5), cirq.CCZPowGate(exponent=0.5), cirq.S),
|
|
120
|
+
(cirq.XPowGate(exponent=0.5), cirq.CXPowGate(exponent=0.5), cirq.XPowGate(exponent=0.5)),
|
|
121
|
+
(cirq.CXPowGate(exponent=0.5), cirq.CCXPowGate(exponent=0.5), cirq.XPowGate(exponent=0.5)),
|
|
120
122
|
],
|
|
121
123
|
)
|
|
122
|
-
def test_specialized_control(input_gate, specialized_output):
|
|
124
|
+
def test_specialized_control(input_gate, specialized_output, base_gate) -> None:
|
|
123
125
|
# Single qubit control on the input gate gives the specialized output
|
|
124
126
|
assert input_gate.controlled() == specialized_output
|
|
125
127
|
assert input_gate.controlled(num_controls=1) == specialized_output
|
|
@@ -149,20 +151,24 @@ def test_specialized_control(input_gate, specialized_output):
|
|
|
149
151
|
)
|
|
150
152
|
|
|
151
153
|
# When a control_value 1 qubit is not acting first, results in a regular
|
|
152
|
-
# ControlledGate on the
|
|
154
|
+
# ControlledGate on the base gate instance, with any extra control layer
|
|
155
|
+
# of the input gate being absorbed into the ControlledGate.
|
|
156
|
+
absorbed = 0 if base_gate == input_gate else 1
|
|
157
|
+
absorbed_values = ((1,),) * absorbed
|
|
158
|
+
absorbed_shape = (2,) * absorbed
|
|
153
159
|
assert input_gate.controlled(num_controls=1, control_qid_shape=(3,)) == cirq.ControlledGate(
|
|
154
|
-
|
|
160
|
+
base_gate, num_controls=1 + absorbed, control_qid_shape=(3,) + absorbed_shape
|
|
155
161
|
)
|
|
156
162
|
assert input_gate.controlled(control_values=((0,), (1,), (0,))) == cirq.ControlledGate(
|
|
157
|
-
|
|
163
|
+
base_gate, num_controls=3 + absorbed, control_values=((0,), (1,), (0,)) + absorbed_values
|
|
158
164
|
)
|
|
159
165
|
assert input_gate.controlled(control_qid_shape=(3, 2, 3)) == cirq.ControlledGate(
|
|
160
|
-
|
|
166
|
+
base_gate, num_controls=3 + absorbed, control_qid_shape=(3, 2, 3) + absorbed_shape
|
|
161
167
|
)
|
|
162
168
|
assert input_gate.controlled(control_qid_shape=(3,)).controlled(
|
|
163
169
|
control_qid_shape=(2,)
|
|
164
170
|
).controlled(control_qid_shape=(4,)) != cirq.ControlledGate(
|
|
165
|
-
|
|
171
|
+
base_gate, num_controls=3 + absorbed, control_qid_shape=(3, 2, 4) + absorbed_shape
|
|
166
172
|
)
|
|
167
173
|
|
|
168
174
|
|
|
@@ -175,7 +181,7 @@ def test_specialized_control(input_gate, specialized_output):
|
|
|
175
181
|
(cirq.XPowGate(exponent=0.5), cirq.CCXPowGate(exponent=0.5)),
|
|
176
182
|
],
|
|
177
183
|
)
|
|
178
|
-
def test_specialized_control_two_step(input_gate, specialized_output):
|
|
184
|
+
def test_specialized_control_two_step(input_gate, specialized_output) -> None:
|
|
179
185
|
# Two-qubit control on the input gate gives the specialized output
|
|
180
186
|
assert input_gate.controlled().controlled() == specialized_output
|
|
181
187
|
assert input_gate.controlled(num_controls=2) == specialized_output
|
|
@@ -197,7 +203,7 @@ def test_specialized_control_two_step(input_gate, specialized_output):
|
|
|
197
203
|
(cirq.CXPowGate(global_shift=-0.5, exponent=0.5), cirq.CCXPowGate),
|
|
198
204
|
],
|
|
199
205
|
)
|
|
200
|
-
def test_no_specialized_control_for_global_shift_non_zero(gate, specialized_type):
|
|
206
|
+
def test_no_specialized_control_for_global_shift_non_zero(gate, specialized_type) -> None:
|
|
201
207
|
assert not isinstance(gate.controlled(), specialized_type)
|
|
202
208
|
|
|
203
209
|
|
|
@@ -223,11 +229,11 @@ def test_no_specialized_control_for_global_shift_non_zero(gate, specialized_type
|
|
|
223
229
|
),
|
|
224
230
|
],
|
|
225
231
|
)
|
|
226
|
-
def test_global_phase_controlled_gate(gate, matrix):
|
|
232
|
+
def test_global_phase_controlled_gate(gate, matrix) -> None:
|
|
227
233
|
np.testing.assert_equal(cirq.unitary(gate.controlled()), matrix)
|
|
228
234
|
|
|
229
235
|
|
|
230
|
-
def test_rot_gates_eq():
|
|
236
|
+
def test_rot_gates_eq() -> None:
|
|
231
237
|
eq = cirq.testing.EqualsTester()
|
|
232
238
|
gates = [
|
|
233
239
|
lambda p: cirq.CZ**p,
|
|
@@ -257,14 +263,14 @@ def test_rot_gates_eq():
|
|
|
257
263
|
eq.add_equality_group(cirq.CZPowGate(), cirq.CZPowGate(exponent=1), cirq.CZ)
|
|
258
264
|
|
|
259
265
|
|
|
260
|
-
def test_z_unitary():
|
|
266
|
+
def test_z_unitary() -> None:
|
|
261
267
|
assert np.allclose(cirq.unitary(cirq.Z), np.array([[1, 0], [0, -1]]))
|
|
262
268
|
assert np.allclose(cirq.unitary(cirq.Z**0.5), np.array([[1, 0], [0, 1j]]))
|
|
263
269
|
assert np.allclose(cirq.unitary(cirq.Z**0), np.array([[1, 0], [0, 1]]))
|
|
264
270
|
assert np.allclose(cirq.unitary(cirq.Z**-0.5), np.array([[1, 0], [0, -1j]]))
|
|
265
271
|
|
|
266
272
|
|
|
267
|
-
def test_y_unitary():
|
|
273
|
+
def test_y_unitary() -> None:
|
|
268
274
|
assert np.allclose(cirq.unitary(cirq.Y), np.array([[0, -1j], [1j, 0]]))
|
|
269
275
|
|
|
270
276
|
assert np.allclose(
|
|
@@ -278,7 +284,7 @@ def test_y_unitary():
|
|
|
278
284
|
)
|
|
279
285
|
|
|
280
286
|
|
|
281
|
-
def test_x_unitary():
|
|
287
|
+
def test_x_unitary() -> None:
|
|
282
288
|
assert np.allclose(cirq.unitary(cirq.X), np.array([[0, 1], [1, 0]]))
|
|
283
289
|
|
|
284
290
|
assert np.allclose(
|
|
@@ -292,28 +298,28 @@ def test_x_unitary():
|
|
|
292
298
|
)
|
|
293
299
|
|
|
294
300
|
|
|
295
|
-
def test_h_unitary():
|
|
301
|
+
def test_h_unitary() -> None:
|
|
296
302
|
sqrt = cirq.unitary(cirq.H**0.5)
|
|
297
303
|
m = np.dot(sqrt, sqrt)
|
|
298
304
|
assert np.allclose(m, cirq.unitary(cirq.H), atol=1e-8)
|
|
299
305
|
|
|
300
306
|
|
|
301
|
-
def test_h_init():
|
|
307
|
+
def test_h_init() -> None:
|
|
302
308
|
h = cirq.HPowGate(exponent=0.5)
|
|
303
309
|
assert h.exponent == 0.5
|
|
304
310
|
|
|
305
311
|
|
|
306
|
-
def test_h_str():
|
|
312
|
+
def test_h_str() -> None:
|
|
307
313
|
assert str(cirq.H) == 'H'
|
|
308
314
|
assert str(cirq.H**0.5) == 'H**0.5'
|
|
309
315
|
|
|
310
316
|
|
|
311
|
-
def test_phase_exponent():
|
|
317
|
+
def test_phase_exponent() -> None:
|
|
312
318
|
assert cirq.XPowGate(exponent=0.5).phase_exponent == 0.0
|
|
313
319
|
assert cirq.YPowGate(exponent=0.5).phase_exponent == 0.5
|
|
314
320
|
|
|
315
321
|
|
|
316
|
-
def test_x_act_on_tableau():
|
|
322
|
+
def test_x_act_on_tableau() -> None:
|
|
317
323
|
with pytest.raises(TypeError, match="Failed to act"):
|
|
318
324
|
cirq.act_on(cirq.X, ExampleSimulationState(), qubits=())
|
|
319
325
|
original_tableau = cirq.CliffordTableau(num_qubits=5, initial_state=31)
|
|
@@ -362,7 +368,7 @@ class MinusOnePhaseGate(cirq.testing.SingleQubitGate):
|
|
|
362
368
|
return np.array([[-1, 0], [0, -1]])
|
|
363
369
|
|
|
364
370
|
|
|
365
|
-
def test_y_act_on_tableau():
|
|
371
|
+
def test_y_act_on_tableau() -> None:
|
|
366
372
|
with pytest.raises(TypeError, match="Failed to act"):
|
|
367
373
|
cirq.act_on(cirq.Y, ExampleSimulationState(), qubits=())
|
|
368
374
|
original_tableau = cirq.CliffordTableau(num_qubits=5, initial_state=31)
|
|
@@ -400,7 +406,7 @@ def test_y_act_on_tableau():
|
|
|
400
406
|
cirq.act_on(cirq.Y**foo, state, [cirq.LineQubit(1)])
|
|
401
407
|
|
|
402
408
|
|
|
403
|
-
def test_z_h_act_on_tableau():
|
|
409
|
+
def test_z_h_act_on_tableau() -> None:
|
|
404
410
|
with pytest.raises(TypeError, match="Failed to act"):
|
|
405
411
|
cirq.act_on(cirq.Z, ExampleSimulationState(), qubits=())
|
|
406
412
|
with pytest.raises(TypeError, match="Failed to act"):
|
|
@@ -453,7 +459,7 @@ def test_z_h_act_on_tableau():
|
|
|
453
459
|
cirq.act_on(cirq.H**1.5, state, [cirq.LineQubit(1)])
|
|
454
460
|
|
|
455
461
|
|
|
456
|
-
def test_cx_act_on_tableau():
|
|
462
|
+
def test_cx_act_on_tableau() -> None:
|
|
457
463
|
with pytest.raises(TypeError, match="Failed to act"):
|
|
458
464
|
cirq.act_on(cirq.CX, ExampleSimulationState(), qubits=())
|
|
459
465
|
original_tableau = cirq.CliffordTableau(num_qubits=5, initial_state=31)
|
|
@@ -497,7 +503,7 @@ def test_cx_act_on_tableau():
|
|
|
497
503
|
cirq.act_on(cirq.CX**1.5, state, cirq.LineQubit.range(2))
|
|
498
504
|
|
|
499
505
|
|
|
500
|
-
def test_cz_act_on_tableau():
|
|
506
|
+
def test_cz_act_on_tableau() -> None:
|
|
501
507
|
with pytest.raises(TypeError, match="Failed to act"):
|
|
502
508
|
cirq.act_on(cirq.CZ, ExampleSimulationState(), qubits=())
|
|
503
509
|
original_tableau = cirq.CliffordTableau(num_qubits=5, initial_state=31)
|
|
@@ -541,7 +547,7 @@ def test_cz_act_on_tableau():
|
|
|
541
547
|
cirq.act_on(cirq.CZ**1.5, state, cirq.LineQubit.range(2))
|
|
542
548
|
|
|
543
549
|
|
|
544
|
-
def test_cz_act_on_equivalent_to_h_cx_h_tableau():
|
|
550
|
+
def test_cz_act_on_equivalent_to_h_cx_h_tableau() -> None:
|
|
545
551
|
state1 = cirq.CliffordTableauSimulationState(
|
|
546
552
|
tableau=cirq.CliffordTableau(num_qubits=2),
|
|
547
553
|
qubits=cirq.LineQubit.range(2),
|
|
@@ -601,7 +607,7 @@ foo = sympy.Symbol('foo')
|
|
|
601
607
|
([cirq.CZ, MinusOnePhaseGate()], 'Original'),
|
|
602
608
|
],
|
|
603
609
|
)
|
|
604
|
-
def test_act_on_ch_form(input_gate_sequence, outcome):
|
|
610
|
+
def test_act_on_ch_form(input_gate_sequence, outcome) -> None:
|
|
605
611
|
original_state = cirq.StabilizerStateChForm(num_qubits=5, initial_state=31)
|
|
606
612
|
num_qubits = cirq.num_qubits(input_gate_sequence[0])
|
|
607
613
|
if num_qubits == 1:
|
|
@@ -663,13 +669,13 @@ def test_act_on_ch_form(input_gate_sequence, outcome):
|
|
|
663
669
|
(cirq.CZ**0.5, False),
|
|
664
670
|
],
|
|
665
671
|
)
|
|
666
|
-
def test_act_on_consistency(input_gate, assert_implemented):
|
|
672
|
+
def test_act_on_consistency(input_gate, assert_implemented) -> None:
|
|
667
673
|
cirq.testing.assert_all_implemented_act_on_effects_match_unitary(
|
|
668
674
|
input_gate, assert_implemented, assert_implemented
|
|
669
675
|
)
|
|
670
676
|
|
|
671
677
|
|
|
672
|
-
def test_runtime_types_of_rot_gates():
|
|
678
|
+
def test_runtime_types_of_rot_gates() -> None:
|
|
673
679
|
for gate_type in [
|
|
674
680
|
lambda p: cirq.CZPowGate(exponent=p),
|
|
675
681
|
lambda p: cirq.XPowGate(exponent=p),
|
|
@@ -687,7 +693,7 @@ def test_runtime_types_of_rot_gates():
|
|
|
687
693
|
assert cirq.inverse(c) == gate_type(-0.5)
|
|
688
694
|
|
|
689
695
|
|
|
690
|
-
def test_interchangeable_qubit_eq():
|
|
696
|
+
def test_interchangeable_qubit_eq() -> None:
|
|
691
697
|
a = cirq.NamedQubit('a')
|
|
692
698
|
b = cirq.NamedQubit('b')
|
|
693
699
|
c = cirq.NamedQubit('c')
|
|
@@ -701,7 +707,7 @@ def test_interchangeable_qubit_eq():
|
|
|
701
707
|
eq.add_equality_group(cirq.CNOT(a, c))
|
|
702
708
|
|
|
703
709
|
|
|
704
|
-
def test_identity_multiplication():
|
|
710
|
+
def test_identity_multiplication() -> None:
|
|
705
711
|
a, b, c = cirq.LineQubit.range(3)
|
|
706
712
|
assert cirq.I(a) * cirq.CX(a, b) == cirq.CX(a, b)
|
|
707
713
|
assert cirq.CX(a, b) * cirq.I(a) == cirq.CX(a, b)
|
|
@@ -714,7 +720,7 @@ def test_identity_multiplication():
|
|
|
714
720
|
assert cirq.I(c) * cirq.T(b) ** 0.25 == cirq.T(b) ** 0.25
|
|
715
721
|
|
|
716
722
|
|
|
717
|
-
def test_text_diagrams():
|
|
723
|
+
def test_text_diagrams() -> None:
|
|
718
724
|
a = cirq.NamedQubit('a')
|
|
719
725
|
b = cirq.NamedQubit('b')
|
|
720
726
|
circuit = cirq.Circuit(
|
|
@@ -754,7 +760,7 @@ b: -----------------------------@---X---@---X^0.5---@-------------------I---@^t-
|
|
|
754
760
|
)
|
|
755
761
|
|
|
756
762
|
|
|
757
|
-
def test_cnot_unitary():
|
|
763
|
+
def test_cnot_unitary() -> None:
|
|
758
764
|
np.testing.assert_almost_equal(
|
|
759
765
|
cirq.unitary(cirq.CNOT**0.5),
|
|
760
766
|
np.array(
|
|
@@ -768,13 +774,13 @@ def test_cnot_unitary():
|
|
|
768
774
|
)
|
|
769
775
|
|
|
770
776
|
|
|
771
|
-
def test_cnot_decompose():
|
|
777
|
+
def test_cnot_decompose() -> None:
|
|
772
778
|
a = cirq.NamedQubit('a')
|
|
773
779
|
b = cirq.NamedQubit('b')
|
|
774
780
|
assert cirq.decompose_once(cirq.CNOT(a, b) ** sympy.Symbol('x')) is not None
|
|
775
781
|
|
|
776
782
|
|
|
777
|
-
def test_repr():
|
|
783
|
+
def test_repr() -> None:
|
|
778
784
|
assert repr(cirq.X) == 'cirq.X'
|
|
779
785
|
assert repr(cirq.X**0.5) == '(cirq.X**0.5)'
|
|
780
786
|
|
|
@@ -808,7 +814,7 @@ def test_repr():
|
|
|
808
814
|
assert repr(cirq.CZ**0.2) == '(cirq.CZ**0.2)'
|
|
809
815
|
|
|
810
816
|
|
|
811
|
-
def test_str():
|
|
817
|
+
def test_str() -> None:
|
|
812
818
|
assert str(cirq.X) == 'X'
|
|
813
819
|
assert str(cirq.X**0.5) == 'X**0.5'
|
|
814
820
|
assert str(cirq.rx(np.pi)) == 'Rx(π)'
|
|
@@ -844,7 +850,7 @@ def test_str():
|
|
|
844
850
|
assert str(cirq.cphase(np.pi / 2)) == 'CZ**0.5'
|
|
845
851
|
|
|
846
852
|
|
|
847
|
-
def test_rx_unitary():
|
|
853
|
+
def test_rx_unitary() -> None:
|
|
848
854
|
s = np.sqrt(0.5)
|
|
849
855
|
np.testing.assert_allclose(
|
|
850
856
|
cirq.unitary(cirq.rx(np.pi / 2)), np.array([[s, -s * 1j], [-s * 1j, s]])
|
|
@@ -863,7 +869,7 @@ def test_rx_unitary():
|
|
|
863
869
|
np.testing.assert_allclose(cirq.unitary(cirq.rx(-np.pi)), np.array([[0, 1j], [1j, 0]]))
|
|
864
870
|
|
|
865
871
|
|
|
866
|
-
def test_ry_unitary():
|
|
872
|
+
def test_ry_unitary() -> None:
|
|
867
873
|
s = np.sqrt(0.5)
|
|
868
874
|
np.testing.assert_allclose(cirq.unitary(cirq.ry(np.pi / 2)), np.array([[s, -s], [s, s]]))
|
|
869
875
|
|
|
@@ -878,7 +884,7 @@ def test_ry_unitary():
|
|
|
878
884
|
np.testing.assert_allclose(cirq.unitary(cirq.ry(-np.pi)), np.array([[0, 1], [-1, 0]]))
|
|
879
885
|
|
|
880
886
|
|
|
881
|
-
def test_rz_unitary():
|
|
887
|
+
def test_rz_unitary() -> None:
|
|
882
888
|
s = np.sqrt(0.5)
|
|
883
889
|
np.testing.assert_allclose(
|
|
884
890
|
cirq.unitary(cirq.rz(np.pi / 2)), np.array([[s - s * 1j, 0], [0, s + s * 1j]])
|
|
@@ -901,17 +907,17 @@ def test_rz_unitary():
|
|
|
901
907
|
'angle_rads, expected_unitary',
|
|
902
908
|
[(0, np.eye(4)), (1, np.diag([1, 1, 1, np.exp(1j)])), (np.pi / 2, np.diag([1, 1, 1, 1j]))],
|
|
903
909
|
)
|
|
904
|
-
def test_cphase_unitary(angle_rads, expected_unitary):
|
|
910
|
+
def test_cphase_unitary(angle_rads, expected_unitary) -> None:
|
|
905
911
|
np.testing.assert_allclose(cirq.unitary(cirq.cphase(angle_rads)), expected_unitary)
|
|
906
912
|
|
|
907
913
|
|
|
908
|
-
def test_parameterized_cphase():
|
|
914
|
+
def test_parameterized_cphase() -> None:
|
|
909
915
|
assert cirq.cphase(sympy.pi) == cirq.CZ
|
|
910
916
|
assert cirq.cphase(sympy.pi / 2) == cirq.CZ**0.5
|
|
911
917
|
|
|
912
918
|
|
|
913
919
|
@pytest.mark.parametrize('gate', [cirq.X, cirq.Y, cirq.Z])
|
|
914
|
-
def test_x_y_z_stabilizer(gate):
|
|
920
|
+
def test_x_y_z_stabilizer(gate) -> None:
|
|
915
921
|
assert cirq.has_stabilizer_effect(gate)
|
|
916
922
|
assert cirq.has_stabilizer_effect(gate**0.5)
|
|
917
923
|
assert cirq.has_stabilizer_effect(gate**0)
|
|
@@ -922,7 +928,7 @@ def test_x_y_z_stabilizer(gate):
|
|
|
922
928
|
assert not cirq.has_stabilizer_effect(gate**foo)
|
|
923
929
|
|
|
924
930
|
|
|
925
|
-
def test_h_stabilizer():
|
|
931
|
+
def test_h_stabilizer() -> None:
|
|
926
932
|
gate = cirq.H
|
|
927
933
|
assert cirq.has_stabilizer_effect(gate)
|
|
928
934
|
assert not cirq.has_stabilizer_effect(gate**0.5)
|
|
@@ -935,7 +941,7 @@ def test_h_stabilizer():
|
|
|
935
941
|
|
|
936
942
|
|
|
937
943
|
@pytest.mark.parametrize('gate', [cirq.CX, cirq.CZ])
|
|
938
|
-
def test_cx_cz_stabilizer(gate):
|
|
944
|
+
def test_cx_cz_stabilizer(gate) -> None:
|
|
939
945
|
assert cirq.has_stabilizer_effect(gate)
|
|
940
946
|
assert not cirq.has_stabilizer_effect(gate**0.5)
|
|
941
947
|
assert cirq.has_stabilizer_effect(gate**0)
|
|
@@ -946,13 +952,13 @@ def test_cx_cz_stabilizer(gate):
|
|
|
946
952
|
assert not cirq.has_stabilizer_effect(gate**foo)
|
|
947
953
|
|
|
948
954
|
|
|
949
|
-
def test_phase_by_xy():
|
|
955
|
+
def test_phase_by_xy() -> None:
|
|
950
956
|
assert cirq.phase_by(cirq.X, 0.25, 0) == cirq.Y
|
|
951
957
|
assert cirq.phase_by(cirq.X**0.5, 0.25, 0) == cirq.Y**0.5
|
|
952
958
|
assert cirq.phase_by(cirq.X**-0.5, 0.25, 0) == cirq.Y**-0.5
|
|
953
959
|
|
|
954
960
|
|
|
955
|
-
def test_ixyz_circuit_diagram():
|
|
961
|
+
def test_ixyz_circuit_diagram() -> None:
|
|
956
962
|
q = cirq.NamedQubit('q')
|
|
957
963
|
ix = cirq.XPowGate(exponent=1, global_shift=0.5)
|
|
958
964
|
iy = cirq.YPowGate(exponent=1, global_shift=0.5)
|
|
@@ -997,7 +1003,7 @@ q: ───Z───Z───Z───S───S───
|
|
|
997
1003
|
(sympy.Symbol("theta"), sympy.Symbol("exp")),
|
|
998
1004
|
],
|
|
999
1005
|
)
|
|
1000
|
-
def test_rxyz_exponent(theta, exp):
|
|
1006
|
+
def test_rxyz_exponent(theta, exp) -> None:
|
|
1001
1007
|
def resolve(gate):
|
|
1002
1008
|
return cirq.resolve_parameters(gate, {'theta': np.pi / 4}, {'exp': 1 / 4})
|
|
1003
1009
|
|
|
@@ -1006,7 +1012,7 @@ def test_rxyz_exponent(theta, exp):
|
|
|
1006
1012
|
assert resolve(cirq.Rz(rads=theta) ** exp) == resolve(cirq.Rz(rads=theta * exp))
|
|
1007
1013
|
|
|
1008
1014
|
|
|
1009
|
-
def test_rxyz_circuit_diagram():
|
|
1015
|
+
def test_rxyz_circuit_diagram() -> None:
|
|
1010
1016
|
q = cirq.NamedQubit('q')
|
|
1011
1017
|
|
|
1012
1018
|
cirq.testing.assert_has_diagram(
|
|
@@ -1063,7 +1069,7 @@ q: ───Rz(π)───Rz(-π)───Rz(-π)───Rz(0.5π)───Rz(
|
|
|
1063
1069
|
)
|
|
1064
1070
|
|
|
1065
1071
|
|
|
1066
|
-
def test_trace_distance():
|
|
1072
|
+
def test_trace_distance() -> None:
|
|
1067
1073
|
foo = sympy.Symbol('foo')
|
|
1068
1074
|
sx = cirq.X**foo
|
|
1069
1075
|
sy = cirq.Y**foo
|
|
@@ -1088,13 +1094,13 @@ def test_trace_distance():
|
|
|
1088
1094
|
assert cirq.approx_eq(cirq.trace_distance_bound(cirq.CZ ** (1 / 9)), np.sin(np.pi / 18))
|
|
1089
1095
|
|
|
1090
1096
|
|
|
1091
|
-
def test_commutes():
|
|
1097
|
+
def test_commutes() -> None:
|
|
1092
1098
|
assert cirq.commutes(cirq.ZPowGate(exponent=sympy.Symbol('t')), cirq.Z)
|
|
1093
1099
|
assert cirq.commutes(cirq.Z, cirq.Z(cirq.LineQubit(0)), default=None) is None
|
|
1094
1100
|
assert cirq.commutes(cirq.Z**0.1, cirq.XPowGate(exponent=0))
|
|
1095
1101
|
|
|
1096
1102
|
|
|
1097
|
-
def test_approx_eq():
|
|
1103
|
+
def test_approx_eq() -> None:
|
|
1098
1104
|
assert cirq.approx_eq(cirq.Z**0.1, cirq.Z**0.2, atol=0.3)
|
|
1099
1105
|
assert not cirq.approx_eq(cirq.Z**0.1, cirq.Z**0.2, atol=0.05)
|
|
1100
1106
|
assert cirq.approx_eq(cirq.Y**0.1, cirq.Y**0.2, atol=0.3)
|
|
@@ -1103,15 +1109,15 @@ def test_approx_eq():
|
|
|
1103
1109
|
assert not cirq.approx_eq(cirq.X**0.1, cirq.X**0.2, atol=0.05)
|
|
1104
1110
|
|
|
1105
1111
|
|
|
1106
|
-
def test_xpow_dim_3():
|
|
1112
|
+
def test_xpow_dim_3() -> None:
|
|
1107
1113
|
x = cirq.XPowGate(dimension=3)
|
|
1108
1114
|
assert cirq.X != x
|
|
1109
1115
|
# fmt: off
|
|
1110
|
-
expected = [
|
|
1116
|
+
expected = np.asarray([
|
|
1111
1117
|
[0, 0, 1],
|
|
1112
1118
|
[1, 0, 0],
|
|
1113
1119
|
[0, 1, 0],
|
|
1114
|
-
]
|
|
1120
|
+
])
|
|
1115
1121
|
# fmt: on
|
|
1116
1122
|
assert np.allclose(cirq.unitary(x), expected)
|
|
1117
1123
|
|
|
@@ -1119,28 +1125,28 @@ def test_xpow_dim_3():
|
|
|
1119
1125
|
circuit = cirq.Circuit([x(cirq.LineQid(0, 3)) ** 0.5] * 6)
|
|
1120
1126
|
svs = [step.state_vector(copy=True) for step in sim.simulate_moment_steps(circuit)]
|
|
1121
1127
|
# fmt: off
|
|
1122
|
-
expected = [
|
|
1128
|
+
expected = np.asarray([
|
|
1123
1129
|
[0.67, 0.67, 0.33],
|
|
1124
1130
|
[0.0, 1.0, 0.0],
|
|
1125
1131
|
[0.33, 0.67, 0.67],
|
|
1126
1132
|
[0.0, 0.0, 1.0],
|
|
1127
1133
|
[0.67, 0.33, 0.67],
|
|
1128
1134
|
[1.0, 0.0, 0.0],
|
|
1129
|
-
]
|
|
1135
|
+
])
|
|
1130
1136
|
# fmt: on
|
|
1131
1137
|
assert np.allclose(np.abs(svs), expected, atol=1e-2)
|
|
1132
1138
|
|
|
1133
1139
|
|
|
1134
|
-
def test_xpow_dim_4():
|
|
1140
|
+
def test_xpow_dim_4() -> None:
|
|
1135
1141
|
x = cirq.XPowGate(dimension=4)
|
|
1136
1142
|
assert cirq.X != x
|
|
1137
1143
|
# fmt: off
|
|
1138
|
-
expected = [
|
|
1144
|
+
expected = np.asarray([
|
|
1139
1145
|
[0, 0, 0, 1],
|
|
1140
1146
|
[1, 0, 0, 0],
|
|
1141
1147
|
[0, 1, 0, 0],
|
|
1142
1148
|
[0, 0, 1, 0],
|
|
1143
|
-
]
|
|
1149
|
+
])
|
|
1144
1150
|
# fmt: on
|
|
1145
1151
|
assert np.allclose(cirq.unitary(x), expected)
|
|
1146
1152
|
|
|
@@ -1148,7 +1154,7 @@ def test_xpow_dim_4():
|
|
|
1148
1154
|
circuit = cirq.Circuit([x(cirq.LineQid(0, 4)) ** 0.5] * 8)
|
|
1149
1155
|
svs = [step.state_vector(copy=True) for step in sim.simulate_moment_steps(circuit)]
|
|
1150
1156
|
# fmt: off
|
|
1151
|
-
expected = [
|
|
1157
|
+
expected = np.asarray([
|
|
1152
1158
|
[0.65, 0.65, 0.27, 0.27],
|
|
1153
1159
|
[0.0, 1.0, 0.0, 0.0],
|
|
1154
1160
|
[0.27, 0.65, 0.65, 0.27],
|
|
@@ -1157,22 +1163,22 @@ def test_xpow_dim_4():
|
|
|
1157
1163
|
[0.0, 0.0, 0.0, 1.0],
|
|
1158
1164
|
[0.65, 0.27, 0.27, 0.65],
|
|
1159
1165
|
[1.0, 0.0, 0.0, 0.0],
|
|
1160
|
-
]
|
|
1166
|
+
])
|
|
1161
1167
|
# fmt: on
|
|
1162
1168
|
assert np.allclose(np.abs(svs), expected, atol=1e-2)
|
|
1163
1169
|
|
|
1164
1170
|
|
|
1165
|
-
def test_zpow_dim_3():
|
|
1171
|
+
def test_zpow_dim_3() -> None:
|
|
1166
1172
|
L = np.exp(2 * np.pi * 1j / 3)
|
|
1167
1173
|
L2 = L**2
|
|
1168
1174
|
z = cirq.ZPowGate(dimension=3)
|
|
1169
1175
|
assert cirq.Z != z
|
|
1170
1176
|
# fmt: off
|
|
1171
|
-
expected = [
|
|
1177
|
+
expected = np.asarray([
|
|
1172
1178
|
[1, 0, 0],
|
|
1173
1179
|
[0, L, 0],
|
|
1174
1180
|
[0, 0, L2],
|
|
1175
|
-
]
|
|
1181
|
+
])
|
|
1176
1182
|
# fmt: on
|
|
1177
1183
|
assert np.allclose(cirq.unitary(z), expected)
|
|
1178
1184
|
|
|
@@ -1181,21 +1187,21 @@ def test_zpow_dim_3():
|
|
|
1181
1187
|
svs = [
|
|
1182
1188
|
step.state_vector(copy=True) for step in sim.simulate_moment_steps(circuit, initial_state=0)
|
|
1183
1189
|
]
|
|
1184
|
-
expected = [[1, 0, 0]] * 6
|
|
1190
|
+
expected = np.asarray([[1, 0, 0]] * 6)
|
|
1185
1191
|
assert np.allclose((svs), expected)
|
|
1186
1192
|
|
|
1187
1193
|
svs = [
|
|
1188
1194
|
step.state_vector(copy=True) for step in sim.simulate_moment_steps(circuit, initial_state=1)
|
|
1189
1195
|
]
|
|
1190
1196
|
# fmt: off
|
|
1191
|
-
expected = [
|
|
1197
|
+
expected = np.asarray([
|
|
1192
1198
|
[0, L**0.5, 0],
|
|
1193
1199
|
[0, L**1.0, 0],
|
|
1194
1200
|
[0, L**1.5, 0],
|
|
1195
1201
|
[0, L**2.0, 0],
|
|
1196
1202
|
[0, L**2.5, 0],
|
|
1197
1203
|
[0, 1, 0],
|
|
1198
|
-
]
|
|
1204
|
+
])
|
|
1199
1205
|
# fmt: on
|
|
1200
1206
|
assert np.allclose((svs), expected)
|
|
1201
1207
|
|
|
@@ -1203,28 +1209,28 @@ def test_zpow_dim_3():
|
|
|
1203
1209
|
step.state_vector(copy=True) for step in sim.simulate_moment_steps(circuit, initial_state=2)
|
|
1204
1210
|
]
|
|
1205
1211
|
# fmt: off
|
|
1206
|
-
expected = [
|
|
1212
|
+
expected = np.asarray([
|
|
1207
1213
|
[0, 0, L],
|
|
1208
1214
|
[0, 0, L2],
|
|
1209
1215
|
[0, 0, 1],
|
|
1210
1216
|
[0, 0, L],
|
|
1211
1217
|
[0, 0, L2],
|
|
1212
1218
|
[0, 0, 1],
|
|
1213
|
-
]
|
|
1219
|
+
])
|
|
1214
1220
|
# fmt: on
|
|
1215
1221
|
assert np.allclose((svs), expected)
|
|
1216
1222
|
|
|
1217
1223
|
|
|
1218
|
-
def test_zpow_dim_4():
|
|
1224
|
+
def test_zpow_dim_4() -> None:
|
|
1219
1225
|
z = cirq.ZPowGate(dimension=4)
|
|
1220
1226
|
assert cirq.Z != z
|
|
1221
1227
|
# fmt: off
|
|
1222
|
-
expected = [
|
|
1228
|
+
expected = np.asarray([
|
|
1223
1229
|
[1, 0, 0, 0],
|
|
1224
1230
|
[0, 1j, 0, 0],
|
|
1225
1231
|
[0, 0, -1, 0],
|
|
1226
1232
|
[0, 0, 0, -1j],
|
|
1227
|
-
]
|
|
1233
|
+
])
|
|
1228
1234
|
# fmt: on
|
|
1229
1235
|
assert np.allclose(cirq.unitary(z), expected)
|
|
1230
1236
|
|
|
@@ -1233,14 +1239,14 @@ def test_zpow_dim_4():
|
|
|
1233
1239
|
svs = [
|
|
1234
1240
|
step.state_vector(copy=True) for step in sim.simulate_moment_steps(circuit, initial_state=0)
|
|
1235
1241
|
]
|
|
1236
|
-
expected = [[1, 0, 0, 0]] * 8
|
|
1242
|
+
expected = np.asarray([[1, 0, 0, 0]] * 8)
|
|
1237
1243
|
assert np.allclose((svs), expected)
|
|
1238
1244
|
|
|
1239
1245
|
svs = [
|
|
1240
1246
|
step.state_vector(copy=True) for step in sim.simulate_moment_steps(circuit, initial_state=1)
|
|
1241
1247
|
]
|
|
1242
1248
|
# fmt: off
|
|
1243
|
-
expected = [
|
|
1249
|
+
expected = np.asarray([
|
|
1244
1250
|
[0, 1j**0.5, 0, 0],
|
|
1245
1251
|
[0, 1j**1.0, 0, 0],
|
|
1246
1252
|
[0, 1j**1.5, 0, 0],
|
|
@@ -1249,7 +1255,7 @@ def test_zpow_dim_4():
|
|
|
1249
1255
|
[0, 1j**3.0, 0, 0],
|
|
1250
1256
|
[0, 1j**3.5, 0, 0],
|
|
1251
1257
|
[0, 1, 0, 0],
|
|
1252
|
-
]
|
|
1258
|
+
])
|
|
1253
1259
|
# fmt: on
|
|
1254
1260
|
assert np.allclose(svs, expected)
|
|
1255
1261
|
|
|
@@ -1257,7 +1263,7 @@ def test_zpow_dim_4():
|
|
|
1257
1263
|
step.state_vector(copy=True) for step in sim.simulate_moment_steps(circuit, initial_state=2)
|
|
1258
1264
|
]
|
|
1259
1265
|
# fmt: off
|
|
1260
|
-
expected = [
|
|
1266
|
+
expected = np.asarray([
|
|
1261
1267
|
[0, 0, 1j, 0],
|
|
1262
1268
|
[0, 0, -1, 0],
|
|
1263
1269
|
[0, 0, -1j, 0],
|
|
@@ -1266,7 +1272,7 @@ def test_zpow_dim_4():
|
|
|
1266
1272
|
[0, 0, -1, 0],
|
|
1267
1273
|
[0, 0, -1j, 0],
|
|
1268
1274
|
[0, 0, 1, 0],
|
|
1269
|
-
]
|
|
1275
|
+
])
|
|
1270
1276
|
# fmt: on
|
|
1271
1277
|
assert np.allclose(svs, expected)
|
|
1272
1278
|
|
|
@@ -1274,7 +1280,7 @@ def test_zpow_dim_4():
|
|
|
1274
1280
|
step.state_vector(copy=True) for step in sim.simulate_moment_steps(circuit, initial_state=3)
|
|
1275
1281
|
]
|
|
1276
1282
|
# fmt: off
|
|
1277
|
-
expected = [
|
|
1283
|
+
expected = np.asarray([
|
|
1278
1284
|
[0, 0, 0, 1j**1.5],
|
|
1279
1285
|
[0, 0, 0, 1j**3],
|
|
1280
1286
|
[0, 0, 0, 1j**0.5],
|
|
@@ -1283,12 +1289,12 @@ def test_zpow_dim_4():
|
|
|
1283
1289
|
[0, 0, 0, 1j**1],
|
|
1284
1290
|
[0, 0, 0, 1j**2.5],
|
|
1285
1291
|
[0, 0, 0, 1],
|
|
1286
|
-
]
|
|
1292
|
+
])
|
|
1287
1293
|
# fmt: on
|
|
1288
1294
|
assert np.allclose(svs, expected)
|
|
1289
1295
|
|
|
1290
1296
|
|
|
1291
|
-
def test_wrong_dims():
|
|
1297
|
+
def test_wrong_dims() -> None:
|
|
1292
1298
|
x3 = cirq.XPowGate(dimension=3)
|
|
1293
1299
|
with pytest.raises(ValueError, match='Wrong shape'):
|
|
1294
1300
|
_ = x3.on(cirq.LineQubit(0))
|
|
@@ -1310,9 +1316,43 @@ def test_wrong_dims():
|
|
|
1310
1316
|
|
|
1311
1317
|
@pytest.mark.parametrize('gate_type', [cirq.XPowGate, cirq.YPowGate, cirq.ZPowGate])
|
|
1312
1318
|
@pytest.mark.parametrize('exponent', [sympy.Symbol('s'), sympy.Symbol('s') * 2])
|
|
1313
|
-
def test_parameterized_pauli_expansion(gate_type, exponent):
|
|
1319
|
+
def test_parameterized_pauli_expansion(gate_type, exponent) -> None:
|
|
1314
1320
|
gate = gate_type(exponent=exponent)
|
|
1315
1321
|
pauli = cirq.pauli_expansion(gate)
|
|
1316
1322
|
gate_resolved = cirq.resolve_parameters(gate, {'s': 0.5})
|
|
1317
1323
|
pauli_resolved = cirq.resolve_parameters(pauli, {'s': 0.5})
|
|
1318
1324
|
assert cirq.approx_eq(pauli_resolved, cirq.pauli_expansion(gate_resolved))
|
|
1325
|
+
|
|
1326
|
+
|
|
1327
|
+
@pytest.mark.parametrize('gate_type', [cirq.XPowGate, cirq.YPowGate, cirq.ZPowGate, cirq.CZPowGate])
|
|
1328
|
+
@pytest.mark.parametrize('exponent', [0, 0.5, 2, 3, -0.5, -2, -3, sympy.Symbol('s')])
|
|
1329
|
+
def test_decompose_with_extracted_phases(gate_type: type, exponent: cirq.TParamVal) -> None:
|
|
1330
|
+
context = cirq.DecompositionContext(cirq.SimpleQubitManager(), extract_global_phases=True)
|
|
1331
|
+
test_shift = 2 / 3 # Interesting because e.g. X(shift=2/3) ** 3 == X with no phase
|
|
1332
|
+
gate = gate_type(exponent=exponent, global_shift=test_shift)
|
|
1333
|
+
op = gate.on(*cirq.LineQubit.range(cirq.num_qubits(gate)))
|
|
1334
|
+
decomposed = cirq.decompose(op, context=context)
|
|
1335
|
+
|
|
1336
|
+
# The first gate should be the original gate, but with shift removed.
|
|
1337
|
+
gate0 = decomposed[0].gate
|
|
1338
|
+
assert isinstance(gate0, gate_type)
|
|
1339
|
+
assert isinstance(gate0, cirq.EigenGate)
|
|
1340
|
+
assert gate0.global_shift == 0
|
|
1341
|
+
assert gate0.exponent == exponent
|
|
1342
|
+
if exponent % 3 == 0:
|
|
1343
|
+
# Since test_shift == 2/3, gate**3 nullifies the phase, leaving only the unphased gate.
|
|
1344
|
+
assert len(decomposed) == 1
|
|
1345
|
+
else:
|
|
1346
|
+
# Other exponents emit a global phase gate to compensate.
|
|
1347
|
+
assert len(decomposed) == 2
|
|
1348
|
+
gate1 = decomposed[1].gate
|
|
1349
|
+
assert isinstance(gate1, cirq.GlobalPhaseGate)
|
|
1350
|
+
assert gate1.coefficient == 1j ** (2 * exponent * test_shift)
|
|
1351
|
+
|
|
1352
|
+
# Sanity check that the decomposition is equivalent to the original.
|
|
1353
|
+
decomposed_circuit = cirq.Circuit(decomposed)
|
|
1354
|
+
if cirq.is_parameterized(exponent):
|
|
1355
|
+
resolver = {'s': -1.234} # arbitrary
|
|
1356
|
+
op = cirq.resolve_parameters(op, resolver)
|
|
1357
|
+
decomposed_circuit = cirq.resolve_parameters(decomposed_circuit, resolver)
|
|
1358
|
+
np.testing.assert_allclose(cirq.unitary(op), cirq.unitary(decomposed_circuit), atol=1e-10)
|