cirq-core 1.4.1__py3-none-any.whl → 1.5.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 +587 -569
- cirq/_compat.py +9 -0
- cirq/_compat_test.py +11 -9
- cirq/_import.py +7 -8
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/__init__.py +15 -9
- cirq/circuits/_block_diagram_drawer.py +1 -2
- cirq/circuits/_block_diagram_drawer_test.py +3 -3
- cirq/circuits/_box_drawing_character_data.py +0 -1
- cirq/circuits/_box_drawing_character_data_test.py +2 -2
- cirq/circuits/_bucket_priority_queue.py +0 -1
- cirq/circuits/_bucket_priority_queue_test.py +1 -1
- cirq/circuits/circuit.py +336 -234
- cirq/circuits/circuit_operation.py +102 -52
- cirq/circuits/circuit_operation_test.py +85 -4
- cirq/circuits/circuit_test.py +101 -32
- cirq/circuits/frozen_circuit.py +36 -32
- cirq/circuits/insert_strategy.py +10 -0
- cirq/circuits/insert_strategy_test.py +20 -0
- cirq/circuits/moment.py +79 -80
- cirq/circuits/moment_test.py +105 -2
- cirq/circuits/optimization_pass.py +15 -15
- cirq/circuits/optimization_pass_test.py +8 -9
- cirq/circuits/qasm_output.py +64 -33
- cirq/circuits/qasm_output_test.py +63 -2
- cirq/circuits/text_diagram_drawer.py +26 -56
- cirq/circuits/text_diagram_drawer_test.py +5 -4
- cirq/contrib/__init__.py +2 -2
- cirq/contrib/acquaintance/__init__.py +44 -29
- cirq/contrib/acquaintance/bipartite.py +8 -7
- cirq/contrib/acquaintance/bipartite_test.py +11 -1
- cirq/contrib/acquaintance/devices.py +5 -4
- cirq/contrib/acquaintance/devices_test.py +5 -1
- cirq/contrib/acquaintance/executor.py +18 -21
- cirq/contrib/acquaintance/executor_test.py +3 -2
- cirq/contrib/acquaintance/gates.py +36 -27
- cirq/contrib/acquaintance/gates_test.py +1 -1
- cirq/contrib/acquaintance/inspection_utils.py +10 -9
- cirq/contrib/acquaintance/inspection_utils_test.py +6 -1
- cirq/contrib/acquaintance/mutation_utils.py +10 -10
- cirq/contrib/acquaintance/optimizers.py +7 -6
- cirq/contrib/acquaintance/optimizers_test.py +1 -1
- cirq/contrib/acquaintance/permutation.py +22 -21
- cirq/contrib/acquaintance/permutation_test.py +1 -1
- cirq/contrib/acquaintance/shift.py +8 -6
- cirq/contrib/acquaintance/shift_swap_network.py +6 -4
- cirq/contrib/acquaintance/strategies/__init__.py +9 -3
- cirq/contrib/acquaintance/strategies/complete.py +4 -3
- cirq/contrib/acquaintance/strategies/cubic.py +5 -3
- cirq/contrib/acquaintance/strategies/quartic_paired.py +8 -6
- cirq/contrib/acquaintance/topological_sort.py +4 -2
- cirq/contrib/bayesian_network/__init__.py +3 -1
- cirq/contrib/bayesian_network/bayesian_network_gate.py +5 -3
- cirq/contrib/circuitdag/__init__.py +1 -1
- cirq/contrib/circuitdag/circuit_dag.py +24 -24
- cirq/contrib/circuitdag/circuit_dag_test.py +1 -1
- cirq/contrib/custom_simulators/custom_state_simulator.py +10 -8
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +15 -11
- cirq/contrib/graph_device/__init__.py +8 -8
- cirq/contrib/graph_device/graph_device.py +8 -8
- cirq/contrib/graph_device/graph_device_test.py +0 -1
- cirq/contrib/graph_device/hypergraph_test.py +1 -0
- cirq/contrib/json.py +1 -2
- cirq/contrib/json_test.py +2 -2
- cirq/contrib/noise_models/__init__.py +5 -6
- cirq/contrib/noise_models/noise_models.py +8 -6
- cirq/contrib/paulistring/__init__.py +22 -10
- cirq/contrib/paulistring/clifford_optimize.py +1 -1
- cirq/contrib/paulistring/clifford_optimize_test.py +0 -1
- cirq/contrib/paulistring/clifford_target_gateset.py +15 -12
- cirq/contrib/paulistring/optimize.py +2 -2
- cirq/contrib/paulistring/optimize_test.py +0 -1
- cirq/contrib/paulistring/pauli_string_dag_test.py +0 -1
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +379 -0
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +523 -0
- cirq/contrib/paulistring/pauli_string_optimize.py +3 -1
- cirq/contrib/paulistring/pauli_string_optimize_test.py +1 -3
- cirq/contrib/paulistring/recombine.py +2 -2
- cirq/contrib/paulistring/recombine_test.py +2 -2
- cirq/contrib/paulistring/separate.py +3 -4
- cirq/contrib/qasm_import/__init__.py +2 -2
- cirq/contrib/qasm_import/_lexer.py +21 -26
- cirq/contrib/qasm_import/_lexer_test.py +90 -6
- cirq/contrib/qasm_import/_parser.py +238 -47
- cirq/contrib/qasm_import/_parser_test.py +514 -59
- cirq/contrib/qasm_import/qasm_test.py +1 -1
- cirq/contrib/qcircuit/__init__.py +6 -4
- cirq/contrib/qcircuit/qcircuit_diagram.py +5 -2
- cirq/contrib/qcircuit/qcircuit_pdf.py +1 -2
- cirq/{experiments/grid_parallel_two_qubit_xeb_test.py → contrib/qcircuit/qcircuit_pdf_test.py} +13 -12
- cirq/contrib/qcircuit/qcircuit_test.py +1 -1
- cirq/contrib/quantum_volume/__init__.py +7 -7
- cirq/contrib/quantum_volume/quantum_volume.py +6 -11
- cirq/contrib/quantum_volume/quantum_volume_test.py +3 -1
- cirq/contrib/quimb/__init__.py +16 -13
- cirq/contrib/quimb/density_matrix.py +1 -1
- cirq/contrib/quimb/mps_simulator.py +27 -28
- cirq/contrib/quimb/mps_simulator_test.py +5 -0
- cirq/contrib/quimb/state_vector.py +3 -10
- cirq/contrib/quirk/__init__.py +1 -1
- cirq/contrib/quirk/export_to_quirk.py +3 -3
- cirq/contrib/routing/__init__.py +12 -9
- cirq/contrib/routing/device.py +1 -1
- cirq/contrib/routing/device_test.py +1 -2
- cirq/contrib/routing/greedy.py +7 -5
- cirq/contrib/routing/greedy_test.py +5 -3
- cirq/contrib/routing/initialization.py +3 -1
- cirq/contrib/routing/initialization_test.py +1 -1
- cirq/contrib/routing/swap_network.py +6 -6
- cirq/contrib/routing/utils.py +6 -4
- cirq/contrib/routing/utils_test.py +1 -2
- cirq/{type_workarounds.py → contrib/shuffle_circuits/__init__.py} +5 -10
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +250 -0
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +363 -0
- cirq/contrib/svg/__init__.py +1 -1
- cirq/contrib/svg/svg.py +12 -10
- cirq/contrib/svg/svg_test.py +3 -2
- cirq/devices/__init__.py +34 -25
- cirq/devices/device.py +16 -12
- cirq/devices/device_test.py +1 -0
- cirq/devices/grid_device_metadata.py +16 -12
- cirq/devices/grid_device_metadata_test.py +2 -1
- cirq/devices/grid_qubit.py +31 -26
- cirq/devices/grid_qubit_test.py +30 -1
- cirq/devices/insertion_noise_model.py +6 -6
- cirq/devices/insertion_noise_model_test.py +1 -1
- cirq/devices/line_qubit.py +28 -20
- cirq/devices/line_qubit_test.py +26 -0
- cirq/devices/named_topologies.py +12 -10
- cirq/devices/named_topologies_test.py +5 -4
- cirq/devices/noise_model.py +29 -33
- cirq/devices/noise_properties.py +2 -2
- cirq/devices/noise_properties_test.py +2 -2
- cirq/devices/noise_utils.py +3 -3
- cirq/devices/superconducting_qubits_noise_properties.py +2 -2
- cirq/devices/superconducting_qubits_noise_properties_test.py +3 -3
- cirq/devices/thermal_noise_model.py +2 -1
- cirq/devices/unconstrained_device.py +1 -1
- cirq/devices/unconstrained_device_test.py +6 -0
- cirq/experiments/__init__.py +51 -34
- cirq/experiments/qubit_characterizations.py +17 -15
- cirq/experiments/qubit_characterizations_test.py +4 -6
- cirq/experiments/random_quantum_circuit_generation.py +10 -9
- cirq/experiments/random_quantum_circuit_generation_test.py +21 -4
- cirq/experiments/readout_confusion_matrix.py +73 -8
- cirq/experiments/readout_confusion_matrix_test.py +104 -1
- cirq/experiments/single_qubit_readout_calibration.py +8 -6
- cirq/experiments/single_qubit_readout_calibration_test.py +1 -1
- cirq/experiments/t1_decay_experiment.py +4 -5
- cirq/experiments/t1_decay_experiment_test.py +1 -2
- cirq/experiments/t2_decay_experiment.py +0 -1
- cirq/experiments/t2_decay_experiment_test.py +1 -2
- cirq/experiments/two_qubit_xeb.py +157 -33
- cirq/experiments/two_qubit_xeb_test.py +38 -22
- cirq/experiments/xeb_fitting.py +99 -19
- cirq/experiments/xeb_fitting_test.py +64 -25
- cirq/experiments/xeb_sampling.py +14 -18
- cirq/experiments/xeb_simulation.py +4 -3
- cirq/experiments/xeb_simulation_test.py +20 -14
- cirq/experiments/z_phase_calibration.py +368 -0
- cirq/experiments/z_phase_calibration_test.py +241 -0
- cirq/interop/__init__.py +4 -1
- cirq/interop/quirk/__init__.py +7 -4
- cirq/interop/quirk/cells/__init__.py +17 -6
- cirq/interop/quirk/cells/arithmetic_cells.py +8 -8
- cirq/interop/quirk/cells/arithmetic_cells_test.py +1 -1
- cirq/interop/quirk/cells/cell.py +6 -6
- cirq/interop/quirk/cells/composite_cell.py +5 -5
- cirq/interop/quirk/cells/composite_cell_test.py +1 -1
- cirq/interop/quirk/cells/control_cells.py +1 -1
- cirq/interop/quirk/cells/frequency_space_cells.py +2 -2
- cirq/interop/quirk/cells/ignored_cells.py +1 -1
- cirq/interop/quirk/cells/input_cells.py +1 -1
- cirq/interop/quirk/cells/input_cells_test.py +1 -1
- cirq/interop/quirk/cells/input_rotation_cells.py +1 -1
- cirq/interop/quirk/cells/input_rotation_cells_test.py +1 -1
- cirq/interop/quirk/cells/measurement_cells.py +1 -1
- cirq/interop/quirk/cells/parse.py +8 -7
- cirq/interop/quirk/cells/parse_test.py +2 -2
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +1 -1
- cirq/interop/quirk/cells/swap_cell_test.py +1 -1
- cirq/interop/quirk/cells/unsupported_cells.py +1 -1
- cirq/interop/quirk/url_to_circuit.py +7 -7
- cirq/interop/quirk/url_to_circuit_test.py +1 -1
- cirq/ion/__init__.py +4 -2
- cirq/json_resolver_cache.py +15 -7
- cirq/linalg/__init__.py +62 -51
- cirq/linalg/combinators.py +4 -4
- cirq/linalg/combinators_test.py +4 -1
- cirq/linalg/decompositions.py +15 -40
- cirq/linalg/decompositions_test.py +16 -22
- cirq/linalg/diagonalize.py +1 -1
- cirq/linalg/diagonalize_test.py +1 -1
- cirq/linalg/operator_spaces.py +20 -4
- cirq/linalg/operator_spaces_test.py +15 -2
- cirq/linalg/predicates.py +3 -3
- cirq/linalg/predicates_test.py +1 -0
- cirq/linalg/tolerance.py +2 -2
- cirq/linalg/transformations.py +30 -12
- cirq/linalg/transformations_test.py +13 -0
- cirq/neutral_atoms/__init__.py +2 -2
- cirq/neutral_atoms/convert_to_neutral_atom_gates_test.py +0 -1
- cirq/ops/__init__.py +172 -132
- cirq/ops/arithmetic_operation.py +2 -2
- cirq/ops/arithmetic_operation_test.py +2 -2
- cirq/ops/boolean_hamiltonian.py +3 -2
- cirq/ops/classically_controlled_operation.py +39 -12
- cirq/ops/classically_controlled_operation_test.py +147 -1
- cirq/ops/clifford_gate.py +38 -36
- cirq/ops/clifford_gate_test.py +75 -1
- cirq/ops/common_channels.py +16 -45
- cirq/ops/common_channels_test.py +10 -0
- cirq/ops/common_gate_families.py +1 -1
- cirq/ops/common_gate_families_test.py +1 -0
- cirq/ops/common_gates.py +48 -49
- cirq/ops/common_gates_test.py +18 -2
- cirq/ops/control_values.py +3 -3
- cirq/ops/control_values_test.py +2 -1
- cirq/ops/controlled_gate.py +36 -23
- cirq/ops/controlled_gate_test.py +70 -3
- cirq/ops/controlled_operation.py +6 -5
- cirq/ops/controlled_operation_test.py +7 -3
- cirq/ops/dense_pauli_string.py +11 -11
- cirq/ops/diagonal_gate.py +2 -2
- cirq/ops/diagonal_gate_test.py +1 -0
- cirq/ops/eigen_gate.py +16 -36
- cirq/ops/eigen_gate_test.py +60 -10
- cirq/ops/fourier_transform.py +1 -3
- cirq/ops/fourier_transform_test.py +2 -1
- cirq/ops/fsim_gate.py +42 -3
- cirq/ops/fsim_gate_test.py +21 -0
- cirq/ops/gate_operation.py +8 -8
- cirq/ops/gate_operation_test.py +4 -2
- cirq/ops/gateset_test.py +11 -2
- cirq/ops/global_phase_op.py +8 -7
- cirq/ops/global_phase_op_test.py +1 -1
- cirq/ops/greedy_qubit_manager_test.py +5 -0
- cirq/ops/identity.py +14 -4
- cirq/ops/identity_test.py +24 -0
- cirq/ops/kraus_channel.py +1 -0
- cirq/ops/kraus_channel_test.py +3 -1
- cirq/ops/linear_combinations.py +27 -21
- cirq/ops/linear_combinations_test.py +23 -4
- cirq/ops/matrix_gates.py +24 -8
- cirq/ops/measure_util.py +2 -2
- cirq/ops/measurement_gate.py +7 -4
- cirq/ops/measurement_gate_test.py +2 -1
- cirq/ops/mixed_unitary_channel.py +1 -0
- cirq/ops/mixed_unitary_channel_test.py +3 -1
- cirq/ops/named_qubit.py +8 -1
- cirq/ops/op_tree.py +3 -30
- cirq/ops/op_tree_test.py +4 -0
- cirq/ops/parallel_gate.py +2 -3
- cirq/ops/parallel_gate_test.py +2 -1
- cirq/ops/parity_gates.py +7 -8
- cirq/ops/parity_gates_test.py +1 -0
- cirq/ops/pauli_gates.py +5 -11
- cirq/ops/pauli_gates_test.py +1 -0
- cirq/ops/pauli_interaction_gate.py +11 -5
- cirq/ops/pauli_interaction_gate_test.py +2 -3
- cirq/ops/pauli_measurement_gate.py +6 -5
- cirq/ops/pauli_measurement_gate_test.py +1 -0
- cirq/ops/pauli_string.py +115 -130
- cirq/ops/pauli_string_phasor.py +21 -20
- cirq/ops/pauli_string_phasor_test.py +13 -3
- cirq/ops/pauli_string_raw_types.py +1 -0
- cirq/ops/pauli_string_test.py +192 -55
- cirq/ops/pauli_sum_exponential.py +3 -4
- cirq/ops/pauli_sum_exponential_test.py +0 -1
- cirq/ops/permutation_gate.py +2 -2
- cirq/ops/permutation_gate_test.py +1 -1
- cirq/ops/phased_iswap_gate.py +6 -7
- cirq/ops/phased_iswap_gate_test.py +21 -5
- cirq/ops/phased_x_gate.py +11 -25
- cirq/ops/phased_x_gate_test.py +19 -3
- cirq/ops/phased_x_z_gate.py +12 -11
- cirq/ops/projector.py +4 -5
- cirq/ops/qubit_manager.py +2 -1
- cirq/ops/qubit_manager_test.py +2 -1
- cirq/ops/qubit_order.py +1 -1
- cirq/ops/random_gate_channel.py +1 -1
- cirq/ops/random_gate_channel_test.py +0 -6
- cirq/ops/raw_types.py +146 -50
- cirq/ops/raw_types_test.py +37 -3
- cirq/ops/state_preparation_channel.py +2 -2
- cirq/ops/state_preparation_channel_test.py +2 -1
- cirq/ops/swap_gates.py +9 -4
- cirq/ops/three_qubit_gates.py +8 -8
- cirq/ops/three_qubit_gates_test.py +1 -0
- cirq/ops/two_qubit_diagonal_gate.py +4 -3
- cirq/ops/uniform_superposition_gate.py +4 -4
- cirq/ops/uniform_superposition_gate_test.py +1 -0
- cirq/ops/wait_gate.py +6 -8
- cirq/protocols/__init__.py +135 -83
- cirq/protocols/act_on_protocol.py +1 -1
- cirq/protocols/act_on_protocol_test.py +1 -1
- cirq/protocols/apply_channel_protocol.py +3 -3
- cirq/protocols/apply_mixture_protocol.py +15 -9
- cirq/protocols/apply_mixture_protocol_test.py +11 -0
- cirq/protocols/apply_unitary_protocol.py +2 -2
- cirq/protocols/apply_unitary_protocol_test.py +2 -1
- cirq/protocols/approximate_equality_protocol.py +7 -8
- cirq/protocols/approximate_equality_protocol_test.py +3 -1
- cirq/protocols/circuit_diagram_info_protocol.py +8 -6
- cirq/protocols/circuit_diagram_info_protocol_test.py +5 -0
- cirq/protocols/commutes_protocol.py +6 -6
- cirq/protocols/control_key_protocol.py +1 -1
- cirq/protocols/decompose_protocol.py +4 -5
- cirq/protocols/decompose_protocol_test.py +2 -1
- cirq/protocols/equal_up_to_global_phase_protocol.py +3 -3
- cirq/protocols/equal_up_to_global_phase_protocol_test.py +7 -0
- cirq/protocols/has_stabilizer_effect_protocol.py +5 -5
- cirq/protocols/has_unitary_protocol.py +1 -1
- cirq/protocols/has_unitary_protocol_test.py +8 -7
- cirq/protocols/hash_from_pickle_test.py +120 -0
- cirq/protocols/inverse_protocol.py +1 -1
- cirq/protocols/json_serialization.py +14 -1
- cirq/protocols/json_serialization_test.py +28 -7
- cirq/protocols/json_test_data/BitMaskKeyCondition.json +86 -0
- cirq/protocols/json_test_data/BitMaskKeyCondition.repr +7 -0
- cirq/protocols/json_test_data/Concat.json +19 -0
- cirq/protocols/json_test_data/Concat.repr +1 -0
- cirq/protocols/json_test_data/README.md +4 -2
- cirq/protocols/json_test_data/SympyCondition.json +60 -15
- cirq/protocols/json_test_data/SympyCondition.repr +4 -1
- cirq/protocols/json_test_data/_InverseCompositeGate.json +10 -0
- cirq/protocols/json_test_data/_InverseCompositeGate.repr +1 -0
- cirq/protocols/json_test_data/__init__.py +1 -1
- cirq/protocols/json_test_data/sympy.And.json +13 -0
- cirq/protocols/json_test_data/sympy.And.repr +1 -0
- cirq/protocols/json_test_data/sympy.Indexed.json +18 -0
- cirq/protocols/json_test_data/sympy.Indexed.repr +1 -0
- cirq/protocols/json_test_data/sympy.IndexedBase.json +9 -0
- cirq/protocols/json_test_data/sympy.IndexedBase.repr +1 -0
- cirq/protocols/json_test_data/sympy.Not.json +9 -0
- cirq/protocols/json_test_data/sympy.Not.repr +1 -0
- cirq/protocols/json_test_data/sympy.Or.json +13 -0
- cirq/protocols/json_test_data/sympy.Or.repr +1 -0
- cirq/protocols/json_test_data/sympy.Xor.json +13 -0
- cirq/protocols/json_test_data/sympy.Xor.repr +1 -0
- cirq/protocols/kraus_protocol.py +8 -8
- cirq/protocols/kraus_protocol_test.py +0 -1
- cirq/protocols/measurement_key_protocol.py +1 -1
- cirq/protocols/measurement_key_protocol_test.py +7 -7
- cirq/protocols/mixture_protocol.py +6 -4
- cirq/protocols/mixture_protocol_test.py +21 -13
- cirq/protocols/pauli_expansion_protocol.py +1 -0
- cirq/protocols/pow_protocol.py +1 -1
- cirq/protocols/qasm.py +25 -6
- cirq/protocols/qasm_test.py +17 -0
- cirq/protocols/qid_shape_protocol.py +2 -2
- cirq/protocols/resolve_parameters.py +2 -3
- cirq/protocols/resolve_parameters_test.py +2 -1
- cirq/protocols/trace_distance_bound.py +1 -1
- cirq/protocols/trace_distance_bound_test.py +1 -0
- cirq/protocols/unitary_protocol.py +3 -3
- cirq/protocols/unitary_protocol_test.py +1 -1
- cirq/qis/__init__.py +48 -35
- cirq/qis/channels_test.py +0 -9
- cirq/qis/clifford_tableau.py +46 -26
- cirq/qis/clifford_tableau_test.py +2 -1
- cirq/qis/entropy.py +115 -0
- cirq/qis/entropy_test.py +43 -0
- cirq/qis/measures.py +5 -4
- cirq/qis/measures_test.py +7 -0
- cirq/qis/noise_utils_test.py +4 -4
- cirq/qis/quantum_state_representation.py +1 -1
- cirq/qis/states.py +7 -7
- cirq/sim/__init__.py +55 -37
- cirq/sim/classical_simulator.py +7 -6
- cirq/sim/classical_simulator_test.py +3 -1
- cirq/sim/clifford/__init__.py +17 -9
- cirq/sim/clifford/clifford_simulator.py +5 -4
- cirq/sim/clifford/clifford_simulator_test.py +32 -9
- cirq/sim/clifford/clifford_tableau_simulation_state.py +1 -1
- cirq/sim/clifford/stabilizer_simulation_state.py +1 -1
- cirq/sim/clifford/stabilizer_state_ch_form.py +4 -3
- cirq/sim/density_matrix_simulator.py +3 -2
- cirq/sim/density_matrix_simulator_test.py +12 -4
- cirq/sim/density_matrix_utils.py +1 -1
- cirq/sim/mux.py +2 -2
- cirq/sim/simulation_state.py +4 -5
- cirq/sim/simulation_state_base.py +2 -2
- cirq/sim/simulation_state_test.py +1 -1
- cirq/sim/simulation_utils.py +3 -1
- cirq/sim/simulation_utils_test.py +2 -3
- cirq/sim/simulator.py +7 -6
- cirq/sim/simulator_base.py +5 -5
- cirq/sim/simulator_test.py +14 -3
- cirq/sim/sparse_simulator.py +4 -3
- cirq/sim/sparse_simulator_test.py +17 -9
- cirq/sim/state_vector.py +2 -2
- cirq/sim/state_vector_simulation_state_test.py +1 -1
- cirq/sim/state_vector_simulator.py +4 -4
- cirq/sim/state_vector_test.py +27 -32
- cirq/study/__init__.py +27 -21
- cirq/study/flatten_expressions.py +5 -6
- cirq/study/flatten_expressions_test.py +1 -1
- cirq/study/resolver.py +14 -11
- cirq/study/resolver_test.py +10 -1
- cirq/study/result.py +3 -3
- cirq/study/sweepable.py +15 -9
- cirq/study/sweepable_test.py +27 -0
- cirq/study/sweeps.py +65 -10
- cirq/study/sweeps_test.py +123 -0
- cirq/testing/__init__.py +86 -57
- cirq/testing/_compat_test_data/module_a/__init__.py +2 -2
- cirq/testing/_compat_test_data/module_a/sub/subsub/__init__.py +1 -1
- cirq/testing/circuit_compare.py +3 -4
- cirq/testing/circuit_compare_test.py +7 -8
- cirq/testing/consistent_act_on.py +3 -3
- cirq/testing/consistent_channels_test.py +2 -1
- cirq/testing/consistent_controlled_gate_op.py +3 -2
- cirq/testing/consistent_controlled_gate_op_test.py +2 -3
- cirq/testing/consistent_decomposition.py +1 -1
- cirq/testing/consistent_decomposition_test.py +1 -2
- cirq/testing/consistent_pauli_expansion_test.py +1 -1
- cirq/testing/consistent_phase_by.py +1 -1
- cirq/testing/consistent_phase_by_test.py +1 -2
- cirq/testing/consistent_protocols.py +11 -11
- cirq/testing/consistent_protocols_test.py +4 -5
- cirq/testing/consistent_qasm.py +8 -12
- cirq/testing/consistent_qasm_test.py +1 -1
- cirq/testing/consistent_resolve_parameters.py +2 -1
- cirq/testing/consistent_specified_has_unitary_test.py +1 -1
- cirq/testing/consistent_unitary.py +3 -1
- cirq/testing/consistent_unitary_test.py +3 -3
- cirq/testing/devices.py +1 -1
- cirq/testing/devices_test.py +1 -0
- cirq/testing/equals_tester.py +2 -4
- cirq/testing/equals_tester_test.py +6 -5
- cirq/testing/equivalent_basis_map.py +1 -0
- cirq/testing/equivalent_basis_map_test.py +0 -1
- cirq/testing/gate_features_test.py +5 -0
- cirq/testing/json.py +4 -4
- cirq/testing/lin_alg_utils_test.py +1 -1
- cirq/testing/order_tester.py +1 -1
- cirq/testing/order_tester_test.py +1 -1
- cirq/testing/pytest_utils.py +57 -0
- cirq/testing/pytest_utils_test.py +35 -0
- cirq/testing/random_circuit.py +2 -2
- cirq/testing/random_circuit_test.py +2 -2
- cirq/testing/routing_devices_test.py +2 -1
- cirq/testing/sample_circuits.py +1 -1
- cirq/testing/sample_gates.py +5 -4
- cirq/testing/sample_gates_test.py +2 -2
- cirq/transformers/__init__.py +101 -82
- cirq/transformers/align.py +12 -1
- cirq/transformers/align_test.py +13 -0
- cirq/transformers/analytical_decompositions/__init__.py +27 -24
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +2 -1
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +1 -1
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +1 -1
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +1 -1
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +1 -1
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +2 -2
- cirq/transformers/analytical_decompositions/pauli_string_decomposition_test.py +4 -4
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +99 -24
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +105 -14
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +1 -1
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +1 -1
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +1 -0
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +3 -4
- cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py +1 -1
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +5 -6
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +2 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +1 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py +1 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +2 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +2 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +2 -1
- cirq/transformers/drop_empty_moments.py +1 -0
- cirq/transformers/drop_negligible_operations.py +1 -0
- cirq/transformers/dynamical_decoupling.py +255 -43
- cirq/transformers/dynamical_decoupling_test.py +730 -17
- cirq/transformers/eject_phased_paulis.py +29 -15
- cirq/transformers/eject_phased_paulis_test.py +3 -8
- cirq/transformers/eject_z.py +3 -2
- cirq/transformers/eject_z_test.py +3 -3
- cirq/transformers/gauge_compiling/__init__.py +25 -9
- cirq/transformers/gauge_compiling/cphase_gauge.py +146 -0
- cirq/transformers/gauge_compiling/cphase_gauge_test.py +42 -0
- cirq/transformers/gauge_compiling/cz_gauge.py +4 -4
- cirq/transformers/gauge_compiling/gauge_compiling.py +245 -6
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +107 -2
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +39 -2
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils_test.py +10 -1
- cirq/transformers/gauge_compiling/iswap_gauge.py +2 -2
- cirq/transformers/gauge_compiling/spin_inversion_gauge.py +2 -2
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +23 -5
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge.py +3 -2
- cirq/transformers/heuristic_decompositions/__init__.py +3 -3
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +2 -1
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +1 -1
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +4 -4
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation_test.py +4 -4
- cirq/transformers/insertion_sort.py +64 -0
- cirq/transformers/insertion_sort_test.py +34 -0
- cirq/transformers/measurement_transformers.py +14 -1
- cirq/transformers/measurement_transformers_test.py +35 -0
- cirq/transformers/merge_k_qubit_gates.py +2 -2
- cirq/transformers/merge_single_qubit_gates.py +1 -1
- cirq/transformers/merge_single_qubit_gates_test.py +1 -1
- cirq/transformers/noise_adding.py +115 -0
- cirq/transformers/noise_adding_test.py +54 -0
- cirq/transformers/optimize_for_target_gateset.py +1 -1
- cirq/transformers/optimize_for_target_gateset_test.py +3 -2
- cirq/transformers/qubit_management_transformers.py +1 -1
- cirq/transformers/randomized_measurements.py +171 -0
- cirq/transformers/randomized_measurements_test.py +68 -0
- cirq/transformers/routing/__init__.py +14 -5
- cirq/transformers/routing/initial_mapper.py +1 -1
- cirq/transformers/routing/initial_mapper_test.py +1 -0
- cirq/transformers/routing/line_initial_mapper.py +3 -2
- cirq/transformers/routing/mapping_manager.py +2 -2
- cirq/transformers/routing/mapping_manager_test.py +2 -2
- cirq/transformers/routing/route_circuit_cqc.py +3 -2
- cirq/transformers/routing/route_circuit_cqc_test.py +2 -1
- cirq/transformers/routing/visualize_routed_circuit.py +1 -0
- cirq/transformers/routing/visualize_routed_circuit_test.py +1 -0
- cirq/transformers/stratify.py +2 -2
- cirq/transformers/synchronize_terminal_measurements.py +2 -1
- cirq/transformers/target_gatesets/__init__.py +7 -5
- cirq/transformers/target_gatesets/compilation_target_gateset.py +16 -3
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +2 -0
- cirq/transformers/target_gatesets/cz_gateset.py +5 -1
- cirq/transformers/target_gatesets/cz_gateset_test.py +23 -2
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +1 -1
- cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +3 -2
- cirq/transformers/transformer_api.py +5 -4
- cirq/transformers/transformer_api_test.py +11 -3
- cirq/transformers/transformer_primitives.py +9 -31
- cirq/transformers/transformer_primitives_test.py +6 -5
- cirq/value/__init__.py +51 -30
- cirq/value/abc_alt.py +1 -2
- cirq/value/angle.py +2 -0
- cirq/value/classical_data.py +1 -0
- cirq/value/condition.py +149 -3
- cirq/value/condition_test.py +254 -0
- cirq/value/digits.py +1 -1
- cirq/value/duration.py +4 -4
- cirq/value/duration_test.py +2 -1
- cirq/value/linear_dict.py +85 -24
- cirq/value/linear_dict_test.py +94 -3
- cirq/value/measurement_key.py +9 -2
- cirq/value/periodic_value.py +2 -3
- cirq/value/periodic_value_test.py +5 -0
- cirq/value/probability.py +1 -0
- cirq/value/random_state.py +1 -1
- cirq/value/timestamp.py +2 -4
- cirq/value/timestamp_test.py +2 -1
- cirq/value/type_alias.py +2 -2
- cirq/value/value_equality_attr.py +14 -2
- cirq/value/value_equality_attr_test.py +1 -1
- cirq/vis/__init__.py +9 -6
- cirq/vis/density_matrix.py +1 -1
- cirq/vis/density_matrix_test.py +2 -5
- cirq/vis/heatmap.py +49 -12
- cirq/vis/heatmap_test.py +168 -4
- cirq/vis/histogram.py +1 -1
- cirq/vis/histogram_test.py +1 -2
- cirq/vis/state_histogram.py +7 -5
- cirq/vis/state_histogram_test.py +2 -2
- cirq/work/__init__.py +19 -13
- cirq/work/collector.py +2 -2
- cirq/work/observable_grouping.py +2 -2
- cirq/work/observable_measurement.py +3 -3
- cirq/work/observable_measurement_data.py +5 -2
- cirq/work/observable_measurement_test.py +8 -8
- cirq/work/observable_readout_calibration.py +2 -2
- cirq/work/observable_readout_calibration_test.py +2 -1
- cirq/work/observable_settings.py +8 -7
- cirq/work/observable_settings_test.py +3 -2
- cirq/work/pauli_sum_collector.py +1 -1
- cirq/work/sampler.py +8 -20
- cirq/work/sampler_test.py +4 -3
- cirq/work/zeros_sampler.py +1 -1
- cirq_core-1.5.0.dist-info/METADATA +125 -0
- {cirq_core-1.4.1.dist-info → cirq_core-1.5.0.dist-info}/RECORD +586 -552
- {cirq_core-1.4.1.dist-info → cirq_core-1.5.0.dist-info}/WHEEL +1 -1
- cirq/experiments/grid_parallel_two_qubit_xeb.py +0 -62
- cirq/protocols/json_test_data/GridParallelXEBMetadata.json +0 -119
- cirq/protocols/json_test_data/GridParallelXEBMetadata.repr +0 -1
- cirq_core-1.4.1.dist-info/METADATA +0 -45
- {cirq_core-1.4.1.dist-info → cirq_core-1.5.0.dist-info}/LICENSE +0 -0
- {cirq_core-1.4.1.dist-info → cirq_core-1.5.0.dist-info}/top_level.txt +0 -0
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
import
|
|
15
|
+
from __future__ import annotations
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
import collections
|
|
18
|
+
from typing import cast, Dict, List, Optional, Sequence, TYPE_CHECKING, Union
|
|
18
19
|
|
|
19
20
|
from cirq import circuits, ops, transformers
|
|
20
|
-
|
|
21
|
-
from cirq.contrib.acquaintance.gates import SwapNetworkGate, AcquaintanceOpportunityGate
|
|
22
21
|
from cirq.contrib.acquaintance.devices import get_acquaintance_size
|
|
22
|
+
from cirq.contrib.acquaintance.gates import AcquaintanceOpportunityGate, SwapNetworkGate
|
|
23
23
|
from cirq.contrib.acquaintance.permutation import PermutationGate
|
|
24
24
|
|
|
25
25
|
if TYPE_CHECKING:
|
|
@@ -28,7 +28,7 @@ if TYPE_CHECKING:
|
|
|
28
28
|
STRATEGY_GATE = Union[AcquaintanceOpportunityGate, PermutationGate]
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
def rectify_acquaintance_strategy(circuit:
|
|
31
|
+
def rectify_acquaintance_strategy(circuit: cirq.Circuit, acquaint_first: bool = True) -> None:
|
|
32
32
|
"""Splits moments so that they contain either only acquaintance or permutation gates.
|
|
33
33
|
|
|
34
34
|
Orders resulting moments so that the first one is of the same type as the previous one.
|
|
@@ -57,10 +57,10 @@ def rectify_acquaintance_strategy(circuit: 'cirq.Circuit', acquaint_first: bool
|
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
def replace_acquaintance_with_swap_network(
|
|
60
|
-
circuit:
|
|
61
|
-
qubit_order: Sequence[
|
|
60
|
+
circuit: cirq.Circuit,
|
|
61
|
+
qubit_order: Sequence[cirq.Qid],
|
|
62
62
|
acquaintance_size: Optional[int] = 0,
|
|
63
|
-
swap_gate:
|
|
63
|
+
swap_gate: cirq.Gate = ops.SWAP,
|
|
64
64
|
) -> bool:
|
|
65
65
|
"""Replace every rectified moment with acquaintance gates with a generalized swap network.
|
|
66
66
|
|
|
@@ -106,10 +106,10 @@ class ExposeAcquaintanceGates:
|
|
|
106
106
|
not get_acquaintance_size(op) or isinstance(op.gate, AcquaintanceOpportunityGate)
|
|
107
107
|
)
|
|
108
108
|
|
|
109
|
-
def optimize_circuit(self, circuit:
|
|
109
|
+
def optimize_circuit(self, circuit: cirq.Circuit) -> None:
|
|
110
110
|
circuit._moments = [*transformers.expand_composite(circuit, no_decomp=self.no_decomp)]
|
|
111
111
|
|
|
112
|
-
def __call__(self, circuit:
|
|
112
|
+
def __call__(self, circuit: cirq.Circuit) -> None:
|
|
113
113
|
self.optimize_circuit(circuit)
|
|
114
114
|
|
|
115
115
|
|
|
@@ -12,20 +12,21 @@
|
|
|
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
|
from typing import cast, FrozenSet, List, Sequence, Set, TYPE_CHECKING
|
|
16
18
|
|
|
17
19
|
from cirq import circuits
|
|
18
|
-
|
|
19
|
-
from cirq.contrib.acquaintance.gates import acquaint
|
|
20
20
|
from cirq.contrib.acquaintance.executor import AcquaintanceOperation
|
|
21
|
-
from cirq.contrib.acquaintance.
|
|
21
|
+
from cirq.contrib.acquaintance.gates import acquaint
|
|
22
22
|
from cirq.contrib.acquaintance.inspection_utils import LogicalAnnotator
|
|
23
|
+
from cirq.contrib.acquaintance.mutation_utils import expose_acquaintance_gates
|
|
23
24
|
|
|
24
25
|
if TYPE_CHECKING:
|
|
25
26
|
import cirq
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
def remove_redundant_acquaintance_opportunities(strategy:
|
|
29
|
+
def remove_redundant_acquaintance_opportunities(strategy: cirq.Circuit) -> int:
|
|
29
30
|
"""Removes redundant acquaintance opportunities."""
|
|
30
31
|
|
|
31
32
|
qubits = sorted(strategy.all_qubits())
|
|
@@ -35,11 +36,11 @@ def remove_redundant_acquaintance_opportunities(strategy: 'cirq.Circuit') -> int
|
|
|
35
36
|
annotated_strategy = strategy.copy()
|
|
36
37
|
LogicalAnnotator(mapping)(annotated_strategy)
|
|
37
38
|
|
|
38
|
-
new_moments: List[
|
|
39
|
+
new_moments: List[cirq.Moment] = []
|
|
39
40
|
acquaintance_opps: Set[FrozenSet[int]] = set()
|
|
40
41
|
n_removed = 0
|
|
41
42
|
for moment in annotated_strategy:
|
|
42
|
-
new_moment: List[
|
|
43
|
+
new_moment: List[cirq.Operation] = []
|
|
43
44
|
for op in moment:
|
|
44
45
|
if isinstance(op, AcquaintanceOperation):
|
|
45
46
|
opp = frozenset(cast(Sequence[int], op.logical_indices))
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
import cirq
|
|
15
|
-
import cirq.testing as ct
|
|
16
15
|
import cirq.contrib.acquaintance as cca
|
|
16
|
+
import cirq.testing as ct
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
def test_remove_redundant_acquaintance_opportunities():
|
|
@@ -12,22 +12,25 @@
|
|
|
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 abc
|
|
18
|
+
from types import NotImplementedType
|
|
16
19
|
from typing import (
|
|
17
20
|
Any,
|
|
18
21
|
cast,
|
|
19
22
|
Dict,
|
|
20
23
|
Iterable,
|
|
24
|
+
Iterator,
|
|
21
25
|
Optional,
|
|
22
26
|
Sequence,
|
|
23
27
|
Tuple,
|
|
28
|
+
TYPE_CHECKING,
|
|
24
29
|
TypeVar,
|
|
25
30
|
Union,
|
|
26
|
-
TYPE_CHECKING,
|
|
27
31
|
)
|
|
28
32
|
|
|
29
33
|
from cirq import circuits, ops, protocols, transformers, value
|
|
30
|
-
from cirq.type_workarounds import NotImplementedType
|
|
31
34
|
|
|
32
35
|
if TYPE_CHECKING:
|
|
33
36
|
import cirq
|
|
@@ -50,7 +53,7 @@ class PermutationGate(ops.Gate, metaclass=abc.ABCMeta):
|
|
|
50
53
|
qubits (e.g. SWAP or fermionic swap).
|
|
51
54
|
"""
|
|
52
55
|
|
|
53
|
-
def __init__(self, num_qubits: int, swap_gate:
|
|
56
|
+
def __init__(self, num_qubits: int, swap_gate: cirq.Gate = ops.SWAP) -> None:
|
|
54
57
|
self._num_qubits = num_qubits
|
|
55
58
|
self.swap_gate = swap_gate
|
|
56
59
|
|
|
@@ -63,7 +66,7 @@ class PermutationGate(ops.Gate, metaclass=abc.ABCMeta):
|
|
|
63
66
|
the s[i]-th element."""
|
|
64
67
|
|
|
65
68
|
def update_mapping(
|
|
66
|
-
self, mapping: Dict[ops.Qid, LogicalIndex], keys: Sequence[
|
|
69
|
+
self, mapping: Dict[ops.Qid, LogicalIndex], keys: Sequence[cirq.Qid]
|
|
67
70
|
) -> None:
|
|
68
71
|
"""Updates a mapping (in place) from qubits to logical indices.
|
|
69
72
|
|
|
@@ -95,8 +98,8 @@ class PermutationGate(ops.Gate, metaclass=abc.ABCMeta):
|
|
|
95
98
|
raise IndexError('key is out of bounds.')
|
|
96
99
|
|
|
97
100
|
def _circuit_diagram_info_(
|
|
98
|
-
self, args:
|
|
99
|
-
) -> Union[str, Iterable[str],
|
|
101
|
+
self, args: cirq.CircuitDiagramInfoArgs
|
|
102
|
+
) -> Union[str, Iterable[str], cirq.CircuitDiagramInfo]:
|
|
100
103
|
if args.known_qubit_count is None:
|
|
101
104
|
return NotImplemented
|
|
102
105
|
permutation = self.permutation()
|
|
@@ -117,14 +120,12 @@ class MappingDisplayGate(ops.Gate):
|
|
|
117
120
|
def num_qubits(self) -> int:
|
|
118
121
|
return self._num_qubits
|
|
119
122
|
|
|
120
|
-
def _circuit_diagram_info_(
|
|
121
|
-
self, args: 'cirq.CircuitDiagramInfoArgs'
|
|
122
|
-
) -> 'cirq.CircuitDiagramInfo':
|
|
123
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> cirq.CircuitDiagramInfo:
|
|
123
124
|
wire_symbols = tuple('' if i is None else str(i) for i in self.indices)
|
|
124
125
|
return protocols.CircuitDiagramInfo(wire_symbols, connected=False)
|
|
125
126
|
|
|
126
127
|
|
|
127
|
-
def display_mapping(circuit:
|
|
128
|
+
def display_mapping(circuit: cirq.Circuit, initial_mapping: LogicalMapping) -> None:
|
|
128
129
|
"""Inserts display gates between moments to indicate the mapping throughout
|
|
129
130
|
the circuit."""
|
|
130
131
|
qubits = sorted(circuit.all_qubits())
|
|
@@ -146,13 +147,13 @@ def display_mapping(circuit: 'cirq.Circuit', initial_mapping: LogicalMapping) ->
|
|
|
146
147
|
class SwapPermutationGate(PermutationGate):
|
|
147
148
|
"""Generic swap gate."""
|
|
148
149
|
|
|
149
|
-
def __init__(self, swap_gate:
|
|
150
|
+
def __init__(self, swap_gate: cirq.Gate = ops.SWAP):
|
|
150
151
|
super().__init__(2, swap_gate)
|
|
151
152
|
|
|
152
153
|
def permutation(self) -> Dict[int, int]:
|
|
153
154
|
return {0: 1, 1: 0}
|
|
154
155
|
|
|
155
|
-
def _decompose_(self, qubits: Sequence[
|
|
156
|
+
def _decompose_(self, qubits: Sequence[cirq.Qid]) -> Iterator[cirq.OP_TREE]:
|
|
156
157
|
yield self.swap_gate(*qubits)
|
|
157
158
|
|
|
158
159
|
def __repr__(self) -> str:
|
|
@@ -185,7 +186,7 @@ class LinearPermutationGate(PermutationGate):
|
|
|
185
186
|
sorting network."""
|
|
186
187
|
|
|
187
188
|
def __init__(
|
|
188
|
-
self, num_qubits: int, permutation: Dict[int, int], swap_gate:
|
|
189
|
+
self, num_qubits: int, permutation: Dict[int, int], swap_gate: cirq.Gate = ops.SWAP
|
|
189
190
|
) -> None:
|
|
190
191
|
"""Initializes a linear permutation gate.
|
|
191
192
|
|
|
@@ -201,7 +202,7 @@ class LinearPermutationGate(PermutationGate):
|
|
|
201
202
|
def permutation(self) -> Dict[int, int]:
|
|
202
203
|
return self._permutation
|
|
203
204
|
|
|
204
|
-
def _decompose_(self, qubits: Sequence[
|
|
205
|
+
def _decompose_(self, qubits: Sequence[cirq.Qid]) -> Iterator[cirq.OP_TREE]:
|
|
205
206
|
swap_gate = SwapPermutationGate(self.swap_gate)
|
|
206
207
|
n_qubits = len(qubits)
|
|
207
208
|
mapping = {i: self._permutation.get(i, i) for i in range(n_qubits)}
|
|
@@ -237,7 +238,7 @@ class LinearPermutationGate(PermutationGate):
|
|
|
237
238
|
return NotImplemented
|
|
238
239
|
|
|
239
240
|
|
|
240
|
-
def update_mapping(mapping: Dict[ops.Qid, LogicalIndex], operations:
|
|
241
|
+
def update_mapping(mapping: Dict[ops.Qid, LogicalIndex], operations: cirq.OP_TREE) -> None:
|
|
241
242
|
"""Updates a mapping (in place) from qubits to logical indices according to
|
|
242
243
|
a set of permutation gates. Any gates other than permutation gates are
|
|
243
244
|
ignored.
|
|
@@ -252,8 +253,8 @@ def update_mapping(mapping: Dict[ops.Qid, LogicalIndex], operations: 'cirq.OP_TR
|
|
|
252
253
|
|
|
253
254
|
|
|
254
255
|
def get_logical_operations(
|
|
255
|
-
operations:
|
|
256
|
-
) -> Iterable[
|
|
256
|
+
operations: cirq.OP_TREE, initial_mapping: Dict[ops.Qid, ops.Qid]
|
|
257
|
+
) -> Iterable[cirq.Operation]:
|
|
257
258
|
"""Gets the logical operations specified by the physical operations and
|
|
258
259
|
initial mapping.
|
|
259
260
|
|
|
@@ -299,10 +300,10 @@ class DecomposePermutationGates:
|
|
|
299
300
|
not all([isinstance(op, ops.GateOperation), isinstance(op.gate, PermutationGate)])
|
|
300
301
|
)
|
|
301
302
|
|
|
302
|
-
def optimize_circuit(self, circuit:
|
|
303
|
+
def optimize_circuit(self, circuit: cirq.Circuit) -> None:
|
|
303
304
|
circuit._moments = [*transformers.expand_composite(circuit, no_decomp=self.no_decomp)]
|
|
304
305
|
|
|
305
|
-
def __call__(self, circuit:
|
|
306
|
+
def __call__(self, circuit: cirq.Circuit) -> None:
|
|
306
307
|
self.optimize_circuit(circuit)
|
|
307
308
|
|
|
308
309
|
|
|
@@ -310,7 +311,7 @@ EXPAND_PERMUTATION_GATES = DecomposePermutationGates(keep_swap_permutations=True
|
|
|
310
311
|
DECOMPOSE_PERMUTATION_GATES = DecomposePermutationGates(keep_swap_permutations=False)
|
|
311
312
|
|
|
312
313
|
|
|
313
|
-
def return_to_initial_mapping(circuit:
|
|
314
|
+
def return_to_initial_mapping(circuit: cirq.Circuit, swap_gate: cirq.Gate = ops.SWAP) -> None:
|
|
314
315
|
qubits = sorted(circuit.all_qubits())
|
|
315
316
|
n_qubits = len(qubits)
|
|
316
317
|
|
|
@@ -322,7 +323,7 @@ def return_to_initial_mapping(circuit: 'cirq.Circuit', swap_gate: 'cirq.Gate' =
|
|
|
322
323
|
circuit.append(returning_permutation_op)
|
|
323
324
|
|
|
324
325
|
|
|
325
|
-
def uses_consistent_swap_gate(circuit:
|
|
326
|
+
def uses_consistent_swap_gate(circuit: cirq.Circuit, swap_gate: cirq.Gate) -> bool:
|
|
326
327
|
for op in circuit.all_operations():
|
|
327
328
|
if isinstance(op, ops.GateOperation) and isinstance(op.gate, PermutationGate):
|
|
328
329
|
if op.gate.swap_gate != swap_gate:
|
|
@@ -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 itertools
|
|
16
|
-
from typing import Any, Dict, Sequence, Tuple, TYPE_CHECKING
|
|
18
|
+
from typing import Any, Dict, Iterator, Sequence, Tuple, TYPE_CHECKING
|
|
17
19
|
|
|
18
20
|
from cirq import ops, value
|
|
19
|
-
from cirq.contrib.acquaintance.permutation import
|
|
21
|
+
from cirq.contrib.acquaintance.permutation import PermutationGate, SwapPermutationGate
|
|
20
22
|
|
|
21
23
|
if TYPE_CHECKING:
|
|
22
24
|
import cirq
|
|
@@ -26,7 +28,7 @@ if TYPE_CHECKING:
|
|
|
26
28
|
class CircularShiftGate(PermutationGate):
|
|
27
29
|
"""Performs a cyclical permutation of the qubits to the left by a specified amount."""
|
|
28
30
|
|
|
29
|
-
def __init__(self, num_qubits: int, shift: int, swap_gate:
|
|
31
|
+
def __init__(self, num_qubits: int, shift: int, swap_gate: cirq.Gate = ops.SWAP) -> None:
|
|
30
32
|
"""Construct a circular shift gate.
|
|
31
33
|
|
|
32
34
|
Args:
|
|
@@ -47,7 +49,7 @@ class CircularShiftGate(PermutationGate):
|
|
|
47
49
|
def _value_equality_values_(self) -> Any:
|
|
48
50
|
return self.shift, self.swap_gate, self.num_qubits()
|
|
49
51
|
|
|
50
|
-
def _decompose_(self, qubits: Sequence[
|
|
52
|
+
def _decompose_(self, qubits: Sequence[cirq.Qid]) -> Iterator[cirq.OP_TREE]:
|
|
51
53
|
n = len(qubits)
|
|
52
54
|
left_shift = self.shift % n
|
|
53
55
|
right_shift = n - left_shift
|
|
@@ -58,9 +60,9 @@ class CircularShiftGate(PermutationGate):
|
|
|
58
60
|
for k in range(i, j, 2):
|
|
59
61
|
yield swap_gate(*qubits[k : k + 2])
|
|
60
62
|
|
|
61
|
-
def _circuit_diagram_info_(self, args:
|
|
63
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> Tuple[str, ...]:
|
|
62
64
|
if args.known_qubit_count is None:
|
|
63
|
-
return NotImplemented
|
|
65
|
+
return NotImplemented # pragma: no cover
|
|
64
66
|
direction_symbols = ('╲', '╱') if args.use_unicode_characters else ('\\', '/')
|
|
65
67
|
wire_symbols = tuple(
|
|
66
68
|
direction_symbols[int(i >= self.shift)]
|
|
@@ -12,9 +12,11 @@
|
|
|
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 functools
|
|
16
18
|
import itertools
|
|
17
|
-
from typing import Dict, Iterable, Optional, Sequence, Tuple, TYPE_CHECKING
|
|
19
|
+
from typing import Dict, Iterable, Iterator, Optional, Sequence, Tuple, TYPE_CHECKING
|
|
18
20
|
|
|
19
21
|
from cirq import ops
|
|
20
22
|
from cirq.contrib.acquaintance.gates import acquaint
|
|
@@ -51,7 +53,7 @@ class ShiftSwapNetworkGate(PermutationGate):
|
|
|
51
53
|
self,
|
|
52
54
|
left_part_lens: Iterable[int],
|
|
53
55
|
right_part_lens: Iterable[int],
|
|
54
|
-
swap_gate:
|
|
56
|
+
swap_gate: cirq.Gate = ops.SWAP,
|
|
55
57
|
) -> None:
|
|
56
58
|
|
|
57
59
|
self.part_lens = {'left': tuple(left_part_lens), 'right': tuple(right_part_lens)}
|
|
@@ -65,7 +67,7 @@ class ShiftSwapNetworkGate(PermutationGate):
|
|
|
65
67
|
def acquaintance_size(self) -> int:
|
|
66
68
|
return sum(max(self.part_lens[side]) for side in ('left', 'right'))
|
|
67
69
|
|
|
68
|
-
def _decompose_(self, qubits: Sequence[
|
|
70
|
+
def _decompose_(self, qubits: Sequence[cirq.Qid]) -> Iterator[cirq.OP_TREE]:
|
|
69
71
|
part_lens = list(itertools.chain(*(self.part_lens[side] for side in ('left', 'right'))))
|
|
70
72
|
|
|
71
73
|
n_qubits = 0
|
|
@@ -110,7 +112,7 @@ class ShiftSwapNetworkGate(PermutationGate):
|
|
|
110
112
|
)
|
|
111
113
|
)
|
|
112
114
|
|
|
113
|
-
def _circuit_diagram_info_(self, args:
|
|
115
|
+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> Tuple[str, ...]:
|
|
114
116
|
qubit_count = self.qubit_count()
|
|
115
117
|
assert args.known_qubit_count in (None, qubit_count)
|
|
116
118
|
|
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
|
|
15
15
|
"""Acquaintance strategies."""
|
|
16
16
|
|
|
17
|
-
from cirq.contrib.acquaintance.strategies.complete import
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
from cirq.contrib.acquaintance.strategies.complete import (
|
|
18
|
+
complete_acquaintance_strategy as complete_acquaintance_strategy,
|
|
19
|
+
)
|
|
20
|
+
from cirq.contrib.acquaintance.strategies.cubic import (
|
|
21
|
+
cubic_acquaintance_strategy as cubic_acquaintance_strategy,
|
|
22
|
+
)
|
|
23
|
+
from cirq.contrib.acquaintance.strategies.quartic_paired import (
|
|
24
|
+
quartic_paired_acquaintance_strategy as quartic_paired_acquaintance_strategy,
|
|
25
|
+
)
|
|
@@ -12,10 +12,11 @@
|
|
|
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
|
from typing import Sequence, TYPE_CHECKING
|
|
16
18
|
|
|
17
19
|
from cirq import circuits, ops
|
|
18
|
-
|
|
19
20
|
from cirq.contrib.acquaintance.gates import acquaint
|
|
20
21
|
from cirq.contrib.acquaintance.mutation_utils import (
|
|
21
22
|
expose_acquaintance_gates,
|
|
@@ -27,8 +28,8 @@ if TYPE_CHECKING:
|
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
def complete_acquaintance_strategy(
|
|
30
|
-
qubit_order: Sequence[
|
|
31
|
-
) ->
|
|
31
|
+
qubit_order: Sequence[cirq.Qid], acquaintance_size: int = 0, swap_gate: cirq.Gate = ops.SWAP
|
|
32
|
+
) -> cirq.Circuit:
|
|
32
33
|
"""Returns an acquaintance strategy with can handle the given number of qubits.
|
|
33
34
|
|
|
34
35
|
Args:
|
|
@@ -12,8 +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 itertools
|
|
16
|
-
from typing import Iterable, Sequence, Tuple,
|
|
18
|
+
from typing import Iterable, Sequence, Tuple, TYPE_CHECKING, TypeVar
|
|
17
19
|
|
|
18
20
|
from cirq import circuits, ops
|
|
19
21
|
from cirq.contrib.acquaintance.gates import acquaint
|
|
@@ -35,8 +37,8 @@ def skip_and_wrap_around(items: Sequence[TItem]) -> Tuple[TItem, ...]:
|
|
|
35
37
|
|
|
36
38
|
|
|
37
39
|
def cubic_acquaintance_strategy(
|
|
38
|
-
qubits: Iterable[
|
|
39
|
-
) ->
|
|
40
|
+
qubits: Iterable[cirq.Qid], swap_gate: cirq.Gate = ops.SWAP
|
|
41
|
+
) -> cirq.Circuit:
|
|
40
42
|
"""Acquaints every triple of qubits.
|
|
41
43
|
|
|
42
44
|
Exploits the fact that in a simple linear swap network every pair of
|
|
@@ -12,9 +12,11 @@
|
|
|
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
|
from typing import cast, Iterable, List, Sequence, Tuple, TYPE_CHECKING
|
|
16
18
|
|
|
17
|
-
from cirq import circuits
|
|
19
|
+
from cirq import circuits
|
|
18
20
|
from cirq.contrib.acquaintance.gates import acquaint, SwapNetworkGate
|
|
19
21
|
from cirq.contrib.acquaintance.mutation_utils import expose_acquaintance_gates
|
|
20
22
|
|
|
@@ -22,7 +24,7 @@ if TYPE_CHECKING:
|
|
|
22
24
|
import cirq
|
|
23
25
|
|
|
24
26
|
|
|
25
|
-
def qubit_pairs_to_qubit_order(qubit_pairs: Sequence[Sequence[
|
|
27
|
+
def qubit_pairs_to_qubit_order(qubit_pairs: Sequence[Sequence[cirq.Qid]]) -> List[cirq.Qid]:
|
|
26
28
|
"""Takes a sequence of qubit pairs and returns a sequence in which every
|
|
27
29
|
pair is at distance two.
|
|
28
30
|
|
|
@@ -33,7 +35,7 @@ def qubit_pairs_to_qubit_order(qubit_pairs: Sequence[Sequence['cirq.Qid']]) -> L
|
|
|
33
35
|
if set(len(qubit_pair) for qubit_pair in qubit_pairs) != set((2,)):
|
|
34
36
|
raise ValueError('set(len(qubit_pair) for qubit_pair in qubit_pairs) != set((2,))')
|
|
35
37
|
n_pairs = len(qubit_pairs)
|
|
36
|
-
qubits: List[
|
|
38
|
+
qubits: List[cirq.Qid] = []
|
|
37
39
|
for i in range(0, 2 * (n_pairs // 2), 2):
|
|
38
40
|
qubits += [
|
|
39
41
|
qubit_pairs[i][0],
|
|
@@ -47,15 +49,15 @@ def qubit_pairs_to_qubit_order(qubit_pairs: Sequence[Sequence['cirq.Qid']]) -> L
|
|
|
47
49
|
|
|
48
50
|
|
|
49
51
|
def quartic_paired_acquaintance_strategy(
|
|
50
|
-
qubit_pairs: Iterable[Tuple[
|
|
51
|
-
) -> Tuple[
|
|
52
|
+
qubit_pairs: Iterable[Tuple[cirq.Qid, cirq.Qid]],
|
|
53
|
+
) -> Tuple[cirq.Circuit, Sequence[cirq.Qid]]:
|
|
52
54
|
"""Acquaintance strategy for pairs of pairs.
|
|
53
55
|
|
|
54
56
|
Implements UpCCGSD ansatz from arXiv:1810.02327.
|
|
55
57
|
"""
|
|
56
58
|
|
|
57
59
|
qubit_pairs = tuple(
|
|
58
|
-
cast(Tuple['cirq.Qid',
|
|
60
|
+
cast(Tuple['cirq.Qid', 'cirq.Qid'], tuple(qubit_pair)) for qubit_pair in qubit_pairs
|
|
59
61
|
)
|
|
60
62
|
qubits = qubit_pairs_to_qubit_order(qubit_pairs)
|
|
61
63
|
n_qubits = len(qubits)
|
|
@@ -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 operator
|
|
16
18
|
import random
|
|
17
19
|
from typing import Any, Callable, cast, Iterable, TYPE_CHECKING
|
|
@@ -25,8 +27,8 @@ if TYPE_CHECKING:
|
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
def is_topologically_sorted(
|
|
28
|
-
dag:
|
|
29
|
-
operations:
|
|
30
|
+
dag: cirq.contrib.CircuitDag,
|
|
31
|
+
operations: cirq.OP_TREE,
|
|
30
32
|
equals: Callable[[ops.Operation, ops.Operation], bool] = operator.eq,
|
|
31
33
|
) -> bool:
|
|
32
34
|
"""Whether a given order of operations is consistent with the DAG.
|
|
@@ -12,4 +12,6 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from cirq.contrib.bayesian_network.bayesian_network_gate import
|
|
15
|
+
from cirq.contrib.bayesian_network.bayesian_network_gate import (
|
|
16
|
+
BayesianNetworkGate as BayesianNetworkGate,
|
|
17
|
+
)
|
|
@@ -12,8 +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 math
|
|
16
|
-
from typing import Any, cast, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
|
|
18
|
+
from typing import Any, cast, Dict, Iterator, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
|
|
17
19
|
|
|
18
20
|
from sympy.combinatorics import GrayCode
|
|
19
21
|
|
|
@@ -158,7 +160,7 @@ class BayesianNetworkGate(raw_types.Gate):
|
|
|
158
160
|
raise ValueError('Conditional prob should be between 0 and 1.')
|
|
159
161
|
self._arc_probs = arc_probs
|
|
160
162
|
|
|
161
|
-
def _decompose_(self, qubits: Sequence[
|
|
163
|
+
def _decompose_(self, qubits: Sequence[cirq.Qid]) -> Iterator[cirq.OP_TREE]:
|
|
162
164
|
parameter_names = [init_prob[0] for init_prob in self._init_probs]
|
|
163
165
|
qubit_map = dict(zip(parameter_names, qubits))
|
|
164
166
|
|
|
@@ -188,7 +190,7 @@ class BayesianNetworkGate(raw_types.Gate):
|
|
|
188
190
|
init_probs: List[List[Union[str, Optional[float]]]],
|
|
189
191
|
arc_probs: List[List[Union[str, List[str], List[float]]]],
|
|
190
192
|
**kwargs,
|
|
191
|
-
) ->
|
|
193
|
+
) -> BayesianNetworkGate:
|
|
192
194
|
converted_init_probs = cast(
|
|
193
195
|
List[Tuple[str, Optional[float]]],
|
|
194
196
|
[(param, init_prob) for param, init_prob in init_probs],
|
|
@@ -11,16 +11,16 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
15
16
|
|
|
16
17
|
import functools
|
|
18
|
+
from typing import Any, Callable, cast, Dict, Generic, Iterator, TypeVar
|
|
19
|
+
|
|
17
20
|
import networkx
|
|
18
21
|
|
|
22
|
+
import cirq
|
|
19
23
|
from cirq import ops
|
|
20
|
-
from cirq.circuits import circuit
|
|
21
|
-
|
|
22
|
-
if TYPE_CHECKING:
|
|
23
|
-
import cirq
|
|
24
24
|
|
|
25
25
|
T = TypeVar('T')
|
|
26
26
|
|
|
@@ -50,7 +50,7 @@ class Unique(Generic[T]):
|
|
|
50
50
|
return id(self) < id(other)
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
def _disjoint_qubits(op1:
|
|
53
|
+
def _disjoint_qubits(op1: cirq.Operation, op2: cirq.Operation) -> bool:
|
|
54
54
|
"""Returns true only if the operations have qubits in common."""
|
|
55
55
|
return not set(op1.qubits) & set(op2.qubits)
|
|
56
56
|
|
|
@@ -72,7 +72,7 @@ class CircuitDag(networkx.DiGraph):
|
|
|
72
72
|
|
|
73
73
|
def __init__(
|
|
74
74
|
self,
|
|
75
|
-
can_reorder: Callable[[
|
|
75
|
+
can_reorder: Callable[[cirq.Operation, cirq.Operation], bool] = _disjoint_qubits,
|
|
76
76
|
incoming_graph_data: Any = None,
|
|
77
77
|
) -> None:
|
|
78
78
|
"""Initializes a CircuitDag.
|
|
@@ -93,27 +93,27 @@ class CircuitDag(networkx.DiGraph):
|
|
|
93
93
|
self.can_reorder = can_reorder
|
|
94
94
|
|
|
95
95
|
@staticmethod
|
|
96
|
-
def make_node(op:
|
|
96
|
+
def make_node(op: cirq.Operation) -> Unique:
|
|
97
97
|
return Unique(op)
|
|
98
98
|
|
|
99
99
|
@staticmethod
|
|
100
100
|
def from_circuit(
|
|
101
|
-
circuit:
|
|
102
|
-
can_reorder: Callable[[
|
|
103
|
-
) ->
|
|
101
|
+
circuit: cirq.Circuit,
|
|
102
|
+
can_reorder: Callable[[cirq.Operation, cirq.Operation], bool] = _disjoint_qubits,
|
|
103
|
+
) -> CircuitDag:
|
|
104
104
|
return CircuitDag.from_ops(circuit.all_operations(), can_reorder=can_reorder)
|
|
105
105
|
|
|
106
106
|
@staticmethod
|
|
107
107
|
def from_ops(
|
|
108
|
-
*operations:
|
|
109
|
-
can_reorder: Callable[[
|
|
110
|
-
) ->
|
|
108
|
+
*operations: cirq.OP_TREE,
|
|
109
|
+
can_reorder: Callable[[cirq.Operation, cirq.Operation], bool] = _disjoint_qubits,
|
|
110
|
+
) -> CircuitDag:
|
|
111
111
|
dag = CircuitDag(can_reorder=can_reorder)
|
|
112
112
|
for op in ops.flatten_op_tree(operations):
|
|
113
113
|
dag.append(cast(ops.Operation, op))
|
|
114
114
|
return dag
|
|
115
115
|
|
|
116
|
-
def append(self, op:
|
|
116
|
+
def append(self, op: cirq.Operation) -> None:
|
|
117
117
|
new_node = self.make_node(op)
|
|
118
118
|
for node in list(self.nodes()):
|
|
119
119
|
if not self.can_reorder(node.val, op):
|
|
@@ -142,21 +142,21 @@ class CircuitDag(networkx.DiGraph):
|
|
|
142
142
|
|
|
143
143
|
__hash__ = None # type: ignore
|
|
144
144
|
|
|
145
|
-
def ordered_nodes(self) -> Iterator[Unique[
|
|
145
|
+
def ordered_nodes(self) -> Iterator[Unique[cirq.Operation]]:
|
|
146
146
|
if not self.nodes():
|
|
147
147
|
return
|
|
148
148
|
g = self.copy()
|
|
149
149
|
|
|
150
|
-
def get_root_node(some_node: Unique[
|
|
150
|
+
def get_root_node(some_node: Unique[cirq.Operation]) -> Unique[cirq.Operation]:
|
|
151
151
|
pred = g.pred
|
|
152
152
|
while pred[some_node]:
|
|
153
153
|
some_node = next(iter(pred[some_node]))
|
|
154
154
|
return some_node
|
|
155
155
|
|
|
156
|
-
def get_first_node() -> Unique[
|
|
156
|
+
def get_first_node() -> Unique[cirq.Operation]:
|
|
157
157
|
return get_root_node(next(iter(g.nodes())))
|
|
158
158
|
|
|
159
|
-
def get_next_node(succ: networkx.classes.coreviews.AtlasView) -> Unique[
|
|
159
|
+
def get_next_node(succ: networkx.classes.coreviews.AtlasView) -> Unique[cirq.Operation]:
|
|
160
160
|
if succ:
|
|
161
161
|
return get_root_node(next(iter(succ)))
|
|
162
162
|
|
|
@@ -173,18 +173,18 @@ class CircuitDag(networkx.DiGraph):
|
|
|
173
173
|
|
|
174
174
|
node = get_next_node(succ)
|
|
175
175
|
|
|
176
|
-
def all_operations(self) -> Iterator[
|
|
176
|
+
def all_operations(self) -> Iterator[cirq.Operation]:
|
|
177
177
|
return (node.val for node in self.ordered_nodes())
|
|
178
178
|
|
|
179
179
|
def all_qubits(self):
|
|
180
180
|
return frozenset(q for node in self.nodes for q in node.val.qubits)
|
|
181
181
|
|
|
182
|
-
def to_circuit(self) ->
|
|
183
|
-
return
|
|
182
|
+
def to_circuit(self) -> cirq.Circuit:
|
|
183
|
+
return cirq.Circuit(self.all_operations(), strategy=cirq.InsertStrategy.EARLIEST)
|
|
184
184
|
|
|
185
185
|
def findall_nodes_until_blocked(
|
|
186
|
-
self, is_blocker: Callable[[
|
|
187
|
-
) -> Iterator[Unique[
|
|
186
|
+
self, is_blocker: Callable[[cirq.Operation], bool]
|
|
187
|
+
) -> Iterator[Unique[cirq.Operation]]:
|
|
188
188
|
"""Finds all nodes before blocking ones.
|
|
189
189
|
|
|
190
190
|
Args:
|