cirq-core 1.7.0.dev20250825174419__py3-none-any.whl → 1.7.0.dev20251203004401__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.
- cirq/__init__.py +1 -0
- cirq/_compat.py +3 -2
- cirq/_compat_test.py +16 -15
- cirq/_doc.py +4 -3
- cirq/_import.py +2 -1
- cirq/_version.py +1 -1
- cirq/_version_test.py +1 -1
- cirq/circuits/_bucket_priority_queue.py +2 -1
- cirq/circuits/circuit.py +19 -17
- cirq/circuits/circuit_operation.py +2 -1
- cirq/circuits/circuit_operation_test.py +19 -0
- cirq/circuits/circuit_test.py +31 -12
- cirq/circuits/frozen_circuit.py +3 -2
- cirq/circuits/moment.py +3 -15
- cirq/circuits/optimization_pass.py +2 -1
- cirq/circuits/qasm_output.py +39 -10
- cirq/circuits/qasm_output_test.py +51 -2
- cirq/circuits/text_diagram_drawer.py +2 -1
- cirq/contrib/acquaintance/bipartite.py +2 -1
- cirq/contrib/acquaintance/devices.py +1 -1
- cirq/contrib/acquaintance/executor.py +4 -5
- cirq/contrib/acquaintance/executor_test.py +2 -1
- cirq/contrib/acquaintance/gates.py +2 -1
- cirq/contrib/acquaintance/gates_test.py +1 -1
- cirq/contrib/acquaintance/inspection_utils.py +2 -1
- cirq/contrib/acquaintance/mutation_utils.py +2 -1
- cirq/contrib/acquaintance/optimizers.py +2 -1
- cirq/contrib/acquaintance/permutation.py +2 -1
- cirq/contrib/acquaintance/permutation_test.py +1 -1
- cirq/contrib/acquaintance/shift.py +2 -1
- cirq/contrib/acquaintance/shift_swap_network.py +2 -1
- cirq/contrib/acquaintance/strategies/complete.py +3 -2
- cirq/contrib/acquaintance/strategies/cubic.py +2 -1
- cirq/contrib/acquaintance/strategies/quartic_paired.py +2 -1
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +1 -1
- cirq/contrib/acquaintance/testing.py +2 -1
- cirq/contrib/acquaintance/topological_sort.py +2 -1
- cirq/contrib/bayesian_network/bayesian_network_gate.py +3 -2
- cirq/contrib/circuitdag/circuit_dag.py +4 -2
- cirq/contrib/custom_simulators/custom_state_simulator.py +2 -1
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +1 -1
- cirq/contrib/graph_device/graph_device.py +2 -1
- cirq/contrib/graph_device/graph_device_test.py +2 -1
- cirq/contrib/graph_device/hypergraph.py +2 -1
- cirq/contrib/graph_device/uniform_graph_device.py +2 -1
- cirq/contrib/json.py +14 -2
- cirq/contrib/json_test_data/BayesianNetworkGate.json +10 -0
- cirq/contrib/json_test_data/BayesianNetworkGate.repr +3 -0
- cirq/contrib/json_test_data/QuantumVolumeResult.json +169 -0
- cirq/contrib/json_test_data/QuantumVolumeResult.repr +22 -0
- cirq/contrib/json_test_data/SwapPermutationGate.json +3 -0
- cirq/contrib/json_test_data/SwapPermutationGate.repr +1 -0
- cirq/contrib/json_test_data/spec.py +0 -2
- cirq/contrib/noise_models/noise_models.py +2 -1
- cirq/contrib/paulistring/clifford_optimize.py +20 -2
- cirq/contrib/paulistring/optimize.py +1 -1
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +146 -35
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +81 -178
- cirq/contrib/paulistring/recombine.py +5 -2
- cirq/contrib/paulistring/separate.py +1 -1
- cirq/contrib/qasm_import/_lexer.py +6 -1
- cirq/contrib/qasm_import/_lexer_test.py +1 -1
- cirq/contrib/qasm_import/_parser.py +24 -8
- cirq/contrib/qasm_import/_parser_test.py +44 -6
- cirq/contrib/qcircuit/qcircuit_pdf_test.py +6 -9
- cirq/contrib/quantikz/__init__.py +21 -0
- cirq/contrib/quantikz/circuit_to_latex_quantikz.py +680 -0
- cirq/contrib/quantikz/circuit_to_latex_quantikz_test.py +253 -0
- cirq/contrib/quantikz/circuit_to_latex_render.py +424 -0
- cirq/contrib/quantikz/circuit_to_latex_render_test.py +44 -0
- cirq/contrib/quantum_volume/quantum_volume.py +2 -1
- cirq/contrib/quimb/density_matrix.py +1 -1
- cirq/contrib/quimb/grid_circuits.py +2 -1
- cirq/contrib/quimb/grid_circuits_test.py +1 -1
- cirq/contrib/quimb/mps_simulator.py +4 -3
- cirq/contrib/quimb/state_vector.py +2 -1
- cirq/contrib/quirk/export_to_quirk.py +2 -1
- cirq/contrib/quirk/linearize_circuit.py +1 -1
- cirq/contrib/quirk/quirk_gate.py +2 -1
- cirq/contrib/routing/device.py +1 -1
- cirq/contrib/routing/greedy.py +2 -1
- cirq/contrib/routing/initialization.py +2 -1
- cirq/contrib/routing/router.py +2 -1
- cirq/contrib/routing/swap_network.py +2 -1
- cirq/contrib/routing/utils.py +2 -1
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +7 -5
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +6 -6
- cirq/devices/device.py +2 -1
- cirq/devices/grid_device_metadata.py +2 -1
- cirq/devices/grid_qubit.py +7 -6
- cirq/devices/insertion_noise_model.py +2 -1
- cirq/devices/line_qubit.py +2 -1
- cirq/devices/named_topologies.py +2 -1
- cirq/devices/noise_model.py +2 -1
- cirq/devices/noise_model_test.py +1 -1
- cirq/devices/noise_properties.py +2 -1
- cirq/devices/superconducting_qubits_noise_properties_test.py +2 -1
- cirq/devices/thermal_noise_model.py +2 -1
- cirq/experiments/__init__.py +2 -0
- cirq/experiments/benchmarking/parallel_xeb.py +2 -1
- cirq/experiments/benchmarking/parallel_xeb_test.py +1 -1
- cirq/experiments/fidelity_estimation.py +2 -1
- cirq/experiments/fidelity_estimation_test.py +1 -1
- cirq/experiments/ghz_2d.py +150 -0
- cirq/experiments/ghz_2d_test.py +155 -0
- cirq/experiments/n_qubit_tomography.py +2 -1
- cirq/experiments/n_qubit_tomography_test.py +1 -1
- cirq/experiments/purity_estimation.py +1 -1
- cirq/experiments/qubit_characterizations.py +33 -4
- cirq/experiments/qubit_characterizations_test.py +16 -0
- cirq/experiments/random_quantum_circuit_generation.py +2 -1
- cirq/experiments/random_quantum_circuit_generation_test.py +2 -1
- cirq/experiments/readout_confusion_matrix.py +2 -1
- cirq/experiments/readout_confusion_matrix_test.py +1 -1
- cirq/experiments/single_qubit_readout_calibration.py +2 -1
- cirq/experiments/single_qubit_readout_calibration_test.py +1 -1
- cirq/experiments/t1_decay_experiment.py +2 -1
- cirq/experiments/two_qubit_xeb.py +2 -1
- cirq/experiments/two_qubit_xeb_test.py +1 -1
- cirq/experiments/xeb_fitting.py +2 -1
- cirq/experiments/xeb_fitting_test.py +1 -1
- cirq/experiments/xeb_sampling.py +5 -3
- cirq/experiments/xeb_sampling_test.py +1 -1
- cirq/experiments/xeb_simulation.py +2 -1
- cirq/experiments/xeb_simulation_test.py +2 -1
- cirq/experiments/z_phase_calibration.py +2 -1
- cirq/experiments/z_phase_calibration_test.py +18 -3
- cirq/interop/quirk/cells/__init__.py +1 -2
- cirq/interop/quirk/cells/all_cells.py +2 -1
- cirq/interop/quirk/cells/arithmetic_cells.py +2 -1
- cirq/interop/quirk/cells/cell.py +2 -1
- cirq/interop/quirk/cells/composite_cell.py +2 -1
- cirq/interop/quirk/cells/composite_cell_test.py +1 -1
- cirq/interop/quirk/cells/control_cells.py +2 -1
- cirq/interop/quirk/cells/frequency_space_cells.py +1 -1
- cirq/interop/quirk/cells/ignored_cells.py +1 -1
- cirq/interop/quirk/cells/input_cells.py +2 -1
- cirq/interop/quirk/cells/input_rotation_cells.py +2 -1
- cirq/interop/quirk/cells/measurement_cells.py +2 -1
- cirq/interop/quirk/cells/parse.py +2 -11
- cirq/interop/quirk/cells/qubit_permutation_cells.py +2 -1
- cirq/interop/quirk/cells/scalar_cells.py +2 -1
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +2 -1
- cirq/interop/quirk/cells/swap_cell.py +2 -1
- cirq/interop/quirk/cells/unsupported_cells.py +1 -1
- cirq/interop/quirk/url_to_circuit.py +2 -1
- cirq/json_resolver_cache.py +0 -2
- cirq/linalg/decompositions.py +6 -2
- cirq/linalg/decompositions_test.py +1 -0
- cirq/linalg/diagonalize.py +1 -1
- cirq/linalg/predicates.py +2 -1
- cirq/linalg/tolerance.py +2 -1
- cirq/linalg/transformations.py +3 -2
- cirq/ops/arithmetic_operation.py +4 -3
- cirq/ops/arithmetic_operation_test.py +1 -1
- cirq/ops/boolean_hamiltonian.py +4 -3
- cirq/ops/classically_controlled_operation.py +11 -11
- cirq/ops/classically_controlled_operation_test.py +26 -2
- cirq/ops/clifford_gate.py +3 -2
- cirq/ops/clifford_gate_test.py +1 -2
- cirq/ops/common_channels.py +2 -1
- cirq/ops/common_gates.py +3 -2
- cirq/ops/control_values.py +2 -1
- cirq/ops/controlled_gate.py +3 -2
- cirq/ops/controlled_gate_test.py +2 -1
- cirq/ops/controlled_operation.py +3 -2
- cirq/ops/controlled_operation_test.py +2 -1
- cirq/ops/dense_pauli_string.py +44 -81
- cirq/ops/dense_pauli_string_test.py +21 -0
- cirq/ops/diagonal_gate.py +3 -2
- cirq/ops/eigen_gate.py +9 -7
- cirq/ops/fourier_transform.py +3 -2
- cirq/ops/fourier_transform_test.py +2 -4
- cirq/ops/fsim_gate.py +3 -2
- cirq/ops/gate_operation.py +23 -12
- cirq/ops/gateset.py +22 -2
- cirq/ops/global_phase_op.py +3 -2
- cirq/ops/greedy_qubit_manager.py +2 -1
- cirq/ops/identity.py +2 -1
- cirq/ops/kraus_channel.py +2 -1
- cirq/ops/linear_combinations.py +12 -17
- cirq/ops/linear_combinations_test.py +23 -1
- cirq/ops/matrix_gates.py +2 -1
- cirq/ops/measure_util.py +8 -6
- cirq/ops/measurement_gate.py +2 -1
- cirq/ops/mixed_unitary_channel.py +2 -1
- cirq/ops/named_qubit.py +2 -2
- cirq/ops/op_tree.py +2 -1
- cirq/ops/parallel_gate.py +3 -2
- cirq/ops/parity_gates.py +2 -1
- cirq/ops/parity_gates_test.py +35 -0
- cirq/ops/pauli_interaction_gate.py +2 -1
- cirq/ops/pauli_measurement_gate.py +2 -1
- cirq/ops/pauli_string.py +37 -57
- cirq/ops/pauli_string_phasor.py +6 -5
- cirq/ops/pauli_string_raw_types.py +2 -1
- cirq/ops/pauli_string_test.py +49 -6
- cirq/ops/pauli_sum_exponential.py +2 -1
- cirq/ops/permutation_gate.py +2 -1
- cirq/ops/phased_iswap_gate.py +3 -2
- cirq/ops/phased_x_gate.py +5 -4
- cirq/ops/phased_x_z_gate.py +12 -5
- cirq/ops/projector.py +2 -1
- cirq/ops/qubit_manager.py +2 -1
- cirq/ops/qubit_order.py +2 -1
- cirq/ops/qubit_order_or_list.py +1 -1
- cirq/ops/random_gate_channel.py +3 -2
- cirq/ops/raw_types.py +33 -16
- cirq/ops/raw_types_test.py +4 -3
- cirq/ops/state_preparation_channel.py +2 -1
- cirq/ops/three_qubit_gates.py +3 -2
- cirq/ops/two_qubit_diagonal_gate.py +3 -2
- cirq/ops/uniform_superposition_gate.py +2 -1
- cirq/ops/wait_gate.py +10 -4
- cirq/protocols/act_on_protocol.py +2 -1
- cirq/protocols/act_on_protocol_test.py +2 -1
- cirq/protocols/apply_channel_protocol.py +2 -1
- cirq/protocols/apply_mixture_protocol.py +2 -1
- cirq/protocols/apply_mixture_protocol_test.py +2 -1
- cirq/protocols/apply_unitary_protocol.py +2 -1
- cirq/protocols/apply_unitary_protocol_test.py +2 -0
- cirq/protocols/approximate_equality_protocol.py +2 -1
- cirq/protocols/circuit_diagram_info_protocol.py +2 -1
- cirq/protocols/control_key_protocol.py +7 -0
- cirq/protocols/decompose_protocol.py +2 -12
- cirq/protocols/has_stabilizer_effect_protocol.py +1 -1
- cirq/protocols/has_stabilizer_effect_protocol_test.py +11 -9
- cirq/protocols/has_unitary_protocol_test.py +3 -3
- cirq/protocols/hash_from_pickle_test.py +2 -2
- cirq/protocols/inverse_protocol.py +2 -1
- cirq/protocols/json_serialization.py +5 -4
- cirq/protocols/json_serialization_test.py +31 -31
- cirq/protocols/kraus_protocol.py +4 -3
- cirq/protocols/kraus_protocol_test.py +7 -7
- cirq/protocols/measurement_key_protocol.py +32 -8
- cirq/protocols/mixture_protocol.py +3 -2
- cirq/protocols/mixture_protocol_test.py +7 -7
- cirq/protocols/mul_protocol_test.py +4 -4
- cirq/protocols/phase_protocol.py +13 -4
- cirq/protocols/pow_protocol.py +2 -1
- cirq/protocols/pow_protocol_test.py +5 -5
- cirq/protocols/qasm.py +2 -1
- cirq/protocols/qid_shape_protocol.py +2 -1
- cirq/protocols/resolve_parameters.py +17 -15
- cirq/protocols/trace_distance_bound.py +2 -1
- cirq/protocols/unitary_protocol.py +21 -21
- cirq/protocols/unitary_protocol_test.py +31 -19
- cirq/qis/channels.py +1 -1
- cirq/qis/channels_test.py +1 -1
- cirq/qis/clifford_tableau.py +16 -15
- cirq/qis/clifford_tableau_test.py +17 -17
- cirq/qis/entropy.py +3 -3
- cirq/qis/entropy_test.py +1 -1
- cirq/qis/quantum_state_representation.py +2 -1
- cirq/qis/states.py +7 -2
- cirq/qis/states_test.py +54 -54
- cirq/sim/classical_simulator.py +25 -14
- cirq/sim/classical_simulator_test.py +85 -30
- cirq/sim/clifford/clifford_simulator.py +7 -6
- cirq/sim/clifford/clifford_simulator_test.py +51 -50
- cirq/sim/clifford/clifford_tableau_simulation_state.py +2 -1
- cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +2 -1
- cirq/sim/clifford/stabilizer_sampler.py +1 -1
- cirq/sim/clifford/stabilizer_simulation_state.py +2 -1
- cirq/sim/clifford/stabilizer_state_ch_form.py +16 -15
- cirq/sim/clifford/stabilizer_state_ch_form_test.py +0 -1
- cirq/sim/density_matrix_simulation_state.py +7 -6
- cirq/sim/density_matrix_simulator.py +3 -2
- cirq/sim/density_matrix_simulator_test.py +94 -84
- cirq/sim/density_matrix_utils.py +2 -1
- cirq/sim/density_matrix_utils_test.py +1 -1
- cirq/sim/mux.py +35 -8
- cirq/sim/mux_test.py +39 -26
- cirq/sim/simulation_product_state.py +2 -1
- cirq/sim/simulation_product_state_test.py +8 -7
- cirq/sim/simulation_state.py +6 -5
- cirq/sim/simulation_state_base.py +3 -2
- cirq/sim/simulation_state_test.py +7 -6
- cirq/sim/simulation_utils.py +2 -1
- cirq/sim/simulator.py +4 -3
- cirq/sim/simulator_base.py +2 -1
- cirq/sim/simulator_base_test.py +51 -36
- cirq/sim/simulator_test.py +41 -36
- cirq/sim/sparse_simulator.py +3 -2
- cirq/sim/sparse_simulator_test.py +92 -82
- cirq/sim/state_vector.py +5 -6
- cirq/sim/state_vector_simulation_state.py +10 -9
- cirq/sim/state_vector_simulator.py +2 -1
- cirq/sim/state_vector_simulator_test.py +9 -9
- cirq/sim/state_vector_test.py +40 -39
- cirq/study/__init__.py +1 -0
- cirq/study/flatten_expressions.py +2 -1
- cirq/study/resolver.py +31 -18
- cirq/study/resolver_test.py +1 -1
- cirq/study/result.py +2 -1
- cirq/study/result_test.py +20 -20
- cirq/study/sweepable.py +2 -1
- cirq/study/sweepable_test.py +20 -20
- cirq/study/sweeps.py +26 -1
- cirq/study/sweeps_test.py +67 -43
- cirq/testing/_compat_test_data/__init__.py +3 -3
- cirq/testing/circuit_compare.py +2 -1
- cirq/testing/circuit_compare_test.py +16 -14
- cirq/testing/consistent_act_on_test.py +1 -1
- cirq/testing/consistent_channels.py +2 -2
- cirq/testing/consistent_controlled_gate_op.py +2 -2
- cirq/testing/consistent_controlled_gate_op_test.py +2 -1
- cirq/testing/consistent_decomposition.py +4 -2
- cirq/testing/consistent_phase_by.py +1 -1
- cirq/testing/consistent_protocols.py +2 -1
- cirq/testing/consistent_protocols_test.py +3 -3
- cirq/testing/consistent_qasm.py +4 -3
- cirq/testing/consistent_qasm_test.py +3 -3
- cirq/testing/consistent_resolve_parameters.py +1 -1
- cirq/testing/consistent_unitary.py +1 -1
- cirq/testing/consistent_unitary_test.py +1 -1
- cirq/testing/deprecation.py +1 -1
- cirq/testing/devices.py +3 -2
- cirq/testing/equals_tester.py +4 -3
- cirq/testing/equivalent_basis_map.py +4 -2
- cirq/testing/json.py +3 -2
- cirq/testing/lin_alg_utils.py +1 -1
- cirq/testing/logs.py +1 -1
- cirq/testing/op_tree.py +1 -1
- cirq/testing/order_tester.py +2 -2
- cirq/testing/pytest_utils.py +2 -1
- cirq/testing/random_circuit.py +2 -1
- cirq/testing/random_circuit_test.py +2 -1
- cirq/testing/repr_pretty_tester.py +3 -3
- cirq/transformers/__init__.py +1 -0
- cirq/transformers/_connected_component.py +231 -0
- cirq/transformers/_connected_component_test.py +200 -0
- cirq/transformers/align_test.py +13 -13
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +8 -7
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +5 -5
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +11 -10
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +6 -6
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +3 -2
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +11 -10
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +8 -7
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +17 -20
- cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +33 -27
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +1 -1
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +1 -1
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +12 -11
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +5 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +3 -3
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +2 -2
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +2 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +32 -30
- cirq/transformers/drop_negligible_operations_test.py +7 -7
- cirq/transformers/dynamical_decoupling.py +185 -112
- cirq/transformers/dynamical_decoupling_test.py +195 -201
- cirq/transformers/eject_phased_paulis.py +2 -1
- cirq/transformers/eject_phased_paulis_test.py +3 -2
- cirq/transformers/eject_z.py +5 -3
- cirq/transformers/eject_z_test.py +23 -25
- cirq/transformers/expand_composite.py +3 -2
- cirq/transformers/expand_composite_test.py +14 -14
- cirq/transformers/gauge_compiling/__init__.py +13 -0
- cirq/transformers/gauge_compiling/gauge_compiling.py +3 -2
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +14 -12
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +3 -3
- cirq/transformers/gauge_compiling/idle_moments_gauge.py +225 -0
- cirq/transformers/gauge_compiling/idle_moments_gauge_test.py +193 -0
- cirq/transformers/gauge_compiling/multi_moment_cphase_gauge.py +242 -0
- cirq/transformers/gauge_compiling/multi_moment_cphase_gauge_test.py +243 -0
- cirq/transformers/gauge_compiling/multi_moment_gauge_compiling.py +151 -0
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +2 -1
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +1 -1
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +6 -6
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +3 -2
- cirq/transformers/measurement_transformers.py +2 -1
- cirq/transformers/measurement_transformers_test.py +45 -39
- cirq/transformers/merge_k_qubit_gates.py +2 -1
- cirq/transformers/merge_k_qubit_gates_test.py +1 -1
- cirq/transformers/merge_single_qubit_gates.py +9 -5
- cirq/transformers/merge_single_qubit_gates_test.py +22 -22
- cirq/transformers/noise_adding_test.py +2 -2
- cirq/transformers/optimize_for_target_gateset.py +2 -1
- cirq/transformers/optimize_for_target_gateset_test.py +11 -9
- cirq/transformers/qubit_management_transformers_test.py +6 -2
- cirq/transformers/routing/mapping_manager.py +2 -1
- cirq/transformers/routing/route_circuit_cqc.py +2 -1
- cirq/transformers/stratify.py +2 -1
- cirq/transformers/symbolize.py +2 -1
- cirq/transformers/tag_transformers.py +2 -1
- cirq/transformers/target_gatesets/compilation_target_gateset.py +2 -1
- cirq/transformers/target_gatesets/cz_gateset.py +2 -1
- cirq/transformers/target_gatesets/cz_gateset_test.py +1 -1
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +2 -1
- cirq/transformers/transformer_api.py +2 -1
- cirq/transformers/transformer_primitives.py +271 -145
- cirq/transformers/transformer_primitives_test.py +185 -1
- cirq/value/abc_alt.py +2 -1
- cirq/value/classical_data.py +2 -1
- cirq/value/condition.py +2 -1
- cirq/value/digits.py +9 -2
- cirq/value/duration.py +6 -5
- cirq/value/linear_dict.py +4 -9
- cirq/value/measurement_key.py +2 -1
- cirq/value/periodic_value.py +3 -2
- cirq/value/product_state.py +2 -1
- cirq/value/value_equality_attr.py +2 -1
- cirq/vis/density_matrix.py +1 -1
- cirq/vis/heatmap.py +2 -1
- cirq/vis/histogram.py +2 -1
- cirq/vis/state_histogram.py +2 -1
- cirq/work/collector.py +2 -1
- cirq/work/observable_grouping.py +2 -1
- cirq/work/observable_measurement.py +2 -1
- cirq/work/observable_measurement_data.py +2 -1
- cirq/work/observable_measurement_test.py +1 -1
- cirq/work/observable_readout_calibration.py +2 -1
- cirq/work/observable_readout_calibration_test.py +1 -1
- cirq/work/observable_settings.py +2 -1
- cirq/work/sampler.py +2 -1
- cirq/work/sampler_test.py +1 -1
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/METADATA +5 -6
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/RECORD +425 -406
- cirq/contrib/json_test.py +0 -33
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/WHEEL +0 -0
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.7.0.dev20250825174419.dist-info → cirq_core-1.7.0.dev20251203004401.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Copyright 2025 The Cirq Developers
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Functions for generating and transforming 2D GHZ circuits."""
|
|
16
|
+
|
|
17
|
+
import networkx as nx
|
|
18
|
+
import numpy as np
|
|
19
|
+
|
|
20
|
+
import cirq.circuits as circuits
|
|
21
|
+
import cirq.devices as devices
|
|
22
|
+
import cirq.ops as ops
|
|
23
|
+
import cirq.protocols as protocols
|
|
24
|
+
import cirq.transformers as transformers
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _transform_circuit(circuit: circuits.Circuit) -> circuits.Circuit:
|
|
28
|
+
"""Transforms a Cirq circuit by applying a series of modifications.
|
|
29
|
+
|
|
30
|
+
This is an internal helper function used exclusively by
|
|
31
|
+
`generate_2d_ghz_circuit` when `add_dd_and_align_right` is True.
|
|
32
|
+
|
|
33
|
+
The transformations for a circuit include:
|
|
34
|
+
1. Adding a measurement to all qubits with a key 'm'.
|
|
35
|
+
It serves as a stopping gate for the DD operation.
|
|
36
|
+
2. Aligning the circuit and merging single-qubit gates.
|
|
37
|
+
3. Stratifying the operations based on qubit count
|
|
38
|
+
(1-qubit and 2-qubit gates).
|
|
39
|
+
4. Applying dynamical decoupling to mitigate noise.
|
|
40
|
+
5. Removing the final measurement operation to yield
|
|
41
|
+
the state preparation circuit.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
circuit: A cirq.Circuit object.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
The modified cirq.Circuit object.
|
|
48
|
+
"""
|
|
49
|
+
qubits = list(circuit.all_qubits())
|
|
50
|
+
circuit = circuit + circuits.Circuit(ops.measure(*qubits, key="m"))
|
|
51
|
+
circuit = transformers.align_right(transformers.merge_single_qubit_gates_to_phxz(circuit))
|
|
52
|
+
circuit = transformers.stratified_circuit(
|
|
53
|
+
circuit[::-1], categories=[lambda op: protocols.num_qubits(op) == k for k in (1, 2)]
|
|
54
|
+
)[::-1]
|
|
55
|
+
circuit = transformers.add_dynamical_decoupling(circuit)
|
|
56
|
+
circuit = circuits.Circuit(circuit[:-1])
|
|
57
|
+
return circuit
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def generate_2d_ghz_circuit(
|
|
61
|
+
center: devices.GridQubit,
|
|
62
|
+
graph: nx.Graph,
|
|
63
|
+
num_qubits: int,
|
|
64
|
+
randomized: bool = False,
|
|
65
|
+
rng_or_seed: int | np.random.Generator | None = None,
|
|
66
|
+
add_dd_and_align_right: bool = False,
|
|
67
|
+
) -> circuits.Circuit:
|
|
68
|
+
"""Generates a 2D GHZ state circuit with 'num_qubits' qubits using BFS.
|
|
69
|
+
|
|
70
|
+
The circuit is constructed by connecting qubits
|
|
71
|
+
sequentially based on graph connectivity,
|
|
72
|
+
starting from the 'center' qubit.
|
|
73
|
+
The GHZ state is built using a series of H-CZ-H
|
|
74
|
+
gate sequences.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
center: The starting qubit for the GHZ state.
|
|
79
|
+
graph: The connectivity graph of the qubits.
|
|
80
|
+
num_qubits: The number of qubits for the final
|
|
81
|
+
GHZ state. Must be greater than 0,
|
|
82
|
+
and less than or equal to
|
|
83
|
+
the total number of qubits
|
|
84
|
+
on the processor.
|
|
85
|
+
randomized: If True, neighbors are
|
|
86
|
+
added to the circuit in a random order.
|
|
87
|
+
If False, they are
|
|
88
|
+
added by distance from the center.
|
|
89
|
+
rng_or_seed: An optional seed or numpy random number
|
|
90
|
+
generator. Used only when randomized is True
|
|
91
|
+
add_dd_and_align_right: If True, adds dynamical
|
|
92
|
+
decoupling and aligns right.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
A cirq.Circuit object for the GHZ state.
|
|
96
|
+
|
|
97
|
+
Raises:
|
|
98
|
+
ValueError: If num_qubits is non-positive or exceeds the total
|
|
99
|
+
number of qubits on the processor.
|
|
100
|
+
"""
|
|
101
|
+
if num_qubits <= 0:
|
|
102
|
+
raise ValueError("num_qubits must be a positive integer.")
|
|
103
|
+
|
|
104
|
+
if num_qubits > len(graph.nodes):
|
|
105
|
+
raise ValueError("num_qubits cannot exceed the total number of qubits on the processor.")
|
|
106
|
+
|
|
107
|
+
if randomized:
|
|
108
|
+
rng = (
|
|
109
|
+
rng_or_seed
|
|
110
|
+
if isinstance(rng_or_seed, np.random.Generator)
|
|
111
|
+
else np.random.default_rng(rng_or_seed)
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
def sort_neighbors_fn(neighbors: list) -> list:
|
|
115
|
+
"""If 'randomized' is True, sort the neighbors randomly."""
|
|
116
|
+
neighbors = list(neighbors)
|
|
117
|
+
rng.shuffle(neighbors)
|
|
118
|
+
return neighbors
|
|
119
|
+
|
|
120
|
+
else:
|
|
121
|
+
|
|
122
|
+
def sort_neighbors_fn(neighbors: list) -> list:
|
|
123
|
+
"""If 'randomized' is False, sort the neighbors as per
|
|
124
|
+
distance from the center.
|
|
125
|
+
"""
|
|
126
|
+
return sorted(
|
|
127
|
+
neighbors, key=lambda q: (q.row - center.row) ** 2 + (q.col - center.col) ** 2
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
bfs_tree = nx.bfs_tree(graph, center, sort_neighbors=sort_neighbors_fn)
|
|
131
|
+
qubits_to_include = list(bfs_tree.nodes)[:num_qubits]
|
|
132
|
+
final_tree = bfs_tree.subgraph(qubits_to_include)
|
|
133
|
+
|
|
134
|
+
ghz_ops = []
|
|
135
|
+
|
|
136
|
+
for node in nx.topological_sort(final_tree):
|
|
137
|
+
# Handling the center qubit first
|
|
138
|
+
if node == center:
|
|
139
|
+
ghz_ops.append(ops.H(node))
|
|
140
|
+
continue
|
|
141
|
+
|
|
142
|
+
for parent in final_tree.predecessors(node):
|
|
143
|
+
ghz_ops.extend([ops.H(node), ops.CZ(parent, node), ops.H(node)])
|
|
144
|
+
|
|
145
|
+
circuit = circuits.Circuit(ghz_ops)
|
|
146
|
+
|
|
147
|
+
if add_dd_and_align_right:
|
|
148
|
+
return _transform_circuit(circuit)
|
|
149
|
+
else:
|
|
150
|
+
return circuit
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# Copyright 2025 The Cirq Developers
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Tests for generating and validating 2D GHZ state circuits."""
|
|
16
|
+
|
|
17
|
+
from typing import cast
|
|
18
|
+
|
|
19
|
+
import networkx as nx
|
|
20
|
+
import numpy as np
|
|
21
|
+
import pytest
|
|
22
|
+
|
|
23
|
+
import cirq
|
|
24
|
+
import cirq.experiments.ghz_2d as ghz_2d
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _create_mock_graph():
|
|
28
|
+
qubits = cirq.GridQubit.rect(6, 6)
|
|
29
|
+
g = nx.Graph()
|
|
30
|
+
for q in qubits:
|
|
31
|
+
g.add_node(q)
|
|
32
|
+
if q.col + 1 < 6:
|
|
33
|
+
g.add_edge(q, cirq.GridQubit(q.row, q.col + 1))
|
|
34
|
+
if q.row + 1 < 6:
|
|
35
|
+
g.add_edge(q, cirq.GridQubit(q.row + 1, q.col))
|
|
36
|
+
return g, cirq.GridQubit(3, 3)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
graph, center_qubit = _create_mock_graph()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@pytest.mark.parametrize("num_qubits", list(range(1, len(graph.nodes) + 1)))
|
|
43
|
+
@pytest.mark.parametrize("randomized", [True, False])
|
|
44
|
+
@pytest.mark.parametrize("add_dd_and_align_right", [True, False])
|
|
45
|
+
def test_ghz_circuits_size(num_qubits: int, randomized: bool, add_dd_and_align_right: bool) -> None:
|
|
46
|
+
"""Tests the size of the GHZ circuits."""
|
|
47
|
+
circuit = ghz_2d.generate_2d_ghz_circuit(
|
|
48
|
+
center_qubit,
|
|
49
|
+
graph,
|
|
50
|
+
num_qubits=num_qubits,
|
|
51
|
+
randomized=randomized,
|
|
52
|
+
add_dd_and_align_right=add_dd_and_align_right,
|
|
53
|
+
)
|
|
54
|
+
assert len(circuit.all_qubits()) == num_qubits
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@pytest.mark.parametrize("num_qubits", [2, 3, 4, 5, 6, 8, 10])
|
|
58
|
+
@pytest.mark.parametrize("randomized", [True, False])
|
|
59
|
+
@pytest.mark.parametrize("add_dd_and_align_right", [True, False]) # , True
|
|
60
|
+
def test_ghz_circuits_state(
|
|
61
|
+
num_qubits: int, randomized: bool, add_dd_and_align_right: bool
|
|
62
|
+
) -> None:
|
|
63
|
+
"""Tests the state vector form of the GHZ circuits."""
|
|
64
|
+
|
|
65
|
+
circuit = ghz_2d.generate_2d_ghz_circuit(
|
|
66
|
+
center_qubit,
|
|
67
|
+
graph,
|
|
68
|
+
num_qubits=num_qubits,
|
|
69
|
+
randomized=randomized,
|
|
70
|
+
add_dd_and_align_right=add_dd_and_align_right,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
simulator = cirq.Simulator()
|
|
74
|
+
result = simulator.simulate(circuit)
|
|
75
|
+
state = result.final_state_vector
|
|
76
|
+
|
|
77
|
+
np.testing.assert_allclose(np.abs(state[0]), 1 / np.sqrt(2), atol=1e-7)
|
|
78
|
+
np.testing.assert_allclose(np.abs(state[-1]), 1 / np.sqrt(2), atol=1e-7)
|
|
79
|
+
|
|
80
|
+
if num_qubits > 1:
|
|
81
|
+
np.testing.assert_allclose(state[1:-1], 0)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_transform_circuit_properties() -> None:
|
|
85
|
+
"""Tests that _transform_circuit preserves circuit properties."""
|
|
86
|
+
circuit = ghz_2d.generate_2d_ghz_circuit(
|
|
87
|
+
center_qubit, graph, num_qubits=9, randomized=False, add_dd_and_align_right=False
|
|
88
|
+
)
|
|
89
|
+
transformed_circuit = ghz_2d._transform_circuit(circuit)
|
|
90
|
+
|
|
91
|
+
assert transformed_circuit.all_qubits() == circuit.all_qubits()
|
|
92
|
+
|
|
93
|
+
assert len(transformed_circuit) >= len(circuit)
|
|
94
|
+
|
|
95
|
+
final_moment = transformed_circuit[-1]
|
|
96
|
+
assert not any(isinstance(op.gate, cirq.MeasurementGate) for op in final_moment)
|
|
97
|
+
|
|
98
|
+
assert cirq.equal_up_to_global_phase(circuit.unitary(), transformed_circuit.unitary())
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def manhattan_distance(q1: cirq.GridQubit, q2: cirq.GridQubit) -> int:
|
|
102
|
+
"""Calculates the Manhattan distance between two GridQubits."""
|
|
103
|
+
return abs(q1.row - q2.row) + abs(q1.col - q2.col)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@pytest.mark.parametrize("num_qubits", [2, 4, 9, 15, 20])
|
|
107
|
+
def test_ghz_circuits_bfs_order(num_qubits: int) -> None:
|
|
108
|
+
"""Verifies that the circuit construction maintains BFS order"""
|
|
109
|
+
|
|
110
|
+
circuit = ghz_2d.generate_2d_ghz_circuit(
|
|
111
|
+
center_qubit,
|
|
112
|
+
graph,
|
|
113
|
+
num_qubits=num_qubits,
|
|
114
|
+
randomized=False, # Test must run on the deterministic BFS order
|
|
115
|
+
add_dd_and_align_right=False, # Test must run on the raw circuit
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
max_dist_seen = 0
|
|
119
|
+
|
|
120
|
+
for moment in circuit:
|
|
121
|
+
for op in moment:
|
|
122
|
+
if isinstance(op.gate, cirq.CZPowGate):
|
|
123
|
+
qubits = op.qubits
|
|
124
|
+
|
|
125
|
+
dist_q0 = manhattan_distance(center_qubit, cast(cirq.GridQubit, qubits[0]))
|
|
126
|
+
dist_q1 = manhattan_distance(center_qubit, cast(cirq.GridQubit, qubits[1]))
|
|
127
|
+
|
|
128
|
+
child_qubit_distance = max(dist_q0, dist_q1)
|
|
129
|
+
|
|
130
|
+
if child_qubit_distance > max_dist_seen:
|
|
131
|
+
assert child_qubit_distance == max_dist_seen + 1
|
|
132
|
+
max_dist_seen = child_qubit_distance
|
|
133
|
+
|
|
134
|
+
assert child_qubit_distance <= max_dist_seen
|
|
135
|
+
|
|
136
|
+
included_qubits = circuit.all_qubits()
|
|
137
|
+
if included_qubits:
|
|
138
|
+
max_dist_required = max(
|
|
139
|
+
manhattan_distance(center_qubit, cast(cirq.GridQubit, q)) for q in included_qubits
|
|
140
|
+
)
|
|
141
|
+
assert max_dist_seen == max_dist_required
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def test_ghz_invalid_inputs():
|
|
145
|
+
"""Tests that the function raises errors for invalid inputs."""
|
|
146
|
+
|
|
147
|
+
with pytest.raises(ValueError, match="num_qubits must be a positive integer."):
|
|
148
|
+
ghz_2d.generate_2d_ghz_circuit(center_qubit, graph, num_qubits=0) # invalid
|
|
149
|
+
|
|
150
|
+
with pytest.raises(
|
|
151
|
+
ValueError, match="num_qubits cannot exceed the total number of qubits on the processor."
|
|
152
|
+
):
|
|
153
|
+
ghz_2d.generate_2d_ghz_circuit(
|
|
154
|
+
center_qubit, graph, num_qubits=len(graph.nodes) + 1 # invalid
|
|
155
|
+
)
|
|
@@ -20,7 +20,8 @@ so that occurs outside of the StateTomographyExperiment class.
|
|
|
20
20
|
|
|
21
21
|
from __future__ import annotations
|
|
22
22
|
|
|
23
|
-
from
|
|
23
|
+
from collections.abc import Sequence
|
|
24
|
+
from typing import TYPE_CHECKING
|
|
24
25
|
|
|
25
26
|
import numpy as np
|
|
26
27
|
import sympy
|
|
@@ -18,7 +18,8 @@ import dataclasses
|
|
|
18
18
|
import functools
|
|
19
19
|
import itertools
|
|
20
20
|
import uuid
|
|
21
|
-
from
|
|
21
|
+
from collections.abc import Iterator, Mapping, Sequence
|
|
22
|
+
from typing import Any, cast, Optional, TYPE_CHECKING
|
|
22
23
|
|
|
23
24
|
import attrs
|
|
24
25
|
import numpy as np
|
|
@@ -73,7 +74,12 @@ class Cliffords:
|
|
|
73
74
|
class RandomizedBenchMarkResult:
|
|
74
75
|
"""Results from a randomized benchmarking experiment."""
|
|
75
76
|
|
|
76
|
-
def __init__(
|
|
77
|
+
def __init__(
|
|
78
|
+
self,
|
|
79
|
+
num_cliffords: Sequence[int],
|
|
80
|
+
ground_state_probabilities: Sequence[float],
|
|
81
|
+
ground_state_probabilities_std: Optional[Sequence[float]] | None = None,
|
|
82
|
+
):
|
|
77
83
|
"""Inits RandomizedBenchMarkResult.
|
|
78
84
|
|
|
79
85
|
Args:
|
|
@@ -81,9 +87,20 @@ class RandomizedBenchMarkResult:
|
|
|
81
87
|
study.
|
|
82
88
|
ground_state_probabilities: The corresponding average ground state
|
|
83
89
|
probabilities.
|
|
90
|
+
ground_state_probabilities_std: The standard deviation of the probabilities.
|
|
84
91
|
"""
|
|
85
92
|
self._num_cfds_seq = num_cliffords
|
|
86
93
|
self._gnd_state_probs = ground_state_probabilities
|
|
94
|
+
if ground_state_probabilities_std is None or np.all(
|
|
95
|
+
np.isclose(ground_state_probabilities_std, 0)
|
|
96
|
+
):
|
|
97
|
+
self._gnd_state_probs_std = None
|
|
98
|
+
else:
|
|
99
|
+
self._gnd_state_probs_std = np.array(ground_state_probabilities_std)
|
|
100
|
+
zeros = np.isclose(self._gnd_state_probs_std, 0)
|
|
101
|
+
self._gnd_state_probs_std[zeros] = self._gnd_state_probs_std[
|
|
102
|
+
np.logical_not(zeros)
|
|
103
|
+
].min()
|
|
87
104
|
|
|
88
105
|
@property
|
|
89
106
|
def data(self) -> Sequence[tuple[int, float]]:
|
|
@@ -142,6 +159,7 @@ class RandomizedBenchMarkResult:
|
|
|
142
159
|
f=exp_fit,
|
|
143
160
|
xdata=self._num_cfds_seq,
|
|
144
161
|
ydata=self._gnd_state_probs,
|
|
162
|
+
sigma=self._gnd_state_probs_std,
|
|
145
163
|
p0=[0.5, 0.5, 1.0 - 1e-3],
|
|
146
164
|
bounds=([0, -1, 0], [1, 1, 1]),
|
|
147
165
|
)
|
|
@@ -534,6 +552,7 @@ def parallel_single_qubit_rb(
|
|
|
534
552
|
# run circuits
|
|
535
553
|
results = sampler.run_batch(circuits_all, repetitions=parameters.repetitions)
|
|
536
554
|
gnd_probs: dict = {q: [] for q in qubits}
|
|
555
|
+
gnd_probs_std: dict = {q: [] for q in qubits}
|
|
537
556
|
idx = 0
|
|
538
557
|
for num_cliffords in parameters.num_clifford_range:
|
|
539
558
|
excited_probs: dict[cirq.Qid, list[float]] = {q: [] for q in qubits}
|
|
@@ -544,9 +563,17 @@ def parallel_single_qubit_rb(
|
|
|
544
563
|
idx += 1
|
|
545
564
|
for qubit in qubits:
|
|
546
565
|
gnd_probs[qubit].append(1.0 - np.mean(excited_probs[qubit]))
|
|
566
|
+
gnd_probs_std[qubit].append(
|
|
567
|
+
np.std(excited_probs[qubit]) / np.sqrt(parameters.repetitions)
|
|
568
|
+
)
|
|
547
569
|
|
|
548
570
|
return ParallelRandomizedBenchmarkingResult(
|
|
549
|
-
{
|
|
571
|
+
{
|
|
572
|
+
q: RandomizedBenchMarkResult(
|
|
573
|
+
parameters.num_clifford_range, gnd_probs[q], gnd_probs_std[q]
|
|
574
|
+
)
|
|
575
|
+
for q in qubits
|
|
576
|
+
}
|
|
550
577
|
)
|
|
551
578
|
|
|
552
579
|
|
|
@@ -595,6 +622,7 @@ def two_qubit_randomized_benchmarking(
|
|
|
595
622
|
cliffords = _single_qubit_cliffords()
|
|
596
623
|
cfd_matrices = _two_qubit_clifford_matrices(first_qubit, second_qubit, cliffords)
|
|
597
624
|
gnd_probs = []
|
|
625
|
+
gnd_probs_std = []
|
|
598
626
|
for num_cfds in num_clifford_range:
|
|
599
627
|
gnd_probs_l = []
|
|
600
628
|
for _ in range(num_circuits):
|
|
@@ -606,8 +634,9 @@ def two_qubit_randomized_benchmarking(
|
|
|
606
634
|
gnds = [(not r[0] and not r[1]) for r in results.measurements['z']]
|
|
607
635
|
gnd_probs_l.append(np.mean(gnds))
|
|
608
636
|
gnd_probs.append(float(np.mean(gnd_probs_l)))
|
|
637
|
+
gnd_probs_std.append(float(np.std(gnd_probs_l) / np.sqrt(repetitions)))
|
|
609
638
|
|
|
610
|
-
return RandomizedBenchMarkResult(num_clifford_range, gnd_probs)
|
|
639
|
+
return RandomizedBenchMarkResult(num_clifford_range, gnd_probs, gnd_probs_std)
|
|
611
640
|
|
|
612
641
|
|
|
613
642
|
def single_qubit_state_tomography(
|
|
@@ -140,6 +140,22 @@ def test_parallel_single_qubit_parallel_single_qubit_randomized_benchmarking() -
|
|
|
140
140
|
_ = results.plot_integrated_histogram()
|
|
141
141
|
|
|
142
142
|
|
|
143
|
+
@mock.patch.dict(os.environ, clear='CIRQ_TESTING')
|
|
144
|
+
def test_parallel_single_qubit_randomized_benchmarking_with_noise() -> None:
|
|
145
|
+
simulator = sim.Simulator(noise=cirq.depolarize(1e-3), seed=0)
|
|
146
|
+
qubits = (GridQubit(0, 0), GridQubit(0, 1))
|
|
147
|
+
num_cfds = range(5, 7, 1)
|
|
148
|
+
results = parallel_single_qubit_randomized_benchmarking(
|
|
149
|
+
simulator, num_clifford_range=num_cfds, repetitions=10, qubits=qubits
|
|
150
|
+
)
|
|
151
|
+
for qubit in qubits:
|
|
152
|
+
g_pops = np.asarray(results.results_dictionary[qubit].data)[:, 1]
|
|
153
|
+
assert np.isclose(np.mean(g_pops), 0.99, atol=1e-2)
|
|
154
|
+
_ = results.plot_single_qubit(qubit)
|
|
155
|
+
pauli_errors = results.pauli_error()
|
|
156
|
+
assert len(pauli_errors) == len(qubits)
|
|
157
|
+
|
|
158
|
+
|
|
143
159
|
def test_two_qubit_randomized_benchmarking() -> None:
|
|
144
160
|
# Check that the ground state population at the end of the Clifford
|
|
145
161
|
# sequences is always unity.
|
|
@@ -17,7 +17,8 @@ from __future__ import annotations
|
|
|
17
17
|
|
|
18
18
|
import dataclasses
|
|
19
19
|
import itertools
|
|
20
|
-
from
|
|
20
|
+
from collections.abc import Callable, Container, Iterable, Iterator, Sequence
|
|
21
|
+
from typing import Any, TYPE_CHECKING
|
|
21
22
|
|
|
22
23
|
import numpy as np
|
|
23
24
|
|
|
@@ -18,7 +18,8 @@ from __future__ import annotations
|
|
|
18
18
|
|
|
19
19
|
import dataclasses
|
|
20
20
|
import time
|
|
21
|
-
from
|
|
21
|
+
from collections.abc import Iterable
|
|
22
|
+
from typing import Any, cast, TYPE_CHECKING
|
|
22
23
|
|
|
23
24
|
import matplotlib.pyplot as plt
|
|
24
25
|
import numpy as np
|
|
@@ -18,9 +18,10 @@ from __future__ import annotations
|
|
|
18
18
|
|
|
19
19
|
import functools
|
|
20
20
|
import itertools
|
|
21
|
+
from collections.abc import Mapping, Sequence
|
|
21
22
|
from dataclasses import dataclass
|
|
22
23
|
from types import MappingProxyType
|
|
23
|
-
from typing import Any, cast,
|
|
24
|
+
from typing import Any, cast, TYPE_CHECKING
|
|
24
25
|
|
|
25
26
|
import networkx as nx
|
|
26
27
|
import numpy as np
|
cirq/experiments/xeb_fitting.py
CHANGED
|
@@ -18,7 +18,8 @@ from __future__ import annotations
|
|
|
18
18
|
|
|
19
19
|
import dataclasses
|
|
20
20
|
from abc import ABC, abstractmethod
|
|
21
|
-
from
|
|
21
|
+
from collections.abc import Iterable, Sequence
|
|
22
|
+
from typing import TYPE_CHECKING
|
|
22
23
|
|
|
23
24
|
import numpy as np
|
|
24
25
|
import pandas as pd
|
cirq/experiments/xeb_sampling.py
CHANGED
|
@@ -19,8 +19,10 @@ from __future__ import annotations
|
|
|
19
19
|
import os
|
|
20
20
|
import time
|
|
21
21
|
import uuid
|
|
22
|
+
from collections.abc import Callable, Sequence
|
|
23
|
+
from contextlib import AbstractContextManager
|
|
22
24
|
from dataclasses import dataclass
|
|
23
|
-
from typing import Any,
|
|
25
|
+
from typing import Any, TYPE_CHECKING
|
|
24
26
|
|
|
25
27
|
import numpy as np
|
|
26
28
|
import pandas as pd
|
|
@@ -257,7 +259,7 @@ def _execute_sample_2q_xeb_tasks_in_batches(
|
|
|
257
259
|
combinations_by_layer: list[CircuitLibraryCombination],
|
|
258
260
|
repetitions: int,
|
|
259
261
|
batch_size: int,
|
|
260
|
-
progress_bar: Callable[...,
|
|
262
|
+
progress_bar: Callable[..., AbstractContextManager],
|
|
261
263
|
dataset_directory: str | None = None,
|
|
262
264
|
) -> list[dict[str, Any]]:
|
|
263
265
|
"""Helper function used in `sample_2q_xeb_circuits` to batch and execute sampling tasks."""
|
|
@@ -287,7 +289,7 @@ def sample_2q_xeb_circuits(
|
|
|
287
289
|
*,
|
|
288
290
|
repetitions: int = 10_000,
|
|
289
291
|
batch_size: int = 9,
|
|
290
|
-
progress_bar: Callable[...,
|
|
292
|
+
progress_bar: Callable[..., AbstractContextManager] | None = tqdm.tqdm,
|
|
291
293
|
combinations_by_layer: list[CircuitLibraryCombination] | None = None,
|
|
292
294
|
shuffle: cirq.RANDOM_STATE_OR_SEED_LIKE | None = None,
|
|
293
295
|
dataset_directory: str | None = None,
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
+
from collections.abc import Sequence
|
|
19
20
|
from dataclasses import dataclass
|
|
20
|
-
from typing import Any,
|
|
21
|
+
from typing import Any, TYPE_CHECKING
|
|
21
22
|
|
|
22
23
|
import numpy as np
|
|
23
24
|
import pandas as pd
|
|
@@ -18,7 +18,8 @@ from __future__ import annotations
|
|
|
18
18
|
|
|
19
19
|
import multiprocessing
|
|
20
20
|
import multiprocessing.pool
|
|
21
|
-
from
|
|
21
|
+
from collections.abc import Sequence
|
|
22
|
+
from typing import Any, TYPE_CHECKING
|
|
22
23
|
|
|
23
24
|
import matplotlib.pyplot as plt
|
|
24
25
|
import numpy as np
|