cirq-core 1.5.0.dev20250409222543__py3-none-any.whl → 1.6.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 +16 -17
- cirq/_compat.py +21 -20
- cirq/_compat_test.py +14 -34
- cirq/_doc.py +4 -2
- cirq/_import.py +8 -6
- cirq/_import_test.py +4 -2
- cirq/_version.py +6 -6
- cirq/_version_test.py +2 -2
- cirq/circuits/_block_diagram_drawer.py +11 -10
- cirq/circuits/_block_diagram_drawer_test.py +8 -6
- cirq/circuits/_box_drawing_character_data.py +8 -8
- cirq/circuits/_box_drawing_character_data_test.py +3 -1
- cirq/circuits/_bucket_priority_queue.py +9 -7
- cirq/circuits/_bucket_priority_queue_test.py +22 -20
- cirq/circuits/circuit.py +248 -172
- cirq/circuits/circuit_operation.py +73 -83
- cirq/circuits/circuit_operation_test.py +128 -90
- cirq/circuits/circuit_test.py +211 -151
- cirq/circuits/frozen_circuit.py +23 -60
- cirq/circuits/frozen_circuit_test.py +31 -8
- cirq/circuits/insert_strategy.py +7 -5
- cirq/circuits/insert_strategy_test.py +4 -2
- cirq/circuits/moment.py +88 -40
- cirq/circuits/moment_test.py +128 -51
- cirq/circuits/optimization_pass.py +5 -5
- cirq/circuits/optimization_pass_test.py +10 -10
- cirq/circuits/qasm_output.py +11 -11
- cirq/circuits/qasm_output_test.py +25 -22
- cirq/circuits/text_diagram_drawer.py +23 -38
- cirq/circuits/text_diagram_drawer_test.py +19 -17
- cirq/conftest.py +4 -3
- cirq/contrib/__init__.py +4 -4
- cirq/contrib/acquaintance/__init__.py +1 -1
- cirq/contrib/acquaintance/bipartite.py +5 -8
- cirq/contrib/acquaintance/bipartite_test.py +18 -13
- cirq/contrib/acquaintance/devices.py +2 -2
- cirq/contrib/acquaintance/devices_test.py +5 -3
- cirq/contrib/acquaintance/executor.py +5 -5
- cirq/contrib/acquaintance/executor_test.py +13 -9
- cirq/contrib/acquaintance/gates.py +18 -28
- cirq/contrib/acquaintance/gates_test.py +24 -20
- cirq/contrib/acquaintance/inspection_utils.py +8 -4
- cirq/contrib/acquaintance/inspection_utils_test.py +4 -2
- cirq/contrib/acquaintance/mutation_utils.py +4 -4
- cirq/contrib/acquaintance/mutation_utils_test.py +4 -2
- cirq/contrib/acquaintance/optimizers.py +4 -4
- cirq/contrib/acquaintance/optimizers_test.py +4 -1
- cirq/contrib/acquaintance/permutation.py +15 -27
- cirq/contrib/acquaintance/permutation_test.py +26 -17
- cirq/contrib/acquaintance/shift.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network.py +4 -4
- cirq/contrib/acquaintance/shift_swap_network_test.py +9 -6
- cirq/contrib/acquaintance/shift_test.py +8 -6
- cirq/contrib/acquaintance/strategies/cubic.py +2 -2
- cirq/contrib/acquaintance/strategies/cubic_test.py +4 -2
- cirq/contrib/acquaintance/strategies/quartic_paired.py +6 -6
- cirq/contrib/acquaintance/strategies/quartic_paired_test.py +10 -6
- cirq/contrib/acquaintance/testing.py +2 -0
- cirq/contrib/acquaintance/topological_sort.py +2 -2
- cirq/contrib/acquaintance/topological_sort_test.py +3 -1
- cirq/contrib/bayesian_network/bayesian_network_gate.py +9 -10
- cirq/contrib/bayesian_network/bayesian_network_gate_test.py +14 -9
- cirq/contrib/circuitdag/circuit_dag.py +4 -4
- cirq/contrib/circuitdag/circuit_dag_test.py +17 -15
- cirq/contrib/custom_simulators/custom_state_simulator.py +5 -5
- cirq/contrib/custom_simulators/custom_state_simulator_test.py +22 -17
- cirq/contrib/graph_device/graph_device.py +12 -11
- cirq/contrib/graph_device/graph_device_test.py +18 -14
- cirq/contrib/graph_device/hypergraph.py +16 -14
- cirq/contrib/graph_device/hypergraph_test.py +13 -11
- cirq/contrib/graph_device/uniform_graph_device.py +6 -4
- cirq/contrib/graph_device/uniform_graph_device_test.py +11 -3
- cirq/contrib/hacks/disable_validation.py +6 -1
- cirq/contrib/hacks/disable_validation_test.py +3 -1
- cirq/contrib/json.py +31 -5
- cirq/contrib/json_test.py +6 -3
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DampedReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.json +12 -0
- cirq/contrib/json_test_data/DepolarizingNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.json +6 -0
- cirq/contrib/json_test_data/DepolarizingWithDampedReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.json +5 -0
- cirq/contrib/json_test_data/DepolarizingWithReadoutNoiseModel.repr +1 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.json +12 -0
- cirq/contrib/json_test_data/ReadoutNoiseModel.repr +4 -0
- cirq/contrib/json_test_data/__init__.py +17 -0
- cirq/contrib/json_test_data/spec.py +32 -0
- cirq/contrib/noise_models/noise_models.py +119 -5
- cirq/contrib/noise_models/noise_models_test.py +37 -9
- cirq/contrib/paulistring/clifford_optimize.py +6 -4
- cirq/contrib/paulistring/clifford_optimize_test.py +6 -5
- cirq/contrib/paulistring/clifford_target_gateset.py +10 -10
- cirq/contrib/paulistring/clifford_target_gateset_test.py +13 -11
- cirq/contrib/paulistring/optimize.py +2 -0
- cirq/contrib/paulistring/optimize_test.py +4 -3
- cirq/contrib/paulistring/pauli_string_dag.py +2 -0
- cirq/contrib/paulistring/pauli_string_dag_test.py +3 -1
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation.py +255 -120
- cirq/contrib/paulistring/pauli_string_measurement_with_readout_mitigation_test.py +398 -19
- cirq/contrib/paulistring/pauli_string_optimize.py +7 -1
- cirq/contrib/paulistring/pauli_string_optimize_test.py +5 -3
- cirq/contrib/paulistring/recombine.py +6 -4
- cirq/contrib/paulistring/recombine_test.py +3 -1
- cirq/contrib/paulistring/separate.py +9 -6
- cirq/contrib/paulistring/separate_test.py +3 -1
- cirq/contrib/qasm_import/_lexer.py +3 -2
- cirq/contrib/qasm_import/_lexer_test.py +49 -13
- cirq/contrib/qasm_import/_parser.py +547 -83
- cirq/contrib/qasm_import/_parser_test.py +988 -97
- cirq/contrib/qasm_import/exception.py +2 -0
- cirq/contrib/qasm_import/qasm.py +8 -2
- cirq/contrib/qasm_import/qasm_test.py +7 -4
- cirq/contrib/qcircuit/qcircuit_diagram_info.py +5 -5
- cirq/contrib/qcircuit/qcircuit_diagram_info_test.py +4 -1
- cirq/contrib/qcircuit/qcircuit_pdf.py +7 -3
- cirq/contrib/qcircuit/qcircuit_pdf_test.py +3 -1
- cirq/contrib/qcircuit/qcircuit_test.py +10 -8
- cirq/contrib/quantum_volume/quantum_volume.py +31 -27
- cirq/contrib/quantum_volume/quantum_volume_test.py +19 -16
- cirq/contrib/quimb/density_matrix.py +15 -14
- cirq/contrib/quimb/density_matrix_test.py +10 -7
- cirq/contrib/quimb/grid_circuits.py +5 -2
- cirq/contrib/quimb/grid_circuits_test.py +3 -0
- cirq/contrib/quimb/mps_simulator.py +20 -20
- cirq/contrib/quimb/mps_simulator_test.py +3 -0
- cirq/contrib/quimb/state_vector.py +12 -11
- cirq/contrib/quimb/state_vector_test.py +3 -0
- cirq/contrib/quirk/export_to_quirk.py +5 -3
- cirq/contrib/quirk/export_to_quirk_test.py +18 -16
- cirq/contrib/quirk/linearize_circuit.py +2 -0
- cirq/contrib/quirk/quirk_gate.py +18 -17
- cirq/contrib/routing/device.py +5 -3
- cirq/contrib/routing/device_test.py +2 -0
- cirq/contrib/routing/greedy.py +10 -21
- cirq/contrib/routing/greedy_test.py +4 -2
- cirq/contrib/routing/initialization.py +2 -2
- cirq/contrib/routing/initialization_test.py +5 -3
- cirq/contrib/routing/router.py +9 -5
- cirq/contrib/routing/router_test.py +2 -0
- cirq/contrib/routing/swap_network.py +3 -3
- cirq/contrib/routing/swap_network_test.py +3 -1
- cirq/contrib/routing/utils.py +2 -2
- cirq/contrib/routing/utils_test.py +3 -0
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking.py +15 -9
- cirq/contrib/shuffle_circuits/shuffle_circuits_with_readout_benchmarking_test.py +3 -0
- cirq/contrib/svg/svg.py +3 -3
- cirq/contrib/svg/svg_test.py +8 -5
- cirq/devices/device.py +4 -4
- cirq/devices/device_test.py +7 -4
- cirq/devices/grid_device_metadata.py +10 -10
- cirq/devices/grid_device_metadata_test.py +3 -0
- cirq/devices/grid_qubit.py +29 -21
- cirq/devices/grid_qubit_test.py +3 -0
- cirq/devices/insertion_noise_model.py +7 -7
- cirq/devices/insertion_noise_model_test.py +7 -5
- cirq/devices/line_qubit.py +13 -13
- cirq/devices/line_qubit_test.py +2 -0
- cirq/devices/named_topologies.py +18 -29
- cirq/devices/named_topologies_test.py +13 -10
- cirq/devices/noise_model.py +3 -3
- cirq/devices/noise_model_test.py +19 -15
- cirq/devices/noise_properties.py +15 -6
- cirq/devices/noise_properties_test.py +34 -3
- cirq/devices/noise_utils.py +11 -9
- cirq/devices/noise_utils_test.py +2 -0
- cirq/devices/superconducting_qubits_noise_properties.py +23 -22
- cirq/devices/superconducting_qubits_noise_properties_test.py +6 -6
- cirq/devices/thermal_noise_model.py +107 -37
- cirq/devices/thermal_noise_model_test.py +21 -0
- cirq/devices/unconstrained_device.py +5 -3
- cirq/devices/unconstrained_device_test.py +2 -0
- cirq/experiments/__init__.py +4 -2
- cirq/experiments/benchmarking/__init__.py +17 -0
- cirq/experiments/benchmarking/parallel_xeb.py +677 -0
- cirq/experiments/benchmarking/parallel_xeb_test.py +447 -0
- cirq/experiments/fidelity_estimation.py +14 -8
- cirq/experiments/fidelity_estimation_test.py +3 -0
- cirq/experiments/n_qubit_tomography.py +17 -16
- cirq/experiments/n_qubit_tomography_test.py +8 -5
- cirq/experiments/purity_estimation.py +2 -0
- cirq/experiments/purity_estimation_test.py +2 -0
- cirq/experiments/qubit_characterizations.py +207 -103
- cirq/experiments/qubit_characterizations_test.py +40 -12
- cirq/experiments/random_quantum_circuit_generation.py +56 -70
- cirq/experiments/random_quantum_circuit_generation_test.py +11 -8
- cirq/experiments/readout_confusion_matrix.py +24 -22
- cirq/experiments/readout_confusion_matrix_test.py +2 -0
- cirq/experiments/single_qubit_readout_calibration.py +30 -15
- cirq/experiments/single_qubit_readout_calibration_test.py +5 -2
- cirq/experiments/t1_decay_experiment.py +9 -7
- cirq/experiments/t1_decay_experiment_test.py +13 -11
- cirq/experiments/t2_decay_experiment.py +16 -13
- cirq/experiments/t2_decay_experiment_test.py +2 -0
- cirq/experiments/two_qubit_xeb.py +64 -57
- cirq/experiments/two_qubit_xeb_test.py +10 -6
- cirq/experiments/xeb_fitting.py +39 -35
- cirq/experiments/xeb_sampling.py +37 -44
- cirq/experiments/xeb_sampling_test.py +3 -0
- cirq/experiments/xeb_simulation.py +14 -10
- cirq/experiments/xeb_simulation_test.py +5 -5
- cirq/experiments/z_phase_calibration.py +32 -29
- cirq/experiments/z_phase_calibration_test.py +3 -4
- cirq/interop/quirk/cells/__init__.py +1 -1
- cirq/interop/quirk/cells/all_cells.py +7 -2
- cirq/interop/quirk/cells/arithmetic_cells.py +29 -41
- cirq/interop/quirk/cells/arithmetic_cells_test.py +17 -14
- cirq/interop/quirk/cells/cell.py +19 -28
- cirq/interop/quirk/cells/cell_test.py +3 -0
- cirq/interop/quirk/cells/composite_cell.py +13 -28
- cirq/interop/quirk/cells/composite_cell_test.py +2 -0
- cirq/interop/quirk/cells/control_cells.py +15 -15
- cirq/interop/quirk/cells/control_cells_test.py +7 -5
- cirq/interop/quirk/cells/frequency_space_cells.py +4 -3
- cirq/interop/quirk/cells/frequency_space_cells_test.py +3 -1
- cirq/interop/quirk/cells/ignored_cells.py +3 -0
- cirq/interop/quirk/cells/ignored_cells_test.py +3 -1
- cirq/interop/quirk/cells/input_cells.py +7 -5
- cirq/interop/quirk/cells/input_cells_test.py +7 -5
- cirq/interop/quirk/cells/input_rotation_cells.py +15 -13
- cirq/interop/quirk/cells/input_rotation_cells_test.py +9 -7
- cirq/interop/quirk/cells/measurement_cells.py +5 -2
- cirq/interop/quirk/cells/measurement_cells_test.py +3 -1
- cirq/interop/quirk/cells/parse.py +22 -23
- cirq/interop/quirk/cells/parse_test.py +12 -10
- cirq/interop/quirk/cells/qubit_permutation_cells.py +5 -3
- cirq/interop/quirk/cells/qubit_permutation_cells_test.py +9 -7
- cirq/interop/quirk/cells/scalar_cells.py +4 -1
- cirq/interop/quirk/cells/scalar_cells_test.py +3 -1
- cirq/interop/quirk/cells/single_qubit_rotation_cells.py +5 -2
- cirq/interop/quirk/cells/single_qubit_rotation_cells_test.py +5 -3
- cirq/interop/quirk/cells/swap_cell.py +8 -6
- cirq/interop/quirk/cells/swap_cell_test.py +6 -4
- cirq/interop/quirk/cells/testing.py +6 -6
- cirq/interop/quirk/cells/testing_test.py +8 -6
- cirq/interop/quirk/cells/unsupported_cells.py +3 -0
- cirq/interop/quirk/cells/unsupported_cells_test.py +4 -2
- cirq/interop/quirk/url_to_circuit.py +23 -36
- cirq/interop/quirk/url_to_circuit_test.py +4 -1
- cirq/json_resolver_cache.py +14 -12
- cirq/linalg/__init__.py +4 -6
- cirq/linalg/combinators.py +7 -5
- cirq/linalg/combinators_test.py +10 -7
- cirq/linalg/decompositions.py +24 -35
- cirq/linalg/decompositions_test.py +3 -1
- cirq/linalg/diagonalize.py +6 -4
- cirq/linalg/diagonalize_test.py +15 -14
- cirq/linalg/operator_spaces.py +14 -14
- cirq/linalg/operator_spaces_test.py +13 -11
- cirq/linalg/predicates.py +18 -9
- cirq/linalg/predicates_test.py +5 -0
- cirq/linalg/tolerance.py +6 -3
- cirq/linalg/tolerance_test.py +6 -4
- cirq/linalg/transformations.py +23 -20
- cirq/linalg/transformations_test.py +73 -43
- cirq/neutral_atoms/convert_to_neutral_atom_gates.py +9 -3
- cirq/neutral_atoms/convert_to_neutral_atom_gates_test.py +3 -1
- cirq/neutral_atoms/neutral_atom_devices.py +2 -0
- cirq/ops/__init__.py +2 -0
- cirq/ops/arithmetic_operation.py +21 -21
- cirq/ops/arithmetic_operation_test.py +7 -8
- cirq/ops/boolean_hamiltonian.py +23 -22
- cirq/ops/boolean_hamiltonian_test.py +12 -9
- cirq/ops/classically_controlled_operation.py +31 -36
- cirq/ops/classically_controlled_operation_test.py +121 -117
- cirq/ops/clifford_gate.py +98 -81
- cirq/ops/clifford_gate_test.py +72 -57
- cirq/ops/common_channels.py +44 -44
- cirq/ops/common_channels_test.py +83 -81
- cirq/ops/common_gate_families.py +9 -7
- cirq/ops/common_gate_families_test.py +11 -7
- cirq/ops/common_gates.py +164 -183
- cirq/ops/common_gates_test.py +135 -95
- cirq/ops/control_values.py +23 -26
- cirq/ops/control_values_test.py +22 -20
- cirq/ops/controlled_gate.py +64 -112
- cirq/ops/controlled_gate_test.py +130 -35
- cirq/ops/controlled_operation.py +24 -35
- cirq/ops/controlled_operation_test.py +8 -6
- cirq/ops/dense_pauli_string.py +38 -49
- cirq/ops/dense_pauli_string_test.py +4 -2
- cirq/ops/diagonal_gate.py +18 -31
- cirq/ops/diagonal_gate_test.py +13 -13
- cirq/ops/eigen_gate.py +29 -29
- cirq/ops/eigen_gate_test.py +45 -28
- cirq/ops/fourier_transform.py +14 -20
- cirq/ops/fourier_transform_test.py +15 -12
- cirq/ops/fsim_gate.py +43 -42
- cirq/ops/fsim_gate_test.py +29 -29
- cirq/ops/gate_features.py +2 -0
- cirq/ops/gate_features_test.py +5 -3
- cirq/ops/gate_operation.py +43 -65
- cirq/ops/gate_operation_test.py +46 -42
- cirq/ops/gateset.py +28 -40
- cirq/ops/gateset_test.py +4 -2
- cirq/ops/global_phase_op.py +45 -20
- cirq/ops/global_phase_op_test.py +44 -20
- cirq/ops/greedy_qubit_manager.py +10 -8
- cirq/ops/greedy_qubit_manager_test.py +5 -3
- cirq/ops/identity.py +14 -12
- cirq/ops/identity_test.py +24 -20
- cirq/ops/kraus_channel.py +11 -8
- cirq/ops/kraus_channel_test.py +14 -11
- cirq/ops/linear_combinations.py +65 -77
- cirq/ops/linear_combinations_test.py +14 -9
- cirq/ops/matrix_gates.py +21 -18
- cirq/ops/matrix_gates_test.py +16 -0
- cirq/ops/measure_util.py +15 -20
- cirq/ops/measure_util_test.py +2 -0
- cirq/ops/measurement_gate.py +26 -37
- cirq/ops/measurement_gate_test.py +2 -0
- cirq/ops/mixed_unitary_channel.py +12 -9
- cirq/ops/mixed_unitary_channel_test.py +14 -11
- cirq/ops/named_qubit.py +16 -13
- cirq/ops/named_qubit_test.py +15 -13
- cirq/ops/op_tree.py +9 -7
- cirq/ops/op_tree_test.py +22 -19
- cirq/ops/parallel_gate.py +15 -17
- cirq/ops/parallel_gate_test.py +18 -16
- cirq/ops/parity_gates.py +23 -25
- cirq/ops/parity_gates_test.py +36 -32
- cirq/ops/pauli_gates.py +22 -21
- cirq/ops/pauli_gates_test.py +29 -20
- cirq/ops/pauli_interaction_gate.py +15 -19
- cirq/ops/pauli_interaction_gate_test.py +10 -8
- cirq/ops/pauli_measurement_gate.py +23 -35
- cirq/ops/pauli_measurement_gate_test.py +2 -0
- cirq/ops/pauli_string.py +92 -120
- cirq/ops/pauli_string_phasor.py +52 -45
- cirq/ops/pauli_string_phasor_test.py +4 -5
- cirq/ops/pauli_string_raw_types.py +9 -7
- cirq/ops/pauli_string_raw_types_test.py +2 -0
- cirq/ops/pauli_string_test.py +31 -154
- cirq/ops/pauli_sum_exponential.py +12 -12
- cirq/ops/pauli_sum_exponential_test.py +12 -10
- cirq/ops/permutation_gate.py +8 -6
- cirq/ops/permutation_gate_test.py +10 -8
- cirq/ops/phased_iswap_gate.py +16 -16
- cirq/ops/phased_iswap_gate_test.py +17 -15
- cirq/ops/phased_x_gate.py +16 -17
- cirq/ops/phased_x_gate_test.py +18 -16
- cirq/ops/phased_x_z_gate.py +24 -22
- cirq/ops/phased_x_z_gate_test.py +17 -11
- cirq/ops/projector.py +16 -11
- cirq/ops/projector_test.py +19 -16
- cirq/ops/qid_util.py +7 -5
- cirq/ops/qid_util_test.py +2 -0
- cirq/ops/qubit_manager.py +11 -9
- cirq/ops/qubit_manager_test.py +6 -4
- cirq/ops/qubit_order.py +11 -14
- cirq/ops/qubit_order_or_list.py +4 -2
- cirq/ops/qubit_order_test.py +12 -10
- cirq/ops/random_gate_channel.py +12 -10
- cirq/ops/random_gate_channel_test.py +14 -11
- cirq/ops/raw_types.py +109 -129
- cirq/ops/raw_types_test.py +63 -57
- cirq/ops/state_preparation_channel.py +7 -7
- cirq/ops/state_preparation_channel_test.py +11 -9
- cirq/ops/swap_gates.py +13 -15
- cirq/ops/swap_gates_test.py +19 -17
- cirq/ops/tags.py +5 -3
- cirq/ops/tags_test.py +4 -2
- cirq/ops/three_qubit_gates.py +43 -76
- cirq/ops/three_qubit_gates_test.py +19 -17
- cirq/ops/two_qubit_diagonal_gate.py +13 -13
- cirq/ops/two_qubit_diagonal_gate_test.py +10 -8
- cirq/ops/uniform_superposition_gate.py +5 -3
- cirq/ops/uniform_superposition_gate_test.py +5 -3
- cirq/ops/wait_gate.py +17 -14
- cirq/ops/wait_gate_test.py +9 -6
- cirq/protocols/__init__.py +0 -3
- cirq/protocols/act_on_protocol.py +8 -6
- cirq/protocols/act_on_protocol_test.py +15 -12
- cirq/protocols/apply_channel_protocol.py +10 -14
- cirq/protocols/apply_channel_protocol_test.py +2 -0
- cirq/protocols/apply_mixture_protocol.py +13 -42
- cirq/protocols/apply_mixture_protocol_test.py +7 -5
- cirq/protocols/apply_unitary_protocol.py +39 -34
- cirq/protocols/apply_unitary_protocol_test.py +4 -1
- cirq/protocols/approximate_equality_protocol.py +2 -0
- cirq/protocols/approximate_equality_protocol_test.py +2 -0
- cirq/protocols/circuit_diagram_info_protocol.py +58 -42
- cirq/protocols/circuit_diagram_info_protocol_test.py +70 -12
- cirq/protocols/commutes_protocol.py +8 -7
- cirq/protocols/commutes_protocol_test.py +2 -0
- cirq/protocols/control_key_protocol.py +6 -4
- cirq/protocols/control_key_protocol_test.py +3 -1
- cirq/protocols/decompose_protocol.py +49 -48
- cirq/protocols/decompose_protocol_test.py +27 -16
- cirq/protocols/equal_up_to_global_phase_protocol.py +2 -0
- cirq/protocols/equal_up_to_global_phase_protocol_test.py +9 -6
- cirq/protocols/has_stabilizer_effect_protocol.py +7 -5
- cirq/protocols/has_stabilizer_effect_protocol_test.py +7 -5
- cirq/protocols/has_unitary_protocol.py +10 -6
- cirq/protocols/has_unitary_protocol_test.py +13 -8
- cirq/protocols/hash_from_pickle_test.py +2 -11
- cirq/protocols/inverse_protocol.py +13 -16
- cirq/protocols/inverse_protocol_test.py +5 -3
- cirq/protocols/json_serialization.py +35 -54
- cirq/protocols/json_serialization_test.py +14 -21
- cirq/protocols/json_test_data/CXSWAP.json +46 -0
- cirq/protocols/json_test_data/CXSWAP.repr +13 -0
- cirq/protocols/json_test_data/CZSWAP.json +46 -0
- cirq/protocols/json_test_data/CZSWAP.repr +13 -0
- cirq/protocols/json_test_data/CircuitOperation.json +6 -3
- cirq/protocols/json_test_data/CircuitOperation.repr_inward +4 -2
- cirq/protocols/json_test_data/Moment.json +24 -1
- cirq/protocols/json_test_data/Moment.repr +6 -1
- cirq/protocols/json_test_data/ThermalNoiseModel.json +32 -0
- cirq/protocols/json_test_data/ThermalNoiseModel.repr +1 -0
- cirq/protocols/json_test_data/spec.py +6 -2
- cirq/protocols/kraus_protocol.py +47 -7
- cirq/protocols/kraus_protocol_test.py +86 -12
- cirq/protocols/measurement_key_protocol.py +15 -16
- cirq/protocols/measurement_key_protocol_test.py +13 -11
- cirq/protocols/mixture_protocol.py +7 -5
- cirq/protocols/mixture_protocol_test.py +4 -2
- cirq/protocols/mul_protocol.py +2 -3
- cirq/protocols/mul_protocol_test.py +2 -0
- cirq/protocols/pauli_expansion_protocol.py +6 -3
- cirq/protocols/pauli_expansion_protocol_test.py +5 -3
- cirq/protocols/phase_protocol.py +2 -0
- cirq/protocols/phase_protocol_test.py +3 -1
- cirq/protocols/pow_protocol.py +11 -16
- cirq/protocols/pow_protocol_test.py +2 -0
- cirq/protocols/qasm.py +14 -20
- cirq/protocols/qasm_test.py +6 -3
- cirq/protocols/qid_shape_protocol.py +8 -8
- cirq/protocols/qid_shape_protocol_test.py +3 -1
- cirq/protocols/resolve_parameters.py +5 -3
- cirq/protocols/resolve_parameters_test.py +8 -7
- cirq/protocols/trace_distance_bound.py +6 -4
- cirq/protocols/trace_distance_bound_test.py +3 -1
- cirq/protocols/unitary_protocol.py +17 -7
- cirq/protocols/unitary_protocol_test.py +12 -2
- cirq/qis/channels.py +6 -2
- cirq/qis/channels_test.py +20 -16
- cirq/qis/clifford_tableau.py +21 -19
- cirq/qis/clifford_tableau_test.py +2 -2
- cirq/qis/entropy.py +14 -3
- cirq/qis/entropy_test.py +3 -1
- cirq/qis/measures.py +13 -13
- cirq/qis/measures_test.py +20 -14
- cirq/qis/noise_utils.py +2 -0
- cirq/qis/noise_utils_test.py +9 -7
- cirq/qis/quantum_state_representation.py +7 -8
- cirq/qis/states.py +58 -56
- cirq/qis/states_test.py +2 -0
- cirq/sim/classical_simulator.py +23 -22
- cirq/sim/classical_simulator_test.py +2 -0
- cirq/sim/clifford/clifford_simulator.py +23 -21
- cirq/sim/clifford/clifford_simulator_test.py +7 -4
- cirq/sim/clifford/clifford_tableau_simulation_state.py +10 -7
- cirq/sim/clifford/clifford_tableau_simulation_state_test.py +5 -5
- cirq/sim/clifford/stabilizer_ch_form_simulation_state.py +8 -6
- cirq/sim/clifford/stabilizer_ch_form_simulation_state_test.py +8 -6
- cirq/sim/clifford/stabilizer_sampler.py +9 -7
- cirq/sim/clifford/stabilizer_sampler_test.py +4 -2
- cirq/sim/clifford/stabilizer_simulation_state.py +14 -13
- cirq/sim/clifford/stabilizer_simulation_state_test.py +6 -4
- cirq/sim/clifford/stabilizer_state_ch_form.py +13 -11
- cirq/sim/clifford/stabilizer_state_ch_form_test.py +4 -2
- cirq/sim/density_matrix_simulation_state.py +26 -27
- cirq/sim/density_matrix_simulation_state_test.py +10 -8
- cirq/sim/density_matrix_simulator.py +30 -28
- cirq/sim/density_matrix_simulator_test.py +48 -48
- cirq/sim/density_matrix_utils.py +13 -11
- cirq/sim/density_matrix_utils_test.py +38 -36
- cirq/sim/mux.py +33 -31
- cirq/sim/mux_test.py +3 -0
- cirq/sim/simulation_product_state.py +15 -15
- cirq/sim/simulation_product_state_test.py +29 -26
- cirq/sim/simulation_state.py +29 -38
- cirq/sim/simulation_state_base.py +21 -32
- cirq/sim/simulation_state_test.py +15 -13
- cirq/sim/simulation_utils.py +5 -2
- cirq/sim/simulation_utils_test.py +5 -2
- cirq/sim/simulator.py +90 -106
- cirq/sim/simulator_base.py +33 -45
- cirq/sim/simulator_base_test.py +20 -15
- cirq/sim/simulator_test.py +23 -14
- cirq/sim/sparse_simulator.py +19 -17
- cirq/sim/sparse_simulator_test.py +41 -40
- cirq/sim/state_vector.py +15 -12
- cirq/sim/state_vector_simulation_state.py +31 -31
- cirq/sim/state_vector_simulation_state_test.py +16 -14
- cirq/sim/state_vector_simulator.py +17 -14
- cirq/sim/state_vector_simulator_test.py +2 -0
- cirq/sim/state_vector_test.py +6 -3
- cirq/study/flatten_expressions.py +16 -15
- cirq/study/flatten_expressions_test.py +13 -11
- cirq/study/resolver.py +18 -17
- cirq/study/resolver_test.py +22 -20
- cirq/study/result.py +17 -27
- cirq/study/result_test.py +2 -0
- cirq/study/sweepable.py +12 -10
- cirq/study/sweepable_test.py +3 -0
- cirq/study/sweeps.py +42 -61
- cirq/study/sweeps_test.py +33 -0
- cirq/testing/__init__.py +7 -11
- cirq/testing/_compat_test_data/module_a/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/module_b/__init__.py +1 -0
- cirq/testing/_compat_test_data/module_a/sub/__init__.py +1 -0
- cirq/testing/circuit_compare.py +8 -17
- cirq/testing/circuit_compare_test.py +2 -0
- cirq/testing/consistent_act_on.py +13 -11
- cirq/testing/consistent_act_on_test.py +5 -3
- cirq/testing/consistent_channels.py +2 -0
- cirq/testing/consistent_channels_test.py +10 -8
- cirq/testing/consistent_controlled_gate_op.py +5 -5
- cirq/testing/consistent_controlled_gate_op_test.py +18 -18
- cirq/testing/consistent_decomposition.py +2 -2
- cirq/testing/consistent_decomposition_test.py +4 -2
- cirq/testing/consistent_pauli_expansion.py +2 -0
- cirq/testing/consistent_pauli_expansion_test.py +3 -1
- cirq/testing/consistent_phase_by.py +2 -0
- cirq/testing/consistent_phase_by_test.py +3 -1
- cirq/testing/consistent_protocols.py +14 -20
- cirq/testing/consistent_protocols_test.py +13 -11
- cirq/testing/consistent_qasm.py +6 -4
- cirq/testing/consistent_qasm_test.py +7 -7
- cirq/testing/consistent_resolve_parameters.py +2 -0
- cirq/testing/consistent_specified_has_unitary.py +2 -2
- cirq/testing/consistent_specified_has_unitary_test.py +6 -4
- cirq/testing/consistent_unitary.py +1 -0
- cirq/testing/consistent_unitary_test.py +4 -2
- cirq/testing/deprecation.py +5 -2
- cirq/testing/deprecation_test.py +5 -2
- cirq/testing/devices.py +7 -4
- cirq/testing/devices_test.py +7 -4
- cirq/testing/equals_tester.py +4 -2
- cirq/testing/equals_tester_test.py +21 -17
- cirq/testing/equivalent_basis_map.py +6 -4
- cirq/testing/equivalent_basis_map_test.py +6 -4
- cirq/testing/equivalent_repr_eval.py +6 -4
- cirq/testing/equivalent_repr_eval_test.py +5 -3
- cirq/testing/gate_features.py +2 -0
- cirq/testing/gate_features_test.py +7 -5
- cirq/testing/json.py +19 -15
- cirq/testing/json_test.py +5 -3
- cirq/testing/lin_alg_utils.py +10 -11
- cirq/testing/lin_alg_utils_test.py +14 -12
- cirq/testing/logs.py +7 -6
- cirq/testing/logs_test.py +9 -7
- cirq/testing/no_identifier_qubit.py +4 -2
- cirq/testing/no_identifier_qubit_test.py +5 -3
- cirq/testing/op_tree.py +2 -0
- cirq/testing/op_tree_test.py +4 -1
- cirq/testing/order_tester.py +2 -0
- cirq/testing/order_tester_test.py +8 -6
- cirq/testing/pytest_utils.py +2 -0
- cirq/testing/pytest_utils_test.py +4 -2
- cirq/testing/random_circuit.py +21 -20
- cirq/testing/random_circuit_test.py +12 -9
- cirq/testing/repr_pretty_tester.py +1 -0
- cirq/testing/repr_pretty_tester_test.py +5 -3
- cirq/testing/routing_devices.py +4 -1
- cirq/testing/routing_devices_test.py +9 -6
- cirq/testing/sample_circuits.py +4 -1
- cirq/testing/sample_circuits_test.py +3 -1
- cirq/testing/sample_gates.py +3 -0
- cirq/testing/sample_gates_test.py +5 -2
- cirq/transformers/__init__.py +11 -4
- cirq/transformers/align.py +9 -7
- cirq/transformers/align_test.py +2 -0
- cirq/transformers/analytical_decompositions/__init__.py +3 -6
- cirq/transformers/analytical_decompositions/clifford_decomposition.py +18 -16
- cirq/transformers/analytical_decompositions/clifford_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition.py +19 -16
- cirq/transformers/analytical_decompositions/controlled_gate_decomposition_test.py +2 -0
- cirq/transformers/analytical_decompositions/cphase_to_fsim.py +11 -9
- cirq/transformers/analytical_decompositions/cphase_to_fsim_test.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition.py +5 -3
- cirq/transformers/analytical_decompositions/pauli_string_decomposition_test.py +5 -3
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition.py +141 -44
- cirq/transformers/analytical_decompositions/quantum_shannon_decomposition_test.py +35 -1
- cirq/transformers/analytical_decompositions/single_qubit_decompositions.py +8 -7
- cirq/transformers/analytical_decompositions/single_qubit_decompositions_test.py +2 -0
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry.py +7 -4
- cirq/transformers/analytical_decompositions/single_to_two_qubit_isometry_test.py +3 -0
- cirq/transformers/analytical_decompositions/three_qubit_decomposition.py +11 -19
- cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py +8 -33
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation.py +9 -11
- cirq/transformers/analytical_decompositions/two_qubit_state_preparation_test.py +2 -0
- cirq/transformers/analytical_decompositions/two_qubit_to_cz.py +91 -27
- cirq/transformers/analytical_decompositions/two_qubit_to_cz_test.py +36 -7
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim.py +20 -21
- cirq/transformers/analytical_decompositions/two_qubit_to_fsim_test.py +8 -6
- cirq/transformers/analytical_decompositions/two_qubit_to_ms.py +13 -15
- cirq/transformers/analytical_decompositions/two_qubit_to_ms_test.py +3 -1
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py +39 -41
- cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap_test.py +2 -0
- cirq/transformers/drop_empty_moments.py +5 -3
- cirq/transformers/drop_empty_moments_test.py +4 -2
- cirq/transformers/drop_negligible_operations.py +7 -5
- cirq/transformers/drop_negligible_operations_test.py +2 -0
- cirq/transformers/dynamical_decoupling.py +49 -42
- cirq/transformers/dynamical_decoupling_test.py +223 -205
- cirq/transformers/eject_phased_paulis.py +28 -26
- cirq/transformers/eject_phased_paulis_test.py +12 -9
- cirq/transformers/eject_z.py +12 -12
- cirq/transformers/eject_z_test.py +2 -2
- cirq/transformers/expand_composite.py +6 -4
- cirq/transformers/expand_composite_test.py +3 -1
- cirq/transformers/gauge_compiling/__init__.py +3 -1
- cirq/transformers/gauge_compiling/cphase_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cphase_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge.py +2 -0
- cirq/transformers/gauge_compiling/cz_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling.py +45 -41
- cirq/transformers/gauge_compiling/gauge_compiling_test.py +2 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils.py +1 -0
- cirq/transformers/gauge_compiling/gauge_compiling_test_utils_test.py +5 -1
- cirq/transformers/gauge_compiling/iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/iswap_gauge_test.py +1 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge.py +2 -0
- cirq/transformers/gauge_compiling/spin_inversion_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_cz_gauge.py +7 -6
- cirq/transformers/gauge_compiling/sqrt_cz_gauge_test.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge.py +2 -0
- cirq/transformers/gauge_compiling/sqrt_iswap_gauge_test.py +2 -0
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils.py +6 -3
- cirq/transformers/heuristic_decompositions/gate_tabulation_math_utils_test.py +3 -0
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation.py +12 -9
- cirq/transformers/heuristic_decompositions/two_qubit_gate_tabulation_test.py +9 -7
- cirq/transformers/insertion_sort.py +8 -6
- cirq/transformers/insertion_sort_test.py +3 -1
- cirq/transformers/measurement_transformers.py +29 -29
- cirq/transformers/measurement_transformers_test.py +2 -0
- cirq/transformers/merge_k_qubit_gates.py +12 -10
- cirq/transformers/merge_k_qubit_gates_test.py +18 -18
- cirq/transformers/merge_single_qubit_gates.py +197 -20
- cirq/transformers/merge_single_qubit_gates_test.py +177 -5
- cirq/transformers/noise_adding.py +5 -3
- cirq/transformers/noise_adding_test.py +2 -0
- cirq/transformers/optimize_for_target_gateset.py +19 -17
- cirq/transformers/optimize_for_target_gateset_test.py +11 -8
- cirq/transformers/qubit_management_transformers.py +13 -11
- cirq/transformers/qubit_management_transformers_test.py +5 -3
- cirq/transformers/randomized_measurements.py +16 -14
- cirq/transformers/randomized_measurements_test.py +10 -4
- cirq/transformers/routing/initial_mapper.py +6 -4
- cirq/transformers/routing/initial_mapper_test.py +2 -0
- cirq/transformers/routing/line_initial_mapper.py +16 -14
- cirq/transformers/routing/line_initial_mapper_test.py +9 -7
- cirq/transformers/routing/mapping_manager.py +10 -10
- cirq/transformers/routing/mapping_manager_test.py +2 -0
- cirq/transformers/routing/route_circuit_cqc.py +33 -31
- cirq/transformers/routing/route_circuit_cqc_test.py +15 -13
- cirq/transformers/routing/visualize_routed_circuit.py +8 -7
- cirq/transformers/routing/visualize_routed_circuit_test.py +4 -2
- cirq/transformers/stratify.py +17 -15
- cirq/transformers/stratify_test.py +3 -0
- cirq/transformers/symbolize.py +103 -0
- cirq/transformers/symbolize_test.py +62 -0
- cirq/transformers/synchronize_terminal_measurements.py +10 -10
- cirq/transformers/synchronize_terminal_measurements_test.py +12 -10
- cirq/transformers/tag_transformers.py +97 -0
- cirq/transformers/tag_transformers_test.py +103 -0
- cirq/transformers/target_gatesets/compilation_target_gateset.py +21 -19
- cirq/transformers/target_gatesets/compilation_target_gateset_test.py +20 -16
- cirq/transformers/target_gatesets/cz_gateset.py +7 -5
- cirq/transformers/target_gatesets/cz_gateset_test.py +21 -19
- cirq/transformers/target_gatesets/sqrt_iswap_gateset.py +9 -7
- cirq/transformers/target_gatesets/sqrt_iswap_gateset_test.py +25 -25
- cirq/transformers/transformer_api.py +34 -47
- cirq/transformers/transformer_api_test.py +9 -8
- cirq/transformers/transformer_primitives.py +39 -49
- cirq/transformers/transformer_primitives_test.py +10 -17
- cirq/value/abc_alt.py +6 -4
- cirq/value/abc_alt_test.py +5 -3
- cirq/value/angle.py +11 -12
- cirq/value/angle_test.py +5 -3
- cirq/value/classical_data.py +27 -27
- cirq/value/classical_data_test.py +11 -8
- cirq/value/condition.py +26 -24
- cirq/value/condition_test.py +2 -0
- cirq/value/digits.py +14 -11
- cirq/value/digits_test.py +2 -0
- cirq/value/duration.py +23 -20
- cirq/value/duration_test.py +2 -0
- cirq/value/linear_dict.py +25 -30
- cirq/value/linear_dict_test.py +10 -8
- cirq/value/measurement_key.py +12 -12
- cirq/value/measurement_key_test.py +2 -0
- cirq/value/periodic_value.py +4 -4
- cirq/value/periodic_value_test.py +11 -7
- cirq/value/probability.py +3 -1
- cirq/value/probability_test.py +4 -2
- cirq/value/product_state.py +15 -13
- cirq/value/product_state_test.py +4 -1
- cirq/value/random_state.py +2 -0
- cirq/value/random_state_test.py +5 -3
- cirq/value/timestamp.py +11 -7
- cirq/value/timestamp_test.py +14 -12
- cirq/value/type_alias.py +4 -4
- cirq/value/value_equality_attr.py +8 -9
- cirq/value/value_equality_attr_test.py +14 -11
- cirq/vis/density_matrix.py +3 -3
- cirq/vis/density_matrix_test.py +20 -17
- cirq/vis/heatmap.py +24 -37
- cirq/vis/heatmap_test.py +3 -0
- cirq/vis/histogram.py +9 -6
- cirq/vis/histogram_test.py +5 -2
- cirq/vis/state_histogram.py +10 -8
- cirq/vis/state_histogram_test.py +7 -5
- cirq/vis/vis_utils.py +4 -1
- cirq/vis/vis_utils_test.py +4 -1
- cirq/work/collector.py +12 -18
- cirq/work/collector_test.py +15 -10
- cirq/work/observable_grouping.py +6 -7
- cirq/work/observable_grouping_test.py +10 -9
- cirq/work/observable_measurement.py +47 -45
- cirq/work/observable_measurement_data.py +22 -17
- cirq/work/observable_measurement_data_test.py +4 -1
- cirq/work/observable_measurement_test.py +48 -29
- cirq/work/observable_readout_calibration.py +5 -2
- cirq/work/observable_readout_calibration_test.py +5 -2
- cirq/work/observable_settings.py +13 -22
- cirq/work/observable_settings_test.py +9 -7
- cirq/work/pauli_sum_collector.py +12 -10
- cirq/work/pauli_sum_collector_test.py +9 -9
- cirq/work/sampler.py +42 -43
- cirq/work/sampler_test.py +31 -24
- cirq/work/zeros_sampler.py +6 -4
- cirq/work/zeros_sampler_test.py +7 -5
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/METADATA +7 -8
- cirq_core-1.6.0.dist-info/RECORD +1241 -0
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/WHEEL +1 -1
- cirq_core-1.5.0.dev20250409222543.dist-info/RECORD +0 -1216
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/licenses/LICENSE +0 -0
- {cirq_core-1.5.0.dev20250409222543.dist-info → cirq_core-1.6.0.dist-info}/top_level.txt +0 -0
cirq/qis/channels_test.py
CHANGED
|
@@ -11,7 +11,11 @@
|
|
|
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
|
"""Tests for channels."""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
15
19
|
from typing import Iterable, Sequence
|
|
16
20
|
|
|
17
21
|
import numpy as np
|
|
@@ -65,7 +69,7 @@ def compute_choi(channel: cirq.SupportsKraus) -> np.ndarray:
|
|
|
65
69
|
),
|
|
66
70
|
),
|
|
67
71
|
)
|
|
68
|
-
def test_kraus_to_choi(kraus_operators, expected_choi):
|
|
72
|
+
def test_kraus_to_choi(kraus_operators, expected_choi) -> None:
|
|
69
73
|
"""Verifies that cirq.kraus_to_choi computes the correct Choi matrix."""
|
|
70
74
|
assert np.allclose(cirq.kraus_to_choi(kraus_operators), expected_choi)
|
|
71
75
|
|
|
@@ -89,7 +93,7 @@ def test_kraus_to_choi(kraus_operators, expected_choi):
|
|
|
89
93
|
),
|
|
90
94
|
),
|
|
91
95
|
)
|
|
92
|
-
def test_choi_to_kraus_invalid_input(choi, error):
|
|
96
|
+
def test_choi_to_kraus_invalid_input(choi, error) -> None:
|
|
93
97
|
with pytest.raises(ValueError, match=error):
|
|
94
98
|
_ = cirq.choi_to_kraus(choi)
|
|
95
99
|
|
|
@@ -143,7 +147,7 @@ def test_choi_to_kraus_invalid_input(choi, error):
|
|
|
143
147
|
),
|
|
144
148
|
),
|
|
145
149
|
)
|
|
146
|
-
def test_choi_to_kraus_fixed_values(choi, expected_kraus):
|
|
150
|
+
def test_choi_to_kraus_fixed_values(choi, expected_kraus) -> None:
|
|
147
151
|
"""Verifies that cirq.choi_to_kraus gives correct results on a few fixed inputs."""
|
|
148
152
|
actual_kraus = cirq.choi_to_kraus(choi)
|
|
149
153
|
assert len(actual_kraus) == len(expected_kraus)
|
|
@@ -178,7 +182,7 @@ def test_choi_to_kraus_fixed_values(choi, expected_kraus):
|
|
|
178
182
|
),
|
|
179
183
|
),
|
|
180
184
|
)
|
|
181
|
-
def test_choi_to_kraus_action_on_operatorial_basis(choi):
|
|
185
|
+
def test_choi_to_kraus_action_on_operatorial_basis(choi) -> None:
|
|
182
186
|
"""Verifies that cirq.choi_to_kraus computes a valid Kraus representation."""
|
|
183
187
|
kraus_operators = cirq.choi_to_kraus(choi)
|
|
184
188
|
c = np.reshape(choi, (2, 2, 2, 2))
|
|
@@ -217,14 +221,14 @@ def test_choi_to_kraus_action_on_operatorial_basis(choi):
|
|
|
217
221
|
# fmt: on
|
|
218
222
|
),
|
|
219
223
|
)
|
|
220
|
-
def test_choi_to_kraus_inverse_of_kraus_to_choi(choi):
|
|
224
|
+
def test_choi_to_kraus_inverse_of_kraus_to_choi(choi) -> None:
|
|
221
225
|
"""Verifies that cirq.kraus_to_choi(cirq.choi_to_kraus(.)) is identity on Choi matrices."""
|
|
222
226
|
kraus = cirq.choi_to_kraus(choi)
|
|
223
227
|
recovered_choi = cirq.kraus_to_choi(kraus)
|
|
224
228
|
assert np.allclose(recovered_choi, choi)
|
|
225
229
|
|
|
226
230
|
|
|
227
|
-
def test_choi_to_kraus_atol():
|
|
231
|
+
def test_choi_to_kraus_atol() -> None:
|
|
228
232
|
"""Verifies that insignificant Kraus operators are omitted."""
|
|
229
233
|
choi = cirq.kraus_to_choi(cirq.kraus(cirq.phase_damp(1e-6)))
|
|
230
234
|
assert len(cirq.choi_to_kraus(choi, atol=1e-2)) == 1
|
|
@@ -242,7 +246,7 @@ def test_choi_to_kraus_atol():
|
|
|
242
246
|
cirq.amplitude_damp(0.2),
|
|
243
247
|
),
|
|
244
248
|
)
|
|
245
|
-
def test_operation_to_choi(channel):
|
|
249
|
+
def test_operation_to_choi(channel) -> None:
|
|
246
250
|
"""Verifies that cirq.operation_to_choi correctly computes the Choi matrix."""
|
|
247
251
|
n_qubits = cirq.num_qubits(channel)
|
|
248
252
|
actual = cirq.operation_to_choi(channel)
|
|
@@ -251,7 +255,7 @@ def test_operation_to_choi(channel):
|
|
|
251
255
|
assert np.all(actual == expected)
|
|
252
256
|
|
|
253
257
|
|
|
254
|
-
def test_choi_for_completely_dephasing_channel():
|
|
258
|
+
def test_choi_for_completely_dephasing_channel() -> None:
|
|
255
259
|
"""Checks cirq.operation_to_choi on the completely dephasing channel."""
|
|
256
260
|
assert np.all(cirq.operation_to_choi(cirq.phase_damp(1)) == np.diag([1, 0, 0, 1]))
|
|
257
261
|
|
|
@@ -268,7 +272,7 @@ def test_choi_for_completely_dephasing_channel():
|
|
|
268
272
|
),
|
|
269
273
|
),
|
|
270
274
|
)
|
|
271
|
-
def test_superoperator_to_kraus_fixed_values(superoperator, expected_kraus_operators):
|
|
275
|
+
def test_superoperator_to_kraus_fixed_values(superoperator, expected_kraus_operators) -> None:
|
|
272
276
|
"""Verifies that cirq.kraus_to_superoperator computes the correct channel matrix."""
|
|
273
277
|
actual_kraus_operators = cirq.superoperator_to_kraus(superoperator)
|
|
274
278
|
for i in (0, 1):
|
|
@@ -306,14 +310,14 @@ def test_superoperator_to_kraus_fixed_values(superoperator, expected_kraus_opera
|
|
|
306
310
|
# fmt: on
|
|
307
311
|
),
|
|
308
312
|
)
|
|
309
|
-
def test_superoperator_to_kraus_inverse_of_kraus_to_superoperator(superoperator):
|
|
313
|
+
def test_superoperator_to_kraus_inverse_of_kraus_to_superoperator(superoperator) -> None:
|
|
310
314
|
"""Verifies that cirq.kraus_to_superoperator(cirq.superoperator_to_kraus(.)) is identity."""
|
|
311
315
|
kraus = cirq.superoperator_to_kraus(superoperator)
|
|
312
316
|
recovered_superoperator = cirq.kraus_to_superoperator(kraus)
|
|
313
317
|
assert np.allclose(recovered_superoperator, superoperator)
|
|
314
318
|
|
|
315
319
|
|
|
316
|
-
def test_superoperator_to_kraus_atol():
|
|
320
|
+
def test_superoperator_to_kraus_atol() -> None:
|
|
317
321
|
"""Verifies that insignificant Kraus operators are omitted."""
|
|
318
322
|
superop = cirq.kraus_to_superoperator(cirq.kraus(cirq.phase_damp(1e-6)))
|
|
319
323
|
assert len(cirq.superoperator_to_kraus(superop, atol=1e-2)) == 1
|
|
@@ -338,7 +342,7 @@ def test_superoperator_to_kraus_atol():
|
|
|
338
342
|
),
|
|
339
343
|
),
|
|
340
344
|
)
|
|
341
|
-
def test_choi_to_superoperator_invalid_input(choi, error):
|
|
345
|
+
def test_choi_to_superoperator_invalid_input(choi, error) -> None:
|
|
342
346
|
with pytest.raises(ValueError, match=error):
|
|
343
347
|
_ = cirq.choi_to_superoperator(choi)
|
|
344
348
|
|
|
@@ -346,7 +350,7 @@ def test_choi_to_superoperator_invalid_input(choi, error):
|
|
|
346
350
|
@pytest.mark.parametrize(
|
|
347
351
|
'superoperator, error', ((np.array([[1, 2, 3], [4, 5, 6]]), "shape"), (np.eye(2), "shape"))
|
|
348
352
|
)
|
|
349
|
-
def test_superoperator_to_choi_invalid_input(superoperator, error):
|
|
353
|
+
def test_superoperator_to_choi_invalid_input(superoperator, error) -> None:
|
|
350
354
|
with pytest.raises(ValueError, match=error):
|
|
351
355
|
_ = cirq.superoperator_to_choi(superoperator)
|
|
352
356
|
|
|
@@ -402,7 +406,7 @@ def test_superoperator_to_choi_invalid_input(superoperator, error):
|
|
|
402
406
|
),
|
|
403
407
|
),
|
|
404
408
|
)
|
|
405
|
-
def test_superoperator_vs_choi_fixed_values(superoperator, choi):
|
|
409
|
+
def test_superoperator_vs_choi_fixed_values(superoperator, choi) -> None:
|
|
406
410
|
recovered_choi = cirq.superoperator_to_choi(superoperator)
|
|
407
411
|
assert np.allclose(recovered_choi, choi)
|
|
408
412
|
|
|
@@ -436,7 +440,7 @@ def test_superoperator_vs_choi_fixed_values(superoperator, choi):
|
|
|
436
440
|
# fmt: on
|
|
437
441
|
),
|
|
438
442
|
)
|
|
439
|
-
def test_choi_to_superoperator_inverse_of_superoperator_to_choi(choi):
|
|
443
|
+
def test_choi_to_superoperator_inverse_of_superoperator_to_choi(choi) -> None:
|
|
440
444
|
superoperator = cirq.choi_to_superoperator(choi)
|
|
441
445
|
recovered_choi = cirq.superoperator_to_choi(superoperator)
|
|
442
446
|
assert np.allclose(recovered_choi, choi)
|
|
@@ -445,6 +449,6 @@ def test_choi_to_superoperator_inverse_of_superoperator_to_choi(choi):
|
|
|
445
449
|
assert np.allclose(recovered_superoperator, superoperator)
|
|
446
450
|
|
|
447
451
|
|
|
448
|
-
def test_superoperator_for_completely_dephasing_channel():
|
|
452
|
+
def test_superoperator_for_completely_dephasing_channel() -> None:
|
|
449
453
|
"""Checks cirq.operation_to_superoperator on the completely dephasing channel."""
|
|
450
454
|
assert np.all(cirq.operation_to_superoperator(cirq.phase_damp(1)) == np.diag([1, 0, 0, 1]))
|
cirq/qis/clifford_tableau.py
CHANGED
|
@@ -12,8 +12,10 @@
|
|
|
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 abc
|
|
16
|
-
from typing import Any,
|
|
18
|
+
from typing import Any, Sequence, TYPE_CHECKING
|
|
17
19
|
|
|
18
20
|
import numpy as np
|
|
19
21
|
|
|
@@ -145,9 +147,9 @@ class CliffordTableau(StabilizerState):
|
|
|
145
147
|
self,
|
|
146
148
|
num_qubits,
|
|
147
149
|
initial_state: int = 0,
|
|
148
|
-
rs:
|
|
149
|
-
xs:
|
|
150
|
-
zs:
|
|
150
|
+
rs: np.ndarray | None = None,
|
|
151
|
+
xs: np.ndarray | None = None,
|
|
152
|
+
zs: np.ndarray | None = None,
|
|
151
153
|
):
|
|
152
154
|
"""Initializes CliffordTableau
|
|
153
155
|
Args:
|
|
@@ -164,7 +166,7 @@ class CliffordTableau(StabilizerState):
|
|
|
164
166
|
self._xs = self._reconstruct_xs(xs)
|
|
165
167
|
self._zs = self._reconstruct_zs(zs)
|
|
166
168
|
|
|
167
|
-
def _reconstruct_rs(self, rs:
|
|
169
|
+
def _reconstruct_rs(self, rs: np.ndarray | None) -> np.ndarray:
|
|
168
170
|
if rs is None:
|
|
169
171
|
new_rs = np.zeros(2 * self.n + 1, dtype=bool)
|
|
170
172
|
for i, val in enumerate(
|
|
@@ -183,7 +185,7 @@ class CliffordTableau(StabilizerState):
|
|
|
183
185
|
)
|
|
184
186
|
return new_rs
|
|
185
187
|
|
|
186
|
-
def _reconstruct_xs(self, xs:
|
|
188
|
+
def _reconstruct_xs(self, xs: np.ndarray | None) -> np.ndarray:
|
|
187
189
|
if xs is None:
|
|
188
190
|
new_xs = np.zeros((2 * self.n + 1, self.n), dtype=bool)
|
|
189
191
|
for i in range(self.n):
|
|
@@ -205,7 +207,7 @@ class CliffordTableau(StabilizerState):
|
|
|
205
207
|
)
|
|
206
208
|
return new_xs
|
|
207
209
|
|
|
208
|
-
def _reconstruct_zs(self, zs:
|
|
210
|
+
def _reconstruct_zs(self, zs: np.ndarray | None) -> np.ndarray:
|
|
209
211
|
if zs is None:
|
|
210
212
|
new_zs = np.zeros((2 * self.n + 1, self.n), dtype=bool)
|
|
211
213
|
for i in range(self.n):
|
|
@@ -258,7 +260,7 @@ class CliffordTableau(StabilizerState):
|
|
|
258
260
|
"""Returns the 2n * 2n matrix representation of the Clifford tableau."""
|
|
259
261
|
return np.concatenate([self.xs, self.zs], axis=1)
|
|
260
262
|
|
|
261
|
-
def _json_dict_(self) ->
|
|
263
|
+
def _json_dict_(self) -> dict[str, Any]:
|
|
262
264
|
return protocols.obj_to_dict_helper(self, ['n', 'rs', 'xs', 'zs'])
|
|
263
265
|
|
|
264
266
|
@classmethod
|
|
@@ -286,10 +288,10 @@ class CliffordTableau(StabilizerState):
|
|
|
286
288
|
and np.array_equal(self.zs, other.zs)
|
|
287
289
|
)
|
|
288
290
|
|
|
289
|
-
def __copy__(self) ->
|
|
291
|
+
def __copy__(self) -> CliffordTableau:
|
|
290
292
|
return self.copy()
|
|
291
293
|
|
|
292
|
-
def copy(self, deep_copy_buffers: bool = True) ->
|
|
294
|
+
def copy(self, deep_copy_buffers: bool = True) -> CliffordTableau:
|
|
293
295
|
state = CliffordTableau(self.n)
|
|
294
296
|
state.rs = self.rs.copy()
|
|
295
297
|
state.xs = self.xs.copy()
|
|
@@ -364,7 +366,7 @@ class CliffordTableau(StabilizerState):
|
|
|
364
366
|
|
|
365
367
|
return '\n'.join([title_row, divider, *contents]) + '\n'
|
|
366
368
|
|
|
367
|
-
def then(self, second:
|
|
369
|
+
def then(self, second: CliffordTableau) -> CliffordTableau:
|
|
368
370
|
"""Returns a composed CliffordTableau of this tableau and the second tableau.
|
|
369
371
|
|
|
370
372
|
Then composed tableau is equal to (up to global phase) the composed
|
|
@@ -431,7 +433,7 @@ class CliffordTableau(StabilizerState):
|
|
|
431
433
|
|
|
432
434
|
return merged_tableau
|
|
433
435
|
|
|
434
|
-
def inverse(self) ->
|
|
436
|
+
def inverse(self) -> CliffordTableau:
|
|
435
437
|
"""Returns the inverse Clifford tableau of this tableau."""
|
|
436
438
|
ret_table = CliffordTableau(num_qubits=self.n)
|
|
437
439
|
# It relies on the symplectic property of Clifford tableau.
|
|
@@ -450,7 +452,7 @@ class CliffordTableau(StabilizerState):
|
|
|
450
452
|
ret_table.rs = ret_table.then(self).rs
|
|
451
453
|
return ret_table
|
|
452
454
|
|
|
453
|
-
def __matmul__(self, second:
|
|
455
|
+
def __matmul__(self, second: CliffordTableau):
|
|
454
456
|
if not isinstance(second, CliffordTableau):
|
|
455
457
|
return NotImplemented
|
|
456
458
|
return second.then(self)
|
|
@@ -481,7 +483,7 @@ class CliffordTableau(StabilizerState):
|
|
|
481
483
|
self._xs[q1, :] ^= self._xs[q2, :]
|
|
482
484
|
self._zs[q1, :] ^= self._zs[q2, :]
|
|
483
485
|
|
|
484
|
-
def _row_to_dense_pauli(self, i: int) ->
|
|
486
|
+
def _row_to_dense_pauli(self, i: int) -> cirq.DensePauliString:
|
|
485
487
|
"""Return a dense Pauli string for the given row in the tableau.
|
|
486
488
|
|
|
487
489
|
Args:
|
|
@@ -509,12 +511,12 @@ class CliffordTableau(StabilizerState):
|
|
|
509
511
|
pauli_mask += "I"
|
|
510
512
|
return DensePauliString(pauli_mask, coefficient=coefficient)
|
|
511
513
|
|
|
512
|
-
def stabilizers(self) ->
|
|
514
|
+
def stabilizers(self) -> list[cirq.DensePauliString]:
|
|
513
515
|
"""Returns the stabilizer generators of the state. These
|
|
514
516
|
are n operators {S_1,S_2,...,S_n} such that S_i |psi> = |psi>"""
|
|
515
517
|
return [self._row_to_dense_pauli(i) for i in range(self.n, 2 * self.n)]
|
|
516
518
|
|
|
517
|
-
def destabilizers(self) ->
|
|
519
|
+
def destabilizers(self) -> list[cirq.DensePauliString]:
|
|
518
520
|
"""Returns the destabilizer generators of the state. These
|
|
519
521
|
are n operators {S_1,S_2,...,S_n} such that along with the stabilizer
|
|
520
522
|
generators above generate the full Pauli group on n qubits."""
|
|
@@ -662,15 +664,15 @@ class CliffordTableau(StabilizerState):
|
|
|
662
664
|
pass
|
|
663
665
|
|
|
664
666
|
def measure(
|
|
665
|
-
self, axes: Sequence[int], seed:
|
|
666
|
-
) ->
|
|
667
|
+
self, axes: Sequence[int], seed: cirq.RANDOM_STATE_OR_SEED_LIKE = None
|
|
668
|
+
) -> list[int]:
|
|
667
669
|
return [self._measure(axis, random_state.parse_random_state(seed)) for axis in axes]
|
|
668
670
|
|
|
669
671
|
@cached_method
|
|
670
672
|
def __hash__(self) -> int:
|
|
671
673
|
return hash(self.matrix().tobytes() + self.rs.tobytes())
|
|
672
674
|
|
|
673
|
-
def __getstate__(self) ->
|
|
675
|
+
def __getstate__(self) -> dict[str, Any]:
|
|
674
676
|
# clear cached hash value when pickling, see #6674
|
|
675
677
|
state = self.__dict__
|
|
676
678
|
hash_attr = _method_cache_name(self.__hash__)
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
"""Tests for clifford tableau."""
|
|
16
16
|
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
17
19
|
import numpy as np
|
|
18
20
|
import pytest
|
|
19
21
|
|
|
@@ -438,9 +440,7 @@ def test_tableau_matmul():
|
|
|
438
440
|
assert expected_t != t1 @ t2
|
|
439
441
|
|
|
440
442
|
with pytest.raises(TypeError):
|
|
441
|
-
# pylint: disable=pointless-statement
|
|
442
443
|
t1 @ 21
|
|
443
|
-
# pylint: enable=pointless-statement
|
|
444
444
|
|
|
445
445
|
|
|
446
446
|
def test_tableau_then_with_bad_input():
|
cirq/qis/entropy.py
CHANGED
|
@@ -12,10 +12,12 @@
|
|
|
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
|
from collections.abc import Sequence
|
|
16
18
|
from concurrent.futures import ThreadPoolExecutor
|
|
17
19
|
from itertools import product
|
|
18
|
-
from typing import Any,
|
|
20
|
+
from typing import Any, cast, Iterator
|
|
19
21
|
|
|
20
22
|
import numpy as np
|
|
21
23
|
import numpy.typing as npt
|
|
@@ -73,8 +75,17 @@ def _compute_bitstrings_contribution_to_purity(bitstrings: npt.NDArray[np.int8])
|
|
|
73
75
|
"""
|
|
74
76
|
|
|
75
77
|
bitstrings, probs = _bitstrings_to_probs(bitstrings)
|
|
78
|
+
product_iterator = cast(
|
|
79
|
+
Iterator[
|
|
80
|
+
tuple[
|
|
81
|
+
tuple[npt.NDArray[np.int8], npt.NDArray[Any]],
|
|
82
|
+
tuple[npt.NDArray[np.int8], npt.NDArray[Any]],
|
|
83
|
+
]
|
|
84
|
+
],
|
|
85
|
+
product(zip(bitstrings, probs), repeat=2),
|
|
86
|
+
)
|
|
76
87
|
purity = 0
|
|
77
|
-
for (s, p), (s_prime, p_prime) in
|
|
88
|
+
for (s, p), (s_prime, p_prime) in product_iterator:
|
|
78
89
|
purity += (-2.0) ** float(-_get_hamming_distance(s, s_prime)) * p * p_prime
|
|
79
90
|
|
|
80
91
|
return purity * 2 ** (bitstrings.shape[-1])
|
|
@@ -83,7 +94,7 @@ def _compute_bitstrings_contribution_to_purity(bitstrings: npt.NDArray[np.int8])
|
|
|
83
94
|
def process_renyi_entropy_from_bitstrings(
|
|
84
95
|
measured_bitstrings: npt.NDArray[np.int8],
|
|
85
96
|
subsystem: tuple[int] | None = None,
|
|
86
|
-
pool:
|
|
97
|
+
pool: ThreadPoolExecutor | None = None,
|
|
87
98
|
) -> float:
|
|
88
99
|
"""Compute the Rényi entropy of an array of bitstrings.
|
|
89
100
|
Args:
|
cirq/qis/entropy_test.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
|
from concurrent.futures import ThreadPoolExecutor
|
|
16
18
|
|
|
17
19
|
import numpy as np
|
|
@@ -36,7 +38,7 @@ def test_process_renyi_entropy_from_bitstrings(pool):
|
|
|
36
38
|
assert entropy == 0.5145731728297583
|
|
37
39
|
|
|
38
40
|
|
|
39
|
-
def test_process_renyi_entropy_from_bitstrings_safeguards_against_divide_by_0_error():
|
|
41
|
+
def test_process_renyi_entropy_from_bitstrings_safeguards_against_divide_by_0_error() -> None:
|
|
40
42
|
bitstrings = np.array([[[0, 1, 1, 0]], [[0, 1, 1, 0]], [[0, 0, 1, 1]]])
|
|
41
43
|
|
|
42
44
|
entropy = process_renyi_entropy_from_bitstrings(bitstrings)
|
cirq/qis/measures.py
CHANGED
|
@@ -11,10 +11,12 @@
|
|
|
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
|
"""Measures on and between quantum states and operations."""
|
|
15
16
|
|
|
17
|
+
from __future__ import annotations
|
|
16
18
|
|
|
17
|
-
from typing import
|
|
19
|
+
from typing import TYPE_CHECKING
|
|
18
20
|
|
|
19
21
|
import numpy as np
|
|
20
22
|
|
|
@@ -42,7 +44,7 @@ def _sqrt_positive_semidefinite_matrix(mat: np.ndarray) -> np.ndarray:
|
|
|
42
44
|
return vecs @ (np.sqrt(np.abs(eigs)) * vecs).T.conj()
|
|
43
45
|
|
|
44
46
|
|
|
45
|
-
def _validate_int_state(state: int, qid_shape:
|
|
47
|
+
def _validate_int_state(state: int, qid_shape: tuple[int, ...] | None) -> None:
|
|
46
48
|
if state < 0:
|
|
47
49
|
raise ValueError(
|
|
48
50
|
'Invalid state: A state specified as an integer must be non-negative, '
|
|
@@ -58,9 +60,7 @@ def _validate_int_state(state: int, qid_shape: Optional[Tuple[int, ...]]) -> Non
|
|
|
58
60
|
)
|
|
59
61
|
|
|
60
62
|
|
|
61
|
-
def _validate_product_state(
|
|
62
|
-
state: 'cirq.ProductState', qid_shape: Optional[Tuple[int, ...]]
|
|
63
|
-
) -> None:
|
|
63
|
+
def _validate_product_state(state: cirq.ProductState, qid_shape: tuple[int, ...] | None) -> None:
|
|
64
64
|
if qid_shape is not None and qid_shape != (2,) * len(state):
|
|
65
65
|
raise ValueError(
|
|
66
66
|
'Invalid state for given qid shape: '
|
|
@@ -70,9 +70,9 @@ def _validate_product_state(
|
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
def fidelity(
|
|
73
|
-
state1:
|
|
74
|
-
state2:
|
|
75
|
-
qid_shape:
|
|
73
|
+
state1: cirq.QUANTUM_STATE_LIKE,
|
|
74
|
+
state2: cirq.QUANTUM_STATE_LIKE,
|
|
75
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
76
76
|
validate: bool = True,
|
|
77
77
|
atol: float = 1e-7,
|
|
78
78
|
) -> float:
|
|
@@ -156,10 +156,10 @@ def fidelity(
|
|
|
156
156
|
def _numpy_arrays_to_state_vectors_or_density_matrices(
|
|
157
157
|
state1: np.ndarray,
|
|
158
158
|
state2: np.ndarray,
|
|
159
|
-
qid_shape:
|
|
159
|
+
qid_shape: tuple[int, ...] | None,
|
|
160
160
|
validate: bool,
|
|
161
161
|
atol: float,
|
|
162
|
-
) ->
|
|
162
|
+
) -> tuple[np.ndarray, np.ndarray]:
|
|
163
163
|
if state1.ndim > 2 or (state1.ndim == 2 and state1.shape[0] != state1.shape[1]):
|
|
164
164
|
# State tensor, convert to state vector
|
|
165
165
|
state1 = state1.reshape(-1)
|
|
@@ -255,8 +255,8 @@ def _fidelity_state_vectors_or_density_matrices(state1: np.ndarray, state2: np.n
|
|
|
255
255
|
|
|
256
256
|
|
|
257
257
|
def von_neumann_entropy(
|
|
258
|
-
state:
|
|
259
|
-
qid_shape:
|
|
258
|
+
state: cirq.QUANTUM_STATE_LIKE,
|
|
259
|
+
qid_shape: tuple[int, ...] | None = None,
|
|
260
260
|
validate: bool = True,
|
|
261
261
|
atol: float = 1e-7,
|
|
262
262
|
) -> float:
|
|
@@ -298,7 +298,7 @@ def von_neumann_entropy(
|
|
|
298
298
|
return 0.0
|
|
299
299
|
|
|
300
300
|
|
|
301
|
-
def entanglement_fidelity(operation:
|
|
301
|
+
def entanglement_fidelity(operation: cirq.SupportsKraus) -> float:
|
|
302
302
|
r"""Returns entanglement fidelity of a given quantum channel.
|
|
303
303
|
|
|
304
304
|
Entanglement fidelity $F_e$ of a quantum channel $E: L(H) \to L(H)$ is the overlap between
|
cirq/qis/measures_test.py
CHANGED
|
@@ -11,7 +11,11 @@
|
|
|
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
|
"""Tests for measures."""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
15
19
|
import numpy as np
|
|
16
20
|
import pytest
|
|
17
21
|
|
|
@@ -25,7 +29,7 @@ MAT2 = cirq.testing.random_density_matrix(N)
|
|
|
25
29
|
U = cirq.testing.random_unitary(N)
|
|
26
30
|
|
|
27
31
|
|
|
28
|
-
def test_fidelity_symmetric():
|
|
32
|
+
def test_fidelity_symmetric() -> None:
|
|
29
33
|
np.testing.assert_allclose(cirq.fidelity(VEC1, VEC2), cirq.fidelity(VEC2, VEC1))
|
|
30
34
|
np.testing.assert_allclose(cirq.fidelity(VEC1, MAT1), cirq.fidelity(MAT1, VEC1))
|
|
31
35
|
np.testing.assert_allclose(
|
|
@@ -34,27 +38,27 @@ def test_fidelity_symmetric():
|
|
|
34
38
|
)
|
|
35
39
|
|
|
36
40
|
|
|
37
|
-
def test_bad_fidelity():
|
|
41
|
+
def test_bad_fidelity() -> None:
|
|
38
42
|
arr = np.asarray([[[1j, 0], [0, 0]], [[0, 0], [0, 0]]])
|
|
39
43
|
assert arr.ndim > 2
|
|
40
44
|
assert arr.dtype.kind == 'c'
|
|
41
45
|
_ = cirq.fidelity(arr, arr)
|
|
42
46
|
|
|
43
47
|
|
|
44
|
-
def test_fidelity_between_zero_and_one():
|
|
48
|
+
def test_fidelity_between_zero_and_one() -> None:
|
|
45
49
|
assert 0 <= cirq.fidelity(VEC1, VEC2) <= 1
|
|
46
50
|
assert 0 <= cirq.fidelity(VEC1, MAT1) <= 1
|
|
47
51
|
assert 0 <= cirq.fidelity(cirq.density_matrix(MAT1), MAT2) <= 1
|
|
48
52
|
|
|
49
53
|
|
|
50
|
-
def test_fidelity_invariant_under_unitary_transformation():
|
|
54
|
+
def test_fidelity_invariant_under_unitary_transformation() -> None:
|
|
51
55
|
np.testing.assert_allclose(
|
|
52
56
|
cirq.fidelity(cirq.density_matrix(MAT1), MAT2),
|
|
53
57
|
cirq.fidelity(cirq.density_matrix(U @ MAT1 @ U.T.conj()), U @ MAT2 @ U.T.conj()),
|
|
54
58
|
)
|
|
55
59
|
|
|
56
60
|
|
|
57
|
-
def test_fidelity_commuting_matrices():
|
|
61
|
+
def test_fidelity_commuting_matrices() -> None:
|
|
58
62
|
d1 = np.random.uniform(size=N)
|
|
59
63
|
d1 /= np.sum(d1)
|
|
60
64
|
d2 = np.random.uniform(size=N)
|
|
@@ -67,7 +71,7 @@ def test_fidelity_commuting_matrices():
|
|
|
67
71
|
)
|
|
68
72
|
|
|
69
73
|
|
|
70
|
-
def test_fidelity_known_values():
|
|
74
|
+
def test_fidelity_known_values() -> None:
|
|
71
75
|
vec1 = np.array([1, 1j, -1, -1j]) * 0.5
|
|
72
76
|
vec2 = np.array([1, -1, 1, -1], dtype=np.complex128) * 0.5
|
|
73
77
|
vec3 = np.array([1, 0, 0, 0], dtype=np.complex128)
|
|
@@ -94,7 +98,7 @@ def test_fidelity_known_values():
|
|
|
94
98
|
np.testing.assert_allclose(cirq.fidelity(mat3, vec2), 0.7)
|
|
95
99
|
|
|
96
100
|
|
|
97
|
-
def test_fidelity_numpy_arrays():
|
|
101
|
+
def test_fidelity_numpy_arrays() -> None:
|
|
98
102
|
vec1 = np.array([1, 0, 0, 0, 0, 0, 0, 0], dtype=np.complex64)
|
|
99
103
|
vec2 = np.array([1, 0, 0, 0], dtype=np.complex64)
|
|
100
104
|
tensor1 = np.reshape(vec1, (2, 2, 2))
|
|
@@ -122,7 +126,7 @@ def test_fidelity_numpy_arrays():
|
|
|
122
126
|
_ = cirq.fidelity(mat1, mat1)
|
|
123
127
|
|
|
124
128
|
|
|
125
|
-
def test_fidelity_ints():
|
|
129
|
+
def test_fidelity_ints() -> None:
|
|
126
130
|
assert cirq.fidelity(3, 4) == 0.0
|
|
127
131
|
assert cirq.fidelity(4, 4) == 1.0
|
|
128
132
|
|
|
@@ -134,7 +138,7 @@ def test_fidelity_ints():
|
|
|
134
138
|
_ = cirq.fidelity(1, 4, qid_shape=(2,))
|
|
135
139
|
|
|
136
140
|
|
|
137
|
-
def test_fidelity_product_states():
|
|
141
|
+
def test_fidelity_product_states() -> None:
|
|
138
142
|
a, b = cirq.LineQubit.range(2)
|
|
139
143
|
|
|
140
144
|
np.testing.assert_allclose(
|
|
@@ -171,19 +175,19 @@ def test_fidelity_product_states():
|
|
|
171
175
|
)
|
|
172
176
|
|
|
173
177
|
|
|
174
|
-
def test_fidelity_fail_inference():
|
|
178
|
+
def test_fidelity_fail_inference() -> None:
|
|
175
179
|
state_vector = cirq.one_hot(shape=(4,), dtype=np.complex128)
|
|
176
180
|
state_tensor = np.reshape(state_vector, (2, 2))
|
|
177
181
|
with pytest.raises(ValueError, match='Please specify'):
|
|
178
182
|
_ = cirq.fidelity(state_tensor, 4)
|
|
179
183
|
|
|
180
184
|
|
|
181
|
-
def test_fidelity_bad_shape():
|
|
185
|
+
def test_fidelity_bad_shape() -> None:
|
|
182
186
|
with pytest.raises(ValueError, match='Invalid quantum state'):
|
|
183
187
|
_ = cirq.fidelity(np.array([[[1.0]]]), np.array([[[1.0]]]), qid_shape=(1,))
|
|
184
188
|
|
|
185
189
|
|
|
186
|
-
def test_von_neumann_entropy():
|
|
190
|
+
def test_von_neumann_entropy() -> None:
|
|
187
191
|
# 1x1 matrix
|
|
188
192
|
assert cirq.von_neumann_entropy(np.array([[1]])) == 0
|
|
189
193
|
# An EPR pair state (|00> + |11>)(<00| + <11|)
|
|
@@ -243,7 +247,7 @@ def test_von_neumann_entropy():
|
|
|
243
247
|
(cirq.TOFFOLI, 9 / 16),
|
|
244
248
|
),
|
|
245
249
|
)
|
|
246
|
-
def test_entanglement_fidelity_of_unitary_channels(gate, expected_entanglement_fidelity):
|
|
250
|
+
def test_entanglement_fidelity_of_unitary_channels(gate, expected_entanglement_fidelity) -> None:
|
|
247
251
|
assert np.isclose(cirq.entanglement_fidelity(gate), expected_entanglement_fidelity)
|
|
248
252
|
|
|
249
253
|
|
|
@@ -261,7 +265,9 @@ def test_entanglement_fidelity_of_unitary_channels(gate, expected_entanglement_f
|
|
|
261
265
|
(cirq.amplitude_damp, lambda gamma: 1 / 2 - gamma / 4 + np.sqrt(1 - gamma) / 2),
|
|
262
266
|
),
|
|
263
267
|
)
|
|
264
|
-
def test_entanglement_fidelity_of_noisy_channels(
|
|
268
|
+
def test_entanglement_fidelity_of_noisy_channels(
|
|
269
|
+
p, channel_factory, entanglement_fidelity_formula
|
|
270
|
+
) -> None:
|
|
265
271
|
channel = channel_factory(p)
|
|
266
272
|
actual_entanglement_fidelity = cirq.entanglement_fidelity(channel)
|
|
267
273
|
expected_entanglement_fidelity = entanglement_fidelity_formula(p)
|
cirq/qis/noise_utils.py
CHANGED
cirq/qis/noise_utils_test.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 numpy as np
|
|
16
18
|
import pytest
|
|
17
19
|
|
|
@@ -30,7 +32,7 @@ from cirq.qis.noise_utils import (
|
|
|
30
32
|
'decay_constant,num_qubits,expected_output',
|
|
31
33
|
[(0.01, 1, 1 - (0.99 * 1 / 2)), (0.05, 2, 1 - (0.95 * 3 / 4))],
|
|
32
34
|
)
|
|
33
|
-
def test_decay_constant_to_xeb_fidelity(decay_constant, num_qubits, expected_output):
|
|
35
|
+
def test_decay_constant_to_xeb_fidelity(decay_constant, num_qubits, expected_output) -> None:
|
|
34
36
|
val = decay_constant_to_xeb_fidelity(decay_constant, num_qubits)
|
|
35
37
|
assert val == expected_output
|
|
36
38
|
|
|
@@ -39,7 +41,7 @@ def test_decay_constant_to_xeb_fidelity(decay_constant, num_qubits, expected_out
|
|
|
39
41
|
'decay_constant,num_qubits,expected_output',
|
|
40
42
|
[(0.01, 1, 0.99 * 3 / 4), (0.05, 2, 0.95 * 15 / 16)],
|
|
41
43
|
)
|
|
42
|
-
def test_decay_constant_to_pauli_error(decay_constant, num_qubits, expected_output):
|
|
44
|
+
def test_decay_constant_to_pauli_error(decay_constant, num_qubits, expected_output) -> None:
|
|
43
45
|
val = decay_constant_to_pauli_error(decay_constant, num_qubits)
|
|
44
46
|
assert val == expected_output
|
|
45
47
|
|
|
@@ -48,7 +50,7 @@ def test_decay_constant_to_pauli_error(decay_constant, num_qubits, expected_outp
|
|
|
48
50
|
'pauli_error,num_qubits,expected_output',
|
|
49
51
|
[(0.01, 1, 1 - (0.01 / (3 / 4))), (0.05, 2, 1 - (0.05 / (15 / 16)))],
|
|
50
52
|
)
|
|
51
|
-
def test_pauli_error_to_decay_constant(pauli_error, num_qubits, expected_output):
|
|
53
|
+
def test_pauli_error_to_decay_constant(pauli_error, num_qubits, expected_output) -> None:
|
|
52
54
|
val = pauli_error_to_decay_constant(pauli_error, num_qubits)
|
|
53
55
|
assert val == expected_output
|
|
54
56
|
|
|
@@ -57,7 +59,7 @@ def test_pauli_error_to_decay_constant(pauli_error, num_qubits, expected_output)
|
|
|
57
59
|
'xeb_fidelity,num_qubits,expected_output',
|
|
58
60
|
[(0.01, 1, 1 - 0.99 / (1 / 2)), (0.05, 2, 1 - 0.95 / (3 / 4))],
|
|
59
61
|
)
|
|
60
|
-
def test_xeb_fidelity_to_decay_constant(xeb_fidelity, num_qubits, expected_output):
|
|
62
|
+
def test_xeb_fidelity_to_decay_constant(xeb_fidelity, num_qubits, expected_output) -> None:
|
|
61
63
|
val = xeb_fidelity_to_decay_constant(xeb_fidelity, num_qubits)
|
|
62
64
|
assert val == expected_output
|
|
63
65
|
|
|
@@ -69,7 +71,7 @@ def test_xeb_fidelity_to_decay_constant(xeb_fidelity, num_qubits, expected_outpu
|
|
|
69
71
|
(4000, 1e4, (1 - np.exp(-4000 / 2e4)) / 2 + (1 - np.exp(-4000 / 1e4)) / 4),
|
|
70
72
|
],
|
|
71
73
|
)
|
|
72
|
-
def test_pauli_error_from_t1(t, t1_ns, expected_output):
|
|
74
|
+
def test_pauli_error_from_t1(t, t1_ns, expected_output) -> None:
|
|
73
75
|
val = pauli_error_from_t1(t, t1_ns)
|
|
74
76
|
assert val == expected_output
|
|
75
77
|
|
|
@@ -77,7 +79,7 @@ def test_pauli_error_from_t1(t, t1_ns, expected_output):
|
|
|
77
79
|
@pytest.mark.parametrize(
|
|
78
80
|
'decay_constant,num_qubits,expected_output', [(0.01, 1, 0.99 * 1 / 2), (0.05, 2, 0.95 * 3 / 4)]
|
|
79
81
|
)
|
|
80
|
-
def test_average_error(decay_constant, num_qubits, expected_output):
|
|
82
|
+
def test_average_error(decay_constant, num_qubits, expected_output) -> None:
|
|
81
83
|
val = average_error(decay_constant, num_qubits)
|
|
82
84
|
assert val == expected_output
|
|
83
85
|
|
|
@@ -85,7 +87,7 @@ def test_average_error(decay_constant, num_qubits, expected_output):
|
|
|
85
87
|
@pytest.mark.parametrize(
|
|
86
88
|
'T1_ns,Tphi_ns,gate_time_ns', [(1e4, 2e4, 25), (1e5, 2e3, 25), (1e4, 2e4, 4000)]
|
|
87
89
|
)
|
|
88
|
-
def test_decoherence_pauli_error(T1_ns, Tphi_ns, gate_time_ns):
|
|
90
|
+
def test_decoherence_pauli_error(T1_ns, Tphi_ns, gate_time_ns) -> None:
|
|
89
91
|
val = decoherence_pauli_error(T1_ns, Tphi_ns, gate_time_ns)
|
|
90
92
|
# Expected value is of the form:
|
|
91
93
|
#
|