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
|
@@ -14,8 +14,17 @@
|
|
|
14
14
|
|
|
15
15
|
"""Routing utilities in Cirq."""
|
|
16
16
|
|
|
17
|
-
from cirq.transformers.routing.initial_mapper import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
from cirq.transformers.routing.initial_mapper import (
|
|
18
|
+
AbstractInitialMapper as AbstractInitialMapper,
|
|
19
|
+
HardCodedInitialMapper as HardCodedInitialMapper,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
from cirq.transformers.routing.mapping_manager import MappingManager as MappingManager
|
|
23
|
+
|
|
24
|
+
from cirq.transformers.routing.line_initial_mapper import LineInitialMapper as LineInitialMapper
|
|
25
|
+
|
|
26
|
+
from cirq.transformers.routing.route_circuit_cqc import RouteCQC as RouteCQC
|
|
27
|
+
|
|
28
|
+
from cirq.transformers.routing.visualize_routed_circuit import (
|
|
29
|
+
routed_circuit_with_mapping as routed_circuit_with_mapping,
|
|
30
|
+
)
|
|
@@ -30,12 +30,13 @@ If some logical qubits are unampped after this first procedure then there are tw
|
|
|
30
30
|
the nearest available neighbor to the center of the device.
|
|
31
31
|
"""
|
|
32
32
|
|
|
33
|
-
from typing import Deque, Dict, List, Set, Tuple, TYPE_CHECKING
|
|
34
33
|
from collections import deque
|
|
34
|
+
from typing import Deque, Dict, List, Set, Tuple, TYPE_CHECKING
|
|
35
|
+
|
|
35
36
|
import networkx as nx
|
|
36
37
|
|
|
37
|
-
from cirq.transformers.routing import initial_mapper
|
|
38
38
|
from cirq import protocols, value
|
|
39
|
+
from cirq.transformers.routing import initial_mapper
|
|
39
40
|
|
|
40
41
|
if TYPE_CHECKING:
|
|
41
42
|
import cirq
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
|
|
15
15
|
"""Manages the mapping from logical to physical qubits during a routing procedure."""
|
|
16
16
|
|
|
17
|
-
from typing import
|
|
18
|
-
import networkx as nx
|
|
17
|
+
from typing import Dict, List, Sequence, TYPE_CHECKING
|
|
19
18
|
|
|
19
|
+
import networkx as nx
|
|
20
20
|
import numpy as np
|
|
21
21
|
|
|
22
22
|
if TYPE_CHECKING:
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from networkx.utils.misc import graphs_equal
|
|
16
|
-
import pytest
|
|
17
15
|
import networkx as nx
|
|
16
|
+
import pytest
|
|
17
|
+
from networkx.utils.misc import graphs_equal
|
|
18
18
|
|
|
19
19
|
import cirq
|
|
20
20
|
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
|
|
15
15
|
"""Heuristic qubit routing algorithm based on arxiv:1902.08091."""
|
|
16
16
|
|
|
17
|
-
from typing import Any, Dict, List, Optional, Set, Sequence, Tuple, TYPE_CHECKING
|
|
18
17
|
import itertools
|
|
18
|
+
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, TYPE_CHECKING
|
|
19
|
+
|
|
19
20
|
import networkx as nx
|
|
20
21
|
|
|
21
22
|
from cirq import circuits, ops, protocols
|
|
22
23
|
from cirq.transformers import transformer_api, transformer_primitives
|
|
23
|
-
from cirq.transformers.routing import
|
|
24
|
+
from cirq.transformers.routing import line_initial_mapper, mapping_manager
|
|
24
25
|
|
|
25
26
|
if TYPE_CHECKING:
|
|
26
27
|
import cirq
|
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
import cirq
|
|
16
15
|
import pytest
|
|
17
16
|
|
|
17
|
+
import cirq
|
|
18
|
+
|
|
18
19
|
|
|
19
20
|
def test_directed_device():
|
|
20
21
|
device = cirq.testing.construct_ring_device(10, directed=True)
|
cirq/transformers/stratify.py
CHANGED
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"""Transformer pass to repack circuits avoiding simultaneous operations with different classes."""
|
|
16
16
|
|
|
17
17
|
import itertools
|
|
18
|
-
from typing import
|
|
18
|
+
from typing import Callable, Dict, Iterable, List, Optional, Sequence, Type, TYPE_CHECKING, Union
|
|
19
19
|
|
|
20
|
-
from cirq import
|
|
20
|
+
from cirq import _import, circuits, ops, protocols
|
|
21
21
|
from cirq.transformers import transformer_api
|
|
22
22
|
|
|
23
23
|
drop_empty_moments = _import.LazyLoader('drop_empty_moments', globals(), 'cirq.transformers')
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"""Transformer pass to move terminal measurements to the end of circuit."""
|
|
16
16
|
|
|
17
17
|
from typing import List, Optional, Set, Tuple, TYPE_CHECKING
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
from cirq import circuits, protocols
|
|
19
20
|
from cirq.transformers import transformer_api
|
|
20
21
|
|
|
21
22
|
if TYPE_CHECKING:
|
|
@@ -15,11 +15,13 @@
|
|
|
15
15
|
"""Gatesets which can act as compilation targets in Cirq."""
|
|
16
16
|
|
|
17
17
|
from cirq.transformers.target_gatesets.compilation_target_gateset import (
|
|
18
|
-
create_transformer_with_kwargs,
|
|
19
|
-
CompilationTargetGateset,
|
|
20
|
-
TwoQubitCompilationTargetGateset,
|
|
18
|
+
create_transformer_with_kwargs as create_transformer_with_kwargs,
|
|
19
|
+
CompilationTargetGateset as CompilationTargetGateset,
|
|
20
|
+
TwoQubitCompilationTargetGateset as TwoQubitCompilationTargetGateset,
|
|
21
21
|
)
|
|
22
22
|
|
|
23
|
-
from cirq.transformers.target_gatesets.cz_gateset import CZTargetGateset
|
|
23
|
+
from cirq.transformers.target_gatesets.cz_gateset import CZTargetGateset as CZTargetGateset
|
|
24
24
|
|
|
25
|
-
from cirq.transformers.target_gatesets.sqrt_iswap_gateset import
|
|
25
|
+
from cirq.transformers.target_gatesets.sqrt_iswap_gateset import (
|
|
26
|
+
SqrtIswapTargetGateset as SqrtIswapTargetGateset,
|
|
27
|
+
)
|
|
@@ -14,14 +14,13 @@
|
|
|
14
14
|
|
|
15
15
|
"""Base class for creating custom target gatesets which can be used for compilation."""
|
|
16
16
|
|
|
17
|
-
from typing import Optional, List, Hashable, TYPE_CHECKING, Union, Type
|
|
18
17
|
import abc
|
|
18
|
+
from typing import Hashable, List, Optional, Type, TYPE_CHECKING, Union
|
|
19
19
|
|
|
20
20
|
from cirq import circuits, ops, protocols, transformers
|
|
21
21
|
from cirq.protocols.decompose_protocol import DecomposeResult
|
|
22
22
|
from cirq.transformers import merge_k_qubit_gates, merge_single_qubit_gates
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
if TYPE_CHECKING:
|
|
26
25
|
import cirq
|
|
27
26
|
|
|
@@ -76,7 +75,7 @@ def create_transformer_with_kwargs(transformer: 'cirq.TRANSFORMER', **kwargs) ->
|
|
|
76
75
|
class CompilationTargetGateset(ops.Gateset, metaclass=abc.ABCMeta):
|
|
77
76
|
"""Abstract base class to create gatesets that can be used as targets for compilation.
|
|
78
77
|
|
|
79
|
-
An instance of this type can be passed to transformers like `cirq.
|
|
78
|
+
An instance of this type can be passed to transformers like `cirq.optimize_for_target_gateset`,
|
|
80
79
|
which can transform any given circuit to contain gates accepted by this gateset.
|
|
81
80
|
"""
|
|
82
81
|
|
|
@@ -86,6 +85,7 @@ class CompilationTargetGateset(ops.Gateset, metaclass=abc.ABCMeta):
|
|
|
86
85
|
name: Optional[str] = None,
|
|
87
86
|
unroll_circuit_op: bool = True,
|
|
88
87
|
preserve_moment_structure: bool = True,
|
|
88
|
+
reorder_operations: bool = False,
|
|
89
89
|
):
|
|
90
90
|
"""Initializes CompilationTargetGateset.
|
|
91
91
|
|
|
@@ -97,9 +97,18 @@ class CompilationTargetGateset(ops.Gateset, metaclass=abc.ABCMeta):
|
|
|
97
97
|
validated by validating the underlying `cirq.Circuit`.
|
|
98
98
|
preserve_moment_structure: Whether to preserve the moment structure of the
|
|
99
99
|
circuit during compilation or not.
|
|
100
|
+
reorder_operations: Whether to attempt to reorder the operations in order to reduce
|
|
101
|
+
circuit depth or not (can be True only if preserve_moment_structure=False).
|
|
102
|
+
Raises:
|
|
103
|
+
ValueError: If both reorder_operations and preserve_moment_structure are True.
|
|
100
104
|
"""
|
|
105
|
+
if reorder_operations and preserve_moment_structure:
|
|
106
|
+
raise ValueError(
|
|
107
|
+
'reorder_operations and preserve_moment_structure can not both be True'
|
|
108
|
+
)
|
|
101
109
|
super().__init__(*gates, name=name, unroll_circuit_op=unroll_circuit_op)
|
|
102
110
|
self._preserve_moment_structure = preserve_moment_structure
|
|
111
|
+
self._reorder_operations = reorder_operations
|
|
103
112
|
|
|
104
113
|
@property
|
|
105
114
|
@abc.abstractmethod
|
|
@@ -146,11 +155,15 @@ class CompilationTargetGateset(ops.Gateset, metaclass=abc.ABCMeta):
|
|
|
146
155
|
@property
|
|
147
156
|
def preprocess_transformers(self) -> List['cirq.TRANSFORMER']:
|
|
148
157
|
"""List of transformers which should be run before decomposing individual operations."""
|
|
158
|
+
reorder_transfomers = (
|
|
159
|
+
[transformers.insertion_sort_transformer] if self._reorder_operations else []
|
|
160
|
+
)
|
|
149
161
|
return [
|
|
150
162
|
create_transformer_with_kwargs(
|
|
151
163
|
transformers.expand_composite,
|
|
152
164
|
no_decomp=lambda op: protocols.num_qubits(op) <= self.num_qubits,
|
|
153
165
|
),
|
|
166
|
+
*reorder_transfomers,
|
|
154
167
|
create_transformer_with_kwargs(
|
|
155
168
|
merge_k_qubit_gates.merge_k_qubit_unitaries,
|
|
156
169
|
k=self.num_qubits,
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
"""Target gateset used for compiling circuits to CZ + 1-q rotations + measurement gates."""
|
|
16
16
|
|
|
17
|
-
from typing import Any, Dict, Sequence, Type,
|
|
17
|
+
from typing import Any, Dict, Sequence, Type, TYPE_CHECKING, Union
|
|
18
18
|
|
|
19
19
|
from cirq import ops, protocols
|
|
20
20
|
from cirq.transformers.analytical_decompositions import two_qubit_to_cz
|
|
@@ -49,6 +49,7 @@ class CZTargetGateset(compilation_target_gateset.TwoQubitCompilationTargetGatese
|
|
|
49
49
|
allow_partial_czs: bool = False,
|
|
50
50
|
additional_gates: Sequence[Union[Type['cirq.Gate'], 'cirq.Gate', 'cirq.GateFamily']] = (),
|
|
51
51
|
preserve_moment_structure: bool = True,
|
|
52
|
+
reorder_operations: bool = False,
|
|
52
53
|
) -> None:
|
|
53
54
|
"""Initializes CZTargetGateset
|
|
54
55
|
|
|
@@ -60,6 +61,8 @@ class CZTargetGateset(compilation_target_gateset.TwoQubitCompilationTargetGatese
|
|
|
60
61
|
be "accepted" by this gateset. This is empty by default.
|
|
61
62
|
preserve_moment_structure: Whether to preserve the moment structure of the
|
|
62
63
|
circuit during compilation or not.
|
|
64
|
+
reorder_operations: Whether to attempt to reorder the operations in order to reduce
|
|
65
|
+
circuit depth or not (can be True only if preserve_moment_structure=False).
|
|
63
66
|
"""
|
|
64
67
|
super().__init__(
|
|
65
68
|
ops.CZPowGate if allow_partial_czs else ops.CZ,
|
|
@@ -69,6 +72,7 @@ class CZTargetGateset(compilation_target_gateset.TwoQubitCompilationTargetGatese
|
|
|
69
72
|
*additional_gates,
|
|
70
73
|
name='CZPowTargetGateset' if allow_partial_czs else 'CZTargetGateset',
|
|
71
74
|
preserve_moment_structure=preserve_moment_structure,
|
|
75
|
+
reorder_operations=reorder_operations,
|
|
72
76
|
)
|
|
73
77
|
self.additional_gates = tuple(
|
|
74
78
|
g if isinstance(g, ops.GateFamily) else ops.GateFamily(gate=g) for g in additional_gates
|
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
from typing import Optional, Sequence, Type
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
16
18
|
import pytest
|
|
17
|
-
import cirq
|
|
18
19
|
import sympy
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
import cirq
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
def all_gates_of_type(m: cirq.Moment, g: cirq.Gateset):
|
|
@@ -319,3 +321,22 @@ def test_unsupported_gate():
|
|
|
319
321
|
)
|
|
320
322
|
def test_repr(gateset):
|
|
321
323
|
cirq.testing.assert_equivalent_repr(gateset)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def test_with_commutation():
|
|
327
|
+
c = cirq.Circuit(
|
|
328
|
+
cirq.CZ(cirq.q(0), cirq.q(1)), cirq.CZ(cirq.q(1), cirq.q(2)), cirq.CZ(cirq.q(0), cirq.q(1))
|
|
329
|
+
)
|
|
330
|
+
got = cirq.optimize_for_target_gateset(
|
|
331
|
+
c,
|
|
332
|
+
gateset=cirq.CZTargetGateset(preserve_moment_structure=False, reorder_operations=True),
|
|
333
|
+
max_num_passes=1,
|
|
334
|
+
)
|
|
335
|
+
assert got == cirq.Circuit(cirq.CZ(cirq.q(1), cirq.q(2)))
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def test_reorder_operations_and_preserve_moment_structure_raises():
|
|
339
|
+
with pytest.raises(
|
|
340
|
+
ValueError, match='reorder_operations and preserve_moment_structure can not both be True'
|
|
341
|
+
):
|
|
342
|
+
_ = cirq.CZTargetGateset(preserve_moment_structure=True, reorder_operations=True)
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
"""Target gateset used for compiling circuits to √iSWAP + 1-q rotations + measurement gates."""
|
|
16
16
|
|
|
17
|
-
from typing import Any, Dict, Optional, Sequence, Type,
|
|
17
|
+
from typing import Any, Dict, Optional, Sequence, Type, TYPE_CHECKING, Union
|
|
18
18
|
|
|
19
19
|
from cirq import ops, protocols
|
|
20
20
|
from cirq.protocols.decompose_protocol import DecomposeResult
|
|
@@ -15,24 +15,25 @@
|
|
|
15
15
|
"""Defines the API for circuit transformers in Cirq."""
|
|
16
16
|
|
|
17
17
|
import dataclasses
|
|
18
|
-
import inspect
|
|
19
18
|
import enum
|
|
20
19
|
import functools
|
|
20
|
+
import inspect
|
|
21
21
|
import textwrap
|
|
22
22
|
from typing import (
|
|
23
|
-
cast,
|
|
24
23
|
Any,
|
|
25
24
|
Callable,
|
|
26
|
-
|
|
25
|
+
cast,
|
|
27
26
|
Hashable,
|
|
28
27
|
List,
|
|
29
|
-
overload,
|
|
30
28
|
Optional,
|
|
29
|
+
overload,
|
|
30
|
+
Tuple,
|
|
31
31
|
Type,
|
|
32
32
|
TYPE_CHECKING,
|
|
33
33
|
TypeVar,
|
|
34
34
|
Union,
|
|
35
35
|
)
|
|
36
|
+
|
|
36
37
|
from typing_extensions import Protocol
|
|
37
38
|
|
|
38
39
|
from cirq import circuits
|
|
@@ -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
|
-
from unittest import mock
|
|
16
15
|
from typing import Optional
|
|
16
|
+
from unittest import mock
|
|
17
|
+
|
|
18
|
+
import pytest
|
|
17
19
|
|
|
18
20
|
import cirq
|
|
19
21
|
from cirq.transformers.transformer_api import LogLevel
|
|
20
22
|
|
|
21
|
-
import pytest
|
|
22
|
-
|
|
23
23
|
|
|
24
24
|
@cirq.transformer()
|
|
25
25
|
class MockTransformerClass:
|
|
@@ -257,6 +257,14 @@ def test_transformer_stats_logger_show_levels(capfd):
|
|
|
257
257
|
assert all(line not in out for line in [info_line, debug_line, warning_line])
|
|
258
258
|
|
|
259
259
|
|
|
260
|
+
def test_noop_logger():
|
|
261
|
+
logger = cirq.transformers.transformer_api.NoOpTransformerLogger()
|
|
262
|
+
logger.register_initial(cirq.Circuit(), "test")
|
|
263
|
+
logger.log("stuff")
|
|
264
|
+
logger.register_final(cirq.Circuit(), "test")
|
|
265
|
+
logger.show()
|
|
266
|
+
|
|
267
|
+
|
|
260
268
|
def test_transformer_stats_logger_linear_and_nested(capfd):
|
|
261
269
|
q = cirq.LineQubit.range(2)
|
|
262
270
|
circuit = cirq.Circuit(cirq.H.on_each(*q), cirq.CNOT(*q))
|
|
@@ -14,22 +14,21 @@
|
|
|
14
14
|
|
|
15
15
|
"""Defines primitives for common transformer patterns."""
|
|
16
16
|
|
|
17
|
-
from collections import defaultdict
|
|
18
17
|
import bisect
|
|
19
18
|
import dataclasses
|
|
20
|
-
|
|
19
|
+
from collections import defaultdict
|
|
21
20
|
from typing import (
|
|
22
|
-
cast,
|
|
23
21
|
Callable,
|
|
22
|
+
cast,
|
|
24
23
|
Dict,
|
|
25
24
|
Hashable,
|
|
26
25
|
List,
|
|
27
26
|
Optional,
|
|
28
27
|
Sequence,
|
|
29
28
|
Set,
|
|
30
|
-
Union,
|
|
31
29
|
Tuple,
|
|
32
30
|
TYPE_CHECKING,
|
|
31
|
+
Union,
|
|
33
32
|
)
|
|
34
33
|
|
|
35
34
|
from cirq import circuits, ops, protocols
|
|
@@ -196,37 +195,16 @@ def _map_operations_impl(
|
|
|
196
195
|
return mapped_ops
|
|
197
196
|
|
|
198
197
|
new_moments: List[List['cirq.Operation']] = []
|
|
199
|
-
|
|
200
|
-
# Keep track of the latest time index for each qubit, measurement key, and control key.
|
|
201
|
-
qubit_time_index: Dict['cirq.Qid', int] = {}
|
|
202
|
-
measurement_time_index: Dict['cirq.MeasurementKey', int] = {}
|
|
203
|
-
control_time_index: Dict['cirq.MeasurementKey', int] = {}
|
|
204
|
-
|
|
205
|
-
# New mapped operations in the current moment should be inserted after `last_moment_time_index`.
|
|
206
|
-
last_moment_time_index = -1
|
|
207
|
-
|
|
208
198
|
for idx, moment in enumerate(circuit):
|
|
209
|
-
if wrap_in_circuit_op
|
|
210
|
-
|
|
199
|
+
curr_moments: List[List['cirq.Operation']] = [[]] if wrap_in_circuit_op else []
|
|
200
|
+
placement_cache = circuits.circuit._PlacementCache()
|
|
211
201
|
for op in moment:
|
|
212
202
|
mapped_ops = apply_map_func(op, idx)
|
|
213
|
-
|
|
214
203
|
for mapped_op in mapped_ops:
|
|
215
|
-
|
|
216
|
-
placement_index
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
placement_index = max(placement_index, last_moment_time_index + 1)
|
|
220
|
-
new_moments.extend([[] for _ in range(placement_index - len(new_moments) + 1)])
|
|
221
|
-
new_moments[placement_index].append(mapped_op)
|
|
222
|
-
for qubit in mapped_op.qubits:
|
|
223
|
-
qubit_time_index[qubit] = placement_index
|
|
224
|
-
for key in protocols.measurement_key_objs(mapped_op):
|
|
225
|
-
measurement_time_index[key] = placement_index
|
|
226
|
-
for key in protocols.control_keys(mapped_op):
|
|
227
|
-
control_time_index[key] = placement_index
|
|
228
|
-
|
|
229
|
-
last_moment_time_index = len(new_moments) - 1
|
|
204
|
+
placement_index = placement_cache.append(mapped_op)
|
|
205
|
+
curr_moments.extend([[] for _ in range(placement_index - len(curr_moments) + 1)])
|
|
206
|
+
curr_moments[placement_index].append(mapped_op)
|
|
207
|
+
new_moments.extend(curr_moments)
|
|
230
208
|
|
|
231
209
|
return _create_target_circuit_type([circuits.Moment(moment) for moment in new_moments], circuit)
|
|
232
210
|
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from typing import
|
|
15
|
+
from typing import Iterator, List, Optional
|
|
16
|
+
|
|
16
17
|
import pytest
|
|
17
18
|
|
|
18
19
|
import cirq
|
|
@@ -64,7 +65,7 @@ def test_map_operations_does_not_insert_too_many_moments():
|
|
|
64
65
|
q = cirq.LineQubit.range(5)
|
|
65
66
|
c_orig = cirq.Circuit(cirq.CX(q[0], q[1]), cirq.CX(q[3], q[2]), cirq.CX(q[3], q[4]))
|
|
66
67
|
|
|
67
|
-
def map_func(op: cirq.Operation, _: int) -> cirq.OP_TREE:
|
|
68
|
+
def map_func(op: cirq.Operation, _: int) -> Iterator[cirq.OP_TREE]:
|
|
68
69
|
yield cirq.Z.on_each(*op.qubits)
|
|
69
70
|
yield cirq.CX(*op.qubits)
|
|
70
71
|
yield cirq.Z.on_each(*op.qubits)
|
|
@@ -130,7 +131,7 @@ def test_map_operations_deep_subcircuits():
|
|
|
130
131
|
.with_tags("external")
|
|
131
132
|
)
|
|
132
133
|
|
|
133
|
-
def map_func(op: cirq.Operation, _: int) -> cirq.OP_TREE:
|
|
134
|
+
def map_func(op: cirq.Operation, _: int) -> Iterator[cirq.OP_TREE]:
|
|
134
135
|
yield (
|
|
135
136
|
[cirq.Z.on_each(*op.qubits), cirq.CX(*op.qubits), cirq.Z.on_each(*op.qubits)]
|
|
136
137
|
if op.gate == cirq.CX
|
|
@@ -585,7 +586,7 @@ def test_merge_moments_empty_moment_as_intermediate_step():
|
|
|
585
586
|
|
|
586
587
|
def test_merge_moments_empty_circuit():
|
|
587
588
|
def fail_if_called_func(*_):
|
|
588
|
-
assert False
|
|
589
|
+
assert False # pragma: no cover
|
|
589
590
|
|
|
590
591
|
c = cirq.Circuit()
|
|
591
592
|
assert cirq.merge_moments(c, fail_if_called_func) is c
|
|
@@ -600,7 +601,7 @@ def test_merge_operations_raises():
|
|
|
600
601
|
|
|
601
602
|
def test_merge_operations_nothing_to_merge():
|
|
602
603
|
def fail_if_called_func(*_):
|
|
603
|
-
assert False
|
|
604
|
+
assert False # pragma: no cover
|
|
604
605
|
|
|
605
606
|
# Empty Circuit.
|
|
606
607
|
c = cirq.Circuit()
|
cirq/value/__init__.py
CHANGED
|
@@ -13,55 +13,76 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
"""Value conversion utilities and classes for time and quantum states."""
|
|
16
|
-
from cirq.value.abc_alt import
|
|
16
|
+
from cirq.value.abc_alt import (
|
|
17
|
+
ABCMetaImplementAnyOneOf as ABCMetaImplementAnyOneOf,
|
|
18
|
+
alternative as alternative,
|
|
19
|
+
)
|
|
17
20
|
|
|
18
21
|
from cirq.value.angle import (
|
|
19
|
-
canonicalize_half_turns,
|
|
20
|
-
chosen_angle_to_canonical_half_turns,
|
|
21
|
-
chosen_angle_to_half_turns,
|
|
22
|
+
canonicalize_half_turns as canonicalize_half_turns,
|
|
23
|
+
chosen_angle_to_canonical_half_turns as chosen_angle_to_canonical_half_turns,
|
|
24
|
+
chosen_angle_to_half_turns as chosen_angle_to_half_turns,
|
|
22
25
|
)
|
|
23
26
|
|
|
24
27
|
from cirq.value.classical_data import (
|
|
25
|
-
ClassicalDataDictionaryStore,
|
|
26
|
-
ClassicalDataStore,
|
|
27
|
-
ClassicalDataStoreReader,
|
|
28
|
-
MeasurementType,
|
|
28
|
+
ClassicalDataDictionaryStore as ClassicalDataDictionaryStore,
|
|
29
|
+
ClassicalDataStore as ClassicalDataStore,
|
|
30
|
+
ClassicalDataStoreReader as ClassicalDataStoreReader,
|
|
31
|
+
MeasurementType as MeasurementType,
|
|
29
32
|
)
|
|
30
33
|
|
|
31
|
-
from cirq.value.condition import
|
|
34
|
+
from cirq.value.condition import (
|
|
35
|
+
Condition as Condition,
|
|
36
|
+
KeyCondition as KeyCondition,
|
|
37
|
+
SympyCondition as SympyCondition,
|
|
38
|
+
BitMaskKeyCondition as BitMaskKeyCondition,
|
|
39
|
+
)
|
|
32
40
|
|
|
33
41
|
from cirq.value.digits import (
|
|
34
|
-
big_endian_bits_to_int,
|
|
35
|
-
big_endian_digits_to_int,
|
|
36
|
-
big_endian_int_to_bits,
|
|
37
|
-
big_endian_int_to_digits,
|
|
42
|
+
big_endian_bits_to_int as big_endian_bits_to_int,
|
|
43
|
+
big_endian_digits_to_int as big_endian_digits_to_int,
|
|
44
|
+
big_endian_int_to_bits as big_endian_int_to_bits,
|
|
45
|
+
big_endian_int_to_digits as big_endian_int_to_digits,
|
|
38
46
|
)
|
|
39
47
|
|
|
40
|
-
from cirq.value.duration import Duration, DURATION_LIKE
|
|
48
|
+
from cirq.value.duration import Duration as Duration, DURATION_LIKE as DURATION_LIKE
|
|
41
49
|
|
|
42
|
-
from cirq.value.linear_dict import LinearDict, Scalar
|
|
50
|
+
from cirq.value.linear_dict import LinearDict as LinearDict, Scalar as Scalar
|
|
43
51
|
|
|
44
|
-
from cirq.value.measurement_key import
|
|
52
|
+
from cirq.value.measurement_key import (
|
|
53
|
+
MEASUREMENT_KEY_SEPARATOR as MEASUREMENT_KEY_SEPARATOR,
|
|
54
|
+
MeasurementKey as MeasurementKey,
|
|
55
|
+
)
|
|
45
56
|
|
|
46
|
-
from cirq.value.probability import
|
|
57
|
+
from cirq.value.probability import (
|
|
58
|
+
state_vector_to_probabilities as state_vector_to_probabilities,
|
|
59
|
+
validate_probability as validate_probability,
|
|
60
|
+
)
|
|
47
61
|
|
|
48
62
|
from cirq.value.product_state import (
|
|
49
|
-
ProductState,
|
|
50
|
-
KET_PLUS,
|
|
51
|
-
KET_MINUS,
|
|
52
|
-
KET_IMAG,
|
|
53
|
-
KET_MINUS_IMAG,
|
|
54
|
-
KET_ZERO,
|
|
55
|
-
KET_ONE,
|
|
56
|
-
PAULI_STATES,
|
|
63
|
+
ProductState as ProductState,
|
|
64
|
+
KET_PLUS as KET_PLUS,
|
|
65
|
+
KET_MINUS as KET_MINUS,
|
|
66
|
+
KET_IMAG as KET_IMAG,
|
|
67
|
+
KET_MINUS_IMAG as KET_MINUS_IMAG,
|
|
68
|
+
KET_ZERO as KET_ZERO,
|
|
69
|
+
KET_ONE as KET_ONE,
|
|
70
|
+
PAULI_STATES as PAULI_STATES,
|
|
57
71
|
)
|
|
58
72
|
|
|
59
|
-
from cirq.value.periodic_value import PeriodicValue
|
|
73
|
+
from cirq.value.periodic_value import PeriodicValue as PeriodicValue
|
|
60
74
|
|
|
61
|
-
from cirq.value.random_state import
|
|
75
|
+
from cirq.value.random_state import (
|
|
76
|
+
parse_random_state as parse_random_state,
|
|
77
|
+
RANDOM_STATE_OR_SEED_LIKE as RANDOM_STATE_OR_SEED_LIKE,
|
|
78
|
+
)
|
|
62
79
|
|
|
63
|
-
from cirq.value.timestamp import Timestamp
|
|
80
|
+
from cirq.value.timestamp import Timestamp as Timestamp
|
|
64
81
|
|
|
65
|
-
from cirq.value.type_alias import
|
|
82
|
+
from cirq.value.type_alias import (
|
|
83
|
+
TParamKey as TParamKey,
|
|
84
|
+
TParamVal as TParamVal,
|
|
85
|
+
TParamValComplex as TParamValComplex,
|
|
86
|
+
)
|
|
66
87
|
|
|
67
|
-
from cirq.value.value_equality_attr import value_equality
|
|
88
|
+
from cirq.value.value_equality_attr import value_equality as value_equality
|
cirq/value/abc_alt.py
CHANGED