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
|
@@ -12,16 +12,18 @@
|
|
|
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 Sequence
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
18
20
|
import pytest
|
|
19
21
|
|
|
20
22
|
import cirq
|
|
21
|
-
from cirq import add_dynamical_decoupling
|
|
23
|
+
from cirq import add_dynamical_decoupling, CNOT, CZ, CZPowGate, H, X, Y, Z
|
|
22
24
|
|
|
23
25
|
|
|
24
|
-
def assert_sim_eq(circuit1:
|
|
26
|
+
def assert_sim_eq(circuit1: cirq.AbstractCircuit, circuit2: cirq.AbstractCircuit):
|
|
25
27
|
# Simulate 2 circuits and compare final states.
|
|
26
28
|
sampler = cirq.Simulator(dtype=np.complex128)
|
|
27
29
|
psi0 = sampler.simulate(cirq.drop_terminal_measurements(circuit1)).final_state_vector
|
|
@@ -31,9 +33,9 @@ def assert_sim_eq(circuit1: 'cirq.AbstractCircuit', circuit2: 'cirq.AbstractCirc
|
|
|
31
33
|
|
|
32
34
|
|
|
33
35
|
def assert_dd(
|
|
34
|
-
input_circuit:
|
|
35
|
-
expected_circuit:
|
|
36
|
-
schema:
|
|
36
|
+
input_circuit: cirq.AbstractCircuit,
|
|
37
|
+
expected_circuit: str | cirq.AbstractCircuit,
|
|
38
|
+
schema: str | tuple[cirq.Gate, ...] = 'DEFAULT',
|
|
37
39
|
single_qubit_gate_moments_only: bool = True,
|
|
38
40
|
):
|
|
39
41
|
transformed_circuit = add_dynamical_decoupling(
|
|
@@ -66,11 +68,9 @@ def test_no_insertion():
|
|
|
66
68
|
b = cirq.NamedQubit('b')
|
|
67
69
|
|
|
68
70
|
assert_dd(
|
|
69
|
-
input_circuit=cirq.Circuit(
|
|
70
|
-
cirq.Moment(cirq.H(a)), cirq.Moment(cirq.CNOT(a, b)), cirq.Moment(cirq.H(b))
|
|
71
|
-
),
|
|
71
|
+
input_circuit=cirq.Circuit(cirq.Moment(H(a)), cirq.Moment(CNOT(a, b)), cirq.Moment(H(b))),
|
|
72
72
|
expected_circuit=cirq.Circuit(
|
|
73
|
-
cirq.Moment(
|
|
73
|
+
cirq.Moment(H(a)), cirq.Moment(CNOT(a, b)), cirq.Moment(H(b))
|
|
74
74
|
),
|
|
75
75
|
schema='XX_PAIR',
|
|
76
76
|
single_qubit_gate_moments_only=False,
|
|
@@ -79,14 +79,9 @@ def test_no_insertion():
|
|
|
79
79
|
|
|
80
80
|
@pytest.mark.parametrize(
|
|
81
81
|
'schema,inserted_gates',
|
|
82
|
-
[
|
|
83
|
-
('XX_PAIR', (cirq.X, cirq.X)),
|
|
84
|
-
('X_XINV', (cirq.X, cirq.X**-1)),
|
|
85
|
-
('YY_PAIR', (cirq.Y, cirq.Y)),
|
|
86
|
-
('Y_YINV', (cirq.Y, cirq.Y**-1)),
|
|
87
|
-
],
|
|
82
|
+
[('XX_PAIR', (X, X)), ('X_XINV', (X, X**-1)), ('YY_PAIR', (Y, Y)), ('Y_YINV', (Y, Y**-1))],
|
|
88
83
|
)
|
|
89
|
-
def test_insert_provided_schema(schema: str, inserted_gates: Sequence[
|
|
84
|
+
def test_insert_provided_schema(schema: str, inserted_gates: Sequence[cirq.Gate]):
|
|
90
85
|
"""Test case diagrams.
|
|
91
86
|
Input:
|
|
92
87
|
a: ───H───@───────────M───
|
|
@@ -100,17 +95,17 @@ def test_insert_provided_schema(schema: str, inserted_gates: Sequence['cirq.Gate
|
|
|
100
95
|
c = cirq.NamedQubit('c')
|
|
101
96
|
|
|
102
97
|
input_circuit = cirq.Circuit(
|
|
103
|
-
cirq.Moment(
|
|
104
|
-
cirq.Moment(
|
|
105
|
-
cirq.Moment(
|
|
106
|
-
cirq.Moment(
|
|
98
|
+
cirq.Moment(H(a)),
|
|
99
|
+
cirq.Moment(CNOT(a, b)),
|
|
100
|
+
cirq.Moment(CNOT(b, c)),
|
|
101
|
+
cirq.Moment(CNOT(b, c)),
|
|
107
102
|
cirq.Moment([cirq.M(qubit) for qubit in [a, b, c]]),
|
|
108
103
|
)
|
|
109
104
|
expected_circuit = cirq.Circuit(
|
|
110
|
-
cirq.Moment(
|
|
111
|
-
cirq.Moment(
|
|
112
|
-
cirq.Moment(
|
|
113
|
-
cirq.Moment(
|
|
105
|
+
cirq.Moment(H(a)),
|
|
106
|
+
cirq.Moment(CNOT(a, b)),
|
|
107
|
+
cirq.Moment(CNOT(b, c), inserted_gates[0](a)),
|
|
108
|
+
cirq.Moment(CNOT(b, c), inserted_gates[1](a)),
|
|
114
109
|
cirq.Moment([cirq.M(qubit) for qubit in [a, b, c]]),
|
|
115
110
|
)
|
|
116
111
|
|
|
@@ -139,24 +134,24 @@ def test_insert_by_customized_dd_sequence():
|
|
|
139
134
|
|
|
140
135
|
assert_dd(
|
|
141
136
|
input_circuit=cirq.Circuit(
|
|
142
|
-
cirq.Moment(
|
|
143
|
-
cirq.Moment(
|
|
144
|
-
cirq.Moment(
|
|
145
|
-
cirq.Moment(
|
|
146
|
-
cirq.Moment(
|
|
147
|
-
cirq.Moment(
|
|
148
|
-
cirq.Moment([
|
|
137
|
+
cirq.Moment(H(a)),
|
|
138
|
+
cirq.Moment(CNOT(a, b)),
|
|
139
|
+
cirq.Moment(CNOT(b, c)),
|
|
140
|
+
cirq.Moment(CNOT(b, c)),
|
|
141
|
+
cirq.Moment(CNOT(b, c)),
|
|
142
|
+
cirq.Moment(CNOT(b, c)),
|
|
143
|
+
cirq.Moment([H(qubit) for qubit in [a, b, c]]),
|
|
149
144
|
),
|
|
150
145
|
expected_circuit=cirq.Circuit(
|
|
151
|
-
cirq.Moment(
|
|
152
|
-
cirq.Moment(
|
|
153
|
-
cirq.Moment(
|
|
154
|
-
cirq.Moment(
|
|
155
|
-
cirq.Moment(
|
|
156
|
-
cirq.Moment(
|
|
157
|
-
cirq.Moment([
|
|
158
|
-
),
|
|
159
|
-
schema=[
|
|
146
|
+
cirq.Moment(H(a)),
|
|
147
|
+
cirq.Moment(CNOT(a, b)),
|
|
148
|
+
cirq.Moment(CNOT(b, c), X(a)),
|
|
149
|
+
cirq.Moment(CNOT(b, c), X(a)),
|
|
150
|
+
cirq.Moment(CNOT(b, c), Y(a)),
|
|
151
|
+
cirq.Moment(CNOT(b, c), Y(a)),
|
|
152
|
+
cirq.Moment([H(qubit) for qubit in [a, b, c]]),
|
|
153
|
+
),
|
|
154
|
+
schema=[X, X, Y, Y],
|
|
160
155
|
single_qubit_gate_moments_only=False,
|
|
161
156
|
)
|
|
162
157
|
|
|
@@ -178,19 +173,19 @@ def test_pull_through_h_gate_case1(single_qubit_gate_moments_only: bool):
|
|
|
178
173
|
|
|
179
174
|
assert_dd(
|
|
180
175
|
input_circuit=cirq.Circuit(
|
|
181
|
-
cirq.Moment(
|
|
182
|
-
cirq.Moment(
|
|
183
|
-
cirq.Moment(
|
|
184
|
-
cirq.Moment(
|
|
185
|
-
cirq.Moment(
|
|
176
|
+
cirq.Moment(H(a), H(b)),
|
|
177
|
+
cirq.Moment(H(b)),
|
|
178
|
+
cirq.Moment(H(a), H(b)),
|
|
179
|
+
cirq.Moment(H(b)),
|
|
180
|
+
cirq.Moment(CNOT(a, b)),
|
|
186
181
|
),
|
|
187
182
|
expected_circuit=cirq.Circuit(
|
|
188
|
-
cirq.Moment(
|
|
189
|
-
cirq.Moment(
|
|
190
|
-
cirq.Moment(
|
|
191
|
-
cirq.Moment(
|
|
192
|
-
cirq.Moment(
|
|
193
|
-
cirq.Moment(
|
|
183
|
+
cirq.Moment(H(a), H(b)),
|
|
184
|
+
cirq.Moment(H(b), X(a)),
|
|
185
|
+
cirq.Moment(H(a), H(b)),
|
|
186
|
+
cirq.Moment(H(b), X(a)),
|
|
187
|
+
cirq.Moment(CNOT(a, b)),
|
|
188
|
+
cirq.Moment(Y(a), X(b)),
|
|
194
189
|
),
|
|
195
190
|
schema="XX_PAIR",
|
|
196
191
|
single_qubit_gate_moments_only=single_qubit_gate_moments_only,
|
|
@@ -214,20 +209,19 @@ def test_pull_through_h_gate_case2(single_qubit_gate_moments_only: bool):
|
|
|
214
209
|
|
|
215
210
|
assert_dd(
|
|
216
211
|
input_circuit=cirq.Circuit(
|
|
217
|
-
cirq.Moment(
|
|
218
|
-
cirq.Moment(
|
|
219
|
-
cirq.Moment(
|
|
220
|
-
cirq.Moment(
|
|
221
|
-
cirq.Moment(
|
|
212
|
+
cirq.Moment(H(a), H(b)),
|
|
213
|
+
cirq.Moment(H(b)),
|
|
214
|
+
cirq.Moment(H(a), H(b)),
|
|
215
|
+
cirq.Moment(H(b)),
|
|
216
|
+
cirq.Moment(H(a), H(b)),
|
|
222
217
|
),
|
|
223
218
|
expected_circuit=cirq.Circuit(
|
|
224
|
-
cirq.Moment(
|
|
225
|
-
cirq.Moment(
|
|
226
|
-
cirq.Moment(
|
|
227
|
-
cirq.Moment(
|
|
219
|
+
cirq.Moment(H(a), H(b)),
|
|
220
|
+
cirq.Moment(H(b), X(a)),
|
|
221
|
+
cirq.Moment(H(a), H(b)),
|
|
222
|
+
cirq.Moment(H(b), X(a)),
|
|
228
223
|
cirq.Moment(
|
|
229
|
-
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0.5, z_exponent=1).on(a),
|
|
230
|
-
cirq.H(b),
|
|
224
|
+
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0.5, z_exponent=1).on(a), H(b)
|
|
231
225
|
),
|
|
232
226
|
),
|
|
233
227
|
schema="XX_PAIR",
|
|
@@ -239,22 +233,22 @@ def test_pull_through_h_gate_case2(single_qubit_gate_moments_only: bool):
|
|
|
239
233
|
'schema,error_msg_regex',
|
|
240
234
|
[
|
|
241
235
|
('INVALID_SCHEMA', 'Invalid schema name.'),
|
|
242
|
-
([
|
|
236
|
+
([X], 'Invalid dynamical decoupling sequence. Expect more than one gates.'),
|
|
243
237
|
(
|
|
244
|
-
[
|
|
245
|
-
'Invalid dynamical decoupling sequence. Expect sequence
|
|
238
|
+
[X, Y],
|
|
239
|
+
'Invalid dynamical decoupling sequence. Expect sequence product equals identity'
|
|
246
240
|
' up to a global phase, got',
|
|
247
241
|
),
|
|
248
242
|
(
|
|
249
|
-
[
|
|
243
|
+
[H, H],
|
|
250
244
|
'Dynamical decoupling sequence should only contain gates that are essentially'
|
|
251
245
|
' Pauli gates.',
|
|
252
246
|
),
|
|
253
247
|
],
|
|
254
248
|
)
|
|
255
|
-
def test_invalid_dd_schema(schema:
|
|
249
|
+
def test_invalid_dd_schema(schema: str | tuple[cirq.Gate, ...], error_msg_regex):
|
|
256
250
|
a = cirq.NamedQubit('a')
|
|
257
|
-
input_circuit = cirq.Circuit(
|
|
251
|
+
input_circuit = cirq.Circuit(H(a))
|
|
258
252
|
with pytest.raises(ValueError, match=error_msg_regex):
|
|
259
253
|
add_dynamical_decoupling(input_circuit, schema=schema, single_qubit_gate_moments_only=False)
|
|
260
254
|
|
|
@@ -262,15 +256,15 @@ def test_invalid_dd_schema(schema: Union[str, Tuple['cirq.Gate', ...]], error_ms
|
|
|
262
256
|
def test_single_qubit_gate_moments_only_no_updates_succeeds():
|
|
263
257
|
qubits = cirq.LineQubit.range(9)
|
|
264
258
|
input_circuit = cirq.Circuit(
|
|
265
|
-
cirq.Moment([
|
|
266
|
-
cirq.Moment(
|
|
267
|
-
cirq.Moment(
|
|
268
|
-
cirq.Moment([
|
|
269
|
-
cirq.Moment(
|
|
270
|
-
cirq.Moment([
|
|
271
|
-
cirq.Moment(
|
|
272
|
-
cirq.Moment([
|
|
273
|
-
cirq.Moment(
|
|
259
|
+
cirq.Moment([H(qubits[i]) for i in [3, 4, 5]]),
|
|
260
|
+
cirq.Moment(CZ(*qubits[4:6])),
|
|
261
|
+
cirq.Moment(CZ(*qubits[3:5])),
|
|
262
|
+
cirq.Moment([H(qubits[i]) for i in [2, 3, 5, 6]]),
|
|
263
|
+
cirq.Moment(CZ(*qubits[2:4]), CNOT(*qubits[5:7])),
|
|
264
|
+
cirq.Moment([H(qubits[i]) for i in [1, 2, 6, 7]]),
|
|
265
|
+
cirq.Moment(CZ(*qubits[1:3]), CNOT(*qubits[6:8])),
|
|
266
|
+
cirq.Moment([H(qubits[i]) for i in [0, 1, 7, 8]]),
|
|
267
|
+
cirq.Moment(CZ(*qubits[0:2]), CNOT(*qubits[7:])),
|
|
274
268
|
)
|
|
275
269
|
add_dynamical_decoupling(input_circuit, schema='X_XINV', single_qubit_gate_moments_only=True)
|
|
276
270
|
|
|
@@ -336,37 +330,35 @@ def test_scattered_circuit():
|
|
|
336
330
|
"""
|
|
337
331
|
qubits = cirq.LineQubit.range(9)
|
|
338
332
|
input_circuit = cirq.Circuit(
|
|
339
|
-
cirq.Moment([
|
|
340
|
-
cirq.Moment(
|
|
341
|
-
cirq.Moment(
|
|
342
|
-
cirq.Moment([
|
|
343
|
-
cirq.Moment(
|
|
344
|
-
cirq.Moment([
|
|
345
|
-
cirq.Moment(
|
|
346
|
-
cirq.Moment([
|
|
347
|
-
cirq.Moment(
|
|
348
|
-
cirq.Moment([
|
|
333
|
+
cirq.Moment([H(qubits[i]) for i in [3, 4, 5]]),
|
|
334
|
+
cirq.Moment(CZ(*qubits[4:6])),
|
|
335
|
+
cirq.Moment(CZ(*qubits[3:5])),
|
|
336
|
+
cirq.Moment([H(qubits[i]) for i in [2, 3, 5, 6]]),
|
|
337
|
+
cirq.Moment(CZ(*qubits[2:4]), CZ(*qubits[5:7])),
|
|
338
|
+
cirq.Moment([H(qubits[i]) for i in [1, 2, 6, 7]]),
|
|
339
|
+
cirq.Moment(CZ(*qubits[1:3]), CZ(*qubits[6:8])),
|
|
340
|
+
cirq.Moment([H(qubits[i]) for i in [0, 1, 7, 8]]),
|
|
341
|
+
cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[7:])),
|
|
342
|
+
cirq.Moment([H(q) for q in qubits]),
|
|
349
343
|
)
|
|
350
344
|
expected_circuit_single_qubit_gate_on = cirq.Circuit(
|
|
351
|
-
cirq.Moment([
|
|
352
|
-
cirq.Moment(
|
|
353
|
-
cirq.Moment(
|
|
354
|
-
cirq.Moment([
|
|
355
|
-
cirq.Moment(
|
|
345
|
+
cirq.Moment([H(qubits[i]) for i in [3, 4, 5]]),
|
|
346
|
+
cirq.Moment(CZ(*qubits[4:6])),
|
|
347
|
+
cirq.Moment(CZ(*qubits[3:5])),
|
|
348
|
+
cirq.Moment([H(qubits[i]) for i in [2, 3, 5, 6]] + [X(qubits[4])]),
|
|
349
|
+
cirq.Moment(CZ(*qubits[2:4]), CZ(*qubits[5:7])),
|
|
356
350
|
cirq.Moment(
|
|
357
|
-
[
|
|
358
|
-
+ [cirq.X(qubits[i]) for i in [3, 5]]
|
|
359
|
-
+ [cirq.Y(qubits[4])]
|
|
351
|
+
[H(qubits[i]) for i in [1, 2, 6, 7]] + [X(qubits[i]) for i in [3, 5]] + [Y(qubits[4])]
|
|
360
352
|
),
|
|
361
|
-
cirq.Moment(
|
|
353
|
+
cirq.Moment(CZ(*qubits[1:3]), CZ(*qubits[6:8])),
|
|
362
354
|
cirq.Moment(
|
|
363
|
-
[
|
|
364
|
-
+ [
|
|
365
|
-
+ [
|
|
355
|
+
[H(qubits[i]) for i in [0, 1, 7, 8]]
|
|
356
|
+
+ [X(qubits[i]) for i in [2, 4, 6]]
|
|
357
|
+
+ [Y(qubits[i]) for i in [3, 5]]
|
|
366
358
|
),
|
|
367
|
-
cirq.Moment(
|
|
359
|
+
cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[7:])),
|
|
368
360
|
cirq.Moment(
|
|
369
|
-
[
|
|
361
|
+
[H(qubits[i]) for i in [0, 1, 7, 8]]
|
|
370
362
|
+ [
|
|
371
363
|
cirq.PhasedXZGate(axis_phase_exponent=-0.5, x_exponent=0.5, z_exponent=0).on(
|
|
372
364
|
qubits[2]
|
|
@@ -387,33 +379,29 @@ def test_scattered_circuit():
|
|
|
387
379
|
),
|
|
388
380
|
)
|
|
389
381
|
expected_circuit_single_qubit_gates_off = cirq.Circuit(
|
|
390
|
-
cirq.Moment([
|
|
391
|
-
cirq.Moment(
|
|
392
|
-
cirq.Moment(
|
|
393
|
-
cirq.Moment([
|
|
394
|
-
cirq.Moment(
|
|
382
|
+
cirq.Moment([H(qubits[i]) for i in [3, 4, 5]]),
|
|
383
|
+
cirq.Moment(CZ(*qubits[4:6]), X(qubits[3])),
|
|
384
|
+
cirq.Moment(CZ(*qubits[3:5]), X(qubits[5])),
|
|
385
|
+
cirq.Moment([H(qubits[i]) for i in [2, 3, 5, 6]] + [X(qubits[i]) for i in [4]]),
|
|
386
|
+
cirq.Moment(CZ(*qubits[2:4]), CZ(*qubits[5:7]), Y(qubits[4])),
|
|
395
387
|
cirq.Moment(
|
|
396
|
-
[
|
|
397
|
-
+ [cirq.Y(qubits[i]) for i in [3, 5]]
|
|
398
|
-
+ [cirq.X(qubits[4])]
|
|
388
|
+
[H(qubits[i]) for i in [1, 2, 6, 7]] + [Y(qubits[i]) for i in [3, 5]] + [X(qubits[4])]
|
|
399
389
|
),
|
|
400
390
|
cirq.Moment(
|
|
401
|
-
[
|
|
402
|
-
+ [cirq.X(qubits[i]) for i in [3, 5]]
|
|
403
|
-
+ [cirq.Y(qubits[4])]
|
|
391
|
+
[CZ(*qubits[1:3]), CZ(*qubits[6:8])] + [X(qubits[i]) for i in [3, 5]] + [Y(qubits[4])]
|
|
404
392
|
),
|
|
405
393
|
cirq.Moment(
|
|
406
|
-
[
|
|
407
|
-
+ [
|
|
408
|
-
+ [
|
|
394
|
+
[H(qubits[i]) for i in [0, 1, 7, 8]]
|
|
395
|
+
+ [X(qubits[i]) for i in [2, 4, 6]]
|
|
396
|
+
+ [Y(qubits[i]) for i in [3, 5]]
|
|
409
397
|
),
|
|
410
398
|
cirq.Moment(
|
|
411
|
-
[
|
|
412
|
-
+ [
|
|
413
|
-
+ [
|
|
399
|
+
[CZ(*qubits[0:2]), CZ(*qubits[7:])]
|
|
400
|
+
+ [X(qubits[i]) for i in [3, 5]]
|
|
401
|
+
+ [Y(qubits[i]) for i in [2, 4, 6]]
|
|
414
402
|
),
|
|
415
403
|
cirq.Moment(
|
|
416
|
-
[
|
|
404
|
+
[H(qubits[i]) for i in [0, 1, 4, 7, 8]]
|
|
417
405
|
+ [
|
|
418
406
|
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0.5, z_exponent=0).on(
|
|
419
407
|
qubits[i]
|
|
@@ -478,18 +466,18 @@ def test_scattered_circuit2():
|
|
|
478
466
|
qubits = cirq.LineQubit.range(9)
|
|
479
467
|
assert_dd(
|
|
480
468
|
input_circuit=cirq.Circuit(
|
|
481
|
-
cirq.Moment(
|
|
482
|
-
cirq.Moment(
|
|
483
|
-
cirq.Moment(
|
|
484
|
-
cirq.Moment(
|
|
485
|
-
cirq.Moment(
|
|
469
|
+
cirq.Moment(CZ(*qubits[4:6])),
|
|
470
|
+
cirq.Moment(CZ(*qubits[3:5])),
|
|
471
|
+
cirq.Moment(CZ(*qubits[2:4]), CZ(*qubits[5:7])),
|
|
472
|
+
cirq.Moment(CZ(*qubits[1:3]), CZ(*qubits[6:8])),
|
|
473
|
+
cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[7:])),
|
|
486
474
|
),
|
|
487
475
|
expected_circuit=cirq.Circuit(
|
|
488
|
-
cirq.Moment(
|
|
489
|
-
cirq.Moment(
|
|
490
|
-
cirq.Moment(
|
|
491
|
-
cirq.Moment(
|
|
492
|
-
cirq.Moment(
|
|
476
|
+
cirq.Moment(CZ(*qubits[4:6])),
|
|
477
|
+
cirq.Moment(CZ(*qubits[3:5]), X(qubits[5])),
|
|
478
|
+
cirq.Moment(CZ(*qubits[2:4]), CZ(*qubits[5:7])),
|
|
479
|
+
cirq.Moment(CZ(*qubits[1:3]), CZ(*qubits[6:8]), X(qubits[5])),
|
|
480
|
+
cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[7:]), Z(qubits[6])),
|
|
493
481
|
),
|
|
494
482
|
schema="XX_PAIR",
|
|
495
483
|
single_qubit_gate_moments_only=False,
|
|
@@ -518,20 +506,20 @@ def test_pull_through_chain():
|
|
|
518
506
|
qubits = cirq.LineQubit.range(4)
|
|
519
507
|
assert_dd(
|
|
520
508
|
input_circuit=cirq.Circuit(
|
|
521
|
-
cirq.Moment(
|
|
522
|
-
cirq.Moment(
|
|
509
|
+
cirq.Moment(X(qubits[0])),
|
|
510
|
+
cirq.Moment(Y(qubits[1])),
|
|
523
511
|
cirq.Moment(cirq.SWAP(*qubits[0:2])),
|
|
524
512
|
cirq.Moment(cirq.SWAP(*qubits[1:3])),
|
|
525
513
|
cirq.Moment(cirq.SWAP(*qubits[2:4])),
|
|
526
|
-
cirq.Moment([
|
|
514
|
+
cirq.Moment([X(qubits[i]) for i in range(4)]),
|
|
527
515
|
),
|
|
528
516
|
expected_circuit=cirq.Circuit(
|
|
529
|
-
cirq.Moment(
|
|
530
|
-
cirq.Moment(
|
|
517
|
+
cirq.Moment(X(qubits[0])),
|
|
518
|
+
cirq.Moment(Y(qubits[1]), X(qubits[0])),
|
|
531
519
|
cirq.Moment(cirq.SWAP(*qubits[0:2])),
|
|
532
|
-
cirq.Moment([cirq.SWAP(*qubits[1:3])] + [
|
|
533
|
-
cirq.Moment([cirq.SWAP(*qubits[2:4])] + [
|
|
534
|
-
cirq.Moment(
|
|
520
|
+
cirq.Moment([cirq.SWAP(*qubits[1:3])] + [X(qubits[0])]),
|
|
521
|
+
cirq.Moment([cirq.SWAP(*qubits[2:4])] + [X(qubits[0]), X(qubits[1])]),
|
|
522
|
+
cirq.Moment(X(qubits[0]), cirq.I(qubits[1]), X(qubits[2]), cirq.I(qubits[3])),
|
|
535
523
|
),
|
|
536
524
|
schema='XX_PAIR',
|
|
537
525
|
single_qubit_gate_moments_only=False,
|
|
@@ -553,30 +541,29 @@ def test_multiple_clifford_pieces_case1():
|
|
|
553
541
|
b = cirq.NamedQubit('b')
|
|
554
542
|
assert_dd(
|
|
555
543
|
input_circuit=cirq.Circuit(
|
|
556
|
-
cirq.Moment(
|
|
557
|
-
cirq.Moment(
|
|
558
|
-
cirq.Moment(
|
|
559
|
-
cirq.Moment(
|
|
560
|
-
cirq.Moment(
|
|
561
|
-
cirq.Moment(
|
|
562
|
-
cirq.Moment(
|
|
563
|
-
cirq.Moment(
|
|
564
|
-
cirq.Moment(
|
|
544
|
+
cirq.Moment(H(a), H(b)),
|
|
545
|
+
cirq.Moment(H(b)),
|
|
546
|
+
cirq.Moment(H(a), H(b)),
|
|
547
|
+
cirq.Moment(H(b)),
|
|
548
|
+
cirq.Moment(CZPowGate(exponent=0.5).on(a, b)),
|
|
549
|
+
cirq.Moment(H(b)),
|
|
550
|
+
cirq.Moment(H(a), H(b)),
|
|
551
|
+
cirq.Moment(H(b)),
|
|
552
|
+
cirq.Moment(H(a), H(b)),
|
|
565
553
|
),
|
|
566
554
|
expected_circuit=cirq.Circuit(
|
|
567
|
-
cirq.Moment(
|
|
568
|
-
cirq.Moment(
|
|
569
|
-
cirq.Moment(
|
|
555
|
+
cirq.Moment(H(a), H(b)),
|
|
556
|
+
cirq.Moment(H(b), X(a)),
|
|
557
|
+
cirq.Moment(H(a), H(b)),
|
|
570
558
|
cirq.Moment(
|
|
571
|
-
|
|
572
|
-
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0, z_exponent=-1).on(a),
|
|
559
|
+
H(b), cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0, z_exponent=-1).on(a)
|
|
573
560
|
),
|
|
574
|
-
cirq.Moment(
|
|
575
|
-
cirq.Moment(
|
|
576
|
-
cirq.Moment(
|
|
577
|
-
cirq.Moment(
|
|
561
|
+
cirq.Moment(CZPowGate(exponent=0.5).on(a, b)),
|
|
562
|
+
cirq.Moment(H(b), X(a)),
|
|
563
|
+
cirq.Moment(H(a), H(b)),
|
|
564
|
+
cirq.Moment(H(b), X(a)),
|
|
578
565
|
cirq.Moment(
|
|
579
|
-
|
|
566
|
+
H(b),
|
|
580
567
|
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0.5, z_exponent=-1).on(a),
|
|
581
568
|
),
|
|
582
569
|
),
|
|
@@ -601,19 +588,19 @@ def test_multiple_clifford_pieces_case2():
|
|
|
601
588
|
|
|
602
589
|
assert_dd(
|
|
603
590
|
input_circuit=cirq.Circuit(
|
|
604
|
-
cirq.Moment(
|
|
591
|
+
cirq.Moment(CZ(a, b)),
|
|
605
592
|
cirq.Moment(phased_xz_gate.on(a)),
|
|
606
593
|
cirq.Moment(phased_xz_gate.on(a)),
|
|
607
594
|
cirq.Moment(phased_xz_gate.on(a)),
|
|
608
|
-
cirq.Moment(
|
|
595
|
+
cirq.Moment(CZ(a, b)),
|
|
609
596
|
),
|
|
610
597
|
expected_circuit=cirq.Circuit(
|
|
611
|
-
cirq.Moment(
|
|
612
|
-
cirq.Moment(phased_xz_gate.on(a),
|
|
613
|
-
cirq.Moment(phased_xz_gate.on(a),
|
|
614
|
-
cirq.Moment(phased_xz_gate.on(a),
|
|
615
|
-
cirq.Moment(
|
|
616
|
-
cirq.Moment(
|
|
598
|
+
cirq.Moment(CZ(a, b)),
|
|
599
|
+
cirq.Moment(phased_xz_gate.on(a), X(b)),
|
|
600
|
+
cirq.Moment(phased_xz_gate.on(a), X(b)),
|
|
601
|
+
cirq.Moment(phased_xz_gate.on(a), X(b)),
|
|
602
|
+
cirq.Moment(CZ(a, b)),
|
|
603
|
+
cirq.Moment(Z(a), X(b)),
|
|
617
604
|
),
|
|
618
605
|
schema='XX_PAIR',
|
|
619
606
|
single_qubit_gate_moments_only=False,
|
|
@@ -640,20 +627,20 @@ def test_insert_new_moment():
|
|
|
640
627
|
c = cirq.NamedQubit('c')
|
|
641
628
|
assert_dd(
|
|
642
629
|
input_circuit=cirq.Circuit(
|
|
643
|
-
cirq.Moment(
|
|
644
|
-
cirq.Moment(
|
|
645
|
-
cirq.Moment(
|
|
646
|
-
cirq.Moment(
|
|
647
|
-
cirq.Moment(
|
|
630
|
+
cirq.Moment(H(a), H(b), H(c)),
|
|
631
|
+
cirq.Moment(H(b)),
|
|
632
|
+
cirq.Moment(H(b), H(a)),
|
|
633
|
+
cirq.Moment(CNOT(a, b)),
|
|
634
|
+
cirq.Moment(CZPowGate(exponent=0.5).on(a, b), H(c)),
|
|
648
635
|
),
|
|
649
636
|
expected_circuit=cirq.Circuit(
|
|
650
|
-
cirq.Moment(
|
|
651
|
-
cirq.Moment(
|
|
652
|
-
cirq.Moment(
|
|
653
|
-
cirq.Moment(
|
|
654
|
-
cirq.Moment(
|
|
637
|
+
cirq.Moment(H(a), H(b), H(c)),
|
|
638
|
+
cirq.Moment(H(b), X(a), X(c)),
|
|
639
|
+
cirq.Moment(H(a), H(b), X(c)),
|
|
640
|
+
cirq.Moment(CNOT(a, b)),
|
|
641
|
+
cirq.Moment(Z(a), X(c)),
|
|
655
642
|
cirq.Moment(
|
|
656
|
-
|
|
643
|
+
CZPowGate(exponent=0.5).on(a, b),
|
|
657
644
|
cirq.PhasedXZGate(axis_phase_exponent=-0.5, x_exponent=0.5, z_exponent=0).on(c),
|
|
658
645
|
),
|
|
659
646
|
),
|
|
@@ -683,22 +670,22 @@ def test_with_non_clifford_measurements():
|
|
|
683
670
|
qubits = cirq.LineQubit.range(4)
|
|
684
671
|
assert_dd(
|
|
685
672
|
input_circuit=cirq.Circuit(
|
|
686
|
-
cirq.Moment([
|
|
687
|
-
cirq.Moment(
|
|
688
|
-
cirq.Moment([
|
|
689
|
-
cirq.Moment(
|
|
690
|
-
cirq.Moment([
|
|
673
|
+
cirq.Moment([H(qubits[i]) for i in [1, 2]]),
|
|
674
|
+
cirq.Moment(CZ(*qubits[1:3])),
|
|
675
|
+
cirq.Moment([H(qubits[i]) for i in [0, 2, 3]]),
|
|
676
|
+
cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[2:])),
|
|
677
|
+
cirq.Moment([H(qubits[i]) for i in [0, 3]]),
|
|
691
678
|
cirq.Moment([cirq.M(qubits[i]) for i in [0, 1, 2, 3]]),
|
|
692
679
|
),
|
|
693
680
|
expected_circuit=cirq.Circuit(
|
|
694
|
-
cirq.Moment([
|
|
695
|
-
cirq.Moment(
|
|
696
|
-
cirq.Moment([
|
|
697
|
-
cirq.Moment(
|
|
681
|
+
cirq.Moment([H(qubits[i]) for i in [1, 2]]),
|
|
682
|
+
cirq.Moment(CZ(*qubits[1:3])),
|
|
683
|
+
cirq.Moment([H(qubits[i]) for i in [0, 2, 3]] + [X(qubits[1])]),
|
|
684
|
+
cirq.Moment(CZ(*qubits[0:2]), CZ(*qubits[2:])),
|
|
698
685
|
cirq.Moment(
|
|
699
|
-
|
|
686
|
+
H(qubits[3]),
|
|
700
687
|
cirq.I(qubits[2]),
|
|
701
|
-
|
|
688
|
+
X(qubits[1]),
|
|
702
689
|
cirq.PhasedXZGate(axis_phase_exponent=0.5, x_exponent=0.5, z_exponent=0).on(
|
|
703
690
|
qubits[0]
|
|
704
691
|
),
|
|
@@ -711,7 +698,6 @@ def test_with_non_clifford_measurements():
|
|
|
711
698
|
|
|
712
699
|
|
|
713
700
|
def test_cross_clifford_pieces_filling_merge():
|
|
714
|
-
# pylint: disable=line-too-long
|
|
715
701
|
"""Test case diagrams.
|
|
716
702
|
Input:
|
|
717
703
|
0: ─────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───@─────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───@───PhXZ(a=0.2,x=0.2,z=0.1)───H───
|
|
@@ -742,23 +728,22 @@ def test_cross_clifford_pieces_filling_merge():
|
|
|
742
728
|
5: ───PhXZ(a=0.2,x=0.2,z=0.1)───@───PhXZ(a=0.2,x=0.2,z=0.1)───@─────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───@───PhXZ(a=-0.8,x=0.2,z=-0.9)───H────────────────────────
|
|
743
729
|
│
|
|
744
730
|
6: ───────────────────────────────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───X─────────────────────────@───PhXZ(a=0.8,x=0.8,z=0.5)─────H────────────────────────
|
|
745
|
-
"""
|
|
746
|
-
# pylint: enable
|
|
731
|
+
""" # noqa: E501
|
|
747
732
|
qubits = cirq.LineQubit.range(7)
|
|
748
733
|
phased_xz_gate = cirq.PhasedXZGate(axis_phase_exponent=0.2, x_exponent=0.2, z_exponent=0.1)
|
|
749
734
|
assert_dd(
|
|
750
735
|
input_circuit=cirq.Circuit(
|
|
751
736
|
cirq.Moment([phased_xz_gate.on(qubits[i]) for i in [2, 5]]),
|
|
752
|
-
cirq.Moment(
|
|
737
|
+
cirq.Moment(CZ(qubits[2], qubits[5])),
|
|
753
738
|
cirq.Moment([phased_xz_gate.on(qubits[i]) for i in [0, 1, 2, 3, 5]]),
|
|
754
739
|
cirq.Moment(
|
|
755
|
-
[
|
|
740
|
+
[CZ(qubits[i0], qubits[i1]) for i0, i1 in [(0, 1), (2, 3), (4, 5)]]
|
|
756
741
|
+ [phased_xz_gate.on(qubits[6])]
|
|
757
742
|
),
|
|
758
743
|
cirq.Moment([phased_xz_gate.on(qubits[i]) for i in [0, 1, 2, 5]]),
|
|
759
|
-
cirq.Moment([
|
|
744
|
+
cirq.Moment([CZ(qubits[i0], qubits[i1]) for i0, i1 in [(0, 1), (2, 3), (5, 6)]]),
|
|
760
745
|
cirq.Moment([phased_xz_gate.on(qubits[i]) for i in [0, 1, 5, 6]]),
|
|
761
|
-
cirq.Moment([
|
|
746
|
+
cirq.Moment([H.on(q) for q in qubits]),
|
|
762
747
|
),
|
|
763
748
|
expected_circuit="""
|
|
764
749
|
0: ─────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───@─────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───@───PhXZ(a=0.2,x=0.2,z=0.1)─────H────────────────────────
|
|
@@ -774,7 +759,7 @@ def test_cross_clifford_pieces_filling_merge():
|
|
|
774
759
|
5: ───PhXZ(a=0.2,x=0.2,z=0.1)───@───PhXZ(a=0.2,x=0.2,z=0.1)───@─────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───@───PhXZ(a=-0.8,x=0.2,z=-0.9)───H────────────────────────
|
|
775
760
|
│
|
|
776
761
|
6: ───────────────────────────────────────────────────────────PhXZ(a=0.2,x=0.2,z=0.1)───X─────────────────────────@───PhXZ(a=0.8,x=0.8,z=0.5)─────H────────────────────────
|
|
777
|
-
""",
|
|
762
|
+
""", # noqa: E501
|
|
778
763
|
)
|
|
779
764
|
|
|
780
765
|
|
|
@@ -792,11 +777,11 @@ def test_pull_through_phxz_gate_case1():
|
|
|
792
777
|
phxz = cirq.PhasedXZGate(axis_phase_exponent=0.25, x_exponent=-1, z_exponent=0)
|
|
793
778
|
assert_dd(
|
|
794
779
|
input_circuit=cirq.Circuit(
|
|
795
|
-
cirq.Moment(
|
|
796
|
-
cirq.Moment(
|
|
797
|
-
cirq.Moment(phxz(a),
|
|
798
|
-
cirq.Moment(
|
|
799
|
-
cirq.Moment(
|
|
780
|
+
cirq.Moment(H(a), H(b)),
|
|
781
|
+
cirq.Moment(H(b)),
|
|
782
|
+
cirq.Moment(phxz(a), H(b)),
|
|
783
|
+
cirq.Moment(H(b)),
|
|
784
|
+
cirq.Moment(CNOT(a, b)),
|
|
800
785
|
),
|
|
801
786
|
expected_circuit="""
|
|
802
787
|
a: ───H───X───PhXZ(a=0.25,x=-1,z=0)───X───@───Z───
|
|
@@ -821,11 +806,11 @@ def test_pull_through_phxz_gate_case2():
|
|
|
821
806
|
phxz = cirq.PhasedXZGate(axis_phase_exponent=0.2, x_exponent=-1, z_exponent=0)
|
|
822
807
|
assert_dd(
|
|
823
808
|
input_circuit=cirq.Circuit(
|
|
824
|
-
cirq.Moment(
|
|
825
|
-
cirq.Moment(
|
|
826
|
-
cirq.Moment(phxz(a),
|
|
827
|
-
cirq.Moment(
|
|
828
|
-
cirq.Moment(
|
|
809
|
+
cirq.Moment(H(a), H(b)),
|
|
810
|
+
cirq.Moment(H(b)),
|
|
811
|
+
cirq.Moment(phxz(a), H(b)),
|
|
812
|
+
cirq.Moment(H(b)),
|
|
813
|
+
cirq.Moment(CNOT(a, b)),
|
|
829
814
|
),
|
|
830
815
|
expected_circuit="""
|
|
831
816
|
a: ───H───X───PhXZ(a=0.1,x=0,z=0.4)───X───@───X───
|
|
@@ -834,3 +819,36 @@ b: ───H───H───H───────────────
|
|
|
834
819
|
""",
|
|
835
820
|
schema="XX_PAIR",
|
|
836
821
|
)
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
def test_merge_before_non_cliffords():
|
|
825
|
+
"""Test case diagrams.
|
|
826
|
+
Input circuit:
|
|
827
|
+
0: ───X──────────────────────────────────────────────────M───
|
|
828
|
+
|
|
829
|
+
1: ───X───────PhXZ(a=-1,x=0,z=-0.5)───FSim(0, 0.0637π)───M───
|
|
830
|
+
│
|
|
831
|
+
2: ───X───X───S───────────────────────FSim(0, 0.0637π)───M───
|
|
832
|
+
"""
|
|
833
|
+
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
834
|
+
input_circuit = cirq.Circuit(
|
|
835
|
+
cirq.Moment([X(q) for q in [q0, q1, q2]]),
|
|
836
|
+
cirq.Moment(X(q2)),
|
|
837
|
+
cirq.Moment(
|
|
838
|
+
cirq.PhasedXZGate(axis_phase_exponent=-1, x_exponent=0, z_exponent=-0.5).on(q1),
|
|
839
|
+
(Z**0.5).on(q2),
|
|
840
|
+
),
|
|
841
|
+
cirq.Moment(cirq.FSimGate(theta=0, phi=0.2).on(q1, q2)),
|
|
842
|
+
cirq.Moment([cirq.M(q) for q in [q0, q1, q2]]),
|
|
843
|
+
)
|
|
844
|
+
assert_dd(
|
|
845
|
+
input_circuit=input_circuit,
|
|
846
|
+
expected_circuit="""
|
|
847
|
+
0: ───X───X───X──────────────────────────────────────────M───
|
|
848
|
+
|
|
849
|
+
1: ───X───X───PhXZ(a=-1.25,x=1,z=0)───FSim(0, 0.0637π)───M───
|
|
850
|
+
│
|
|
851
|
+
2: ───X───X───S───────────────────────FSim(0, 0.0637π)───M───
|
|
852
|
+
""",
|
|
853
|
+
schema="XX_PAIR",
|
|
854
|
+
)
|