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/raw_types_test.py
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import AbstractSet, Any, cast, Iterator
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
18
20
|
import pytest
|
|
@@ -26,7 +28,7 @@ class ValidQubit(cirq.Qid):
|
|
|
26
28
|
self._name = name
|
|
27
29
|
|
|
28
30
|
@property
|
|
29
|
-
def dimension(self):
|
|
31
|
+
def dimension(self) -> int:
|
|
30
32
|
return 2
|
|
31
33
|
|
|
32
34
|
def _comparison_key(self):
|
|
@@ -49,19 +51,19 @@ class ValidQid(cirq.Qid):
|
|
|
49
51
|
def dimension(self):
|
|
50
52
|
return self._dimension
|
|
51
53
|
|
|
52
|
-
def with_dimension(self, dimension):
|
|
54
|
+
def with_dimension(self, dimension) -> ValidQid:
|
|
53
55
|
return ValidQid(self._name, dimension)
|
|
54
56
|
|
|
55
57
|
def _comparison_key(self):
|
|
56
58
|
return self._name
|
|
57
59
|
|
|
58
60
|
|
|
59
|
-
def test_wrapped_qid():
|
|
61
|
+
def test_wrapped_qid() -> None:
|
|
60
62
|
assert type(ValidQubit('a').with_dimension(3)) is not ValidQubit
|
|
61
63
|
assert type(ValidQubit('a').with_dimension(2)) is ValidQubit
|
|
62
64
|
assert type(ValidQubit('a').with_dimension(5).with_dimension(2)) is ValidQubit
|
|
63
65
|
assert ValidQubit('a').with_dimension(3).with_dimension(4) == ValidQubit('a').with_dimension(4)
|
|
64
|
-
assert ValidQubit('a').with_dimension(3).qubit == ValidQubit('a')
|
|
66
|
+
assert ValidQubit('a').with_dimension(3).qubit == ValidQubit('a') # type: ignore[attr-defined]
|
|
65
67
|
assert ValidQubit('a').with_dimension(3) == ValidQubit('a').with_dimension(3)
|
|
66
68
|
assert ValidQubit('a').with_dimension(3) < ValidQubit('a').with_dimension(4)
|
|
67
69
|
assert ValidQubit('a').with_dimension(3) < ValidQubit('b').with_dimension(3)
|
|
@@ -72,12 +74,12 @@ def test_wrapped_qid():
|
|
|
72
74
|
)
|
|
73
75
|
assert str(ValidQubit('a').with_dimension(3)) == 'TQ_a (d=3)'
|
|
74
76
|
|
|
75
|
-
assert ValidQubit('zz').with_dimension(3)._json_dict_() == {
|
|
77
|
+
assert ValidQubit('zz').with_dimension(3)._json_dict_() == { # type: ignore[attr-defined]
|
|
76
78
|
'qubit': ValidQubit('zz'),
|
|
77
79
|
'dimension': 3,
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
assert not ValidQubit('zz') == 4
|
|
82
|
+
assert not ValidQubit('zz') == 4 # noqa: SIM201
|
|
81
83
|
assert ValidQubit('zz') != 4
|
|
82
84
|
assert ValidQubit('zz') > ValidQubit('aa')
|
|
83
85
|
assert ValidQubit('zz') <= ValidQubit('zz')
|
|
@@ -85,7 +87,7 @@ def test_wrapped_qid():
|
|
|
85
87
|
assert ValidQubit('zz') >= ValidQubit('aa')
|
|
86
88
|
|
|
87
89
|
|
|
88
|
-
def test_qid_dimension():
|
|
90
|
+
def test_qid_dimension() -> None:
|
|
89
91
|
assert ValidQubit('a').dimension == 2
|
|
90
92
|
assert ValidQubit('a').with_dimension(3).dimension == 3
|
|
91
93
|
with pytest.raises(ValueError, match='Wrong qid dimension'):
|
|
@@ -106,7 +108,7 @@ class ValiGate(cirq.Gate):
|
|
|
106
108
|
def _num_qubits_(self):
|
|
107
109
|
return 2
|
|
108
110
|
|
|
109
|
-
def validate_args(self, qubits):
|
|
111
|
+
def validate_args(self, qubits) -> None:
|
|
110
112
|
if len(qubits) == 1:
|
|
111
113
|
return # Bypass check for some tests
|
|
112
114
|
super().validate_args(qubits)
|
|
@@ -115,7 +117,7 @@ class ValiGate(cirq.Gate):
|
|
|
115
117
|
return True
|
|
116
118
|
|
|
117
119
|
|
|
118
|
-
def test_gate():
|
|
120
|
+
def test_gate() -> None:
|
|
119
121
|
a, b, c = cirq.LineQubit.range(3)
|
|
120
122
|
|
|
121
123
|
g = ValiGate()
|
|
@@ -135,7 +137,7 @@ def test_gate():
|
|
|
135
137
|
assert g.controlled(0) is g
|
|
136
138
|
|
|
137
139
|
|
|
138
|
-
def test_op():
|
|
140
|
+
def test_op() -> None:
|
|
139
141
|
a, b, c, d = cirq.LineQubit.range(4)
|
|
140
142
|
g = ValiGate()
|
|
141
143
|
op = g(a, b)
|
|
@@ -145,7 +147,7 @@ def test_op():
|
|
|
145
147
|
assert controlled_op.controls == (c, d)
|
|
146
148
|
|
|
147
149
|
|
|
148
|
-
def test_op_validate():
|
|
150
|
+
def test_op_validate() -> None:
|
|
149
151
|
op = cirq.X(cirq.LineQid(0, 2))
|
|
150
152
|
op2 = cirq.CNOT(*cirq.LineQid.range(2, dimension=2))
|
|
151
153
|
op.validate_args([cirq.LineQid(1, 2)]) # Valid
|
|
@@ -158,7 +160,7 @@ def test_op_validate():
|
|
|
158
160
|
op2.validate_args([cirq.LineQid(1, 2), cirq.LineQid(1, 2)])
|
|
159
161
|
|
|
160
162
|
|
|
161
|
-
def test_disable_op_validation():
|
|
163
|
+
def test_disable_op_validation() -> None:
|
|
162
164
|
q0, q1 = cirq.LineQubit.range(2)
|
|
163
165
|
h_op = cirq.H(q0)
|
|
164
166
|
|
|
@@ -181,7 +183,7 @@ def test_disable_op_validation():
|
|
|
181
183
|
h_op.validate_args([q0, q1])
|
|
182
184
|
|
|
183
185
|
|
|
184
|
-
def test_default_validation_and_inverse():
|
|
186
|
+
def test_default_validation_and_inverse() -> None:
|
|
185
187
|
class TestGate(cirq.Gate):
|
|
186
188
|
def _num_qubits_(self):
|
|
187
189
|
return 2
|
|
@@ -203,13 +205,15 @@ def test_default_validation_and_inverse():
|
|
|
203
205
|
with pytest.raises(ValueError, match='number of qubits'):
|
|
204
206
|
TestGate().on(a)
|
|
205
207
|
|
|
206
|
-
t = TestGate().on(a, b)
|
|
207
|
-
i = t**-1
|
|
208
|
+
t = cast(cirq.GateOperation, TestGate().on(a, b))
|
|
209
|
+
i = cast(cirq.GateOperation, t**-1)
|
|
208
210
|
assert i**-1 == t
|
|
209
211
|
assert t**-1 == i
|
|
210
212
|
assert cirq.decompose(i) == [cirq.X(a), cirq.S(b) ** -1, cirq.Z(a)]
|
|
211
|
-
assert [*i._decompose_()] == [cirq.X(a), cirq.S(b) ** -1, cirq.Z(a)]
|
|
212
|
-
|
|
213
|
+
assert [*i._decompose_()] == [cirq.X(a), cirq.S(b) ** -1, cirq.Z(a)] # type: ignore[misc]
|
|
214
|
+
gate = i.gate
|
|
215
|
+
assert gate is not None
|
|
216
|
+
assert [*gate._decompose_([a, b])] == [cirq.X(a), cirq.S(b) ** -1, cirq.Z(a)] # type: ignore
|
|
213
217
|
cirq.testing.assert_allclose_up_to_global_phase(
|
|
214
218
|
cirq.unitary(i), cirq.unitary(t).conj().T, atol=1e-8
|
|
215
219
|
)
|
|
@@ -217,7 +221,7 @@ def test_default_validation_and_inverse():
|
|
|
217
221
|
cirq.testing.assert_implements_consistent_protocols(i, local_vals={'TestGate': TestGate})
|
|
218
222
|
|
|
219
223
|
|
|
220
|
-
def test_default_no_qubits():
|
|
224
|
+
def test_default_no_qubits() -> None:
|
|
221
225
|
class TestOp(cirq.Operation):
|
|
222
226
|
def with_qubits(self, *new_qubits):
|
|
223
227
|
raise NotImplementedError()
|
|
@@ -228,11 +232,11 @@ def test_default_no_qubits():
|
|
|
228
232
|
|
|
229
233
|
op = TestOp()
|
|
230
234
|
assert op.controlled_by(*[]) is op
|
|
231
|
-
|
|
232
|
-
assert
|
|
235
|
+
tagged_op = TestOp().with_tags("abc")
|
|
236
|
+
assert tagged_op.classical_controls == frozenset()
|
|
233
237
|
|
|
234
238
|
|
|
235
|
-
def test_default_inverse():
|
|
239
|
+
def test_default_inverse() -> None:
|
|
236
240
|
class TestGate(cirq.Gate):
|
|
237
241
|
def _num_qubits_(self):
|
|
238
242
|
return 3
|
|
@@ -247,7 +251,7 @@ def test_default_inverse():
|
|
|
247
251
|
)
|
|
248
252
|
|
|
249
253
|
|
|
250
|
-
def test_no_inverse_if_not_unitary():
|
|
254
|
+
def test_no_inverse_if_not_unitary() -> None:
|
|
251
255
|
class TestGate(cirq.Gate):
|
|
252
256
|
def _num_qubits_(self):
|
|
253
257
|
return 1
|
|
@@ -258,7 +262,7 @@ def test_no_inverse_if_not_unitary():
|
|
|
258
262
|
assert cirq.inverse(TestGate(), None) is None
|
|
259
263
|
|
|
260
264
|
|
|
261
|
-
def test_default_qudit_inverse():
|
|
265
|
+
def test_default_qudit_inverse() -> None:
|
|
262
266
|
class TestGate(cirq.Gate):
|
|
263
267
|
def _qid_shape_(self):
|
|
264
268
|
return (1, 2, 3)
|
|
@@ -283,11 +287,11 @@ def test_default_qudit_inverse():
|
|
|
283
287
|
(-cirq.X * sympy.Symbol('s'), -sympy.Symbol('s') * cirq.X),
|
|
284
288
|
),
|
|
285
289
|
)
|
|
286
|
-
def test_gate_algebra(expression, expected_result):
|
|
290
|
+
def test_gate_algebra(expression, expected_result) -> None:
|
|
287
291
|
assert expression == expected_result
|
|
288
292
|
|
|
289
293
|
|
|
290
|
-
def test_gate_shape():
|
|
294
|
+
def test_gate_shape() -> None:
|
|
291
295
|
class ShapeGate(cirq.Gate):
|
|
292
296
|
def _qid_shape_(self):
|
|
293
297
|
return (1, 2, 3, 4)
|
|
@@ -316,7 +320,7 @@ def test_gate_shape():
|
|
|
316
320
|
assert dep_gate.num_qubits() == 3
|
|
317
321
|
|
|
318
322
|
|
|
319
|
-
def test_gate_shape_protocol():
|
|
323
|
+
def test_gate_shape_protocol() -> None:
|
|
320
324
|
"""This test is only needed while the `_num_qubits_` and `_qid_shape_`
|
|
321
325
|
methods are implemented as alternatives. This can be removed once the
|
|
322
326
|
deprecated `num_qubits` method is removed."""
|
|
@@ -376,7 +380,7 @@ def test_gate_shape_protocol():
|
|
|
376
380
|
assert QubitGate().num_qubits() == 2 # Deprecated
|
|
377
381
|
|
|
378
382
|
|
|
379
|
-
def test_operation_shape():
|
|
383
|
+
def test_operation_shape() -> None:
|
|
380
384
|
class FixedQids(cirq.Operation):
|
|
381
385
|
def with_qubits(self, *new_qids):
|
|
382
386
|
raise NotImplementedError
|
|
@@ -418,12 +422,12 @@ def test_operation_shape():
|
|
|
418
422
|
assert cirq.num_qubits(shape_op) == 4
|
|
419
423
|
|
|
420
424
|
|
|
421
|
-
def test_gate_json_dict():
|
|
425
|
+
def test_gate_json_dict() -> None:
|
|
422
426
|
g = cirq.CSWAP # not an eigen gate (which has its own _json_dict_)
|
|
423
427
|
assert g._json_dict_() == {}
|
|
424
428
|
|
|
425
429
|
|
|
426
|
-
def test_inverse_composite_diagram_info():
|
|
430
|
+
def test_inverse_composite_diagram_info() -> None:
|
|
427
431
|
class Gate(cirq.Gate):
|
|
428
432
|
def _decompose_(self, qubits):
|
|
429
433
|
return cirq.S.on(qubits[0])
|
|
@@ -450,7 +454,7 @@ def test_inverse_composite_diagram_info():
|
|
|
450
454
|
)
|
|
451
455
|
|
|
452
456
|
|
|
453
|
-
def test_tagged_operation_equality():
|
|
457
|
+
def test_tagged_operation_equality() -> None:
|
|
454
458
|
eq = cirq.testing.EqualsTester()
|
|
455
459
|
q1 = cirq.GridQubit(1, 1)
|
|
456
460
|
op = cirq.X(q1)
|
|
@@ -467,7 +471,7 @@ def test_tagged_operation_equality():
|
|
|
467
471
|
)
|
|
468
472
|
|
|
469
473
|
|
|
470
|
-
def test_tagged_operation():
|
|
474
|
+
def test_tagged_operation() -> None:
|
|
471
475
|
q1 = cirq.GridQubit(1, 1)
|
|
472
476
|
q2 = cirq.GridQubit(2, 2)
|
|
473
477
|
op = cirq.X(q1).with_tags('tag1')
|
|
@@ -488,7 +492,7 @@ def test_tagged_operation():
|
|
|
488
492
|
_ = cirq.X(q1).with_tags(cirq.Circuit)
|
|
489
493
|
|
|
490
494
|
|
|
491
|
-
def test_with_tags_returns_same_instance_if_possible():
|
|
495
|
+
def test_with_tags_returns_same_instance_if_possible() -> None:
|
|
492
496
|
untagged = cirq.X(cirq.GridQubit(1, 1))
|
|
493
497
|
assert untagged.with_tags() is untagged
|
|
494
498
|
|
|
@@ -496,7 +500,7 @@ def test_with_tags_returns_same_instance_if_possible():
|
|
|
496
500
|
assert tagged.with_tags() is tagged
|
|
497
501
|
|
|
498
502
|
|
|
499
|
-
def test_tagged_measurement():
|
|
503
|
+
def test_tagged_measurement() -> None:
|
|
500
504
|
assert not cirq.is_measurement(cirq.global_phase_operation(coefficient=-1.0).with_tags('tag0'))
|
|
501
505
|
|
|
502
506
|
a = cirq.LineQubit(0)
|
|
@@ -510,14 +514,14 @@ def test_tagged_measurement():
|
|
|
510
514
|
assert cirq.with_measurement_key_mapping(op, {'x': 'k'}) == op
|
|
511
515
|
|
|
512
516
|
|
|
513
|
-
def test_cannot_remap_non_measurement_gate():
|
|
517
|
+
def test_cannot_remap_non_measurement_gate() -> None:
|
|
514
518
|
a = cirq.LineQubit(0)
|
|
515
519
|
op = cirq.X(a).with_tags('tag')
|
|
516
520
|
|
|
517
521
|
assert cirq.with_measurement_key_mapping(op, {'m': 'k'}) is NotImplemented
|
|
518
522
|
|
|
519
523
|
|
|
520
|
-
def test_circuit_diagram():
|
|
524
|
+
def test_circuit_diagram() -> None:
|
|
521
525
|
class TaggyTag:
|
|
522
526
|
"""Tag with a custom str function to test circuit diagrams."""
|
|
523
527
|
|
|
@@ -535,7 +539,7 @@ def test_circuit_diagram():
|
|
|
535
539
|
exponent_qubit_index=None,
|
|
536
540
|
auto_exponent_parens=True,
|
|
537
541
|
)
|
|
538
|
-
args = cirq.CircuitDiagramInfoArgs(None, None,
|
|
542
|
+
args = cirq.CircuitDiagramInfoArgs(None, None, False, None, None, False)
|
|
539
543
|
assert cirq.circuit_diagram_info(tagged_h) == expected
|
|
540
544
|
assert cirq.circuit_diagram_info(tagged_h, args) == cirq.circuit_diagram_info(h)
|
|
541
545
|
|
|
@@ -550,9 +554,11 @@ def test_circuit_diagram():
|
|
|
550
554
|
diagram_with_non_string_tag = "(1, 1): ───H[<taggy>]───"
|
|
551
555
|
assert c.to_text_diagram() == diagram_with_non_string_tag
|
|
552
556
|
assert c.to_text_diagram(include_tags=False) == diagram_without_tags
|
|
557
|
+
assert c.to_text_diagram(include_tags={str}) == diagram_without_tags
|
|
558
|
+
assert c.to_text_diagram(include_tags={TaggyTag}) == diagram_with_non_string_tag
|
|
553
559
|
|
|
554
560
|
|
|
555
|
-
def test_circuit_diagram_tagged_global_phase():
|
|
561
|
+
def test_circuit_diagram_tagged_global_phase() -> None:
|
|
556
562
|
# Tests global phase operation
|
|
557
563
|
q = cirq.NamedQubit('a')
|
|
558
564
|
global_phase = cirq.global_phase_operation(coefficient=-1.0).with_tags('tag0')
|
|
@@ -580,8 +586,8 @@ def test_circuit_diagram_tagged_global_phase():
|
|
|
580
586
|
# Operation with no qubits and returns diagram info with no wire symbols
|
|
581
587
|
class NoWireSymbols(cirq.GlobalPhaseGate):
|
|
582
588
|
def _circuit_diagram_info_(
|
|
583
|
-
self, args:
|
|
584
|
-
) ->
|
|
589
|
+
self, args: cirq.CircuitDiagramInfoArgs
|
|
590
|
+
) -> cirq.CircuitDiagramInfo:
|
|
585
591
|
return expected
|
|
586
592
|
|
|
587
593
|
no_wire_symbol_op = NoWireSymbols(coefficient=-1.0)().with_tags('tag0')
|
|
@@ -619,7 +625,7 @@ global phase: 0.5π[tag1] 0.5π[tag2]
|
|
|
619
625
|
)
|
|
620
626
|
|
|
621
627
|
|
|
622
|
-
def test_circuit_diagram_no_circuit_diagram():
|
|
628
|
+
def test_circuit_diagram_no_circuit_diagram() -> None:
|
|
623
629
|
class NoCircuitDiagram(cirq.Gate):
|
|
624
630
|
def num_qubits(self) -> int:
|
|
625
631
|
return 1
|
|
@@ -634,7 +640,7 @@ def test_circuit_diagram_no_circuit_diagram():
|
|
|
634
640
|
assert cirq.Circuit(NoCircuitDiagram()(q).with_tags('taggy')).to_text_diagram() == expected
|
|
635
641
|
|
|
636
642
|
|
|
637
|
-
def test_tagged_operation_forwards_protocols():
|
|
643
|
+
def test_tagged_operation_forwards_protocols() -> None:
|
|
638
644
|
"""The results of all protocols applied to an operation with a tag should
|
|
639
645
|
be equivalent to the result without tags.
|
|
640
646
|
"""
|
|
@@ -647,7 +653,7 @@ def test_tagged_operation_forwards_protocols():
|
|
|
647
653
|
np.testing.assert_equal(cirq.unitary(tagged_h), cirq.unitary(h))
|
|
648
654
|
assert cirq.has_unitary(tagged_h)
|
|
649
655
|
assert cirq.decompose(tagged_h) == cirq.decompose(h)
|
|
650
|
-
assert [*tagged_h._decompose_()] == cirq.
|
|
656
|
+
assert [*tagged_h._decompose_()] == cirq.decompose_once(h)
|
|
651
657
|
assert cirq.pauli_expansion(tagged_h) == cirq.pauli_expansion(h)
|
|
652
658
|
assert cirq.equal_up_to_global_phase(h, tagged_h)
|
|
653
659
|
assert np.isclose(cirq.kraus(h), cirq.kraus(tagged_h)).all()
|
|
@@ -716,7 +722,7 @@ def test_tagged_operation_forwards_protocols():
|
|
|
716
722
|
assert tagged_mixture[1][0] == flip_mixture[1][0]
|
|
717
723
|
assert np.isclose(tagged_mixture[1][1], flip_mixture[1][1]).all()
|
|
718
724
|
|
|
719
|
-
qubit_map = {q1: 'q1'}
|
|
725
|
+
qubit_map: dict[cirq.Qid, str] = {q1: 'q1'}
|
|
720
726
|
qasm_args = cirq.QasmArgs(qubit_id_map=qubit_map)
|
|
721
727
|
assert cirq.qasm(h, args=qasm_args) == cirq.qasm(tagged_h, args=qasm_args)
|
|
722
728
|
|
|
@@ -737,13 +743,13 @@ class ParameterizableTag:
|
|
|
737
743
|
return cirq.parameter_names(self.value)
|
|
738
744
|
|
|
739
745
|
def _resolve_parameters_(
|
|
740
|
-
self, resolver:
|
|
741
|
-
) ->
|
|
746
|
+
self, resolver: cirq.ParamResolver, recursive: bool
|
|
747
|
+
) -> ParameterizableTag:
|
|
742
748
|
return ParameterizableTag(cirq.resolve_parameters(self.value, resolver, recursive))
|
|
743
749
|
|
|
744
750
|
|
|
745
751
|
@pytest.mark.parametrize('resolve_fn', [cirq.resolve_parameters, cirq.resolve_parameters_once])
|
|
746
|
-
def test_tagged_operation_resolves_parameterized_tags(resolve_fn):
|
|
752
|
+
def test_tagged_operation_resolves_parameterized_tags(resolve_fn) -> None:
|
|
747
753
|
q = cirq.GridQubit(0, 0)
|
|
748
754
|
tag = ParameterizableTag(sympy.Symbol('t'))
|
|
749
755
|
assert cirq.is_parameterized(tag)
|
|
@@ -757,10 +763,10 @@ def test_tagged_operation_resolves_parameterized_tags(resolve_fn):
|
|
|
757
763
|
assert cirq.parameter_names(resolved_op) == set()
|
|
758
764
|
|
|
759
765
|
|
|
760
|
-
def test_inverse_composite_standards():
|
|
766
|
+
def test_inverse_composite_standards() -> None:
|
|
761
767
|
@cirq.value_equality
|
|
762
768
|
class Gate(cirq.Gate):
|
|
763
|
-
def __init__(self, param:
|
|
769
|
+
def __init__(self, param: cirq.TParamVal):
|
|
764
770
|
self._param = param
|
|
765
771
|
|
|
766
772
|
def _decompose_(self, qubits):
|
|
@@ -781,7 +787,7 @@ def test_inverse_composite_standards():
|
|
|
781
787
|
def _is_parameterized_(self) -> bool:
|
|
782
788
|
return cirq.is_parameterized(self._param)
|
|
783
789
|
|
|
784
|
-
def _resolve_parameters_(self, resolver:
|
|
790
|
+
def _resolve_parameters_(self, resolver: cirq.ParamResolver, recursive: bool) -> Gate:
|
|
785
791
|
return Gate(cirq.resolve_parameters(self._param, resolver, recursive))
|
|
786
792
|
|
|
787
793
|
def __repr__(self):
|
|
@@ -796,7 +802,7 @@ def test_inverse_composite_standards():
|
|
|
796
802
|
assert str(g) == 'C(a)†'
|
|
797
803
|
|
|
798
804
|
|
|
799
|
-
def test_tagged_act_on():
|
|
805
|
+
def test_tagged_act_on() -> None:
|
|
800
806
|
class YesActOn(cirq.Gate):
|
|
801
807
|
def _num_qubits_(self) -> int:
|
|
802
808
|
return 1
|
|
@@ -830,7 +836,7 @@ def test_tagged_act_on():
|
|
|
830
836
|
cirq.act_on(MissingActOn().with_tags("test"), args)
|
|
831
837
|
|
|
832
838
|
|
|
833
|
-
def test_single_qubit_gate_validates_on_each():
|
|
839
|
+
def test_single_qubit_gate_validates_on_each() -> None:
|
|
834
840
|
class Example(cirq.testing.SingleQubitGate):
|
|
835
841
|
def matrix(self):
|
|
836
842
|
pass
|
|
@@ -854,7 +860,7 @@ def test_single_qubit_gate_validates_on_each():
|
|
|
854
860
|
_ = g.on_each(*test_non_qubits)
|
|
855
861
|
|
|
856
862
|
|
|
857
|
-
def test_on_each():
|
|
863
|
+
def test_on_each() -> None:
|
|
858
864
|
class CustomGate(cirq.testing.SingleQubitGate):
|
|
859
865
|
pass
|
|
860
866
|
|
|
@@ -885,7 +891,7 @@ def test_on_each():
|
|
|
885
891
|
assert c.on_each(qubit_iterator) == [c(a), c(b), c(a), c(b)]
|
|
886
892
|
|
|
887
893
|
|
|
888
|
-
def test_on_each_two_qubits():
|
|
894
|
+
def test_on_each_two_qubits() -> None:
|
|
889
895
|
a = cirq.NamedQubit('a')
|
|
890
896
|
b = cirq.NamedQubit('b')
|
|
891
897
|
g = cirq.testing.TwoQubitGate()
|
|
@@ -940,7 +946,7 @@ def test_on_each_two_qubits():
|
|
|
940
946
|
assert g.on_each(qubit_iterator) == [g(a, b), g(a, b)]
|
|
941
947
|
|
|
942
948
|
|
|
943
|
-
def test_on_each_three_qubits():
|
|
949
|
+
def test_on_each_three_qubits() -> None:
|
|
944
950
|
a = cirq.NamedQubit('a')
|
|
945
951
|
b = cirq.NamedQubit('b')
|
|
946
952
|
c = cirq.NamedQubit('c')
|
|
@@ -990,7 +996,7 @@ def test_on_each_three_qubits():
|
|
|
990
996
|
assert g.on_each(qubit_iterator) == [g(a, b, c), g(a, b, c)]
|
|
991
997
|
|
|
992
998
|
|
|
993
|
-
def test_on_each_iterable_qid():
|
|
999
|
+
def test_on_each_iterable_qid() -> None:
|
|
994
1000
|
class QidIter(cirq.Qid):
|
|
995
1001
|
@property
|
|
996
1002
|
def dimension(self) -> int:
|
|
@@ -1008,7 +1014,7 @@ def test_on_each_iterable_qid():
|
|
|
1008
1014
|
@pytest.mark.parametrize(
|
|
1009
1015
|
'op', [cirq.X(cirq.NamedQubit("q")), cirq.X(cirq.NamedQubit("q")).with_tags("tagged_op")]
|
|
1010
1016
|
)
|
|
1011
|
-
def test_with_methods_return_self_on_empty_conditions(op):
|
|
1017
|
+
def test_with_methods_return_self_on_empty_conditions(op) -> None:
|
|
1012
1018
|
assert op is op.with_tags(*[])
|
|
1013
1019
|
assert op is op.with_classical_controls(*[])
|
|
1014
1020
|
assert op is op.controlled_by(*[])
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
|
|
15
15
|
"""Quantum gates to prepare a given target state."""
|
|
16
16
|
|
|
17
|
-
from
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from typing import Any, Iterable, TYPE_CHECKING
|
|
18
20
|
|
|
19
21
|
import numpy as np
|
|
20
22
|
|
|
@@ -57,14 +59,14 @@ class StatePreparationChannel(raw_types.Gate):
|
|
|
57
59
|
it involves measurement."""
|
|
58
60
|
return False
|
|
59
61
|
|
|
60
|
-
def _json_dict_(self) ->
|
|
62
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
61
63
|
"""Converts the gate object into a serializable dictionary"""
|
|
62
64
|
return {'target_state': self._state.tolist(), 'name': self._name}
|
|
63
65
|
|
|
64
66
|
@classmethod
|
|
65
67
|
def _from_json_dict_(
|
|
66
68
|
cls, target_state: np.ndarray, name: str, **kwargs
|
|
67
|
-
) ->
|
|
69
|
+
) -> StatePreparationChannel:
|
|
68
70
|
"""Recreates the channel object from it's serialized form
|
|
69
71
|
|
|
70
72
|
Args:
|
|
@@ -77,12 +79,10 @@ class StatePreparationChannel(raw_types.Gate):
|
|
|
77
79
|
def _num_qubits_(self) -> int:
|
|
78
80
|
return self._num_qubits
|
|
79
81
|
|
|
80
|
-
def _qid_shape_(self) ->
|
|
82
|
+
def _qid_shape_(self) -> tuple[int, ...]:
|
|
81
83
|
return self._qid_shape
|
|
82
84
|
|
|
83
|
-
def _circuit_diagram_info_(
|
|
84
|
-
self, _args: 'cirq.CircuitDiagramInfoArgs'
|
|
85
|
-
) -> 'cirq.CircuitDiagramInfo':
|
|
85
|
+
def _circuit_diagram_info_(self, _args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
86
86
|
"""Returns the information required to draw out the circuit diagram for this channel."""
|
|
87
87
|
symbols = (
|
|
88
88
|
[self._name]
|
|
@@ -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
|
|
|
@@ -36,7 +38,7 @@ import cirq
|
|
|
36
38
|
]
|
|
37
39
|
),
|
|
38
40
|
)
|
|
39
|
-
def test_state_prep_channel_kraus(state):
|
|
41
|
+
def test_state_prep_channel_kraus(state) -> None:
|
|
40
42
|
qubits = cirq.LineQubit.range(2)
|
|
41
43
|
gate = cirq.StatePreparationChannel(state)(qubits[0], qubits[1])
|
|
42
44
|
cirq.testing.assert_consistent_channel(gate)
|
|
@@ -53,7 +55,7 @@ def test_state_prep_channel_kraus(state):
|
|
|
53
55
|
)
|
|
54
56
|
|
|
55
57
|
|
|
56
|
-
def test_state_prep_channel_kraus_small():
|
|
58
|
+
def test_state_prep_channel_kraus_small() -> None:
|
|
57
59
|
gate = cirq.StatePreparationChannel(np.array([0.0, 1.0]))(cirq.LineQubit(0))
|
|
58
60
|
np.testing.assert_almost_equal(
|
|
59
61
|
cirq.kraus(gate), (np.array([[0.0, 0.0], [1.0, 0.0]]), np.array([[0.0, 0.0], [0.0, 1.0]]))
|
|
@@ -69,7 +71,7 @@ def test_state_prep_channel_kraus_small():
|
|
|
69
71
|
assert not cirq.has_mixture(gate)
|
|
70
72
|
|
|
71
73
|
|
|
72
|
-
def test_state_prep_gate_printing():
|
|
74
|
+
def test_state_prep_gate_printing() -> None:
|
|
73
75
|
circuit = cirq.Circuit()
|
|
74
76
|
qubits = cirq.LineQubit.range(2)
|
|
75
77
|
gate = cirq.StatePreparationChannel(np.array([1, 0, 0, 1]) / np.sqrt(2))
|
|
@@ -87,7 +89,7 @@ def test_state_prep_gate_printing():
|
|
|
87
89
|
|
|
88
90
|
|
|
89
91
|
@pytest.mark.parametrize('name', ['Prep', 'S'])
|
|
90
|
-
def test_state_prep_gate_printing_with_name(name):
|
|
92
|
+
def test_state_prep_gate_printing_with_name(name) -> None:
|
|
91
93
|
circuit = cirq.Circuit()
|
|
92
94
|
qubits = cirq.LineQubit.range(2)
|
|
93
95
|
gate = cirq.StatePreparationChannel(np.array([1, 0, 0, 1]) / np.sqrt(2), name=name)
|
|
@@ -104,7 +106,7 @@ def test_state_prep_gate_printing_with_name(name):
|
|
|
104
106
|
)
|
|
105
107
|
|
|
106
108
|
|
|
107
|
-
def test_gate_params():
|
|
109
|
+
def test_gate_params() -> None:
|
|
108
110
|
state = np.array([1, 0, 0, 0], dtype=np.complex64)
|
|
109
111
|
gate = cirq.StatePreparationChannel(state)
|
|
110
112
|
assert gate.num_qubits() == 2
|
|
@@ -114,19 +116,19 @@ def test_gate_params():
|
|
|
114
116
|
cirq.testing.assert_equivalent_repr(gate)
|
|
115
117
|
|
|
116
118
|
|
|
117
|
-
def test_gate_error_handling():
|
|
119
|
+
def test_gate_error_handling() -> None:
|
|
118
120
|
with pytest.raises(ValueError, match='`target_state` must be a 1d numpy array.'):
|
|
119
121
|
cirq.StatePreparationChannel(np.eye(2))
|
|
120
122
|
with pytest.raises(ValueError, match='Matrix width \\(5\\) is not a power of 2'):
|
|
121
123
|
cirq.StatePreparationChannel(np.ones(shape=5))
|
|
122
124
|
|
|
123
125
|
|
|
124
|
-
def test_equality_of_gates():
|
|
126
|
+
def test_equality_of_gates() -> None:
|
|
125
127
|
state = np.array([1, 0, 0, 0], dtype=np.complex64)
|
|
126
128
|
gate_1 = cirq.StatePreparationChannel(state)
|
|
127
129
|
gate_2 = cirq.StatePreparationChannel(state)
|
|
128
130
|
assert gate_1 == gate_2, "Equal state not leading to same gate"
|
|
129
|
-
assert not gate_1 == state, "Incompatible objects shouldn't be equal"
|
|
131
|
+
assert not gate_1 == state, "Incompatible objects shouldn't be equal" # noqa: SIM201
|
|
130
132
|
state = np.array([0, 1, 0, 0], dtype=np.complex64)
|
|
131
133
|
gate_3 = cirq.StatePreparationChannel(state, name='gate_a')
|
|
132
134
|
gate_4 = cirq.StatePreparationChannel(state, name='gate_b')
|
|
@@ -134,7 +136,7 @@ def test_equality_of_gates():
|
|
|
134
136
|
assert gate_1 != gate_3, "Different states shouldn't lead to same gate"
|
|
135
137
|
|
|
136
138
|
|
|
137
|
-
def test_approx_equality_of_gates():
|
|
139
|
+
def test_approx_equality_of_gates() -> None:
|
|
138
140
|
state = np.array([1, 0, 0, 0], dtype=np.complex64)
|
|
139
141
|
gate_1 = cirq.StatePreparationChannel(state)
|
|
140
142
|
gate_2 = cirq.StatePreparationChannel(state)
|
cirq/ops/swap_gates.py
CHANGED
|
@@ -25,7 +25,9 @@ raised to a power (i.e. SQRT_ISWAP_INV=cirq.ISWAP**-0.5). See the definition in
|
|
|
25
25
|
EigenGate.
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
|
-
from
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
from typing import cast, TYPE_CHECKING
|
|
29
31
|
|
|
30
32
|
import numpy as np
|
|
31
33
|
import sympy
|
|
@@ -81,7 +83,7 @@ class SwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate)
|
|
|
81
83
|
)
|
|
82
84
|
yield common_gates.CNOT(a, b)
|
|
83
85
|
|
|
84
|
-
def _eigen_components(self) ->
|
|
86
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
85
87
|
# yapf: disable
|
|
86
88
|
return [
|
|
87
89
|
(0, np.array([[1, 0, 0, 0],
|
|
@@ -95,17 +97,17 @@ class SwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate)
|
|
|
95
97
|
]
|
|
96
98
|
# yapf: enable
|
|
97
99
|
|
|
98
|
-
def _trace_distance_bound_(self) ->
|
|
100
|
+
def _trace_distance_bound_(self) -> float | None:
|
|
99
101
|
if self._is_parameterized_():
|
|
100
102
|
return None
|
|
101
103
|
return abs(np.sin(self._exponent * 0.5 * np.pi))
|
|
102
104
|
|
|
103
|
-
def _has_stabilizer_effect_(self) ->
|
|
105
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
104
106
|
if self._is_parameterized_():
|
|
105
107
|
return None
|
|
106
108
|
return self.exponent % 1 == 0
|
|
107
109
|
|
|
108
|
-
def _apply_unitary_(self, args:
|
|
110
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
109
111
|
if self._exponent != 1:
|
|
110
112
|
return NotImplemented
|
|
111
113
|
|
|
@@ -134,9 +136,7 @@ class SwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate)
|
|
|
134
136
|
}
|
|
135
137
|
)
|
|
136
138
|
|
|
137
|
-
def _circuit_diagram_info_(
|
|
138
|
-
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
139
|
-
) -> 'cirq.CircuitDiagramInfo':
|
|
139
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
140
140
|
if not args.use_unicode_characters:
|
|
141
141
|
return protocols.CircuitDiagramInfo(
|
|
142
142
|
wire_symbols=('Swap', 'Swap'), exponent=self._diagram_exponent(args)
|
|
@@ -145,7 +145,7 @@ class SwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate)
|
|
|
145
145
|
wire_symbols=('×', '×'), exponent=self._diagram_exponent(args)
|
|
146
146
|
)
|
|
147
147
|
|
|
148
|
-
def _qasm_(self, args:
|
|
148
|
+
def _qasm_(self, args: cirq.QasmArgs, qubits: tuple[cirq.Qid, ...]) -> str | None:
|
|
149
149
|
if self._exponent != 1:
|
|
150
150
|
return None # Don't have an equivalent gate in QASM
|
|
151
151
|
args.validate_version('2.0', '3.0')
|
|
@@ -204,7 +204,7 @@ class ISwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate
|
|
|
204
204
|
def _num_qubits_(self) -> int:
|
|
205
205
|
return 2
|
|
206
206
|
|
|
207
|
-
def _eigen_components(self) ->
|
|
207
|
+
def _eigen_components(self) -> list[tuple[float, np.ndarray]]:
|
|
208
208
|
# yapf: disable
|
|
209
209
|
return [
|
|
210
210
|
(0, np.diag([1, 0, 0, 1])),
|
|
@@ -219,7 +219,7 @@ class ISwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate
|
|
|
219
219
|
]
|
|
220
220
|
# yapf: enable
|
|
221
221
|
|
|
222
|
-
def _has_stabilizer_effect_(self) ->
|
|
222
|
+
def _has_stabilizer_effect_(self) -> bool | None:
|
|
223
223
|
if self._is_parameterized_():
|
|
224
224
|
return None
|
|
225
225
|
return self.exponent % 1 == 0
|
|
@@ -240,7 +240,7 @@ class ISwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate
|
|
|
240
240
|
yield common_gates.H(a)
|
|
241
241
|
yield common_gates.CNOT(a, b)
|
|
242
242
|
|
|
243
|
-
def _apply_unitary_(self, args:
|
|
243
|
+
def _apply_unitary_(self, args: protocols.ApplyUnitaryArgs) -> np.ndarray | None:
|
|
244
244
|
if self._exponent != 1:
|
|
245
245
|
return NotImplemented
|
|
246
246
|
|
|
@@ -271,9 +271,7 @@ class ISwapPowGate(gate_features.InterchangeableQubitsGate, eigen_gate.EigenGate
|
|
|
271
271
|
}
|
|
272
272
|
)
|
|
273
273
|
|
|
274
|
-
def _circuit_diagram_info_(
|
|
275
|
-
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
276
|
-
) -> 'cirq.CircuitDiagramInfo':
|
|
274
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
277
275
|
return protocols.CircuitDiagramInfo(
|
|
278
276
|
wire_symbols=('iSwap', 'iSwap'), exponent=self._diagram_exponent(args)
|
|
279
277
|
)
|