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/vis/heatmap.py
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
14
17
|
import copy
|
|
15
18
|
from dataclasses import astuple, dataclass
|
|
16
19
|
from typing import (
|
|
@@ -111,6 +114,7 @@ class Heatmap:
|
|
|
111
114
|
applying format(value, annotation_format) for each key in value_map.
|
|
112
115
|
This is ignored if annotation_map is explicitly specified.
|
|
113
116
|
annotation_text_kwargs: Matplotlib Text **kwargs,
|
|
117
|
+
highlighted_qubits: An iterable of qubits to highlight.
|
|
114
118
|
|
|
115
119
|
colorbar_position: {'right', 'left', 'top', 'bottom'}, default = 'right'
|
|
116
120
|
colorbar_size: str, default = '5%'
|
|
@@ -157,6 +161,7 @@ class Heatmap:
|
|
|
157
161
|
"annotation_map",
|
|
158
162
|
"annotation_text_kwargs",
|
|
159
163
|
"annotation_format",
|
|
164
|
+
"highlighted_qubits",
|
|
160
165
|
]
|
|
161
166
|
valid_kwargs = (
|
|
162
167
|
valid_colorbar_kwargs
|
|
@@ -231,13 +236,14 @@ class Heatmap:
|
|
|
231
236
|
ax: plt.Axes,
|
|
232
237
|
) -> None:
|
|
233
238
|
"""Writes annotations to the center of cells. Internal."""
|
|
234
|
-
|
|
239
|
+
face_colors = cast(np.ndarray, collection.get_facecolor())
|
|
240
|
+
for (center, annotation), facecolor in zip(centers_and_annot, face_colors):
|
|
235
241
|
# Calculate the center of the cell, assuming that it is a square
|
|
236
242
|
# centered at (x=col, y=row).
|
|
237
243
|
if not annotation:
|
|
238
244
|
continue
|
|
239
245
|
x, y = center
|
|
240
|
-
face_luminance = vis_utils.relative_luminance(facecolor)
|
|
246
|
+
face_luminance = vis_utils.relative_luminance(facecolor)
|
|
241
247
|
text_color = 'black' if face_luminance > 0.4 else 'white'
|
|
242
248
|
text_kwargs: Dict[str, Any] = dict(color=text_color, ha="center", va="center")
|
|
243
249
|
text_kwargs.update(self._config.get('annotation_text_kwargs', {}))
|
|
@@ -294,11 +300,41 @@ class Heatmap:
|
|
|
294
300
|
is plotted on. ``collection`` is the collection of paths drawn and filled.
|
|
295
301
|
"""
|
|
296
302
|
show_plot = not ax
|
|
297
|
-
if
|
|
303
|
+
if ax is None:
|
|
298
304
|
fig, ax = plt.subplots(figsize=(8, 8))
|
|
299
|
-
ax = cast(plt.Axes, ax)
|
|
300
305
|
original_config = copy.deepcopy(self._config)
|
|
301
306
|
self.update_config(**kwargs)
|
|
307
|
+
|
|
308
|
+
highlighted_qubits = frozenset(kwargs.get("highlighted_qubits", ()))
|
|
309
|
+
if highlighted_qubits:
|
|
310
|
+
edgecolors = tuple(
|
|
311
|
+
(
|
|
312
|
+
"red"
|
|
313
|
+
if not highlighted_qubits.isdisjoint(qubits)
|
|
314
|
+
else self._config["collection_options"].get("edgecolors", "grey")
|
|
315
|
+
)
|
|
316
|
+
for qubits in sorted(self._value_map.keys())
|
|
317
|
+
)
|
|
318
|
+
linestyles = tuple(
|
|
319
|
+
(
|
|
320
|
+
"solid"
|
|
321
|
+
if not highlighted_qubits.isdisjoint(qubits)
|
|
322
|
+
else self._config["collection_options"].get("linestyles", "dashed")
|
|
323
|
+
)
|
|
324
|
+
for qubits in sorted(self._value_map.keys())
|
|
325
|
+
)
|
|
326
|
+
linewidths = tuple(
|
|
327
|
+
(
|
|
328
|
+
4
|
|
329
|
+
if not highlighted_qubits.isdisjoint(qubits)
|
|
330
|
+
else self._config["collection_options"].get("linewidths", 2)
|
|
331
|
+
)
|
|
332
|
+
for qubits in sorted(self._value_map.keys())
|
|
333
|
+
)
|
|
334
|
+
self._config["collection_options"].update(
|
|
335
|
+
{"edgecolors": edgecolors, "linestyles": linestyles, "linewidths": linewidths}
|
|
336
|
+
)
|
|
337
|
+
|
|
302
338
|
collection = self._plot_on_axis(ax)
|
|
303
339
|
if show_plot:
|
|
304
340
|
fig.show()
|
|
@@ -381,22 +417,23 @@ class TwoQubitInteractionHeatmap(Heatmap):
|
|
|
381
417
|
is plotted on. ``collection`` is the collection of paths drawn and filled.
|
|
382
418
|
"""
|
|
383
419
|
show_plot = not ax
|
|
384
|
-
if
|
|
420
|
+
if ax is None:
|
|
385
421
|
fig, ax = plt.subplots(figsize=(8, 8))
|
|
386
|
-
ax = cast(plt.Axes, ax)
|
|
387
422
|
original_config = copy.deepcopy(self._config)
|
|
388
423
|
self.update_config(**kwargs)
|
|
389
424
|
qubits = set([q for qubits in self._value_map.keys() for q in qubits])
|
|
425
|
+
collection_options: Dict[str, Any] = {"cmap": "binary"}
|
|
426
|
+
highlighted_qubits = frozenset(kwargs.get("highlighted_qubits", ()))
|
|
427
|
+
if not highlighted_qubits:
|
|
428
|
+
collection_options.update(
|
|
429
|
+
{"linewidths": 2, "edgecolors": "lightgrey", "linestyles": "dashed"}
|
|
430
|
+
)
|
|
390
431
|
Heatmap({q: 0.0 for q in qubits}).plot(
|
|
391
432
|
ax=ax,
|
|
392
|
-
collection_options=
|
|
393
|
-
'cmap': 'binary',
|
|
394
|
-
'linewidths': 2,
|
|
395
|
-
'edgecolor': 'lightgrey',
|
|
396
|
-
'linestyle': 'dashed',
|
|
397
|
-
},
|
|
433
|
+
collection_options=collection_options,
|
|
398
434
|
plot_colorbar=False,
|
|
399
435
|
annotation_format=None,
|
|
436
|
+
highlighted_qubits=highlighted_qubits,
|
|
400
437
|
)
|
|
401
438
|
collection = self._plot_on_axis(ax)
|
|
402
439
|
if show_plot:
|
cirq/vis/heatmap_test.py
CHANGED
|
@@ -18,11 +18,11 @@ import shutil
|
|
|
18
18
|
import string
|
|
19
19
|
from tempfile import mkdtemp
|
|
20
20
|
|
|
21
|
-
import numpy as np
|
|
22
|
-
import pytest
|
|
23
|
-
|
|
24
21
|
import matplotlib as mpl
|
|
25
22
|
import matplotlib.pyplot as plt
|
|
23
|
+
import numpy as np
|
|
24
|
+
import pytest
|
|
25
|
+
from matplotlib.colors import to_rgba_array
|
|
26
26
|
|
|
27
27
|
from cirq.devices import grid_qubit
|
|
28
28
|
from cirq.vis import heatmap
|
|
@@ -34,6 +34,11 @@ def ax():
|
|
|
34
34
|
return figure.add_subplot(111)
|
|
35
35
|
|
|
36
36
|
|
|
37
|
+
def _to_linestyle_tuple(linestyles, linewidths=None):
|
|
38
|
+
collection = mpl.collections.Collection(linestyles=linestyles, linewidths=linewidths)
|
|
39
|
+
return collection.get_linestyles()[0]
|
|
40
|
+
|
|
41
|
+
|
|
37
42
|
def test_default_ax():
|
|
38
43
|
row_col_list = ((0, 5), (8, 1), (7, 0), (13, 5), (1, 6), (3, 2), (2, 8))
|
|
39
44
|
test_value_map = {
|
|
@@ -240,7 +245,7 @@ def test_non_float_values(ax, format_string):
|
|
|
240
245
|
for artist in ax.get_children():
|
|
241
246
|
if isinstance(artist, mpl.text.Text):
|
|
242
247
|
col, row = artist.get_position()
|
|
243
|
-
if (row, col) in test_value_map:
|
|
248
|
+
if (row, col) in test_value_map: # pragma: no cover
|
|
244
249
|
foo = test_value_map[(row, col)]
|
|
245
250
|
actual_text = artist.get_text()
|
|
246
251
|
expected_text = format(foo, format_string)
|
|
@@ -343,3 +348,162 @@ def test_plot_updates_local_config():
|
|
|
343
348
|
_, ax = plt.subplots()
|
|
344
349
|
random_heatmap.plot(ax)
|
|
345
350
|
assert ax.get_title() == original_title
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
@pytest.mark.usefixtures('closefigures')
|
|
354
|
+
def test_heatmap_plot_highlighted_qubits():
|
|
355
|
+
value_map = {
|
|
356
|
+
(grid_qubit.GridQubit(0, 0),): 0.1,
|
|
357
|
+
(grid_qubit.GridQubit(0, 1),): 0.2,
|
|
358
|
+
(grid_qubit.GridQubit(0, 2),): 0.3,
|
|
359
|
+
(grid_qubit.GridQubit(1, 0),): 0.4,
|
|
360
|
+
}
|
|
361
|
+
single_qubit_heatmap = heatmap.Heatmap(value_map)
|
|
362
|
+
|
|
363
|
+
highlighted_qubits = [grid_qubit.GridQubit(0, 1), grid_qubit.GridQubit(1, 0)]
|
|
364
|
+
|
|
365
|
+
expected_linewidths = [2, 4, 2, 4]
|
|
366
|
+
expected_edgecolors = np.vstack(
|
|
367
|
+
(to_rgba_array("grey"), to_rgba_array("red"), to_rgba_array("grey"), to_rgba_array("red"))
|
|
368
|
+
)
|
|
369
|
+
# list of tuples: (offset, onoffseq), onoffseq = None for solid line.
|
|
370
|
+
expected_linestyles = [
|
|
371
|
+
_to_linestyle_tuple("dashed", linewidths=2),
|
|
372
|
+
_to_linestyle_tuple("solid"),
|
|
373
|
+
_to_linestyle_tuple("dashed", linewidths=2),
|
|
374
|
+
_to_linestyle_tuple("solid"),
|
|
375
|
+
]
|
|
376
|
+
|
|
377
|
+
_, ax = plt.subplots()
|
|
378
|
+
_ = single_qubit_heatmap.plot(ax, highlighted_qubits=highlighted_qubits)
|
|
379
|
+
|
|
380
|
+
for artist in ax.get_children():
|
|
381
|
+
if isinstance(artist, mpl.collections.PolyCollection):
|
|
382
|
+
assert np.all(artist.get_linewidths() == expected_linewidths)
|
|
383
|
+
assert np.array_equal(artist.get_edgecolors(), expected_edgecolors)
|
|
384
|
+
assert artist.get_linestyles() == expected_linestyles
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
@pytest.mark.usefixtures('closefigures')
|
|
388
|
+
def test_heatmap_plot_highlighted_qubits_two_qubit():
|
|
389
|
+
value_map = {
|
|
390
|
+
(grid_qubit.GridQubit(0, 0), grid_qubit.GridQubit(0, 1)): 0.1,
|
|
391
|
+
(grid_qubit.GridQubit(0, 1), grid_qubit.GridQubit(0, 2)): 0.2,
|
|
392
|
+
(grid_qubit.GridQubit(1, 0), grid_qubit.GridQubit(0, 0)): 0.3,
|
|
393
|
+
(grid_qubit.GridQubit(3, 3), grid_qubit.GridQubit(3, 2)): 0.9,
|
|
394
|
+
}
|
|
395
|
+
two_qubit_interaction_heatmap = heatmap.TwoQubitInteractionHeatmap(value_map)
|
|
396
|
+
|
|
397
|
+
highlighted_qubits = [
|
|
398
|
+
grid_qubit.GridQubit(0, 1),
|
|
399
|
+
grid_qubit.GridQubit(0, 0),
|
|
400
|
+
grid_qubit.GridQubit(3, 3),
|
|
401
|
+
]
|
|
402
|
+
|
|
403
|
+
expected_linewidths = [4, 4, 2, 2, 2, 4]
|
|
404
|
+
expected_edgecolors = np.vstack(
|
|
405
|
+
(
|
|
406
|
+
to_rgba_array("red"),
|
|
407
|
+
to_rgba_array("red"),
|
|
408
|
+
to_rgba_array("grey"),
|
|
409
|
+
to_rgba_array("grey"),
|
|
410
|
+
to_rgba_array("grey"),
|
|
411
|
+
to_rgba_array("red"),
|
|
412
|
+
)
|
|
413
|
+
)
|
|
414
|
+
# list of tuples: (offset, onoffseq), onoffseq = None for solid line.
|
|
415
|
+
expected_linestyles = [
|
|
416
|
+
_to_linestyle_tuple("solid"),
|
|
417
|
+
_to_linestyle_tuple("solid"),
|
|
418
|
+
_to_linestyle_tuple("dashed", linewidths=2),
|
|
419
|
+
_to_linestyle_tuple("dashed", linewidths=2),
|
|
420
|
+
_to_linestyle_tuple("dashed", linewidths=2),
|
|
421
|
+
_to_linestyle_tuple("solid"),
|
|
422
|
+
]
|
|
423
|
+
|
|
424
|
+
_, ax = plt.subplots()
|
|
425
|
+
_ = two_qubit_interaction_heatmap.plot(ax, highlighted_qubits=highlighted_qubits)
|
|
426
|
+
|
|
427
|
+
for artist in ax.get_children():
|
|
428
|
+
if isinstance(artist, mpl.collections.PolyCollection):
|
|
429
|
+
# Since for two qubit interactions, there are two collections:
|
|
430
|
+
# one to highlight individual qubits and one showing their interaction.
|
|
431
|
+
# Here, the former is required, so the latter is excluded.
|
|
432
|
+
if artist.get_cmap().name != 'viridis': # assuming 'viridis' is the default cmap used.
|
|
433
|
+
assert np.all(artist.get_linewidths() == expected_linewidths)
|
|
434
|
+
assert np.array_equal(artist.get_edgecolors(), expected_edgecolors)
|
|
435
|
+
assert artist.get_linestyles() == expected_linestyles
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
@pytest.mark.usefixtures('closefigures')
|
|
439
|
+
def test_heatmap_highlighted_repeat_qubits():
|
|
440
|
+
value_map = {
|
|
441
|
+
(grid_qubit.GridQubit(0, 0), grid_qubit.GridQubit(0, 1)): 0.1,
|
|
442
|
+
(grid_qubit.GridQubit(0, 1), grid_qubit.GridQubit(0, 2)): 0.2,
|
|
443
|
+
(grid_qubit.GridQubit(1, 0), grid_qubit.GridQubit(0, 0)): 0.3,
|
|
444
|
+
(grid_qubit.GridQubit(3, 3), grid_qubit.GridQubit(3, 2)): 0.9,
|
|
445
|
+
}
|
|
446
|
+
two_qubit_interaction_heatmap = heatmap.TwoQubitInteractionHeatmap(value_map)
|
|
447
|
+
|
|
448
|
+
highlighted_qubits_1 = [
|
|
449
|
+
grid_qubit.GridQubit(0, 1),
|
|
450
|
+
grid_qubit.GridQubit(0, 0),
|
|
451
|
+
grid_qubit.GridQubit(3, 3),
|
|
452
|
+
]
|
|
453
|
+
highlighted_qubits_2 = highlighted_qubits_1 + [grid_qubit.GridQubit(0, 0)] * 5
|
|
454
|
+
|
|
455
|
+
_, ax1 = plt.subplots()
|
|
456
|
+
_ = two_qubit_interaction_heatmap.plot(ax1, highlighted_qubits=highlighted_qubits_1)
|
|
457
|
+
_, ax2 = plt.subplots()
|
|
458
|
+
_ = two_qubit_interaction_heatmap.plot(ax2, highlighted_qubits=highlighted_qubits_2)
|
|
459
|
+
|
|
460
|
+
for artist_1, artist_2 in zip(ax1.get_children(), ax2.get_children()):
|
|
461
|
+
if isinstance(artist_1, mpl.collections.PolyCollection) and isinstance(
|
|
462
|
+
artist_2, mpl.collections.PolyCollection
|
|
463
|
+
):
|
|
464
|
+
# Since for two qubit interactions, there are two collections:
|
|
465
|
+
# one to highlight individual qubits and one showing their interaction.
|
|
466
|
+
# Here, the former is required, so the latter is excluded.
|
|
467
|
+
if (
|
|
468
|
+
artist_1.get_cmap().name != 'viridis' and artist_2.get_cmap().name != 'viridis'
|
|
469
|
+
): # assuming 'viridis' is the default cmap used.
|
|
470
|
+
assert np.all(artist_1.get_linewidths() == artist_1.get_linewidths())
|
|
471
|
+
assert np.array_equal(artist_1.get_edgecolors(), artist_2.get_edgecolors())
|
|
472
|
+
assert artist_1.get_linestyles() == artist_2.get_linestyles()
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
@pytest.mark.usefixtures('closefigures')
|
|
476
|
+
def test_heatmap_highlighted_init_collection_options_used():
|
|
477
|
+
value_map = {
|
|
478
|
+
(grid_qubit.GridQubit(0, 0),): 0.1,
|
|
479
|
+
(grid_qubit.GridQubit(0, 1),): 0.2,
|
|
480
|
+
(grid_qubit.GridQubit(0, 2),): 0.3,
|
|
481
|
+
(grid_qubit.GridQubit(1, 0),): 0.4,
|
|
482
|
+
}
|
|
483
|
+
single_qubit_heatmap = heatmap.Heatmap(
|
|
484
|
+
value_map,
|
|
485
|
+
collection_options={"edgecolors": "blue", "linewidths": 6, "linestyles": "dashed"},
|
|
486
|
+
)
|
|
487
|
+
|
|
488
|
+
highlighted_qubits = [grid_qubit.GridQubit(0, 1), grid_qubit.GridQubit(1, 0)]
|
|
489
|
+
|
|
490
|
+
expected_linewidths = [6, 4, 6, 4]
|
|
491
|
+
expected_edgecolors = np.vstack(
|
|
492
|
+
(to_rgba_array("blue"), to_rgba_array("red"), to_rgba_array("blue"), to_rgba_array("red"))
|
|
493
|
+
)
|
|
494
|
+
# list of tuples: (offset, onoffseq), onoffseq = None for solid line.
|
|
495
|
+
expected_linestyles = [
|
|
496
|
+
_to_linestyle_tuple("dashed", linewidths=6),
|
|
497
|
+
_to_linestyle_tuple("solid"),
|
|
498
|
+
_to_linestyle_tuple("dashed", linewidths=6),
|
|
499
|
+
_to_linestyle_tuple("solid"),
|
|
500
|
+
]
|
|
501
|
+
|
|
502
|
+
_, ax = plt.subplots()
|
|
503
|
+
_ = single_qubit_heatmap.plot(ax, highlighted_qubits=highlighted_qubits)
|
|
504
|
+
|
|
505
|
+
for artist in ax.get_children():
|
|
506
|
+
if isinstance(artist, mpl.collections.PolyCollection):
|
|
507
|
+
assert np.all(artist.get_linewidths() == expected_linewidths)
|
|
508
|
+
assert np.array_equal(artist.get_edgecolors(), expected_edgecolors)
|
|
509
|
+
assert artist.get_linestyles() == expected_linestyles
|
cirq/vis/histogram.py
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
-
from typing import Any, Mapping, Optional, Sequence,
|
|
14
|
+
from typing import Any, Mapping, Optional, Sequence, SupportsFloat, Union
|
|
15
15
|
|
|
16
16
|
import numpy as np
|
|
17
17
|
from matplotlib import pyplot as plt
|
cirq/vis/histogram_test.py
CHANGED
cirq/vis/state_histogram.py
CHANGED
|
@@ -14,10 +14,12 @@
|
|
|
14
14
|
|
|
15
15
|
"""Tool to visualize the results of a study."""
|
|
16
16
|
|
|
17
|
-
from typing import cast, Optional, Sequence, SupportsFloat, Union
|
|
18
17
|
import collections
|
|
19
|
-
import
|
|
18
|
+
from typing import Optional, Sequence, SupportsFloat, Union
|
|
19
|
+
|
|
20
20
|
import matplotlib.pyplot as plt
|
|
21
|
+
import numpy as np
|
|
22
|
+
|
|
21
23
|
import cirq.study.result as result
|
|
22
24
|
|
|
23
25
|
|
|
@@ -85,13 +87,13 @@ def plot_state_histogram(
|
|
|
85
87
|
The axis that was plotted on.
|
|
86
88
|
"""
|
|
87
89
|
show_fig = not ax
|
|
88
|
-
if
|
|
90
|
+
if ax is None:
|
|
89
91
|
fig, ax = plt.subplots(1, 1)
|
|
90
|
-
ax = cast(plt.Axes, ax)
|
|
91
92
|
if isinstance(data, result.Result):
|
|
92
93
|
values = get_state_histogram(data)
|
|
93
94
|
elif isinstance(data, collections.Counter):
|
|
94
|
-
tick_label,
|
|
95
|
+
tick_label, counts = zip(*sorted(data.items()))
|
|
96
|
+
values = np.asarray(counts)
|
|
95
97
|
else:
|
|
96
98
|
values = np.array(data)
|
|
97
99
|
if tick_label is None:
|
cirq/vis/state_histogram_test.py
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
|
|
15
15
|
"""Tests for state_histogram."""
|
|
16
16
|
|
|
17
|
-
import numpy as np
|
|
18
|
-
from matplotlib import pyplot as plt
|
|
19
17
|
import matplotlib as mpl
|
|
18
|
+
import numpy as np
|
|
20
19
|
import pytest
|
|
20
|
+
from matplotlib import pyplot as plt
|
|
21
21
|
|
|
22
22
|
import cirq
|
|
23
23
|
from cirq.devices import GridQubit
|
cirq/work/__init__.py
CHANGED
|
@@ -14,20 +14,26 @@
|
|
|
14
14
|
|
|
15
15
|
"""Workflow utilities for sampling and measurement collection."""
|
|
16
16
|
|
|
17
|
-
from cirq.work.collector import CircuitSampleJob, Collector
|
|
18
|
-
from cirq.work.pauli_sum_collector import PauliSumCollector
|
|
19
|
-
from cirq.work.observable_settings import
|
|
20
|
-
|
|
17
|
+
from cirq.work.collector import CircuitSampleJob as CircuitSampleJob, Collector as Collector
|
|
18
|
+
from cirq.work.pauli_sum_collector import PauliSumCollector as PauliSumCollector
|
|
19
|
+
from cirq.work.observable_settings import (
|
|
20
|
+
InitObsSetting as InitObsSetting,
|
|
21
|
+
_MeasurementSpec as _MeasurementSpec,
|
|
22
|
+
observables_to_settings as observables_to_settings,
|
|
23
|
+
)
|
|
24
|
+
from cirq.work.observable_grouping import group_settings_greedy as group_settings_greedy
|
|
21
25
|
from cirq.work.observable_measurement_data import (
|
|
22
|
-
ObservableMeasuredResult,
|
|
23
|
-
BitstringAccumulator,
|
|
24
|
-
flatten_grouped_results,
|
|
26
|
+
ObservableMeasuredResult as ObservableMeasuredResult,
|
|
27
|
+
BitstringAccumulator as BitstringAccumulator,
|
|
28
|
+
flatten_grouped_results as flatten_grouped_results,
|
|
25
29
|
)
|
|
26
30
|
from cirq.work.observable_measurement import (
|
|
27
|
-
VarianceStoppingCriteria,
|
|
28
|
-
RepetitionsStoppingCriteria,
|
|
29
|
-
measure_grouped_settings,
|
|
31
|
+
VarianceStoppingCriteria as VarianceStoppingCriteria,
|
|
32
|
+
RepetitionsStoppingCriteria as RepetitionsStoppingCriteria,
|
|
33
|
+
measure_grouped_settings as measure_grouped_settings,
|
|
34
|
+
)
|
|
35
|
+
from cirq.work.observable_readout_calibration import (
|
|
36
|
+
calibrate_readout_error as calibrate_readout_error,
|
|
30
37
|
)
|
|
31
|
-
from cirq.work.
|
|
32
|
-
from cirq.work.
|
|
33
|
-
from cirq.work.zeros_sampler import ZerosSampler
|
|
38
|
+
from cirq.work.sampler import Sampler as Sampler
|
|
39
|
+
from cirq.work.zeros_sampler import ZerosSampler as ZerosSampler
|
cirq/work/collector.py
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
|
|
15
15
|
import abc
|
|
16
16
|
from typing import Any, Iterator, List, Optional, Tuple, TYPE_CHECKING, Union
|
|
17
|
-
from typing_extensions import Protocol
|
|
18
17
|
|
|
19
18
|
import duet
|
|
20
19
|
import numpy as np
|
|
20
|
+
from typing_extensions import Protocol
|
|
21
21
|
|
|
22
22
|
from cirq import study, value
|
|
23
23
|
|
|
@@ -171,7 +171,7 @@ class Collector(metaclass=abc.ABCMeta):
|
|
|
171
171
|
job_error = None
|
|
172
172
|
running_jobs = 0
|
|
173
173
|
queued_jobs: List[CircuitSampleJob] = []
|
|
174
|
-
remaining_samples = np.
|
|
174
|
+
remaining_samples = np.inf if max_total_samples is None else max_total_samples
|
|
175
175
|
|
|
176
176
|
async def run_job(job):
|
|
177
177
|
nonlocal job_error
|
cirq/work/observable_grouping.py
CHANGED
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from typing import
|
|
15
|
+
from typing import Callable, cast, Dict, Iterable, List, TYPE_CHECKING
|
|
16
16
|
|
|
17
17
|
from cirq import ops, value
|
|
18
|
-
from cirq.work.observable_settings import
|
|
18
|
+
from cirq.work.observable_settings import _max_weight_observable, _max_weight_state, InitObsSetting
|
|
19
19
|
|
|
20
20
|
if TYPE_CHECKING:
|
|
21
21
|
pass
|
|
@@ -24,15 +24,15 @@ import numpy as np
|
|
|
24
24
|
import pandas as pd
|
|
25
25
|
import sympy
|
|
26
26
|
|
|
27
|
-
from cirq import circuits,
|
|
27
|
+
from cirq import circuits, ops, protocols, study, value
|
|
28
28
|
from cirq._doc import document
|
|
29
29
|
from cirq.work.observable_grouping import group_settings_greedy, GROUPER_T
|
|
30
30
|
from cirq.work.observable_measurement_data import (
|
|
31
31
|
BitstringAccumulator,
|
|
32
|
-
ObservableMeasuredResult,
|
|
33
32
|
flatten_grouped_results,
|
|
33
|
+
ObservableMeasuredResult,
|
|
34
34
|
)
|
|
35
|
-
from cirq.work.observable_settings import InitObsSetting, observables_to_settings
|
|
35
|
+
from cirq.work.observable_settings import _MeasurementSpec, InitObsSetting, observables_to_settings
|
|
36
36
|
|
|
37
37
|
if TYPE_CHECKING:
|
|
38
38
|
import cirq
|
|
@@ -18,14 +18,14 @@ from typing import Any, Dict, Iterable, List, Mapping, Optional, Tuple, TYPE_CHE
|
|
|
18
18
|
|
|
19
19
|
import numpy as np
|
|
20
20
|
import sympy
|
|
21
|
-
from cirq import ops, protocols, value
|
|
22
21
|
|
|
22
|
+
from cirq import ops, protocols, value
|
|
23
23
|
from cirq._compat import proper_repr
|
|
24
24
|
from cirq.work.observable_settings import (
|
|
25
|
-
InitObsSetting,
|
|
26
25
|
_max_weight_observable,
|
|
27
26
|
_max_weight_state,
|
|
28
27
|
_MeasurementSpec,
|
|
28
|
+
InitObsSetting,
|
|
29
29
|
zeros_state,
|
|
30
30
|
)
|
|
31
31
|
|
|
@@ -109,6 +109,9 @@ class ObservableMeasuredResult:
|
|
|
109
109
|
repetitions: int
|
|
110
110
|
circuit_params: Mapping[Union[str, sympy.Expr], Union[value.Scalar, sympy.Expr]]
|
|
111
111
|
|
|
112
|
+
# unhashable because of the mapping-type circuit_params attribute
|
|
113
|
+
__hash__ = None # type: ignore
|
|
114
|
+
|
|
112
115
|
def __repr__(self):
|
|
113
116
|
# I wish we could use the default dataclass __repr__ but
|
|
114
117
|
# we need to prefix our class name with `cirq.work.`
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
import tempfile
|
|
15
|
-
from typing import
|
|
15
|
+
from typing import Dict, Iterable, List
|
|
16
16
|
|
|
17
17
|
import numpy as np
|
|
18
18
|
import pytest
|
|
@@ -21,19 +21,19 @@ import cirq
|
|
|
21
21
|
import cirq.work as cw
|
|
22
22
|
from cirq.work import _MeasurementSpec, BitstringAccumulator, group_settings_greedy, InitObsSetting
|
|
23
23
|
from cirq.work.observable_measurement import (
|
|
24
|
-
_with_parameterized_layers,
|
|
25
|
-
_get_params_for_setting,
|
|
26
|
-
_pad_setting,
|
|
27
|
-
_subdivide_meas_specs,
|
|
28
24
|
_aggregate_n_repetitions,
|
|
29
25
|
_check_meas_specs_still_todo,
|
|
30
|
-
|
|
26
|
+
_get_params_for_setting,
|
|
27
|
+
_pad_setting,
|
|
31
28
|
_parse_checkpoint_options,
|
|
32
|
-
|
|
29
|
+
_subdivide_meas_specs,
|
|
30
|
+
_with_parameterized_layers,
|
|
33
31
|
CheckpointFileOptions,
|
|
34
|
-
VarianceStoppingCriteria,
|
|
35
32
|
measure_observables,
|
|
33
|
+
measure_observables_df,
|
|
36
34
|
RepetitionsStoppingCriteria,
|
|
35
|
+
StoppingCriteria,
|
|
36
|
+
VarianceStoppingCriteria,
|
|
37
37
|
)
|
|
38
38
|
|
|
39
39
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# pylint: disable=wrong-or-nonexistent-copyright-notice
|
|
2
2
|
import dataclasses
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import Iterable, TYPE_CHECKING, Union
|
|
4
4
|
|
|
5
|
-
from cirq import circuits,
|
|
5
|
+
from cirq import circuits, ops, study
|
|
6
6
|
from cirq.work.observable_measurement import measure_grouped_settings, StoppingCriteria
|
|
7
7
|
from cirq.work.observable_settings import InitObsSetting, zeros_state
|
|
8
8
|
|
cirq/work/observable_settings.py
CHANGED
|
@@ -16,19 +16,19 @@ import dataclasses
|
|
|
16
16
|
import numbers
|
|
17
17
|
from typing import (
|
|
18
18
|
AbstractSet,
|
|
19
|
-
Mapping,
|
|
20
|
-
Union,
|
|
21
|
-
Iterable,
|
|
22
19
|
Dict,
|
|
20
|
+
FrozenSet,
|
|
21
|
+
Iterable,
|
|
22
|
+
Mapping,
|
|
23
23
|
Optional,
|
|
24
|
-
TYPE_CHECKING,
|
|
25
24
|
Tuple,
|
|
26
|
-
|
|
25
|
+
TYPE_CHECKING,
|
|
26
|
+
Union,
|
|
27
27
|
)
|
|
28
28
|
|
|
29
29
|
import sympy
|
|
30
30
|
|
|
31
|
-
from cirq import ops,
|
|
31
|
+
from cirq import ops, protocols, value
|
|
32
32
|
|
|
33
33
|
if TYPE_CHECKING:
|
|
34
34
|
import cirq
|
|
@@ -149,7 +149,8 @@ def _fix_precision(val: Union[value.Scalar, sympy.Expr], precision) -> Union[int
|
|
|
149
149
|
raise ValueError(f'Cannot convert {val} to fixed precision in observable settings')
|
|
150
150
|
if isinstance(val, (complex, numbers.Complex)):
|
|
151
151
|
return int(val.real * precision), int(val.imag * precision)
|
|
152
|
-
|
|
152
|
+
# Pretty much all numbers are instances of numbers.Complex
|
|
153
|
+
return int(val * precision) # pragma: no cover
|
|
153
154
|
|
|
154
155
|
|
|
155
156
|
def _hashable_param(
|
|
@@ -16,8 +16,8 @@ import pytest
|
|
|
16
16
|
import sympy
|
|
17
17
|
|
|
18
18
|
import cirq
|
|
19
|
-
from cirq.work
|
|
20
|
-
from cirq.work import
|
|
19
|
+
from cirq.work import _MeasurementSpec, InitObsSetting, observables_to_settings
|
|
20
|
+
from cirq.work.observable_settings import _hashable_param, _max_weight_observable, _max_weight_state
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
def test_init_obs_setting():
|
|
@@ -68,6 +68,7 @@ def test_param_hash():
|
|
|
68
68
|
params3 = [('beta', 1.24), ('gamma', 4.57)]
|
|
69
69
|
params4 = [('beta', 1.23 + 0.01j), ('gamma', 4.56 + 0.01j)]
|
|
70
70
|
params5 = [('beta', 1.23 + 0.01j), ('gamma', 4.56 + 0.01j)]
|
|
71
|
+
params3 = [('beta', 1.24), ('gamma', 4.57)]
|
|
71
72
|
assert _hashable_param(params1) == _hashable_param(params1)
|
|
72
73
|
assert hash(_hashable_param(params1)) == hash(_hashable_param(params1))
|
|
73
74
|
assert _hashable_param(params1) == _hashable_param(params2)
|