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,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import numbers
|
|
16
16
|
from collections.abc import Iterable
|
|
17
|
-
from typing import Any
|
|
17
|
+
from typing import Any
|
|
18
18
|
|
|
19
19
|
import numpy as np
|
|
20
20
|
from typing_extensions import Protocol
|
|
@@ -28,7 +28,7 @@ class SupportsEqualUpToGlobalPhase(Protocol):
|
|
|
28
28
|
"""Object which can be compared for equality mod global phase."""
|
|
29
29
|
|
|
30
30
|
@doc_private
|
|
31
|
-
def _equal_up_to_global_phase_(self, other: Any, *, atol:
|
|
31
|
+
def _equal_up_to_global_phase_(self, other: Any, *, atol: float) -> bool:
|
|
32
32
|
"""Approximate comparator.
|
|
33
33
|
|
|
34
34
|
Types implementing this protocol define their own logic for comparison
|
|
@@ -46,7 +46,7 @@ class SupportsEqualUpToGlobalPhase(Protocol):
|
|
|
46
46
|
"""
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
def equal_up_to_global_phase(val: Any, other: Any, *, atol:
|
|
49
|
+
def equal_up_to_global_phase(val: Any, other: Any, *, atol: float = 1e-8) -> bool:
|
|
50
50
|
"""Determine whether two objects are equal up to global phase.
|
|
51
51
|
|
|
52
52
|
If `val` implements a `_equal_up_to_global_phase_` method then it is
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
import numpy as np
|
|
15
|
+
|
|
15
16
|
import cirq
|
|
16
17
|
|
|
17
18
|
|
|
@@ -117,3 +118,9 @@ def test_equal_up_to_global_phase_eq_supported():
|
|
|
117
118
|
# cast types
|
|
118
119
|
assert cirq.equal_up_to_global_phase(A(0.1), A(0.1j), atol=1e-2)
|
|
119
120
|
assert not cirq.equal_up_to_global_phase(1e-8j, B(0.0), atol=1e-10)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_equal_up_to_global_phase_non_eigen_gates():
|
|
124
|
+
gate1 = cirq.PhasedXPowGate(phase_exponent=1.5, exponent=1.0)
|
|
125
|
+
gate2 = cirq.PhasedXPowGate(phase_exponent=0.5, exponent=1.0)
|
|
126
|
+
assert cirq.equal_up_to_global_phase(gate1, gate2)
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
|
|
15
15
|
from typing import Any, Optional
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
from cirq.ops.dense_pauli_string import DensePauliString
|
|
19
|
-
from cirq._import import LazyLoader
|
|
20
|
-
import cirq.protocols.unitary_protocol as unitary_protocol
|
|
17
|
+
import cirq.protocols.decompose_protocol as decompose_protocol
|
|
21
18
|
import cirq.protocols.has_unitary_protocol as has_unitary_protocol
|
|
22
19
|
import cirq.protocols.qid_shape_protocol as qid_shape_protocol
|
|
23
|
-
import cirq.protocols.
|
|
20
|
+
import cirq.protocols.unitary_protocol as unitary_protocol
|
|
21
|
+
from cirq._import import LazyLoader
|
|
22
|
+
from cirq.ops.clifford_gate import SingleQubitCliffordGate
|
|
23
|
+
from cirq.ops.dense_pauli_string import DensePauliString
|
|
24
24
|
|
|
25
25
|
pauli_string_decomposition = LazyLoader(
|
|
26
26
|
"pauli_string_decomposition",
|
|
@@ -12,7 +12,7 @@
|
|
|
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,
|
|
15
|
+
from typing import Any, Optional, TypeVar
|
|
16
16
|
|
|
17
17
|
import numpy as np
|
|
18
18
|
from typing_extensions import Protocol
|
|
@@ -80,7 +80,8 @@ def test_via_apply_unitary():
|
|
|
80
80
|
|
|
81
81
|
class No4: # A non-operation non-gate.
|
|
82
82
|
def _apply_unitary_(self, args):
|
|
83
|
-
|
|
83
|
+
# Because has_unitary doesn't understand how to call.
|
|
84
|
+
assert False # pragma: no cover
|
|
84
85
|
|
|
85
86
|
class Yes1(EmptyOp):
|
|
86
87
|
def _apply_unitary_(self, args):
|
|
@@ -155,13 +156,13 @@ def test_order():
|
|
|
155
156
|
return True
|
|
156
157
|
|
|
157
158
|
def _decompose_(self):
|
|
158
|
-
assert False
|
|
159
|
+
assert False # pragma: no cover
|
|
159
160
|
|
|
160
161
|
def _apply_unitary_(self, args):
|
|
161
|
-
assert False
|
|
162
|
+
assert False # pragma: no cover
|
|
162
163
|
|
|
163
164
|
def _unitary_(self):
|
|
164
|
-
assert False
|
|
165
|
+
assert False # pragma: no cover
|
|
165
166
|
|
|
166
167
|
class Yes2(EmptyOp):
|
|
167
168
|
def _has_unitary_(self):
|
|
@@ -171,10 +172,10 @@ def test_order():
|
|
|
171
172
|
return []
|
|
172
173
|
|
|
173
174
|
def _apply_unitary_(self, args):
|
|
174
|
-
assert False
|
|
175
|
+
assert False # pragma: no cover
|
|
175
176
|
|
|
176
177
|
def _unitary_(self):
|
|
177
|
-
assert False
|
|
178
|
+
assert False # pragma: no cover
|
|
178
179
|
|
|
179
180
|
class Yes3(EmptyOp):
|
|
180
181
|
def _has_unitary_(self):
|
|
@@ -187,7 +188,7 @@ def test_order():
|
|
|
187
188
|
return args.target_tensor
|
|
188
189
|
|
|
189
190
|
def _unitary_(self):
|
|
190
|
-
assert False
|
|
191
|
+
assert False # pragma: no cover
|
|
191
192
|
|
|
192
193
|
class Yes4(EmptyOp):
|
|
193
194
|
def _has_unitary_(self):
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Copyright 2024 The Cirq Developers
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import multiprocessing
|
|
18
|
+
import os
|
|
19
|
+
import pathlib
|
|
20
|
+
import pickle
|
|
21
|
+
from collections.abc import Iterator
|
|
22
|
+
from typing import Any, Hashable
|
|
23
|
+
|
|
24
|
+
import pytest
|
|
25
|
+
|
|
26
|
+
import cirq
|
|
27
|
+
from cirq.protocols.json_serialization_test import MODULE_TEST_SPECS
|
|
28
|
+
|
|
29
|
+
_EXCLUDE_JSON_FILES = (
|
|
30
|
+
# sympy - related objects
|
|
31
|
+
"cirq/protocols/json_test_data/sympy.Add.json",
|
|
32
|
+
"cirq/protocols/json_test_data/sympy.E.json",
|
|
33
|
+
"cirq/protocols/json_test_data/sympy.Equality.json",
|
|
34
|
+
"cirq/protocols/json_test_data/sympy.EulerGamma.json",
|
|
35
|
+
"cirq/protocols/json_test_data/sympy.Float.json",
|
|
36
|
+
"cirq/protocols/json_test_data/sympy.GreaterThan.json",
|
|
37
|
+
"cirq/protocols/json_test_data/sympy.Integer.json",
|
|
38
|
+
"cirq/protocols/json_test_data/sympy.LessThan.json",
|
|
39
|
+
"cirq/protocols/json_test_data/sympy.Mul.json",
|
|
40
|
+
"cirq/protocols/json_test_data/sympy.Pow.json",
|
|
41
|
+
"cirq/protocols/json_test_data/sympy.Rational.json",
|
|
42
|
+
"cirq/protocols/json_test_data/sympy.StrictGreaterThan.json",
|
|
43
|
+
"cirq/protocols/json_test_data/sympy.StrictLessThan.json",
|
|
44
|
+
"cirq/protocols/json_test_data/sympy.Symbol.json",
|
|
45
|
+
"cirq/protocols/json_test_data/sympy.Unequality.json",
|
|
46
|
+
"cirq/protocols/json_test_data/sympy.And.json",
|
|
47
|
+
"cirq/protocols/json_test_data/sympy.Not.json",
|
|
48
|
+
"cirq/protocols/json_test_data/sympy.Or.json",
|
|
49
|
+
"cirq/protocols/json_test_data/sympy.Xor.json",
|
|
50
|
+
"cirq/protocols/json_test_data/sympy.Indexed.json",
|
|
51
|
+
"cirq/protocols/json_test_data/sympy.IndexedBase.json",
|
|
52
|
+
"cirq/protocols/json_test_data/sympy.pi.json",
|
|
53
|
+
# Cirq-Rigetti is deprecated per #7058
|
|
54
|
+
# Instead of handling deprecation-in-test errors we exclude
|
|
55
|
+
# all cirq_rigetti classes here.
|
|
56
|
+
"cirq_rigetti/json_test_data/AspenQubit.json",
|
|
57
|
+
"cirq_rigetti/json_test_data/OctagonalQubit.json",
|
|
58
|
+
# RigettiQCSAspenDevice does not pickle
|
|
59
|
+
"cirq_rigetti/json_test_data/RigettiQCSAspenDevice.json",
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _is_included(json_filename: str) -> bool:
|
|
64
|
+
json_posix_path = pathlib.PurePath(json_filename).as_posix()
|
|
65
|
+
if any(json_posix_path.endswith(t) for t in _EXCLUDE_JSON_FILES):
|
|
66
|
+
return False
|
|
67
|
+
if not os.path.isfile(json_filename):
|
|
68
|
+
return False
|
|
69
|
+
return True
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@pytest.fixture(scope='module')
|
|
73
|
+
def pool() -> Iterator[multiprocessing.pool.Pool]:
|
|
74
|
+
ctx = multiprocessing.get_context("spawn")
|
|
75
|
+
with ctx.Pool(1) as pool:
|
|
76
|
+
yield pool
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _read_json(json_filename: str) -> Any:
|
|
80
|
+
obj = cirq.read_json(json_filename)
|
|
81
|
+
obj = obj[0] if isinstance(obj, list) else obj
|
|
82
|
+
# trigger possible caching of the hash value
|
|
83
|
+
if isinstance(obj, Hashable):
|
|
84
|
+
_ = hash(obj)
|
|
85
|
+
return obj
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_exclude_json_files_has_valid_entries() -> None:
|
|
89
|
+
"""Verify _EXCLUDE_JSON_FILES has valid entries."""
|
|
90
|
+
# do not check rigetti files if not installed
|
|
91
|
+
skip_rigetti = all(m.name != "cirq_rigetti" for m in MODULE_TEST_SPECS)
|
|
92
|
+
json_file_validates = lambda f: any(
|
|
93
|
+
m.test_data_path.joinpath(os.path.basename(f)).is_file() for m in MODULE_TEST_SPECS
|
|
94
|
+
) or (skip_rigetti and f.startswith("cirq_rigetti/"))
|
|
95
|
+
invalid_json_paths = [f for f in _EXCLUDE_JSON_FILES if not json_file_validates(f)]
|
|
96
|
+
assert invalid_json_paths == []
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@pytest.mark.parametrize(
|
|
100
|
+
'json_filename',
|
|
101
|
+
[
|
|
102
|
+
f"{abs_path}.json"
|
|
103
|
+
for m in MODULE_TEST_SPECS
|
|
104
|
+
for abs_path in m.all_test_data_keys()
|
|
105
|
+
if _is_included(f"{abs_path}.json")
|
|
106
|
+
],
|
|
107
|
+
)
|
|
108
|
+
def test_hash_from_pickle(json_filename: str, pool: multiprocessing.pool.Pool):
|
|
109
|
+
obj_local = _read_json(json_filename)
|
|
110
|
+
if not isinstance(obj_local, Hashable):
|
|
111
|
+
return
|
|
112
|
+
# check if pickling works in the main process for the sake of debugging
|
|
113
|
+
obj_copy = pickle.loads(pickle.dumps(obj_local))
|
|
114
|
+
assert obj_copy == obj_local
|
|
115
|
+
assert hash(obj_copy) == hash(obj_local)
|
|
116
|
+
# Read and hash the object in a separate worker process and then
|
|
117
|
+
# send it back which requires pickling and unpickling.
|
|
118
|
+
obj_worker = pool.apply(_read_json, [json_filename])
|
|
119
|
+
assert obj_worker == obj_local
|
|
120
|
+
assert hash(obj_worker) == hash(obj_local)
|
|
@@ -12,7 +12,7 @@
|
|
|
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, List, overload, Tuple, TYPE_CHECKING, TypeVar, Union
|
|
15
|
+
from typing import Any, Iterable, List, overload, Tuple, TYPE_CHECKING, TypeVar, Union
|
|
16
16
|
|
|
17
17
|
from cirq import ops
|
|
18
18
|
|
|
@@ -17,6 +17,7 @@ import gzip
|
|
|
17
17
|
import json
|
|
18
18
|
import numbers
|
|
19
19
|
import pathlib
|
|
20
|
+
from types import NotImplementedType
|
|
20
21
|
from typing import (
|
|
21
22
|
Any,
|
|
22
23
|
Callable,
|
|
@@ -33,13 +34,13 @@ from typing import (
|
|
|
33
34
|
Union,
|
|
34
35
|
)
|
|
35
36
|
|
|
37
|
+
import attrs
|
|
36
38
|
import numpy as np
|
|
37
39
|
import pandas as pd
|
|
38
40
|
import sympy
|
|
39
41
|
from typing_extensions import Protocol
|
|
40
42
|
|
|
41
43
|
from cirq._doc import doc_private
|
|
42
|
-
from cirq.type_workarounds import NotImplementedType
|
|
43
44
|
|
|
44
45
|
ObjectFactory = Union[Type, Callable[..., Any]]
|
|
45
46
|
|
|
@@ -182,6 +183,12 @@ def dataclass_json_dict(obj: Any) -> Dict[str, Any]:
|
|
|
182
183
|
return obj_to_dict_helper(obj, attribute_names)
|
|
183
184
|
|
|
184
185
|
|
|
186
|
+
def attrs_json_dict(obj: Any) -> Dict[str, Any]:
|
|
187
|
+
"""Return a dictionary suitable for `_json_dict_` from an attrs dataclass."""
|
|
188
|
+
attribute_names = [f.name for f in attrs.fields(type(obj))]
|
|
189
|
+
return obj_to_dict_helper(obj, attribute_names)
|
|
190
|
+
|
|
191
|
+
|
|
185
192
|
def _json_dict_with_cirq_type(obj: Any):
|
|
186
193
|
base_dict = obj._json_dict_()
|
|
187
194
|
if 'cirq_type' in base_dict:
|
|
@@ -255,6 +262,12 @@ class CirqEncoder(json.JSONEncoder):
|
|
|
255
262
|
sympy.StrictLessThan,
|
|
256
263
|
sympy.Equality,
|
|
257
264
|
sympy.Unequality,
|
|
265
|
+
sympy.And,
|
|
266
|
+
sympy.Or,
|
|
267
|
+
sympy.Not,
|
|
268
|
+
sympy.Xor,
|
|
269
|
+
sympy.Indexed,
|
|
270
|
+
sympy.IndexedBase,
|
|
258
271
|
),
|
|
259
272
|
):
|
|
260
273
|
return {'cirq_type': f'sympy.{o.__class__.__name__}', 'args': o.args}
|
|
@@ -24,6 +24,7 @@ import warnings
|
|
|
24
24
|
from typing import Dict, List, Optional, Tuple, Type
|
|
25
25
|
from unittest import mock
|
|
26
26
|
|
|
27
|
+
import attrs
|
|
27
28
|
import networkx as nx
|
|
28
29
|
import numpy as np
|
|
29
30
|
import pandas as pd
|
|
@@ -33,7 +34,7 @@ import sympy
|
|
|
33
34
|
import cirq
|
|
34
35
|
from cirq._compat import proper_eq
|
|
35
36
|
from cirq.protocols import json_serialization
|
|
36
|
-
from cirq.testing.json import ModuleJsonTestSpec, spec_for
|
|
37
|
+
from cirq.testing.json import assert_json_roundtrip_works, ModuleJsonTestSpec, spec_for
|
|
37
38
|
|
|
38
39
|
REPO_ROOT = pathlib.Path(__file__).parent.parent.parent.parent
|
|
39
40
|
|
|
@@ -55,6 +56,13 @@ TESTED_MODULES: Dict[str, Optional[_ModuleDeprecation]] = {
|
|
|
55
56
|
'non_existent_should_be_fine': None,
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
# TODO(#6706) remove after cirq_rigetti supports NumPy 2.0
|
|
60
|
+
if np.__version__.startswith("2."): # pragma: no cover
|
|
61
|
+
warnings.warn(
|
|
62
|
+
"json_serialization_test - ignoring cirq_rigetti due to incompatibility with NumPy 2.0"
|
|
63
|
+
)
|
|
64
|
+
del TESTED_MODULES["cirq_rigetti"]
|
|
65
|
+
|
|
58
66
|
|
|
59
67
|
def _get_testspecs_for_modules() -> List[ModuleJsonTestSpec]:
|
|
60
68
|
modules = []
|
|
@@ -76,20 +84,20 @@ def test_deprecated_cirq_type_in_json_dict():
|
|
|
76
84
|
__module__ = 'test.noncirq.namespace'
|
|
77
85
|
|
|
78
86
|
def __eq__(self, other):
|
|
79
|
-
return isinstance(other, HasOldJsonDict)
|
|
87
|
+
return isinstance(other, HasOldJsonDict) # pragma: no cover
|
|
80
88
|
|
|
81
89
|
def _json_dict_(self):
|
|
82
90
|
return {'cirq_type': 'test.noncirq.namespace.HasOldJsonDict'}
|
|
83
91
|
|
|
84
92
|
@classmethod
|
|
85
93
|
def _from_json_dict_(cls, **kwargs):
|
|
86
|
-
return cls()
|
|
94
|
+
return cls() # pragma: no cover
|
|
87
95
|
|
|
88
96
|
with pytest.raises(ValueError, match='not a Cirq type'):
|
|
89
97
|
_ = cirq.json_cirq_type(HasOldJsonDict)
|
|
90
98
|
|
|
91
99
|
def custom_resolver(name):
|
|
92
|
-
if name == 'test.noncirq.namespace.HasOldJsonDict':
|
|
100
|
+
if name == 'test.noncirq.namespace.HasOldJsonDict': # pragma: no cover
|
|
93
101
|
return HasOldJsonDict
|
|
94
102
|
|
|
95
103
|
test_resolvers = [custom_resolver] + cirq.DEFAULT_RESOLVERS
|
|
@@ -275,6 +283,7 @@ def test_builtins():
|
|
|
275
283
|
def test_numpy():
|
|
276
284
|
x = np.ones(1)[0]
|
|
277
285
|
|
|
286
|
+
assert_json_roundtrip_works(np.bool_(True))
|
|
278
287
|
assert_json_roundtrip_works(x.astype(np.int8))
|
|
279
288
|
assert_json_roundtrip_works(x.astype(np.int16))
|
|
280
289
|
assert_json_roundtrip_works(x.astype(np.int32))
|
|
@@ -359,7 +368,7 @@ class SBKImpl(cirq.SerializableByKey):
|
|
|
359
368
|
|
|
360
369
|
def __eq__(self, other):
|
|
361
370
|
if not isinstance(other, SBKImpl):
|
|
362
|
-
return False
|
|
371
|
+
return False # pragma: no cover
|
|
363
372
|
return (
|
|
364
373
|
self.name == other.name
|
|
365
374
|
and self.data_list == other.data_list
|
|
@@ -534,7 +543,7 @@ def test_type_serialization(mod_spec: ModuleJsonTestSpec, cirq_obj_name: str, cl
|
|
|
534
543
|
return pytest.xfail(reason="Not serializable (yet)")
|
|
535
544
|
|
|
536
545
|
if cls is None:
|
|
537
|
-
pytest.skip(f'No serialization for None-mapped type: {cirq_obj_name}')
|
|
546
|
+
pytest.skip(f'No serialization for None-mapped type: {cirq_obj_name}') # pragma: no cover
|
|
538
547
|
|
|
539
548
|
try:
|
|
540
549
|
typename = cirq.json_cirq_type(cls)
|
|
@@ -606,7 +615,7 @@ def _eval_repr_data_file(path: pathlib.Path, deprecation_deadline: Optional[str]
|
|
|
606
615
|
|
|
607
616
|
for deprecation in TESTED_MODULES.values():
|
|
608
617
|
if deprecation is not None and deprecation.old_name in content:
|
|
609
|
-
ctx_managers.append(deprecation.deprecation_assertion)
|
|
618
|
+
ctx_managers.append(deprecation.deprecation_assertion) # pragma: no cover
|
|
610
619
|
|
|
611
620
|
imports = {'cirq': cirq, 'pd': pd, 'sympy': sympy, 'np': np, 'datetime': datetime, 'nx': nx}
|
|
612
621
|
|
|
@@ -783,3 +792,15 @@ def test_datetime():
|
|
|
783
792
|
assert re_pst_dt == pst_dt
|
|
784
793
|
assert re_pst_dt == utc_dt
|
|
785
794
|
assert re_pst_dt == re_naive_dt
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
@attrs.frozen
|
|
798
|
+
class _TestAttrsClas:
|
|
799
|
+
name: str
|
|
800
|
+
x: int
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
def test_attrs_json_dict():
|
|
804
|
+
obj = _TestAttrsClas('test', x=123)
|
|
805
|
+
js = json_serialization.attrs_json_dict(obj)
|
|
806
|
+
assert js == {'name': 'test', 'x': 123}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"cirq_type": "BitMaskKeyCondition",
|
|
4
|
+
"key": {
|
|
5
|
+
"cirq_type": "MeasurementKey",
|
|
6
|
+
"name": "a",
|
|
7
|
+
"path": []
|
|
8
|
+
},
|
|
9
|
+
"index": 59,
|
|
10
|
+
"target_value": 0,
|
|
11
|
+
"equal_target": false,
|
|
12
|
+
"bitmask": null
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"cirq_type": "BitMaskKeyCondition",
|
|
16
|
+
"key": {
|
|
17
|
+
"cirq_type": "MeasurementKey",
|
|
18
|
+
"name": "b",
|
|
19
|
+
"path": []
|
|
20
|
+
},
|
|
21
|
+
"index": 58,
|
|
22
|
+
"target_value": 3,
|
|
23
|
+
"equal_target": false,
|
|
24
|
+
"bitmask": null
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"cirq_type": "BitMaskKeyCondition",
|
|
28
|
+
"key": {
|
|
29
|
+
"cirq_type": "MeasurementKey",
|
|
30
|
+
"name": "c",
|
|
31
|
+
"path": []
|
|
32
|
+
},
|
|
33
|
+
"index": 57,
|
|
34
|
+
"target_value": 0,
|
|
35
|
+
"equal_target": false,
|
|
36
|
+
"bitmask": 13
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"cirq_type": "BitMaskKeyCondition",
|
|
40
|
+
"key": {
|
|
41
|
+
"cirq_type": "MeasurementKey",
|
|
42
|
+
"name": "d",
|
|
43
|
+
"path": []
|
|
44
|
+
},
|
|
45
|
+
"index": 56,
|
|
46
|
+
"target_value": 12,
|
|
47
|
+
"equal_target": false,
|
|
48
|
+
"bitmask": 13
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"cirq_type": "BitMaskKeyCondition",
|
|
52
|
+
"key": {
|
|
53
|
+
"cirq_type": "MeasurementKey",
|
|
54
|
+
"name": "d",
|
|
55
|
+
"path": []
|
|
56
|
+
},
|
|
57
|
+
"index": 55,
|
|
58
|
+
"target_value": 12,
|
|
59
|
+
"equal_target": true,
|
|
60
|
+
"bitmask": 13
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"cirq_type": "BitMaskKeyCondition",
|
|
64
|
+
"key": {
|
|
65
|
+
"cirq_type": "MeasurementKey",
|
|
66
|
+
"name": "e",
|
|
67
|
+
"path": []
|
|
68
|
+
},
|
|
69
|
+
"index": 54,
|
|
70
|
+
"target_value": 11,
|
|
71
|
+
"equal_target": true,
|
|
72
|
+
"bitmask": 11
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"cirq_type": "BitMaskKeyCondition",
|
|
76
|
+
"key": {
|
|
77
|
+
"cirq_type": "MeasurementKey",
|
|
78
|
+
"name": "e",
|
|
79
|
+
"path": []
|
|
80
|
+
},
|
|
81
|
+
"index": 53,
|
|
82
|
+
"target_value": 9,
|
|
83
|
+
"equal_target": false,
|
|
84
|
+
"bitmask": 9
|
|
85
|
+
}
|
|
86
|
+
]
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
[cirq.BitMaskKeyCondition(key=cirq.MeasurementKey(name='a'), index=59, target_value=0, equal_target=False, bitmask=None),
|
|
2
|
+
cirq.BitMaskKeyCondition(key=cirq.MeasurementKey(name='b'), index=58, target_value=3, equal_target=False, bitmask=None),
|
|
3
|
+
cirq.BitMaskKeyCondition(key=cirq.MeasurementKey(name='c'), index=57, target_value=0, equal_target=False, bitmask=13),
|
|
4
|
+
cirq.BitMaskKeyCondition(key=cirq.MeasurementKey(name='d'), index=56, target_value=12, equal_target=False, bitmask=13),
|
|
5
|
+
cirq.BitMaskKeyCondition(key=cirq.MeasurementKey(name='d'), index=55, target_value=12, equal_target=True, bitmask=13),
|
|
6
|
+
cirq.BitMaskKeyCondition(key=cirq.MeasurementKey(name='e'), index=54, target_value=11, equal_target=True, bitmask=11),
|
|
7
|
+
cirq.BitMaskKeyCondition(key=cirq.MeasurementKey(name='e'), index=53, target_value=9, equal_target=False, bitmask=9)]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cirq.Concat(cirq.Linspace('a', start=0, stop=1, length=2), cirq.Linspace('a', start=0, stop=2, length=4))
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
# JSON test data for Cirq serialization tests
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This folder contains test data for Cirq's JSON serialization functionality. For
|
|
4
|
+
more information, please see
|
|
5
|
+
[`docs/dev/serialization.md`](/docs/dev/serialization.md).
|
|
@@ -1,17 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
"cirq_type": "SympyCondition",
|
|
3
|
-
"expr":
|
|
1
|
+
[
|
|
4
2
|
{
|
|
5
|
-
"cirq_type": "
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
"cirq_type": "SympyCondition",
|
|
4
|
+
"expr": {
|
|
5
|
+
"cirq_type": "sympy.GreaterThan",
|
|
6
|
+
"args": [
|
|
7
|
+
{
|
|
8
|
+
"cirq_type": "sympy.Symbol",
|
|
9
|
+
"name": "a"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"cirq_type": "sympy.Symbol",
|
|
13
|
+
"name": "b"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"cirq_type": "SympyCondition",
|
|
20
|
+
"expr": {
|
|
21
|
+
"cirq_type": "sympy.Xor",
|
|
22
|
+
"args": [
|
|
23
|
+
{
|
|
24
|
+
"cirq_type": "sympy.Indexed",
|
|
25
|
+
"args": [
|
|
26
|
+
{
|
|
27
|
+
"cirq_type": "sympy.IndexedBase",
|
|
28
|
+
"args": [
|
|
29
|
+
{
|
|
30
|
+
"cirq_type": "sympy.Symbol",
|
|
31
|
+
"name": "a"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"cirq_type": "sympy.Integer",
|
|
37
|
+
"i": 0
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"cirq_type": "sympy.Indexed",
|
|
43
|
+
"args": [
|
|
44
|
+
{
|
|
45
|
+
"cirq_type": "sympy.IndexedBase",
|
|
46
|
+
"args": [
|
|
47
|
+
{
|
|
48
|
+
"cirq_type": "sympy.Symbol",
|
|
49
|
+
"name": "a"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"cirq_type": "sympy.Integer",
|
|
55
|
+
"i": 1
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
16
61
|
}
|
|
17
|
-
|
|
62
|
+
]
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
[
|
|
2
|
+
cirq.SympyCondition(sympy.GreaterThan(sympy.Symbol('a'), sympy.Symbol('b'))),
|
|
3
|
+
cirq.SympyCondition(sympy.Xor(sympy.Indexed(sympy.IndexedBase(sympy.Symbol('a')), sympy.Integer(0)), sympy.Indexed(sympy.IndexedBase(sympy.Symbol('a')), sympy.Integer(1))))
|
|
4
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(cirq.QubitPermutationGate(permutation=(0, 1, 2))**-1)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sympy.And(sympy.Symbol('s'), sympy.Symbol('t'))
|