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
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import cast,
|
|
17
|
+
from typing import cast, Sequence, TYPE_CHECKING
|
|
18
18
|
|
|
19
19
|
from cirq import circuits
|
|
20
20
|
from cirq.contrib.acquaintance.executor import AcquaintanceOperation
|
|
@@ -36,11 +36,11 @@ def remove_redundant_acquaintance_opportunities(strategy: cirq.Circuit) -> int:
|
|
|
36
36
|
annotated_strategy = strategy.copy()
|
|
37
37
|
LogicalAnnotator(mapping)(annotated_strategy)
|
|
38
38
|
|
|
39
|
-
new_moments:
|
|
40
|
-
acquaintance_opps:
|
|
39
|
+
new_moments: list[cirq.Moment] = []
|
|
40
|
+
acquaintance_opps: set[frozenset[int]] = set()
|
|
41
41
|
n_removed = 0
|
|
42
42
|
for moment in annotated_strategy:
|
|
43
|
-
new_moment:
|
|
43
|
+
new_moment: list[cirq.Operation] = []
|
|
44
44
|
for op in moment:
|
|
45
45
|
if isinstance(op, AcquaintanceOperation):
|
|
46
46
|
opp = frozenset(cast(Sequence[int], op.logical_indices))
|
|
@@ -11,12 +11,15 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
import cirq
|
|
15
18
|
import cirq.contrib.acquaintance as cca
|
|
16
19
|
import cirq.testing as ct
|
|
17
20
|
|
|
18
21
|
|
|
19
|
-
def test_remove_redundant_acquaintance_opportunities():
|
|
22
|
+
def test_remove_redundant_acquaintance_opportunities() -> None:
|
|
20
23
|
a, b, c, d, e = cirq.LineQubit.range(5)
|
|
21
24
|
swap = cca.SwapPermutationGate()
|
|
22
25
|
|
|
@@ -16,19 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import abc
|
|
18
18
|
from types import NotImplementedType
|
|
19
|
-
from typing import
|
|
20
|
-
Any,
|
|
21
|
-
cast,
|
|
22
|
-
Dict,
|
|
23
|
-
Iterable,
|
|
24
|
-
Iterator,
|
|
25
|
-
Optional,
|
|
26
|
-
Sequence,
|
|
27
|
-
Tuple,
|
|
28
|
-
TYPE_CHECKING,
|
|
29
|
-
TypeVar,
|
|
30
|
-
Union,
|
|
31
|
-
)
|
|
19
|
+
from typing import Any, cast, Iterable, Iterator, Sequence, TYPE_CHECKING, TypeVar
|
|
32
20
|
|
|
33
21
|
from cirq import circuits, ops, protocols, transformers, value
|
|
34
22
|
|
|
@@ -37,10 +25,10 @@ if TYPE_CHECKING:
|
|
|
37
25
|
|
|
38
26
|
|
|
39
27
|
LogicalIndex = TypeVar('LogicalIndex', int, ops.Qid)
|
|
40
|
-
LogicalIndexSequence =
|
|
41
|
-
LogicalGates =
|
|
28
|
+
LogicalIndexSequence = Sequence[int] | Sequence['cirq.Qid']
|
|
29
|
+
LogicalGates = dict[tuple[LogicalIndex, ...], ops.Gate]
|
|
42
30
|
LogicalMappingKey = TypeVar('LogicalMappingKey', bound=ops.Qid)
|
|
43
|
-
LogicalMapping =
|
|
31
|
+
LogicalMapping = dict[LogicalMappingKey, LogicalIndex]
|
|
44
32
|
|
|
45
33
|
|
|
46
34
|
class PermutationGate(ops.Gate, metaclass=abc.ABCMeta):
|
|
@@ -61,12 +49,12 @@ class PermutationGate(ops.Gate, metaclass=abc.ABCMeta):
|
|
|
61
49
|
return self._num_qubits
|
|
62
50
|
|
|
63
51
|
@abc.abstractmethod
|
|
64
|
-
def permutation(self) ->
|
|
52
|
+
def permutation(self) -> dict[int, int]:
|
|
65
53
|
"""permutation = {i: s[i]} indicates that the i-th element is mapped to
|
|
66
54
|
the s[i]-th element."""
|
|
67
55
|
|
|
68
56
|
def update_mapping(
|
|
69
|
-
self, mapping:
|
|
57
|
+
self, mapping: dict[ops.Qid, LogicalIndex], keys: Sequence[cirq.Qid]
|
|
70
58
|
) -> None:
|
|
71
59
|
"""Updates a mapping (in place) from qubits to logical indices.
|
|
72
60
|
|
|
@@ -86,7 +74,7 @@ class PermutationGate(ops.Gate, metaclass=abc.ABCMeta):
|
|
|
86
74
|
mapping[new_key] = old_element
|
|
87
75
|
|
|
88
76
|
@staticmethod
|
|
89
|
-
def validate_permutation(permutation:
|
|
77
|
+
def validate_permutation(permutation: dict[int, int], n_elements: int | None = None) -> None:
|
|
90
78
|
if not permutation:
|
|
91
79
|
return
|
|
92
80
|
if set(permutation.values()) != set(permutation):
|
|
@@ -99,7 +87,7 @@ class PermutationGate(ops.Gate, metaclass=abc.ABCMeta):
|
|
|
99
87
|
|
|
100
88
|
def _circuit_diagram_info_(
|
|
101
89
|
self, args: cirq.CircuitDiagramInfoArgs
|
|
102
|
-
) ->
|
|
90
|
+
) -> str | Iterable[str] | cirq.CircuitDiagramInfo:
|
|
103
91
|
if args.known_qubit_count is None:
|
|
104
92
|
return NotImplemented
|
|
105
93
|
permutation = self.permutation()
|
|
@@ -150,7 +138,7 @@ class SwapPermutationGate(PermutationGate):
|
|
|
150
138
|
def __init__(self, swap_gate: cirq.Gate = ops.SWAP):
|
|
151
139
|
super().__init__(2, swap_gate)
|
|
152
140
|
|
|
153
|
-
def permutation(self) ->
|
|
141
|
+
def permutation(self) -> dict[int, int]:
|
|
154
142
|
return {0: 1, 1: 0}
|
|
155
143
|
|
|
156
144
|
def _decompose_(self, qubits: Sequence[cirq.Qid]) -> Iterator[cirq.OP_TREE]:
|
|
@@ -166,7 +154,7 @@ class SwapPermutationGate(PermutationGate):
|
|
|
166
154
|
def _value_equality_values_(self) -> Any:
|
|
167
155
|
return (self.swap_gate,)
|
|
168
156
|
|
|
169
|
-
def _commutes_(self, other: Any, *, atol: float = 1e-8) ->
|
|
157
|
+
def _commutes_(self, other: Any, *, atol: float = 1e-8) -> bool | NotImplementedType:
|
|
170
158
|
if (
|
|
171
159
|
isinstance(other, ops.Gate)
|
|
172
160
|
and isinstance(other, ops.InterchangeableQubitsGate)
|
|
@@ -176,7 +164,7 @@ class SwapPermutationGate(PermutationGate):
|
|
|
176
164
|
return NotImplemented
|
|
177
165
|
|
|
178
166
|
|
|
179
|
-
def _canonicalize_permutation(permutation:
|
|
167
|
+
def _canonicalize_permutation(permutation: dict[int, int]) -> dict[int, int]:
|
|
180
168
|
return {i: j for i, j in permutation.items() if i != j}
|
|
181
169
|
|
|
182
170
|
|
|
@@ -186,7 +174,7 @@ class LinearPermutationGate(PermutationGate):
|
|
|
186
174
|
sorting network."""
|
|
187
175
|
|
|
188
176
|
def __init__(
|
|
189
|
-
self, num_qubits: int, permutation:
|
|
177
|
+
self, num_qubits: int, permutation: dict[int, int], swap_gate: cirq.Gate = ops.SWAP
|
|
190
178
|
) -> None:
|
|
191
179
|
"""Initializes a linear permutation gate.
|
|
192
180
|
|
|
@@ -199,7 +187,7 @@ class LinearPermutationGate(PermutationGate):
|
|
|
199
187
|
PermutationGate.validate_permutation(permutation, num_qubits)
|
|
200
188
|
self._permutation = permutation
|
|
201
189
|
|
|
202
|
-
def permutation(self) ->
|
|
190
|
+
def permutation(self) -> dict[int, int]:
|
|
203
191
|
return self._permutation
|
|
204
192
|
|
|
205
193
|
def _decompose_(self, qubits: Sequence[cirq.Qid]) -> Iterator[cirq.OP_TREE]:
|
|
@@ -238,7 +226,7 @@ class LinearPermutationGate(PermutationGate):
|
|
|
238
226
|
return NotImplemented
|
|
239
227
|
|
|
240
228
|
|
|
241
|
-
def update_mapping(mapping:
|
|
229
|
+
def update_mapping(mapping: dict[ops.Qid, LogicalIndex], operations: cirq.OP_TREE) -> None:
|
|
242
230
|
"""Updates a mapping (in place) from qubits to logical indices according to
|
|
243
231
|
a set of permutation gates. Any gates other than permutation gates are
|
|
244
232
|
ignored.
|
|
@@ -253,7 +241,7 @@ def update_mapping(mapping: Dict[ops.Qid, LogicalIndex], operations: cirq.OP_TRE
|
|
|
253
241
|
|
|
254
242
|
|
|
255
243
|
def get_logical_operations(
|
|
256
|
-
operations: cirq.OP_TREE, initial_mapping:
|
|
244
|
+
operations: cirq.OP_TREE, initial_mapping: dict[ops.Qid, ops.Qid]
|
|
257
245
|
) -> Iterable[cirq.Operation]:
|
|
258
246
|
"""Gets the logical operations specified by the physical operations and
|
|
259
247
|
initial mapping.
|
|
@@ -12,7 +12,10 @@
|
|
|
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 random
|
|
18
|
+
from typing import Iterator
|
|
16
19
|
|
|
17
20
|
import pytest
|
|
18
21
|
|
|
@@ -21,7 +24,7 @@ import cirq.contrib.acquaintance as cca
|
|
|
21
24
|
import cirq.testing as ct
|
|
22
25
|
|
|
23
26
|
|
|
24
|
-
def test_swap_permutation_gate():
|
|
27
|
+
def test_swap_permutation_gate() -> None:
|
|
25
28
|
no_decomp = lambda op: (isinstance(op, cirq.GateOperation) and op.gate == cirq.SWAP)
|
|
26
29
|
a, b = cirq.NamedQubit('a'), cirq.NamedQubit('b')
|
|
27
30
|
gate = cca.SwapPermutationGate()
|
|
@@ -40,7 +43,7 @@ def test_swap_permutation_gate():
|
|
|
40
43
|
cirq.commutes(gate, cirq.CCZ)
|
|
41
44
|
|
|
42
45
|
|
|
43
|
-
def test_validate_permutation_errors():
|
|
46
|
+
def test_validate_permutation_errors() -> None:
|
|
44
47
|
validate_permutation = cca.PermutationGate.validate_permutation
|
|
45
48
|
validate_permutation({})
|
|
46
49
|
|
|
@@ -57,7 +60,7 @@ def test_validate_permutation_errors():
|
|
|
57
60
|
assert cirq.circuit_diagram_info(gate, default=None) is None
|
|
58
61
|
|
|
59
62
|
|
|
60
|
-
def test_diagram():
|
|
63
|
+
def test_diagram() -> None:
|
|
61
64
|
gate = cca.SwapPermutationGate()
|
|
62
65
|
a, b = cirq.NamedQubit('a'), cirq.NamedQubit('b')
|
|
63
66
|
circuit = cirq.Circuit([gate(a, b)])
|
|
@@ -70,17 +73,19 @@ b: ───1↦0───
|
|
|
70
73
|
assert actual_text_diagram == expected_text_diagram
|
|
71
74
|
|
|
72
75
|
|
|
73
|
-
def test_update_mapping():
|
|
76
|
+
def test_update_mapping() -> None:
|
|
74
77
|
gate = cca.SwapPermutationGate()
|
|
75
78
|
a, b, c = (cirq.NamedQubit(s) for s in 'abc')
|
|
79
|
+
mapping: dict[cirq.Qid, int]
|
|
76
80
|
mapping = {s: i for i, s in enumerate((a, b, c))}
|
|
77
81
|
ops = [gate(a, b), gate(b, c)]
|
|
78
82
|
cca.update_mapping(mapping, ops)
|
|
79
83
|
assert mapping == {a: 1, b: 2, c: 0}
|
|
80
84
|
|
|
81
85
|
|
|
82
|
-
def test_get_logical_operations():
|
|
86
|
+
def test_get_logical_operations() -> None:
|
|
83
87
|
a, b, c, d = qubits = cirq.LineQubit.range(4)
|
|
88
|
+
mapping: dict[cirq.Qid, cirq.Qid]
|
|
84
89
|
mapping = dict(zip(qubits, qubits))
|
|
85
90
|
operations = [
|
|
86
91
|
cirq.ZZ(a, b),
|
|
@@ -104,7 +109,7 @@ def test_get_logical_operations():
|
|
|
104
109
|
for n_elements in (random.randint(5, 20) for _ in range(20))
|
|
105
110
|
),
|
|
106
111
|
)
|
|
107
|
-
def test_linear_permutation_gate(n_elements, n_permuted):
|
|
112
|
+
def test_linear_permutation_gate(n_elements, n_permuted) -> None:
|
|
108
113
|
qubits = cirq.LineQubit.range(n_elements)
|
|
109
114
|
elements = tuple(range(n_elements))
|
|
110
115
|
elements_to_permute = random.sample(elements, n_permuted)
|
|
@@ -114,16 +119,18 @@ def test_linear_permutation_gate(n_elements, n_permuted):
|
|
|
114
119
|
gate = cca.LinearPermutationGate(n_elements, permutation)
|
|
115
120
|
ct.assert_equivalent_repr(gate)
|
|
116
121
|
assert gate.permutation() == permutation
|
|
122
|
+
mapping: dict[cirq.Qid, int]
|
|
117
123
|
mapping = dict(zip(qubits, elements))
|
|
118
124
|
for swap in cirq.flatten_op_tree(cirq.decompose_once_with_qubits(gate, qubits)):
|
|
119
125
|
assert isinstance(swap, cirq.GateOperation)
|
|
126
|
+
assert isinstance(swap.gate, cca.PermutationGate)
|
|
120
127
|
swap.gate.update_mapping(mapping, swap.qubits)
|
|
121
128
|
for i in range(n_elements):
|
|
122
129
|
p = permutation.get(elements[i], i)
|
|
123
130
|
assert mapping.get(qubits[p], elements[i]) == i
|
|
124
131
|
|
|
125
132
|
|
|
126
|
-
def random_equal_permutations(n_perms, n_items, prob):
|
|
133
|
+
def random_equal_permutations(n_perms, n_items, prob) -> list[dict[int, int]]:
|
|
127
134
|
indices_to_permute = [i for i in range(n_items) if random.random() <= prob]
|
|
128
135
|
permuted_indices = random.sample(indices_to_permute, len(indices_to_permute))
|
|
129
136
|
base_permutation = dict(zip(indices_to_permute, permuted_indices))
|
|
@@ -136,7 +143,9 @@ def random_equal_permutations(n_perms, n_items, prob):
|
|
|
136
143
|
return permutations
|
|
137
144
|
|
|
138
145
|
|
|
139
|
-
def random_permutation_equality_groups(
|
|
146
|
+
def random_permutation_equality_groups(
|
|
147
|
+
n_groups, n_perms_per_group, n_items, prob
|
|
148
|
+
) -> Iterator[list[dict[int, int]]]:
|
|
140
149
|
fingerprints = set()
|
|
141
150
|
for _ in range(n_groups):
|
|
142
151
|
perms = random_equal_permutations(n_perms_per_group, n_items, prob)
|
|
@@ -148,7 +157,7 @@ def random_permutation_equality_groups(n_groups, n_perms_per_group, n_items, pro
|
|
|
148
157
|
|
|
149
158
|
|
|
150
159
|
@pytest.mark.parametrize('permutation_sets', [random_permutation_equality_groups(5, 3, 10, 0.5)])
|
|
151
|
-
def test_linear_permutation_gate_equality(permutation_sets):
|
|
160
|
+
def test_linear_permutation_gate_equality(permutation_sets) -> None:
|
|
152
161
|
swap_gates = [cirq.SWAP, cirq.CNOT]
|
|
153
162
|
equals_tester = ct.EqualsTester()
|
|
154
163
|
for swap_gate in swap_gates:
|
|
@@ -161,7 +170,7 @@ def test_linear_permutation_gate_equality(permutation_sets):
|
|
|
161
170
|
)
|
|
162
171
|
|
|
163
172
|
|
|
164
|
-
def test_linear_permutation_gate_pow_not_implemented():
|
|
173
|
+
def test_linear_permutation_gate_pow_not_implemented() -> None:
|
|
165
174
|
permutation_gate = cca.LinearPermutationGate(3, {0: 1, 1: 2, 2: 0})
|
|
166
175
|
|
|
167
176
|
assert permutation_gate.__pow__(0) is NotImplemented
|
|
@@ -181,7 +190,7 @@ def test_linear_permutation_gate_pow_not_implemented():
|
|
|
181
190
|
(4, {0: 3, 1: 2, 2: 1, 3: 0}),
|
|
182
191
|
],
|
|
183
192
|
)
|
|
184
|
-
def test_linear_permutation_gate_pow_identity(num_qubits, permutation):
|
|
193
|
+
def test_linear_permutation_gate_pow_identity(num_qubits, permutation) -> None:
|
|
185
194
|
permutation_gate = cca.LinearPermutationGate(num_qubits, permutation)
|
|
186
195
|
|
|
187
196
|
assert permutation_gate**1 == permutation_gate
|
|
@@ -197,7 +206,7 @@ def test_linear_permutation_gate_pow_identity(num_qubits, permutation):
|
|
|
197
206
|
(4, {0: 3, 1: 2, 2: 1, 3: 0}, {0: 3, 1: 2, 2: 1, 3: 0}),
|
|
198
207
|
],
|
|
199
208
|
)
|
|
200
|
-
def test_linear_permutation_gate_pow_inverse(num_qubits, permutation, inverse):
|
|
209
|
+
def test_linear_permutation_gate_pow_inverse(num_qubits, permutation, inverse) -> None:
|
|
201
210
|
permutation_gate = cca.LinearPermutationGate(num_qubits, permutation)
|
|
202
211
|
inverse_gate = cca.LinearPermutationGate(num_qubits, inverse)
|
|
203
212
|
|
|
@@ -205,7 +214,7 @@ def test_linear_permutation_gate_pow_inverse(num_qubits, permutation, inverse):
|
|
|
205
214
|
assert cirq.inverse(permutation_gate) == inverse_gate
|
|
206
215
|
|
|
207
216
|
|
|
208
|
-
def test_display_mapping():
|
|
217
|
+
def test_display_mapping() -> None:
|
|
209
218
|
indices = [4, 2, 0, 1, 3]
|
|
210
219
|
qubits = cirq.LineQubit.range(len(indices))
|
|
211
220
|
circuit = cca.complete_acquaintance_strategy(qubits, 2)
|
|
@@ -236,7 +245,7 @@ def test_display_mapping():
|
|
|
236
245
|
for _ in range(4)
|
|
237
246
|
],
|
|
238
247
|
)
|
|
239
|
-
def test_return_to_initial_mapping(circuit):
|
|
248
|
+
def test_return_to_initial_mapping(circuit) -> None:
|
|
240
249
|
qubits = sorted(circuit.all_qubits())
|
|
241
250
|
cca.return_to_initial_mapping(circuit)
|
|
242
251
|
initial_mapping = {q: i for i, q in enumerate(qubits)}
|
|
@@ -245,7 +254,7 @@ def test_return_to_initial_mapping(circuit):
|
|
|
245
254
|
assert mapping == initial_mapping
|
|
246
255
|
|
|
247
256
|
|
|
248
|
-
def test_uses_consistent_swap_gate():
|
|
257
|
+
def test_uses_consistent_swap_gate() -> None:
|
|
249
258
|
a, b = cirq.LineQubit.range(2)
|
|
250
259
|
circuit = cirq.Circuit([cca.SwapPermutationGate()(a, b), cca.SwapPermutationGate()(a, b)])
|
|
251
260
|
assert cca.uses_consistent_swap_gate(circuit, cirq.SWAP)
|
|
@@ -262,7 +271,7 @@ def test_uses_consistent_swap_gate():
|
|
|
262
271
|
assert not cca.uses_consistent_swap_gate(circuit, cirq.CZ)
|
|
263
272
|
|
|
264
273
|
|
|
265
|
-
def test_swap_gate_eq():
|
|
274
|
+
def test_swap_gate_eq() -> None:
|
|
266
275
|
assert cca.SwapPermutationGate() == cca.SwapPermutationGate(cirq.SWAP)
|
|
267
276
|
assert cca.SwapPermutationGate() != cca.SwapPermutationGate(cirq.CZ)
|
|
268
277
|
assert cca.SwapPermutationGate(cirq.CZ) == cca.SwapPermutationGate(cirq.CZ)
|
|
@@ -276,5 +285,5 @@ def test_swap_gate_eq():
|
|
|
276
285
|
cca.SwapPermutationGate(cirq.CZ),
|
|
277
286
|
],
|
|
278
287
|
)
|
|
279
|
-
def test_swap_gate_repr(gate):
|
|
288
|
+
def test_swap_gate_repr(gate) -> None:
|
|
280
289
|
cirq.testing.assert_equivalent_repr(gate)
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import itertools
|
|
18
|
-
from typing import Any,
|
|
18
|
+
from typing import Any, Iterator, Sequence, TYPE_CHECKING
|
|
19
19
|
|
|
20
20
|
from cirq import ops, value
|
|
21
21
|
from cirq.contrib.acquaintance.permutation import PermutationGate, SwapPermutationGate
|
|
@@ -36,7 +36,7 @@ class CircularShiftGate(PermutationGate):
|
|
|
36
36
|
shift: The number of positions to circularly left shift the qubits.
|
|
37
37
|
swap_gate: The gate to use when decomposing.
|
|
38
38
|
"""
|
|
39
|
-
super(
|
|
39
|
+
super().__init__(num_qubits, swap_gate)
|
|
40
40
|
self.shift = shift
|
|
41
41
|
|
|
42
42
|
def __repr__(self) -> str:
|
|
@@ -60,7 +60,7 @@ class CircularShiftGate(PermutationGate):
|
|
|
60
60
|
for k in range(i, j, 2):
|
|
61
61
|
yield swap_gate(*qubits[k : k + 2])
|
|
62
62
|
|
|
63
|
-
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) ->
|
|
63
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> tuple[str, ...]:
|
|
64
64
|
if args.known_qubit_count is None:
|
|
65
65
|
return NotImplemented # pragma: no cover
|
|
66
66
|
direction_symbols = ('╲', '╱') if args.use_unicode_characters else ('\\', '/')
|
|
@@ -72,7 +72,7 @@ class CircularShiftGate(PermutationGate):
|
|
|
72
72
|
)
|
|
73
73
|
return wire_symbols
|
|
74
74
|
|
|
75
|
-
def permutation(self) ->
|
|
75
|
+
def permutation(self) -> dict[int, int]:
|
|
76
76
|
shift = self.shift % self.num_qubits()
|
|
77
77
|
permuted_indices = itertools.chain(range(shift, self.num_qubits()), range(shift))
|
|
78
78
|
return {s: i for i, s in enumerate(permuted_indices)}
|
|
@@ -16,7 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
|
|
17
17
|
import functools
|
|
18
18
|
import itertools
|
|
19
|
-
from typing import
|
|
19
|
+
from typing import Iterable, Iterator, Sequence, TYPE_CHECKING
|
|
20
20
|
|
|
21
21
|
from cirq import ops
|
|
22
22
|
from cirq.contrib.acquaintance.gates import acquaint
|
|
@@ -93,7 +93,7 @@ class ShiftSwapNetworkGate(PermutationGate):
|
|
|
93
93
|
parts[k] = parts_qubits[: len(right_part)]
|
|
94
94
|
parts[k + 1] = parts_qubits[len(right_part) :]
|
|
95
95
|
|
|
96
|
-
def qubit_count(self, side:
|
|
96
|
+
def qubit_count(self, side: str | None = None) -> int:
|
|
97
97
|
if side is None:
|
|
98
98
|
return sum(self.qubit_count(side) for side in self.part_lens)
|
|
99
99
|
return sum(self.part_lens[side])
|
|
@@ -101,7 +101,7 @@ class ShiftSwapNetworkGate(PermutationGate):
|
|
|
101
101
|
def num_qubits(self) -> int:
|
|
102
102
|
return self.qubit_count()
|
|
103
103
|
|
|
104
|
-
def permutation(self) ->
|
|
104
|
+
def permutation(self) -> dict[int, int]:
|
|
105
105
|
return dict(
|
|
106
106
|
zip(
|
|
107
107
|
range(self.num_qubits()),
|
|
@@ -112,7 +112,7 @@ class ShiftSwapNetworkGate(PermutationGate):
|
|
|
112
112
|
)
|
|
113
113
|
)
|
|
114
114
|
|
|
115
|
-
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) ->
|
|
115
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> tuple[str, ...]:
|
|
116
116
|
qubit_count = self.qubit_count()
|
|
117
117
|
assert args.known_qubit_count in (None, qubit_count)
|
|
118
118
|
|
|
@@ -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 itertools
|
|
16
18
|
import random
|
|
17
19
|
|
|
@@ -21,7 +23,7 @@ import cirq
|
|
|
21
23
|
import cirq.contrib.acquaintance as cca
|
|
22
24
|
|
|
23
25
|
|
|
24
|
-
def random_part_lens(max_n_parts, max_part_size):
|
|
26
|
+
def random_part_lens(max_n_parts, max_part_size) -> tuple[int, ...]:
|
|
25
27
|
return tuple(random.randint(1, max_part_size) for _ in range(random.randint(1, max_n_parts)))
|
|
26
28
|
|
|
27
29
|
|
|
@@ -29,7 +31,7 @@ def random_part_lens(max_n_parts, max_part_size):
|
|
|
29
31
|
'left_part_lens,right_part_lens',
|
|
30
32
|
[tuple(random_part_lens(7, 2) for _ in ('left', 'right')) for _ in range(5)],
|
|
31
33
|
)
|
|
32
|
-
def test_shift_swap_network_gate_acquaintance_opps(left_part_lens, right_part_lens):
|
|
34
|
+
def test_shift_swap_network_gate_acquaintance_opps(left_part_lens, right_part_lens) -> None:
|
|
33
35
|
|
|
34
36
|
gate = cca.ShiftSwapNetworkGate(left_part_lens, right_part_lens)
|
|
35
37
|
n_qubits = gate.qubit_count()
|
|
@@ -43,6 +45,7 @@ def test_shift_swap_network_gate_acquaintance_opps(left_part_lens, right_part_le
|
|
|
43
45
|
# expected opps
|
|
44
46
|
i = 0
|
|
45
47
|
sides = ('left', 'right')
|
|
48
|
+
parts: dict[str, list[set[int]]]
|
|
46
49
|
parts = {side: [] for side in sides}
|
|
47
50
|
for side, part_lens in zip(sides, (left_part_lens, right_part_lens)):
|
|
48
51
|
for part_len in part_lens:
|
|
@@ -203,7 +206,7 @@ circuit_diagrams = {
|
|
|
203
206
|
|
|
204
207
|
|
|
205
208
|
@pytest.mark.parametrize('left_part_lens,right_part_lens', set(key[1:] for key in circuit_diagrams))
|
|
206
|
-
def test_shift_swap_network_gate_diagrams(left_part_lens, right_part_lens):
|
|
209
|
+
def test_shift_swap_network_gate_diagrams(left_part_lens, right_part_lens) -> None:
|
|
207
210
|
|
|
208
211
|
gate = cca.ShiftSwapNetworkGate(left_part_lens, right_part_lens)
|
|
209
212
|
n_qubits = gate.qubit_count()
|
|
@@ -218,7 +221,7 @@ def test_shift_swap_network_gate_diagrams(left_part_lens, right_part_lens):
|
|
|
218
221
|
cirq.testing.assert_has_diagram(circuit, diagram)
|
|
219
222
|
|
|
220
223
|
|
|
221
|
-
def test_shift_swap_network_gate_bad_part_lens():
|
|
224
|
+
def test_shift_swap_network_gate_bad_part_lens() -> None:
|
|
222
225
|
with pytest.raises(ValueError):
|
|
223
226
|
cca.ShiftSwapNetworkGate((0, 1, 1), (2, 2))
|
|
224
227
|
with pytest.raises(ValueError):
|
|
@@ -233,7 +236,7 @@ def test_shift_swap_network_gate_bad_part_lens():
|
|
|
233
236
|
'left_part_lens,right_part_lens',
|
|
234
237
|
[tuple(random_part_lens(2, 2) for _ in ('left', 'right')) for _ in range(5)],
|
|
235
238
|
)
|
|
236
|
-
def test_shift_swap_network_gate_repr(left_part_lens, right_part_lens):
|
|
239
|
+
def test_shift_swap_network_gate_repr(left_part_lens, right_part_lens) -> None:
|
|
237
240
|
gate = cca.ShiftSwapNetworkGate(left_part_lens, right_part_lens)
|
|
238
241
|
cirq.testing.assert_equivalent_repr(gate)
|
|
239
242
|
|
|
@@ -245,7 +248,7 @@ def test_shift_swap_network_gate_repr(left_part_lens, right_part_lens):
|
|
|
245
248
|
'left_part_lens,right_part_lens',
|
|
246
249
|
[tuple(random_part_lens(2, 2) for _ in ('left', 'right')) for _ in range(5)],
|
|
247
250
|
)
|
|
248
|
-
def test_shift_swap_network_gate_permutation(left_part_lens, right_part_lens):
|
|
251
|
+
def test_shift_swap_network_gate_permutation(left_part_lens, right_part_lens) -> None:
|
|
249
252
|
gate = cca.ShiftSwapNetworkGate(left_part_lens, right_part_lens)
|
|
250
253
|
n_qubits = gate.qubit_count()
|
|
251
254
|
cca.testing.assert_permutation_decomposition_equivalence(gate, n_qubits)
|
|
@@ -12,11 +12,13 @@
|
|
|
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 cirq
|
|
16
18
|
import cirq.contrib.acquaintance as cca
|
|
17
19
|
|
|
18
20
|
|
|
19
|
-
def test_circular_shift_gate_init():
|
|
21
|
+
def test_circular_shift_gate_init() -> None:
|
|
20
22
|
g = cca.CircularShiftGate(4, 2)
|
|
21
23
|
assert g.num_qubits() == 4
|
|
22
24
|
assert g.shift == 2
|
|
@@ -25,7 +27,7 @@ def test_circular_shift_gate_init():
|
|
|
25
27
|
assert g.swap_gate == cirq.CZ
|
|
26
28
|
|
|
27
29
|
|
|
28
|
-
def test_circular_shift_gate_eq():
|
|
30
|
+
def test_circular_shift_gate_eq() -> None:
|
|
29
31
|
equals_tester = cirq.testing.EqualsTester()
|
|
30
32
|
equals_tester.add_equality_group(cca.CircularShiftGate(4, 1), cca.CircularShiftGate(4, 1))
|
|
31
33
|
equals_tester.add_equality_group(cca.CircularShiftGate(4, 1, swap_gate=cirq.CZ))
|
|
@@ -34,19 +36,19 @@ def test_circular_shift_gate_eq():
|
|
|
34
36
|
equals_tester.add_equality_group(cca.CircularShiftGate(3, 2, swap_gate=cirq.CZ))
|
|
35
37
|
|
|
36
38
|
|
|
37
|
-
def test_circular_shift_gate_permutation():
|
|
39
|
+
def test_circular_shift_gate_permutation() -> None:
|
|
38
40
|
assert cca.CircularShiftGate(3, 4).permutation() == {0: 2, 1: 0, 2: 1}
|
|
39
41
|
assert cca.CircularShiftGate(4, 0).permutation() == {0: 0, 1: 1, 2: 2, 3: 3}
|
|
40
42
|
|
|
41
43
|
assert cca.CircularShiftGate(5, 2).permutation() == {0: 3, 1: 4, 2: 0, 3: 1, 4: 2}
|
|
42
44
|
|
|
43
45
|
|
|
44
|
-
def test_circular_shift_gate_repr():
|
|
46
|
+
def test_circular_shift_gate_repr() -> None:
|
|
45
47
|
g = cca.CircularShiftGate(3, 2)
|
|
46
48
|
cirq.testing.assert_equivalent_repr(g)
|
|
47
49
|
|
|
48
50
|
|
|
49
|
-
def test_circular_shift_gate_decomposition():
|
|
51
|
+
def test_circular_shift_gate_decomposition() -> None:
|
|
50
52
|
qubits = [cirq.NamedQubit(q) for q in 'abcdef']
|
|
51
53
|
|
|
52
54
|
circular_shift = cca.CircularShiftGate(2, 1, cirq.CZ)(*qubits[:2])
|
|
@@ -92,7 +94,7 @@ f: ───────────────×───────
|
|
|
92
94
|
assert actual_text_diagram == expected_text_diagram
|
|
93
95
|
|
|
94
96
|
|
|
95
|
-
def test_circular_shift_gate_wire_symbols():
|
|
97
|
+
def test_circular_shift_gate_wire_symbols() -> None:
|
|
96
98
|
qubits = [cirq.NamedQubit(q) for q in 'xyz']
|
|
97
99
|
circuit = cirq.Circuit(cca.CircularShiftGate(3, 2)(*qubits))
|
|
98
100
|
actual_text_diagram = circuit.to_text_diagram().strip()
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import itertools
|
|
18
|
-
from typing import Iterable, Sequence,
|
|
18
|
+
from typing import Iterable, Sequence, TYPE_CHECKING, TypeVar
|
|
19
19
|
|
|
20
20
|
from cirq import circuits, ops
|
|
21
21
|
from cirq.contrib.acquaintance.gates import acquaint
|
|
@@ -27,7 +27,7 @@ if TYPE_CHECKING:
|
|
|
27
27
|
TItem = TypeVar('TItem')
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
def skip_and_wrap_around(items: Sequence[TItem]) ->
|
|
30
|
+
def skip_and_wrap_around(items: Sequence[TItem]) -> tuple[TItem, ...]:
|
|
31
31
|
n_items = len(items)
|
|
32
32
|
positions = {
|
|
33
33
|
p: i
|
|
@@ -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 itertools
|
|
16
18
|
|
|
17
19
|
import pytest
|
|
@@ -21,7 +23,7 @@ import cirq.contrib.acquaintance as cca
|
|
|
21
23
|
import cirq.contrib.acquaintance.strategies.cubic as ccasc
|
|
22
24
|
|
|
23
25
|
|
|
24
|
-
def test_skip_and_wrap_around():
|
|
26
|
+
def test_skip_and_wrap_around() -> None:
|
|
25
27
|
assert ccasc.skip_and_wrap_around(range(3)) == (0, 2, 1)
|
|
26
28
|
assert ccasc.skip_and_wrap_around(range(4)) == (0, 3, 1, 2)
|
|
27
29
|
assert ccasc.skip_and_wrap_around('abcde') == tuple('aebdc')
|
|
@@ -29,7 +31,7 @@ def test_skip_and_wrap_around():
|
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
@pytest.mark.parametrize('n_qubits', range(3, 9))
|
|
32
|
-
def test_cubic_acquaintance_strategy(n_qubits):
|
|
34
|
+
def test_cubic_acquaintance_strategy(n_qubits) -> None:
|
|
33
35
|
qubits = tuple(cirq.LineQubit.range(n_qubits))
|
|
34
36
|
strategy = cca.cubic_acquaintance_strategy(qubits)
|
|
35
37
|
initial_mapping = {q: i for i, q in enumerate(qubits)}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
from typing import cast, Iterable,
|
|
17
|
+
from typing import cast, Iterable, Sequence, TYPE_CHECKING
|
|
18
18
|
|
|
19
19
|
from cirq import circuits
|
|
20
20
|
from cirq.contrib.acquaintance.gates import acquaint, SwapNetworkGate
|
|
@@ -24,7 +24,7 @@ if TYPE_CHECKING:
|
|
|
24
24
|
import cirq
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
def qubit_pairs_to_qubit_order(qubit_pairs: Sequence[Sequence[cirq.Qid]]) ->
|
|
27
|
+
def qubit_pairs_to_qubit_order(qubit_pairs: Sequence[Sequence[cirq.Qid]]) -> list[cirq.Qid]:
|
|
28
28
|
"""Takes a sequence of qubit pairs and returns a sequence in which every
|
|
29
29
|
pair is at distance two.
|
|
30
30
|
|
|
@@ -35,7 +35,7 @@ def qubit_pairs_to_qubit_order(qubit_pairs: Sequence[Sequence[cirq.Qid]]) -> Lis
|
|
|
35
35
|
if set(len(qubit_pair) for qubit_pair in qubit_pairs) != set((2,)):
|
|
36
36
|
raise ValueError('set(len(qubit_pair) for qubit_pair in qubit_pairs) != set((2,))')
|
|
37
37
|
n_pairs = len(qubit_pairs)
|
|
38
|
-
qubits:
|
|
38
|
+
qubits: list[cirq.Qid] = []
|
|
39
39
|
for i in range(0, 2 * (n_pairs // 2), 2):
|
|
40
40
|
qubits += [
|
|
41
41
|
qubit_pairs[i][0],
|
|
@@ -49,15 +49,15 @@ def qubit_pairs_to_qubit_order(qubit_pairs: Sequence[Sequence[cirq.Qid]]) -> Lis
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
def quartic_paired_acquaintance_strategy(
|
|
52
|
-
qubit_pairs: Iterable[
|
|
53
|
-
) ->
|
|
52
|
+
qubit_pairs: Iterable[tuple[cirq.Qid, cirq.Qid]],
|
|
53
|
+
) -> tuple[cirq.Circuit, Sequence[cirq.Qid]]:
|
|
54
54
|
"""Acquaintance strategy for pairs of pairs.
|
|
55
55
|
|
|
56
56
|
Implements UpCCGSD ansatz from arXiv:1810.02327.
|
|
57
57
|
"""
|
|
58
58
|
|
|
59
59
|
qubit_pairs = tuple(
|
|
60
|
-
cast(
|
|
60
|
+
cast(tuple['cirq.Qid', 'cirq.Qid'], tuple(qubit_pair)) for qubit_pair in qubit_pairs
|
|
61
61
|
)
|
|
62
62
|
qubits = qubit_pairs_to_qubit_order(qubit_pairs)
|
|
63
63
|
n_qubits = len(qubits)
|