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
cirq/ops/clifford_gate.py
CHANGED
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from typing import Any, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
|
|
16
|
-
|
|
17
15
|
import functools
|
|
18
16
|
from dataclasses import dataclass
|
|
17
|
+
from types import NotImplementedType
|
|
18
|
+
from typing import Any, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
|
|
19
|
+
|
|
19
20
|
import numpy as np
|
|
20
21
|
|
|
21
|
-
from cirq import
|
|
22
|
-
from cirq._import import LazyLoader
|
|
22
|
+
from cirq import linalg, protocols, qis, value
|
|
23
23
|
from cirq._compat import cached_method
|
|
24
|
-
from cirq.
|
|
24
|
+
from cirq._import import LazyLoader
|
|
25
|
+
from cirq.ops import common_gates, named_qubit, pauli_gates, phased_x_z_gate, raw_types
|
|
25
26
|
from cirq.ops.pauli_gates import Pauli
|
|
26
|
-
from cirq.type_workarounds import NotImplementedType
|
|
27
27
|
|
|
28
28
|
if TYPE_CHECKING:
|
|
29
29
|
import cirq
|
|
@@ -130,22 +130,10 @@ def _pad_tableau(
|
|
|
130
130
|
return padded_tableau
|
|
131
131
|
|
|
132
132
|
|
|
133
|
-
def _gate_tableau(num_qubits: int, gate: raw_types.Gate) -> 'cirq.CliffordTableau':
|
|
134
|
-
qubits = devices.LineQubit.range(num_qubits)
|
|
135
|
-
t = qis.CliffordTableau(num_qubits=num_qubits)
|
|
136
|
-
args = sim.CliffordTableauSimulationState(
|
|
137
|
-
tableau=t, qubits=qubits, prng=np.random.RandomState()
|
|
138
|
-
)
|
|
139
|
-
protocols.act_on(gate, args, qubits, allow_decompose=False)
|
|
140
|
-
return args.tableau
|
|
141
|
-
|
|
142
|
-
|
|
143
133
|
class CommonCliffordGateMetaClass(value.ABCMetaImplementAnyOneOf):
|
|
144
134
|
"""A metaclass used to lazy initialize several common Clifford Gate as class attributes."""
|
|
145
135
|
|
|
146
136
|
# These are class properties so we define them as properties on a metaclass.
|
|
147
|
-
# Note that in python 3.9+ @classmethod can be used with @property, so these
|
|
148
|
-
# can be moved to CommonCliffordGates.
|
|
149
137
|
|
|
150
138
|
@property
|
|
151
139
|
def all_single_qubit_cliffords(cls) -> Sequence['cirq.SingleQubitCliffordGate']:
|
|
@@ -322,7 +310,7 @@ class CommonCliffordGates(metaclass=CommonCliffordGateMetaClass):
|
|
|
322
310
|
ValueError: When one or more operations do not have stabilizer effect.
|
|
323
311
|
"""
|
|
324
312
|
for op in operations:
|
|
325
|
-
if op.gate and op.gate
|
|
313
|
+
if op.gate and protocols.has_stabilizer_effect(op.gate):
|
|
326
314
|
continue
|
|
327
315
|
raise ValueError(
|
|
328
316
|
"Clifford Gate can only be constructed from the "
|
|
@@ -377,7 +365,10 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
|
|
|
377
365
|
# ZI [ 0 0 | 1 0 | 1 ]
|
|
378
366
|
# IZ [ 1 0 | 1 1 | 0 ]
|
|
379
367
|
# Take the third row as example: this means the ZI gate after the this gate,
|
|
380
|
-
# more precisely the conjugate transformation of ZI by this gate, becomes -ZI
|
|
368
|
+
# more precisely the conjugate transformation of ZI by this gate, becomes -ZI:
|
|
369
|
+
# ---(CliffordGate^-1)---ZI---CliffordGate---
|
|
370
|
+
# = unitary(CliffordGate)@unitary(ZI)@unitary(CliffordGate).conj().T
|
|
371
|
+
# = -ZI.
|
|
381
372
|
# (Note the real clifford tableau has to satify the Symplectic property.
|
|
382
373
|
# here is just for illustration)
|
|
383
374
|
object.__setattr__(self, '_clifford_tableau', _clifford_tableau.copy())
|
|
@@ -402,7 +393,7 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
|
|
|
402
393
|
|
|
403
394
|
def __pow__(self, exponent: float) -> 'CliffordGate':
|
|
404
395
|
if exponent != int(exponent):
|
|
405
|
-
return NotImplemented
|
|
396
|
+
return NotImplemented # pragma: no cover
|
|
406
397
|
exponent = int(exponent)
|
|
407
398
|
|
|
408
399
|
if exponent == -1:
|
|
@@ -433,19 +424,19 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
|
|
|
433
424
|
return CliffordGate.from_clifford_tableau(base_tableau)
|
|
434
425
|
|
|
435
426
|
def __repr__(self) -> str:
|
|
436
|
-
return f"Clifford Gate with Tableau:\n
|
|
427
|
+
return f"Clifford Gate with Tableau:\n{self.clifford_tableau._str_full_()}"
|
|
437
428
|
|
|
438
429
|
def _commutes_(
|
|
439
430
|
self, other: Any, *, atol: float = 1e-8
|
|
440
431
|
) -> Union[bool, NotImplementedType, None]:
|
|
441
|
-
# Note even if we assume two gates define the
|
|
432
|
+
# Note even if we assume two gates define the tableau based on the same qubit order,
|
|
442
433
|
# the following approach cannot judge it:
|
|
443
434
|
# self.clifford_tableau.then(other.clifford_tableau) == other.clifford_tableau.then(
|
|
444
435
|
# self.clifford_tableau
|
|
445
436
|
# )
|
|
446
437
|
# For example: X.then(Z) and Z.then(X) both return same tableau
|
|
447
438
|
# it is because Clifford tableau ignores the global phase information.
|
|
448
|
-
return NotImplemented
|
|
439
|
+
return NotImplemented # pragma: no cover
|
|
449
440
|
|
|
450
441
|
def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
|
|
451
442
|
return transformers.analytical_decompositions.decompose_clifford_tableau_to_operations(
|
|
@@ -474,7 +465,7 @@ class CliffordGate(raw_types.Gate, CommonCliffordGates):
|
|
|
474
465
|
# is aimed to fix that.
|
|
475
466
|
return NotImplemented
|
|
476
467
|
|
|
477
|
-
return NotImplemented
|
|
468
|
+
return NotImplemented # pragma: no cover
|
|
478
469
|
|
|
479
470
|
|
|
480
471
|
@dataclass(frozen=True, init=False, eq=False, repr=False)
|
|
@@ -742,17 +733,23 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
742
733
|
z = -0.5 if x_to_flip else 0.5
|
|
743
734
|
return phased_x_z_gate.PhasedXZGate(x_exponent=x, z_exponent=z, axis_phase_exponent=a)
|
|
744
735
|
|
|
745
|
-
def __pow__(self, exponent:
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
736
|
+
def __pow__(self, exponent: float) -> 'SingleQubitCliffordGate':
|
|
737
|
+
if int(exponent) == exponent:
|
|
738
|
+
# The single qubit Clifford gates are a group of size 24
|
|
739
|
+
exp = int(exponent) % 24
|
|
740
|
+
ret_gate = super().__pow__(exp if exp != 23 else -1)
|
|
741
|
+
return SingleQubitCliffordGate.from_clifford_tableau(ret_gate.clifford_tableau)
|
|
742
|
+
elif int(2 * exponent) == 2 * exponent:
|
|
743
|
+
# If exponent = k/2 for integer k, then we compute the k-th power of the square root
|
|
744
|
+
if exponent < 0:
|
|
745
|
+
sqrt_exp = -0.5
|
|
746
|
+
else:
|
|
747
|
+
sqrt_exp = 0.5
|
|
748
|
+
pow_gate = self._get_sqrt_map()[sqrt_exp].get(self, None)
|
|
749
749
|
if pow_gate:
|
|
750
|
-
return pow_gate
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
if ret_gate is NotImplemented:
|
|
754
|
-
return NotImplemented
|
|
755
|
-
return SingleQubitCliffordGate.from_clifford_tableau(ret_gate.clifford_tableau)
|
|
750
|
+
return pow_gate ** (abs(2 * exponent))
|
|
751
|
+
|
|
752
|
+
return NotImplemented
|
|
756
753
|
|
|
757
754
|
def _act_on_(
|
|
758
755
|
self,
|
|
@@ -897,7 +894,12 @@ class SingleQubitCliffordGate(CliffordGate):
|
|
|
897
894
|
return self.merged_with(after).merged_with(self**-1)
|
|
898
895
|
|
|
899
896
|
def __repr__(self) -> str:
|
|
900
|
-
return
|
|
897
|
+
return (
|
|
898
|
+
f'cirq.ops.SingleQubitCliffordGate(_clifford_tableau=cirq.CliffordTableau(1, '
|
|
899
|
+
f'rs=np.array({self._clifford_tableau.rs.tolist()!r}), '
|
|
900
|
+
f'xs=np.array({self._clifford_tableau.xs.tolist()!r}), '
|
|
901
|
+
f'zs=np.array({self._clifford_tableau.zs.tolist()!r})))'
|
|
902
|
+
)
|
|
901
903
|
|
|
902
904
|
def _circuit_diagram_info_(
|
|
903
905
|
self, args: 'cirq.CircuitDiagramInfoArgs'
|
cirq/ops/clifford_gate_test.py
CHANGED
|
@@ -21,7 +21,7 @@ import pytest
|
|
|
21
21
|
|
|
22
22
|
import cirq
|
|
23
23
|
from cirq.protocols.act_on_protocol_test import ExampleSimulationState
|
|
24
|
-
from cirq.testing import
|
|
24
|
+
from cirq.testing import assert_allclose_up_to_global_phase, EqualsTester
|
|
25
25
|
|
|
26
26
|
_bools = (False, True)
|
|
27
27
|
_paulis = (cirq.X, cirq.Y, cirq.Z)
|
|
@@ -219,6 +219,8 @@ def test_pow():
|
|
|
219
219
|
assert cirq.SingleQubitCliffordGate.Y_nsqrt == cirq.SingleQubitCliffordGate.Y**-0.5
|
|
220
220
|
assert cirq.SingleQubitCliffordGate.Z_nsqrt == cirq.SingleQubitCliffordGate.Z**-0.5
|
|
221
221
|
assert cirq.SingleQubitCliffordGate.X_sqrt**-1 == cirq.SingleQubitCliffordGate.X_nsqrt
|
|
222
|
+
assert cirq.SingleQubitCliffordGate.X_sqrt**3 == cirq.SingleQubitCliffordGate.X**1.5
|
|
223
|
+
assert cirq.SingleQubitCliffordGate.Z**2.0 == cirq.SingleQubitCliffordGate.I
|
|
222
224
|
assert cirq.inverse(cirq.SingleQubitCliffordGate.X_nsqrt) == (
|
|
223
225
|
cirq.SingleQubitCliffordGate.X_sqrt
|
|
224
226
|
)
|
|
@@ -919,3 +921,75 @@ def test_all_single_qubit_clifford_unitaries():
|
|
|
919
921
|
assert cirq.equal_up_to_global_phase(cs[21], (i - 1j * (-x + y - z)) / 2)
|
|
920
922
|
assert cirq.equal_up_to_global_phase(cs[22], (i - 1j * (-x - y + z)) / 2)
|
|
921
923
|
assert cirq.equal_up_to_global_phase(cs[23], (i - 1j * (-x - y - z)) / 2)
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
def test_clifford_gate_repr():
|
|
927
|
+
q0, q1, q2 = cirq.LineQubit.range(3)
|
|
928
|
+
assert (
|
|
929
|
+
repr(cirq.ops.CliffordGate.from_op_list([cirq.ops.X(q0), cirq.CZ(q1, q2)], [q0, q1, q2]))
|
|
930
|
+
== """Clifford Gate with Tableau:
|
|
931
|
+
stable | destable
|
|
932
|
+
---------+----------
|
|
933
|
+
- Z0 | + X0
|
|
934
|
+
+ Z1 | + X1Z2
|
|
935
|
+
+ Z2 | + Z1X2
|
|
936
|
+
"""
|
|
937
|
+
)
|
|
938
|
+
assert (
|
|
939
|
+
repr(cirq.ops.CliffordGate.CNOT)
|
|
940
|
+
== """Clifford Gate with Tableau:
|
|
941
|
+
stable | destable
|
|
942
|
+
-------+----------
|
|
943
|
+
+ Z0 | + X0X1
|
|
944
|
+
+ Z0Z1 | + X1
|
|
945
|
+
"""
|
|
946
|
+
)
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
def test_single_qubit_clifford_gate_repr():
|
|
950
|
+
# Common gates
|
|
951
|
+
assert repr(cirq.ops.SingleQubitCliffordGate.X) == (
|
|
952
|
+
'cirq.ops.SingleQubitCliffordGate(_clifford_tableau=cirq.CliffordTableau(1, '
|
|
953
|
+
'rs=np.array([False, True]), xs=np.array([[True], [False]]), '
|
|
954
|
+
'zs=np.array([[False], [True]])))'
|
|
955
|
+
)
|
|
956
|
+
assert repr(cirq.ops.SingleQubitCliffordGate.Y) == (
|
|
957
|
+
'cirq.ops.SingleQubitCliffordGate(_clifford_tableau=cirq.CliffordTableau(1, '
|
|
958
|
+
'rs=np.array([True, True]), xs=np.array([[True], [False]]), '
|
|
959
|
+
'zs=np.array([[False], [True]])))'
|
|
960
|
+
)
|
|
961
|
+
assert repr(cirq.ops.SingleQubitCliffordGate.Z) == (
|
|
962
|
+
'cirq.ops.SingleQubitCliffordGate(_clifford_tableau=cirq.CliffordTableau(1, '
|
|
963
|
+
'rs=np.array([True, False]), xs=np.array([[True], [False]]), '
|
|
964
|
+
'zs=np.array([[False], [True]])))'
|
|
965
|
+
)
|
|
966
|
+
assert repr(cirq.ops.SingleQubitCliffordGate.I) == (
|
|
967
|
+
'cirq.ops.SingleQubitCliffordGate(_clifford_tableau=cirq.CliffordTableau(1, '
|
|
968
|
+
'rs=np.array([False, False]), xs=np.array([[True], [False]]), '
|
|
969
|
+
'zs=np.array([[False], [True]])))'
|
|
970
|
+
)
|
|
971
|
+
assert repr(cirq.ops.SingleQubitCliffordGate.X_sqrt) == (
|
|
972
|
+
'cirq.ops.SingleQubitCliffordGate(_clifford_tableau=cirq.CliffordTableau(1, '
|
|
973
|
+
'rs=np.array([False, True]), xs=np.array([[True], [True]]), '
|
|
974
|
+
'zs=np.array([[False], [True]])))'
|
|
975
|
+
)
|
|
976
|
+
|
|
977
|
+
assert repr(cirq.ops.SingleQubitCliffordGate.X) == (
|
|
978
|
+
'cirq.ops.SingleQubitCliffordGate(_clifford_tableau=cirq.CliffordTableau(1, '
|
|
979
|
+
'rs=np.array([False, True]), xs=np.array([[True], [False]]), '
|
|
980
|
+
'zs=np.array([[False], [True]])))'
|
|
981
|
+
)
|
|
982
|
+
|
|
983
|
+
# Other gates
|
|
984
|
+
qa = cirq.NamedQubit('a')
|
|
985
|
+
gate = cirq.ops.SingleQubitCliffordGate.from_clifford_tableau(
|
|
986
|
+
cirq.ops.CliffordGate.from_op_list(
|
|
987
|
+
[cirq.ops.PhasedXZGate(axis_phase_exponent=0.25, x_exponent=-1, z_exponent=0).on(qa)],
|
|
988
|
+
[qa],
|
|
989
|
+
).clifford_tableau
|
|
990
|
+
)
|
|
991
|
+
assert repr(gate) == (
|
|
992
|
+
'cirq.ops.SingleQubitCliffordGate(_clifford_tableau=cirq.CliffordTableau(1, '
|
|
993
|
+
'rs=np.array([False, True]), xs=np.array([[True], [False]]), '
|
|
994
|
+
'zs=np.array([[True], [True]])))'
|
|
995
|
+
)
|
cirq/ops/common_channels.py
CHANGED
|
@@ -15,19 +15,19 @@
|
|
|
15
15
|
"""Quantum channels that are commonly used in the literature."""
|
|
16
16
|
|
|
17
17
|
import itertools
|
|
18
|
-
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple,
|
|
18
|
+
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, TYPE_CHECKING, Union
|
|
19
19
|
|
|
20
20
|
import numpy as np
|
|
21
21
|
|
|
22
22
|
from cirq import protocols, value
|
|
23
23
|
from cirq.linalg import transformations
|
|
24
|
-
from cirq.ops import
|
|
24
|
+
from cirq.ops import common_gates, identity, pauli_gates, raw_types
|
|
25
25
|
|
|
26
26
|
if TYPE_CHECKING:
|
|
27
27
|
import cirq
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
@value.value_equality
|
|
30
|
+
@value.value_equality(approximate=True)
|
|
31
31
|
class AsymmetricDepolarizingChannel(raw_types.Gate):
|
|
32
32
|
r"""A channel that depolarizes asymmetrically along different directions.
|
|
33
33
|
|
|
@@ -131,7 +131,7 @@ class AsymmetricDepolarizingChannel(raw_types.Gate):
|
|
|
131
131
|
return True
|
|
132
132
|
|
|
133
133
|
def _value_equality_values_(self):
|
|
134
|
-
return self._num_qubits,
|
|
134
|
+
return self._num_qubits, tuple(sorted(self._error_probabilities.items()))
|
|
135
135
|
|
|
136
136
|
def __repr__(self) -> str:
|
|
137
137
|
return 'cirq.asymmetric_depolarize(' + f"error_probabilities={self._error_probabilities})"
|
|
@@ -196,11 +196,6 @@ class AsymmetricDepolarizingChannel(raw_types.Gate):
|
|
|
196
196
|
def _json_dict_(self) -> Dict[str, Any]:
|
|
197
197
|
return protocols.obj_to_dict_helper(self, ['error_probabilities'])
|
|
198
198
|
|
|
199
|
-
def _approx_eq_(self, other: Any, atol: float) -> bool:
|
|
200
|
-
self_keys, self_values = zip(*sorted(self.error_probabilities.items()))
|
|
201
|
-
other_keys, other_values = zip(*sorted(other.error_probabilities.items()))
|
|
202
|
-
return self_keys == other_keys and protocols.approx_eq(self_values, other_values, atol=atol)
|
|
203
|
-
|
|
204
199
|
|
|
205
200
|
def asymmetric_depolarize(
|
|
206
201
|
p_x: Optional[float] = None,
|
|
@@ -246,7 +241,7 @@ def asymmetric_depolarize(
|
|
|
246
241
|
return AsymmetricDepolarizingChannel(p_x, p_y, p_z, error_probabilities, tol)
|
|
247
242
|
|
|
248
243
|
|
|
249
|
-
@value.value_equality
|
|
244
|
+
@value.value_equality(approximate=True)
|
|
250
245
|
class DepolarizingChannel(raw_types.Gate):
|
|
251
246
|
r"""A channel that depolarizes one or several qubits.
|
|
252
247
|
|
|
@@ -306,7 +301,7 @@ class DepolarizingChannel(raw_types.Gate):
|
|
|
306
301
|
return True
|
|
307
302
|
|
|
308
303
|
def _value_equality_values_(self):
|
|
309
|
-
return self._p
|
|
304
|
+
return self._p, self._n_qubits
|
|
310
305
|
|
|
311
306
|
def __repr__(self) -> str:
|
|
312
307
|
if self._n_qubits == 1:
|
|
@@ -333,7 +328,7 @@ class DepolarizingChannel(raw_types.Gate):
|
|
|
333
328
|
"""The probability that one of the Pauli gates is applied.
|
|
334
329
|
|
|
335
330
|
Each of the Pauli gates is applied independently with probability
|
|
336
|
-
$p / (4^
|
|
331
|
+
$p / (4^n - 1)$, where $n$ is `n_qubits`.
|
|
337
332
|
"""
|
|
338
333
|
return self._p
|
|
339
334
|
|
|
@@ -347,9 +342,6 @@ class DepolarizingChannel(raw_types.Gate):
|
|
|
347
342
|
return protocols.obj_to_dict_helper(self, ['p'])
|
|
348
343
|
return protocols.obj_to_dict_helper(self, ['p', 'n_qubits'])
|
|
349
344
|
|
|
350
|
-
def _approx_eq_(self, other: Any, atol: float) -> bool:
|
|
351
|
-
return np.isclose(self.p, other.p, atol=atol).item() and self.n_qubits == other.n_qubits
|
|
352
|
-
|
|
353
345
|
|
|
354
346
|
def depolarize(p: float, n_qubits: int = 1) -> DepolarizingChannel:
|
|
355
347
|
r"""Returns a DepolarizingChannel with given probability of error.
|
|
@@ -372,7 +364,7 @@ def depolarize(p: float, n_qubits: int = 1) -> DepolarizingChannel:
|
|
|
372
364
|
Args:
|
|
373
365
|
p: The probability that one of the Pauli gates is applied. Each of
|
|
374
366
|
the Pauli gates is applied independently with probability
|
|
375
|
-
$p / (4^n - 1)
|
|
367
|
+
$p / (4^n - 1)$, where $n$ is n_qubits.
|
|
376
368
|
n_qubits: The number of qubits.
|
|
377
369
|
|
|
378
370
|
Raises:
|
|
@@ -381,7 +373,7 @@ def depolarize(p: float, n_qubits: int = 1) -> DepolarizingChannel:
|
|
|
381
373
|
return DepolarizingChannel(p, n_qubits)
|
|
382
374
|
|
|
383
375
|
|
|
384
|
-
@value.value_equality
|
|
376
|
+
@value.value_equality(approximate=True)
|
|
385
377
|
class GeneralizedAmplitudeDampingChannel(raw_types.Gate):
|
|
386
378
|
r"""Dampen qubit amplitudes through non ideal dissipation.
|
|
387
379
|
|
|
@@ -489,12 +481,6 @@ class GeneralizedAmplitudeDampingChannel(raw_types.Gate):
|
|
|
489
481
|
def _json_dict_(self) -> Dict[str, Any]:
|
|
490
482
|
return protocols.obj_to_dict_helper(self, ['p', 'gamma'])
|
|
491
483
|
|
|
492
|
-
def _approx_eq_(self, other: Any, atol: float) -> bool:
|
|
493
|
-
return (
|
|
494
|
-
np.isclose(self.gamma, other.gamma, atol=atol).item()
|
|
495
|
-
and np.isclose(self.p, other.p, atol=atol).item()
|
|
496
|
-
)
|
|
497
|
-
|
|
498
484
|
|
|
499
485
|
def generalized_amplitude_damp(p: float, gamma: float) -> GeneralizedAmplitudeDampingChannel:
|
|
500
486
|
r"""Returns a GeneralizedAmplitudeDampingChannel with probabilities gamma and p.
|
|
@@ -542,7 +528,7 @@ def generalized_amplitude_damp(p: float, gamma: float) -> GeneralizedAmplitudeDa
|
|
|
542
528
|
return GeneralizedAmplitudeDampingChannel(p, gamma)
|
|
543
529
|
|
|
544
530
|
|
|
545
|
-
@value.value_equality
|
|
531
|
+
@value.value_equality(approximate=True)
|
|
546
532
|
class AmplitudeDampingChannel(raw_types.Gate):
|
|
547
533
|
r"""Dampen qubit amplitudes through dissipation.
|
|
548
534
|
|
|
@@ -619,9 +605,6 @@ class AmplitudeDampingChannel(raw_types.Gate):
|
|
|
619
605
|
def _json_dict_(self) -> Dict[str, Any]:
|
|
620
606
|
return protocols.obj_to_dict_helper(self, ['gamma'])
|
|
621
607
|
|
|
622
|
-
def _approx_eq_(self, other: Any, atol: float) -> bool:
|
|
623
|
-
return np.isclose(self.gamma, other.gamma, atol=atol).item()
|
|
624
|
-
|
|
625
608
|
|
|
626
609
|
def amplitude_damp(gamma: float) -> AmplitudeDampingChannel:
|
|
627
610
|
r"""Returns an AmplitudeDampingChannel with the given probability gamma.
|
|
@@ -702,7 +685,7 @@ class ResetChannel(raw_types.Gate):
|
|
|
702
685
|
return True
|
|
703
686
|
|
|
704
687
|
def _qasm_(self, args: 'cirq.QasmArgs', qubits: Tuple['cirq.Qid', ...]) -> Optional[str]:
|
|
705
|
-
args.validate_version('2.0')
|
|
688
|
+
args.validate_version('2.0', '3.0')
|
|
706
689
|
return args.format('reset {0};\n', qubits[0])
|
|
707
690
|
|
|
708
691
|
def _qid_shape_(self):
|
|
@@ -787,7 +770,7 @@ def reset_each(*qubits: 'cirq.Qid') -> List[raw_types.Operation]:
|
|
|
787
770
|
return [ResetChannel(q.dimension).on(q) for q in qubits]
|
|
788
771
|
|
|
789
772
|
|
|
790
|
-
@value.value_equality
|
|
773
|
+
@value.value_equality(approximate=True)
|
|
791
774
|
class PhaseDampingChannel(raw_types.Gate):
|
|
792
775
|
r"""Dampen qubit phase.
|
|
793
776
|
|
|
@@ -881,9 +864,6 @@ class PhaseDampingChannel(raw_types.Gate):
|
|
|
881
864
|
def _json_dict_(self) -> Dict[str, Any]:
|
|
882
865
|
return protocols.obj_to_dict_helper(self, ['gamma'])
|
|
883
866
|
|
|
884
|
-
def _approx_eq_(self, other: Any, atol: float) -> bool:
|
|
885
|
-
return np.isclose(self._gamma, other._gamma, atol=atol).item()
|
|
886
|
-
|
|
887
867
|
|
|
888
868
|
def phase_damp(gamma: float) -> PhaseDampingChannel:
|
|
889
869
|
r"""Creates a PhaseDampingChannel with damping constant gamma.
|
|
@@ -919,7 +899,7 @@ def phase_damp(gamma: float) -> PhaseDampingChannel:
|
|
|
919
899
|
return PhaseDampingChannel(gamma)
|
|
920
900
|
|
|
921
901
|
|
|
922
|
-
@value.value_equality
|
|
902
|
+
@value.value_equality(approximate=True)
|
|
923
903
|
class PhaseFlipChannel(raw_types.Gate):
|
|
924
904
|
r"""Probabilistically flip the sign of the phase of a qubit.
|
|
925
905
|
|
|
@@ -991,9 +971,6 @@ class PhaseFlipChannel(raw_types.Gate):
|
|
|
991
971
|
def _json_dict_(self) -> Dict[str, Any]:
|
|
992
972
|
return protocols.obj_to_dict_helper(self, ['p'])
|
|
993
973
|
|
|
994
|
-
def _approx_eq_(self, other: Any, atol: float) -> bool:
|
|
995
|
-
return np.isclose(self.p, other.p, atol=atol).item()
|
|
996
|
-
|
|
997
974
|
|
|
998
975
|
def _phase_flip_Z() -> common_gates.ZPowGate:
|
|
999
976
|
"""Returns a cirq.Z which corresponds to a guaranteed phase flip."""
|
|
@@ -1073,7 +1050,7 @@ def phase_flip(p: Optional[float] = None) -> Union[common_gates.ZPowGate, PhaseF
|
|
|
1073
1050
|
return _phase_flip(p)
|
|
1074
1051
|
|
|
1075
1052
|
|
|
1076
|
-
@value.value_equality
|
|
1053
|
+
@value.value_equality(approximate=True)
|
|
1077
1054
|
class BitFlipChannel(raw_types.Gate):
|
|
1078
1055
|
r"""Probabilistically flip a qubit from 1 to 0 state or vice versa.
|
|
1079
1056
|
|
|
@@ -1112,15 +1089,12 @@ class BitFlipChannel(raw_types.Gate):
|
|
|
1112
1089
|
ValueError: if p is not a valid probability.
|
|
1113
1090
|
"""
|
|
1114
1091
|
self._p = value.validate_probability(p, 'p')
|
|
1115
|
-
self._delegate = AsymmetricDepolarizingChannel(p, 0.0, 0.0)
|
|
1116
1092
|
|
|
1117
1093
|
def _num_qubits_(self) -> int:
|
|
1118
1094
|
return 1
|
|
1119
1095
|
|
|
1120
|
-
def _mixture_(self) -> Sequence[Tuple[float,
|
|
1121
|
-
|
|
1122
|
-
# just return identity and x term
|
|
1123
|
-
return (mixture[0], mixture[1])
|
|
1096
|
+
def _mixture_(self) -> Sequence[Tuple[float, Any]]:
|
|
1097
|
+
return ((1 - self._p, identity.I), (self._p, pauli_gates.X))
|
|
1124
1098
|
|
|
1125
1099
|
def _has_mixture_(self) -> bool:
|
|
1126
1100
|
return True
|
|
@@ -1148,9 +1122,6 @@ class BitFlipChannel(raw_types.Gate):
|
|
|
1148
1122
|
def _json_dict_(self) -> Dict[str, Any]:
|
|
1149
1123
|
return protocols.obj_to_dict_helper(self, ['p'])
|
|
1150
1124
|
|
|
1151
|
-
def _approx_eq_(self, other: Any, atol: float) -> bool:
|
|
1152
|
-
return np.isclose(self._p, other._p, atol=atol).item()
|
|
1153
|
-
|
|
1154
1125
|
|
|
1155
1126
|
def _bit_flip(p: float) -> BitFlipChannel:
|
|
1156
1127
|
r"""Construct a BitFlipChannel that flips a qubit state with probability of a flip given by p.
|
cirq/ops/common_channels_test.py
CHANGED
|
@@ -92,6 +92,7 @@ def test_asymmetric_depolarizing_channel_eq():
|
|
|
92
92
|
c = cirq.asymmetric_depolarize(0.0, 0.0, 0.0)
|
|
93
93
|
|
|
94
94
|
assert cirq.approx_eq(a, b, atol=1e-2)
|
|
95
|
+
assert not cirq.approx_eq(a, cirq.X)
|
|
95
96
|
|
|
96
97
|
et = cirq.testing.EqualsTester()
|
|
97
98
|
et.make_equality_group(lambda: c)
|
|
@@ -276,6 +277,7 @@ def test_depolarizing_channel_eq():
|
|
|
276
277
|
c = cirq.depolarize(0.0)
|
|
277
278
|
|
|
278
279
|
assert cirq.approx_eq(a, b, atol=1e-2)
|
|
280
|
+
assert not cirq.approx_eq(a, cirq.X)
|
|
279
281
|
|
|
280
282
|
et = cirq.testing.EqualsTester()
|
|
281
283
|
|
|
@@ -283,6 +285,7 @@ def test_depolarizing_channel_eq():
|
|
|
283
285
|
et.add_equality_group(cirq.depolarize(0.1))
|
|
284
286
|
et.add_equality_group(cirq.depolarize(0.9))
|
|
285
287
|
et.add_equality_group(cirq.depolarize(1.0))
|
|
288
|
+
et.add_equality_group(cirq.depolarize(1.0, n_qubits=2))
|
|
286
289
|
|
|
287
290
|
|
|
288
291
|
def test_depolarizing_channel_invalid_probability():
|
|
@@ -349,6 +352,7 @@ def test_generalized_amplitude_damping_channel_eq():
|
|
|
349
352
|
b = cirq.generalized_amplitude_damp(0.01, 0.0099999)
|
|
350
353
|
|
|
351
354
|
assert cirq.approx_eq(a, b, atol=1e-2)
|
|
355
|
+
assert not cirq.approx_eq(a, cirq.X)
|
|
352
356
|
|
|
353
357
|
et = cirq.testing.EqualsTester()
|
|
354
358
|
c = cirq.generalized_amplitude_damp(0.0, 0.0)
|
|
@@ -411,6 +415,7 @@ def test_amplitude_damping_channel_eq():
|
|
|
411
415
|
c = cirq.amplitude_damp(0.0)
|
|
412
416
|
|
|
413
417
|
assert cirq.approx_eq(a, b, atol=1e-2)
|
|
418
|
+
assert not cirq.approx_eq(a, cirq.X)
|
|
414
419
|
|
|
415
420
|
et = cirq.testing.EqualsTester()
|
|
416
421
|
et.make_equality_group(lambda: c)
|
|
@@ -562,6 +567,7 @@ def test_phase_damping_channel_eq():
|
|
|
562
567
|
c = cirq.phase_damp(0.0)
|
|
563
568
|
|
|
564
569
|
assert cirq.approx_eq(a, b, atol=1e-2)
|
|
570
|
+
assert not cirq.approx_eq(a, cirq.X)
|
|
565
571
|
|
|
566
572
|
et = cirq.testing.EqualsTester()
|
|
567
573
|
et.make_equality_group(lambda: c)
|
|
@@ -636,6 +642,7 @@ def test_phase_flip_channel_eq():
|
|
|
636
642
|
c = cirq.phase_flip(0.0)
|
|
637
643
|
|
|
638
644
|
assert cirq.approx_eq(a, b, atol=1e-2)
|
|
645
|
+
assert not cirq.approx_eq(a, cirq.X)
|
|
639
646
|
|
|
640
647
|
et = cirq.testing.EqualsTester()
|
|
641
648
|
et.make_equality_group(lambda: c)
|
|
@@ -701,6 +708,7 @@ def test_bit_flip_channel_eq():
|
|
|
701
708
|
c = cirq.bit_flip(0.0)
|
|
702
709
|
|
|
703
710
|
assert cirq.approx_eq(a, b, atol=1e-2)
|
|
711
|
+
assert not cirq.approx_eq(a, cirq.X)
|
|
704
712
|
|
|
705
713
|
et = cirq.testing.EqualsTester()
|
|
706
714
|
et.make_equality_group(lambda: c)
|
|
@@ -834,6 +842,8 @@ def test_multi_asymmetric_depolarizing_eq():
|
|
|
834
842
|
|
|
835
843
|
assert cirq.approx_eq(a, b, atol=1e-3)
|
|
836
844
|
|
|
845
|
+
assert not cirq.approx_eq(a, cirq.X)
|
|
846
|
+
|
|
837
847
|
|
|
838
848
|
def test_multi_asymmetric_depolarizing_channel_str():
|
|
839
849
|
assert str(cirq.asymmetric_depolarize(error_probabilities={'II': 0.8, 'XX': 0.2})) == (
|
cirq/ops/common_gate_families.py
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
from typing import Any, cast, Optional, Type, Union
|
|
18
18
|
|
|
19
|
-
from cirq.ops import gateset, raw_types, parallel_gate, eigen_gate
|
|
20
19
|
from cirq import protocols
|
|
20
|
+
from cirq.ops import eigen_gate, gateset, parallel_gate, raw_types
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
class AnyUnitaryGateFamily(gateset.GateFamily):
|