cirq-core 1.4.0.dev20240529225110__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 +31 -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.0.dev20240529225110.dist-info → cirq_core-1.5.0.dist-info}/RECORD +586 -552
- {cirq_core-1.4.0.dev20240529225110.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.0.dev20240529225110.dist-info/METADATA +0 -50
- {cirq_core-1.4.0.dev20240529225110.dist-info → cirq_core-1.5.0.dist-info}/LICENSE +0 -0
- {cirq_core-1.4.0.dev20240529225110.dist-info → cirq_core-1.5.0.dist-info}/top_level.txt +0 -0
|
@@ -15,8 +15,8 @@ import numpy as np
|
|
|
15
15
|
|
|
16
16
|
import cirq
|
|
17
17
|
import cirq.testing as ct
|
|
18
|
-
from cirq.testing import consistent_qasm as cq
|
|
19
18
|
from cirq.contrib.qasm_import import circuit_from_qasm
|
|
19
|
+
from cirq.testing import consistent_qasm as cq
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
def test_consistency_with_qasm_output_and_qiskit():
|
|
@@ -14,10 +14,12 @@
|
|
|
14
14
|
|
|
15
15
|
"""Converts cirq circuits into latex using qcircuit."""
|
|
16
16
|
|
|
17
|
-
from cirq.contrib.qcircuit.qcircuit_diagram import
|
|
17
|
+
from cirq.contrib.qcircuit.qcircuit_diagram import (
|
|
18
|
+
circuit_to_latex_using_qcircuit as circuit_to_latex_using_qcircuit,
|
|
19
|
+
)
|
|
18
20
|
|
|
19
21
|
from cirq.contrib.qcircuit.qcircuit_diagram_info import (
|
|
20
|
-
escape_text_for_latex,
|
|
21
|
-
get_multigate_parameters,
|
|
22
|
-
get_qcircuit_diagram_info,
|
|
22
|
+
escape_text_for_latex as escape_text_for_latex,
|
|
23
|
+
get_multigate_parameters as get_multigate_parameters,
|
|
24
|
+
get_qcircuit_diagram_info as get_qcircuit_diagram_info,
|
|
23
25
|
)
|
|
@@ -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
|
from typing import TYPE_CHECKING
|
|
15
18
|
|
|
16
19
|
from cirq import circuits, ops
|
|
@@ -23,7 +26,7 @@ if TYPE_CHECKING:
|
|
|
23
26
|
import cirq
|
|
24
27
|
|
|
25
28
|
|
|
26
|
-
def qcircuit_qubit_namer(qubit:
|
|
29
|
+
def qcircuit_qubit_namer(qubit: cirq.Qid) -> str:
|
|
27
30
|
"""Returns the latex code for a QCircuit label of given qubit.
|
|
28
31
|
|
|
29
32
|
Args:
|
|
@@ -64,7 +67,7 @@ def _render(diagram: circuits.TextDiagramDrawer) -> str:
|
|
|
64
67
|
|
|
65
68
|
|
|
66
69
|
def circuit_to_latex_using_qcircuit(
|
|
67
|
-
circuit:
|
|
70
|
+
circuit: cirq.Circuit, qubit_order: cirq.QubitOrderOrList = ops.QubitOrder.DEFAULT
|
|
68
71
|
) -> str:
|
|
69
72
|
"""Returns a QCircuit-based latex diagram of the given circuit.
|
|
70
73
|
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
# pragma: no cover
|
|
16
15
|
|
|
17
16
|
import errno
|
|
18
17
|
import os
|
|
@@ -65,4 +64,4 @@ def circuit_to_pdf_using_qcircuit_via_tex(
|
|
|
65
64
|
os.remove(filepath + '.' + ext)
|
|
66
65
|
except (OSError, IOError) as e:
|
|
67
66
|
if e.errno != errno.ENOENT:
|
|
68
|
-
raise
|
|
67
|
+
raise # pragma: nocover
|
cirq/{experiments/grid_parallel_two_qubit_xeb_test.py → contrib/qcircuit/qcircuit_pdf_test.py}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2025 The Cirq Developers
|
|
2
2
|
#
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -11,18 +11,19 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
from unittest import mock
|
|
16
|
+
|
|
17
|
+
import pylatex
|
|
18
|
+
|
|
15
19
|
import cirq
|
|
20
|
+
import cirq.contrib.qcircuit.qcircuit_pdf as qcircuit_pdf
|
|
16
21
|
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
cycles=[2, 4, 6, 8, 10],
|
|
25
|
-
layers=[LAYER_A, LAYER_B],
|
|
26
|
-
seed=1234,
|
|
23
|
+
@mock.patch.object(pylatex.Document, "generate_pdf")
|
|
24
|
+
def test_qcircuit_pdf(mock_generate_pdf):
|
|
25
|
+
circuit = cirq.Circuit(cirq.X(cirq.q(0)), cirq.CZ(cirq.q(0), cirq.q(1)))
|
|
26
|
+
qcircuit_pdf.circuit_to_pdf_using_qcircuit_via_tex(circuit, "/tmp/test_file")
|
|
27
|
+
mock_generate_pdf.assert_called_once_with(
|
|
28
|
+
"/tmp/test_file", compiler="latexmk", compiler_args=["-pdfps"]
|
|
27
29
|
)
|
|
28
|
-
cirq.testing.assert_equivalent_repr(metadata)
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
"""Utilities running the Quantum Volume benchmark on devices"""
|
|
15
15
|
|
|
16
16
|
from cirq.contrib.quantum_volume.quantum_volume import (
|
|
17
|
-
generate_model_circuit,
|
|
18
|
-
compute_heavy_set,
|
|
19
|
-
sample_heavy_set,
|
|
20
|
-
compile_circuit,
|
|
21
|
-
calculate_quantum_volume,
|
|
22
|
-
QuantumVolumeResult,
|
|
23
|
-
CompilationResult,
|
|
17
|
+
generate_model_circuit as generate_model_circuit,
|
|
18
|
+
compute_heavy_set as compute_heavy_set,
|
|
19
|
+
sample_heavy_set as sample_heavy_set,
|
|
20
|
+
compile_circuit as compile_circuit,
|
|
21
|
+
calculate_quantum_volume as calculate_quantum_volume,
|
|
22
|
+
QuantumVolumeResult as QuantumVolumeResult,
|
|
23
|
+
CompilationResult as CompilationResult,
|
|
24
24
|
)
|
|
@@ -4,7 +4,7 @@ https://arxiv.org/abs/1811.12926.
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
from dataclasses import dataclass
|
|
7
|
-
from typing import
|
|
7
|
+
from typing import Callable, Dict, List, Optional, Set, Tuple
|
|
8
8
|
|
|
9
9
|
import networkx as nx
|
|
10
10
|
import numpy as np
|
|
@@ -15,7 +15,7 @@ import cirq.contrib.routing as ccr
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
def generate_model_circuit(
|
|
18
|
-
num_qubits: int, depth: int, *, random_state:
|
|
18
|
+
num_qubits: int, depth: int, *, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
19
19
|
) -> cirq.Circuit:
|
|
20
20
|
"""Generates a model circuit with the given number of qubits and depth.
|
|
21
21
|
|
|
@@ -147,7 +147,7 @@ def sample_heavy_set(
|
|
|
147
147
|
|
|
148
148
|
results = results.agg(lambda meas: cirq.value.big_endian_bits_to_int(meas), axis=1)
|
|
149
149
|
# Compute the number of outputs that are in the heavy set.
|
|
150
|
-
num_in_heavy_set = np.sum(np.
|
|
150
|
+
num_in_heavy_set = np.sum(np.isin(results, heavy_set)).item()
|
|
151
151
|
|
|
152
152
|
# Return the number of Heavy outputs over the number of valid runs.
|
|
153
153
|
return num_in_heavy_set / len(results)
|
|
@@ -277,7 +277,7 @@ def compile_circuit(
|
|
|
277
277
|
# Replace the PermutationGates with regular gates, so we don't proliferate
|
|
278
278
|
# the routing implementation details to the compiler and the device itself.
|
|
279
279
|
|
|
280
|
-
def replace_swap_permutation_gate(op:
|
|
280
|
+
def replace_swap_permutation_gate(op: cirq.Operation, _):
|
|
281
281
|
if isinstance(op.gate, cirq.contrib.acquaintance.SwapPermutationGate):
|
|
282
282
|
return [op.gate.swap_gate.on(*op.qubits)]
|
|
283
283
|
return op
|
|
@@ -327,7 +327,7 @@ def prepare_circuits(
|
|
|
327
327
|
num_qubits: int,
|
|
328
328
|
depth: int,
|
|
329
329
|
num_circuits: int,
|
|
330
|
-
random_state:
|
|
330
|
+
random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
|
|
331
331
|
) -> List[Tuple[cirq.Circuit, List[int]]]:
|
|
332
332
|
"""Generates circuits and computes their heavy set.
|
|
333
333
|
|
|
@@ -416,11 +416,6 @@ def execute_circuits(
|
|
|
416
416
|
return results
|
|
417
417
|
|
|
418
418
|
|
|
419
|
-
def _get_device_graph(device_or_qubits: Any):
|
|
420
|
-
qubits = device_or_qubits if isinstance(device_or_qubits, list) else device_or_qubits.qubits
|
|
421
|
-
return ccr.gridqubits_to_graph_device(qubits)
|
|
422
|
-
|
|
423
|
-
|
|
424
419
|
def calculate_quantum_volume(
|
|
425
420
|
*,
|
|
426
421
|
num_qubits: int,
|
|
@@ -428,7 +423,7 @@ def calculate_quantum_volume(
|
|
|
428
423
|
num_circuits: int,
|
|
429
424
|
device_graph: nx.Graph,
|
|
430
425
|
samplers: List[cirq.Sampler],
|
|
431
|
-
random_state:
|
|
426
|
+
random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
|
|
432
427
|
compiler: Optional[Callable[[cirq.Circuit], cirq.Circuit]] = None,
|
|
433
428
|
repetitions=10_000,
|
|
434
429
|
routing_attempts=30,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# pylint: disable=wrong-or-nonexistent-copyright-notice
|
|
2
2
|
"""Tests for the Quantum Volume utilities."""
|
|
3
3
|
|
|
4
|
-
from unittest.mock import Mock, MagicMock
|
|
5
4
|
import io
|
|
5
|
+
from unittest.mock import MagicMock, Mock
|
|
6
|
+
|
|
6
7
|
import numpy as np
|
|
7
8
|
import pytest
|
|
9
|
+
|
|
8
10
|
import cirq
|
|
9
11
|
import cirq.contrib.routing as ccr
|
|
10
12
|
from cirq.contrib.quantum_volume import CompilationResult
|
cirq/contrib/quimb/__init__.py
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
# pylint: disable=wrong-or-nonexistent-copyright-notice
|
|
2
2
|
from cirq.contrib.quimb.state_vector import (
|
|
3
|
-
circuit_for_expectation_value,
|
|
4
|
-
tensor_expectation_value,
|
|
5
|
-
circuit_to_tensors,
|
|
6
|
-
tensor_state_vector,
|
|
7
|
-
tensor_unitary,
|
|
3
|
+
circuit_for_expectation_value as circuit_for_expectation_value,
|
|
4
|
+
tensor_expectation_value as tensor_expectation_value,
|
|
5
|
+
circuit_to_tensors as circuit_to_tensors,
|
|
6
|
+
tensor_state_vector as tensor_state_vector,
|
|
7
|
+
tensor_unitary as tensor_unitary,
|
|
8
8
|
)
|
|
9
9
|
|
|
10
10
|
from cirq.contrib.quimb.density_matrix import (
|
|
11
|
-
tensor_density_matrix,
|
|
12
|
-
circuit_to_density_matrix_tensors,
|
|
11
|
+
tensor_density_matrix as tensor_density_matrix,
|
|
12
|
+
circuit_to_density_matrix_tensors as circuit_to_density_matrix_tensors,
|
|
13
13
|
)
|
|
14
14
|
|
|
15
|
-
from cirq.contrib.quimb.grid_circuits import
|
|
15
|
+
from cirq.contrib.quimb.grid_circuits import (
|
|
16
|
+
simplify_expectation_value_circuit as simplify_expectation_value_circuit,
|
|
17
|
+
get_grid_moments as get_grid_moments,
|
|
18
|
+
)
|
|
16
19
|
|
|
17
20
|
from cirq.contrib.quimb.mps_simulator import (
|
|
18
|
-
MPSOptions,
|
|
19
|
-
MPSSimulator,
|
|
20
|
-
MPSSimulatorStepResult,
|
|
21
|
-
MPSState,
|
|
22
|
-
MPSTrialResult,
|
|
21
|
+
MPSOptions as MPSOptions,
|
|
22
|
+
MPSSimulator as MPSSimulator,
|
|
23
|
+
MPSSimulatorStepResult as MPSSimulatorStepResult,
|
|
24
|
+
MPSState as MPSState,
|
|
25
|
+
MPSTrialResult as MPSTrialResult,
|
|
23
26
|
)
|
|
@@ -17,6 +17,8 @@ This is based on this paper:
|
|
|
17
17
|
https://arxiv.org/abs/2002.07730
|
|
18
18
|
"""
|
|
19
19
|
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
20
22
|
import dataclasses
|
|
21
23
|
import math
|
|
22
24
|
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, TYPE_CHECKING, Union
|
|
@@ -58,10 +60,10 @@ class MPSSimulator(
|
|
|
58
60
|
|
|
59
61
|
def __init__(
|
|
60
62
|
self,
|
|
61
|
-
noise:
|
|
62
|
-
seed:
|
|
63
|
+
noise: cirq.NOISE_MODEL_LIKE = None,
|
|
64
|
+
seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
|
|
63
65
|
simulation_options: MPSOptions = MPSOptions(),
|
|
64
|
-
grouping: Optional[Dict[
|
|
66
|
+
grouping: Optional[Dict[cirq.Qid, int]] = None,
|
|
65
67
|
):
|
|
66
68
|
"""Creates instance of `MPSSimulator`.
|
|
67
69
|
|
|
@@ -84,10 +86,10 @@ class MPSSimulator(
|
|
|
84
86
|
|
|
85
87
|
def _create_partial_simulation_state(
|
|
86
88
|
self,
|
|
87
|
-
initial_state: Union[int,
|
|
88
|
-
qubits: Sequence[
|
|
89
|
-
classical_data:
|
|
90
|
-
) ->
|
|
89
|
+
initial_state: Union[int, MPSState],
|
|
90
|
+
qubits: Sequence[cirq.Qid],
|
|
91
|
+
classical_data: cirq.ClassicalDataStore,
|
|
92
|
+
) -> MPSState:
|
|
91
93
|
"""Creates MPSState args for simulating the Circuit.
|
|
92
94
|
|
|
93
95
|
Args:
|
|
@@ -103,7 +105,7 @@ class MPSSimulator(
|
|
|
103
105
|
MPSState args for simulating the Circuit.
|
|
104
106
|
"""
|
|
105
107
|
if isinstance(initial_state, MPSState):
|
|
106
|
-
return initial_state
|
|
108
|
+
return initial_state # pragma: no cover
|
|
107
109
|
|
|
108
110
|
return MPSState(
|
|
109
111
|
qubits=qubits,
|
|
@@ -114,15 +116,15 @@ class MPSSimulator(
|
|
|
114
116
|
classical_data=classical_data,
|
|
115
117
|
)
|
|
116
118
|
|
|
117
|
-
def _create_step_result(self, sim_state:
|
|
119
|
+
def _create_step_result(self, sim_state: cirq.SimulationStateBase[MPSState]):
|
|
118
120
|
return MPSSimulatorStepResult(sim_state)
|
|
119
121
|
|
|
120
122
|
def _create_simulator_trial_result(
|
|
121
123
|
self,
|
|
122
|
-
params:
|
|
124
|
+
params: cirq.ParamResolver,
|
|
123
125
|
measurements: Dict[str, np.ndarray],
|
|
124
|
-
final_simulator_state:
|
|
125
|
-
) ->
|
|
126
|
+
final_simulator_state: cirq.SimulationStateBase[MPSState],
|
|
127
|
+
) -> MPSTrialResult:
|
|
126
128
|
"""Creates a single trial results with the measurements.
|
|
127
129
|
|
|
128
130
|
Args:
|
|
@@ -144,16 +146,16 @@ class MPSTrialResult(simulator_base.SimulationTrialResultBase['MPSState']):
|
|
|
144
146
|
|
|
145
147
|
def __init__(
|
|
146
148
|
self,
|
|
147
|
-
params:
|
|
149
|
+
params: cirq.ParamResolver,
|
|
148
150
|
measurements: Dict[str, np.ndarray],
|
|
149
|
-
final_simulator_state:
|
|
151
|
+
final_simulator_state: cirq.SimulationStateBase[MPSState],
|
|
150
152
|
) -> None:
|
|
151
153
|
super().__init__(
|
|
152
154
|
params=params, measurements=measurements, final_simulator_state=final_simulator_state
|
|
153
155
|
)
|
|
154
156
|
|
|
155
157
|
@property
|
|
156
|
-
def final_state(self) ->
|
|
158
|
+
def final_state(self) -> MPSState:
|
|
157
159
|
return self._get_merged_sim_state()
|
|
158
160
|
|
|
159
161
|
def __str__(self) -> str:
|
|
@@ -173,7 +175,7 @@ class MPSTrialResult(simulator_base.SimulationTrialResultBase['MPSState']):
|
|
|
173
175
|
class MPSSimulatorStepResult(simulator_base.StepResultBase['MPSState']):
|
|
174
176
|
"""A `StepResult` that can perform measurements."""
|
|
175
177
|
|
|
176
|
-
def __init__(self, sim_state:
|
|
178
|
+
def __init__(self, sim_state: cirq.SimulationStateBase[MPSState]):
|
|
177
179
|
"""Results of a step of the simulator.
|
|
178
180
|
Attributes:
|
|
179
181
|
sim_state: The qubit:SimulationState lookup for this step.
|
|
@@ -309,7 +311,7 @@ class _MPSHandler(qis.QuantumStateRepresentation):
|
|
|
309
311
|
def _value_equality_values_(self) -> Any:
|
|
310
312
|
return self._qid_shape, self._M, self._simulation_options, self._grouping
|
|
311
313
|
|
|
312
|
-
def copy(self, deep_copy_buffers: bool = True) ->
|
|
314
|
+
def copy(self, deep_copy_buffers: bool = True) -> _MPSHandler:
|
|
313
315
|
"""Copies the object.
|
|
314
316
|
|
|
315
317
|
Args:
|
|
@@ -460,7 +462,7 @@ class _MPSHandler(qis.QuantumStateRepresentation):
|
|
|
460
462
|
raise ValueError('Can only handle 1 and 2 qubit operations')
|
|
461
463
|
return True
|
|
462
464
|
|
|
463
|
-
def estimation_stats(self):
|
|
465
|
+
def estimation_stats(self): # pragma: no cover
|
|
464
466
|
"""Returns some statistics about the memory usage and quality of the approximation."""
|
|
465
467
|
|
|
466
468
|
num_coefs_used = sum([Mi.data.size for Mi in self._M])
|
|
@@ -520,7 +522,7 @@ class _MPSHandler(qis.QuantumStateRepresentation):
|
|
|
520
522
|
return results
|
|
521
523
|
|
|
522
524
|
def measure(
|
|
523
|
-
self, axes: Sequence[int], seed:
|
|
525
|
+
self, axes: Sequence[int], seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
524
526
|
) -> List[int]:
|
|
525
527
|
"""Measures the MPS.
|
|
526
528
|
|
|
@@ -533,10 +535,7 @@ class _MPSHandler(qis.QuantumStateRepresentation):
|
|
|
533
535
|
return self._measure(axes, value.parse_random_state(seed))
|
|
534
536
|
|
|
535
537
|
def sample(
|
|
536
|
-
self,
|
|
537
|
-
axes: Sequence[int],
|
|
538
|
-
repetitions: int = 1,
|
|
539
|
-
seed: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None,
|
|
538
|
+
self, axes: Sequence[int], repetitions: int = 1, seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
540
539
|
) -> np.ndarray:
|
|
541
540
|
"""Samples the MPS.
|
|
542
541
|
|
|
@@ -564,12 +563,12 @@ class MPSState(SimulationState[_MPSHandler]):
|
|
|
564
563
|
def __init__(
|
|
565
564
|
self,
|
|
566
565
|
*,
|
|
567
|
-
qubits: Sequence[
|
|
566
|
+
qubits: Sequence[cirq.Qid],
|
|
568
567
|
prng: np.random.RandomState,
|
|
569
568
|
simulation_options: MPSOptions = MPSOptions(),
|
|
570
|
-
grouping: Optional[Dict[
|
|
569
|
+
grouping: Optional[Dict[cirq.Qid, int]] = None,
|
|
571
570
|
initial_state: int = 0,
|
|
572
|
-
classical_data: Optional[
|
|
571
|
+
classical_data: Optional[cirq.ClassicalDataStore] = None,
|
|
573
572
|
):
|
|
574
573
|
"""Creates and MPSState
|
|
575
574
|
|
|
@@ -623,7 +622,7 @@ class MPSState(SimulationState[_MPSHandler]):
|
|
|
623
622
|
"""
|
|
624
623
|
return self._state.state_vector()
|
|
625
624
|
|
|
626
|
-
def partial_trace(self, keep_qubits: Set[
|
|
625
|
+
def partial_trace(self, keep_qubits: Set[cirq.Qid]) -> np.ndarray:
|
|
627
626
|
"""Traces out all qubits except keep_qubits.
|
|
628
627
|
|
|
629
628
|
Args:
|
|
@@ -642,7 +641,7 @@ class MPSState(SimulationState[_MPSHandler]):
|
|
|
642
641
|
return self._state.to_numpy()
|
|
643
642
|
|
|
644
643
|
def _act_on_fallback_(
|
|
645
|
-
self, action: Any, qubits: Sequence[
|
|
644
|
+
self, action: Any, qubits: Sequence[cirq.Qid], allow_decompose: bool = True
|
|
646
645
|
) -> bool:
|
|
647
646
|
"""Delegates the action to self.apply_op"""
|
|
648
647
|
return self._state.apply_op(action, self.get_axes(qubits), self.prng)
|
|
@@ -479,6 +479,11 @@ def test_simulation_state_initializer():
|
|
|
479
479
|
)
|
|
480
480
|
assert s.qubits == (cirq.LineQubit(0),)
|
|
481
481
|
assert s.classical_data == expected_classical_data
|
|
482
|
+
assert s.estimation_stats() == {
|
|
483
|
+
'estimated_fidelity': 1.0,
|
|
484
|
+
'memory_bytes': 16,
|
|
485
|
+
'num_coefs_used': 2,
|
|
486
|
+
}
|
|
482
487
|
|
|
483
488
|
|
|
484
489
|
def test_act_on_gate():
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# pylint: disable=wrong-or-nonexistent-copyright-notice
|
|
2
2
|
import warnings
|
|
3
|
-
from typing import cast,
|
|
3
|
+
from typing import cast, Dict, List, Optional, Sequence, Tuple, Union
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
import quimb
|
|
@@ -170,15 +170,8 @@ def tensor_expectation_value(
|
|
|
170
170
|
)
|
|
171
171
|
else:
|
|
172
172
|
tn.rank_simplify(inplace=True)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
# Avoid bug in quimb-1.8.0.
|
|
176
|
-
# Ref: https://github.com/jcmgray/quimb/issues/231
|
|
177
|
-
if tn.ind_map:
|
|
178
|
-
path_info = tn.contract(get='path-info')
|
|
179
|
-
ram_gb = path_info.largest_intermediate * 128 / 8 / 1024 / 1024 / 1024
|
|
180
|
-
else:
|
|
181
|
-
ram_gb = 0
|
|
173
|
+
path_info = tn.contract(get='path-info')
|
|
174
|
+
ram_gb = path_info.largest_intermediate * 128 / 8 / 1024 / 1024 / 1024
|
|
182
175
|
if ram_gb > max_ram_gb:
|
|
183
176
|
raise MemoryError(f"We estimate that this contraction will take too much RAM! {ram_gb} GB")
|
|
184
177
|
e_val = tn.contract(inplace=True)
|
cirq/contrib/quirk/__init__.py
CHANGED
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
|
|
15
15
|
import json
|
|
16
16
|
import urllib.parse
|
|
17
|
-
from typing import
|
|
17
|
+
from typing import Any, cast, Iterable, List, Tuple
|
|
18
18
|
|
|
19
|
-
from cirq import
|
|
19
|
+
from cirq import circuits, devices, ops, protocols
|
|
20
20
|
from cirq.contrib.quirk.linearize_circuit import linearize_circuit_qubits
|
|
21
21
|
from cirq.contrib.quirk.quirk_gate import (
|
|
22
22
|
known_quirk_op_for_operation,
|
|
23
23
|
QuirkOp,
|
|
24
|
-
UNKNOWN_GATE,
|
|
25
24
|
single_qubit_matrix_gate,
|
|
25
|
+
UNKNOWN_GATE,
|
|
26
26
|
)
|
|
27
27
|
|
|
28
28
|
|
cirq/contrib/routing/__init__.py
CHANGED
|
@@ -14,15 +14,18 @@
|
|
|
14
14
|
"""Utilities for routing circuits on devices"""
|
|
15
15
|
|
|
16
16
|
from cirq.contrib.routing.device import (
|
|
17
|
-
get_linear_device_graph,
|
|
18
|
-
get_grid_device_graph,
|
|
19
|
-
gridqubits_to_graph_device,
|
|
20
|
-
nx_qubit_layout,
|
|
17
|
+
get_linear_device_graph as get_linear_device_graph,
|
|
18
|
+
get_grid_device_graph as get_grid_device_graph,
|
|
19
|
+
gridqubits_to_graph_device as gridqubits_to_graph_device,
|
|
20
|
+
nx_qubit_layout as nx_qubit_layout,
|
|
21
21
|
)
|
|
22
|
-
|
|
23
|
-
from cirq.contrib.routing.
|
|
22
|
+
|
|
23
|
+
from cirq.contrib.routing.router import route_circuit as route_circuit, ROUTERS as ROUTERS
|
|
24
|
+
|
|
25
|
+
from cirq.contrib.routing.swap_network import SwapNetwork as SwapNetwork
|
|
26
|
+
|
|
24
27
|
from cirq.contrib.routing.utils import (
|
|
25
|
-
get_circuit_connectivity,
|
|
26
|
-
is_valid_routing,
|
|
27
|
-
ops_are_consistent_with_device_graph,
|
|
28
|
+
get_circuit_connectivity as get_circuit_connectivity,
|
|
29
|
+
is_valid_routing as is_valid_routing,
|
|
30
|
+
ops_are_consistent_with_device_graph as ops_are_consistent_with_device_graph,
|
|
28
31
|
)
|
cirq/contrib/routing/device.py
CHANGED
cirq/contrib/routing/greedy.py
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import itertools
|
|
16
18
|
from typing import (
|
|
17
19
|
Callable,
|
|
@@ -26,11 +28,11 @@ from typing import (
|
|
|
26
28
|
TYPE_CHECKING,
|
|
27
29
|
)
|
|
28
30
|
|
|
29
|
-
import numpy as np
|
|
30
31
|
import networkx as nx
|
|
32
|
+
import numpy as np
|
|
31
33
|
|
|
32
|
-
from cirq import circuits, ops, value
|
|
33
34
|
import cirq.contrib.acquaintance as cca
|
|
35
|
+
from cirq import circuits, ops, value
|
|
34
36
|
from cirq.contrib import circuitdag
|
|
35
37
|
from cirq.contrib.routing.initialization import get_initial_mapping
|
|
36
38
|
from cirq.contrib.routing.swap_network import SwapNetwork
|
|
@@ -109,7 +111,7 @@ class _GreedyRouter:
|
|
|
109
111
|
op1.qubits
|
|
110
112
|
)
|
|
111
113
|
& set(op2.qubits),
|
|
112
|
-
random_state:
|
|
114
|
+
random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
|
|
113
115
|
):
|
|
114
116
|
|
|
115
117
|
self.prng = value.parse_random_state(random_state)
|
|
@@ -148,12 +150,12 @@ class _GreedyRouter:
|
|
|
148
150
|
]
|
|
149
151
|
return self.edge_sets[edge_set_size]
|
|
150
152
|
|
|
151
|
-
def log_to_phys(self, *qubits:
|
|
153
|
+
def log_to_phys(self, *qubits: cirq.Qid) -> Iterable[ops.Qid]:
|
|
152
154
|
"""Returns an iterator over the physical qubits mapped to by the given
|
|
153
155
|
logical qubits."""
|
|
154
156
|
return (self._log_to_phys[q] for q in qubits)
|
|
155
157
|
|
|
156
|
-
def phys_to_log(self, *qubits:
|
|
158
|
+
def phys_to_log(self, *qubits: cirq.Qid) -> Iterable[Optional[ops.Qid]]:
|
|
157
159
|
"""Returns an iterator over the logical qubits that map to the given
|
|
158
160
|
physical qubits."""
|
|
159
161
|
return (self._phys_to_log[q] for q in qubits)
|
|
@@ -45,15 +45,17 @@ def create_circuit_and_device():
|
|
|
45
45
|
|
|
46
46
|
def create_hanging_routing_instance(circuit, device_graph):
|
|
47
47
|
"""Create a test problem instance."""
|
|
48
|
-
route_circuit_greedily(
|
|
48
|
+
route_circuit_greedily( # pragma: no cover
|
|
49
|
+
circuit, device_graph, max_search_radius=2, random_state=1
|
|
50
|
+
)
|
|
49
51
|
|
|
50
52
|
|
|
51
53
|
def test_router_hanging():
|
|
52
|
-
"""Run a separate process and check if greedy router hits timeout (
|
|
54
|
+
"""Run a separate process and check if greedy router hits timeout (20s)."""
|
|
53
55
|
circuit, device_graph = create_circuit_and_device()
|
|
54
56
|
process = Process(target=create_hanging_routing_instance, args=[circuit, device_graph])
|
|
55
57
|
process.start()
|
|
56
|
-
process.join(timeout=
|
|
58
|
+
process.join(timeout=20)
|
|
57
59
|
try:
|
|
58
60
|
assert not process.is_alive(), "Greedy router timeout"
|
|
59
61
|
finally:
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
15
17
|
import itertools
|
|
16
18
|
from typing import cast, Dict, Hashable, TYPE_CHECKING
|
|
17
19
|
|
|
@@ -32,7 +34,7 @@ def get_center(graph: nx.Graph) -> Hashable:
|
|
|
32
34
|
def get_initial_mapping(
|
|
33
35
|
logical_graph: nx.Graph,
|
|
34
36
|
device_graph: nx.Graph,
|
|
35
|
-
random_state:
|
|
37
|
+
random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None,
|
|
36
38
|
) -> Dict[ops.Qid, ops.Qid]:
|
|
37
39
|
"""Gets an initial mapping of logical to physical qubits for routing.
|
|
38
40
|
|