|
| 1 | +# Copyright 2025 Google LLC |
| 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 | +# http:#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 | +""" |
| 16 | +This module is a dispatcher for DEMfunctionality such as decomposition and re-generalization, |
| 17 | +and related utilities, in `decompose_errors.py` and `generalize_dem.py`. |
| 18 | +""" |
| 19 | + |
| 20 | + |
| 21 | +import stim |
| 22 | + |
| 23 | +from .decompose_errors import ( |
| 24 | + reduce_symmetric_difference as reduce_symmetric_difference, |
| 25 | + reduce_set_symmetric_difference as reduce_set_symmetric_difference, |
| 26 | + undecomposed_error_detectors_and_observables as undecomposed_error_detectors_and_observables, |
| 27 | + get_component_obs_matching_undecomposed_obs as get_component_obs_matching_undecomposed_obs, |
| 28 | + decompose_errors_using_detector_assignment as decompose_errors_using_detector_assignment, |
| 29 | + decompose_errors_using_detector_coordinate_assignment as decompose_errors_using_detector_coordinate_assignment, |
| 30 | + detector_coord_to_basis_for_stim_surface_code_convention as detector_coord_to_basis_for_stim_surface_code_convention, |
| 31 | + decompose_errors_using_last_coordinate_index as decompose_errors_using_last_coordinate_index, |
| 32 | + decompose_errors_for_stim_surface_code_coords as decompose_errors_for_stim_surface_code_coords, |
| 33 | + undecompose_errors as undecompose_errors, |
| 34 | +) |
| 35 | +from .generalize_dem import generalize as regeneralize_spatial_dem |
| 36 | + |
| 37 | + |
| 38 | +__all__ = [ |
| 39 | + "decompose_errors", |
| 40 | + "regeneralize_spatial_dem", |
| 41 | + "reduce_symmetric_difference", |
| 42 | + "reduce_set_symmetric_difference", |
| 43 | + "undecomposed_error_detectors_and_observables", |
| 44 | + "get_component_obs_matching_undecomposed_obs", |
| 45 | + "decompose_errors_using_detector_assignment", |
| 46 | + "decompose_errors_using_detector_coordinate_assignment", |
| 47 | + "detector_coord_to_basis_for_stim_surface_code_convention", |
| 48 | + "decompose_errors_using_last_coordinate_index", |
| 49 | + "decompose_errors_for_stim_surface_code_coords", |
| 50 | + "undecompose_errors", |
| 51 | +] |
| 52 | + |
| 53 | + |
| 54 | +def decompose_errors( |
| 55 | + dem: stim.DetectorErrorModel, method: str = "stim-surfacecode-coords" |
| 56 | +) -> stim.DetectorErrorModel: |
| 57 | + """Dispatch decomposition strategy by method name.""" |
| 58 | + if method == "stim-surfacecode-coords": |
| 59 | + return decompose_errors_for_stim_surface_code_coords(dem) |
| 60 | + if method == "last-coordinate-index": |
| 61 | + return decompose_errors_using_last_coordinate_index(dem) |
| 62 | + raise ValueError( |
| 63 | + "Unknown decomposition method " |
| 64 | + f"{method!r}. Expected 'stim-surfacecode-coords' or 'last-coordinate-index'." |
| 65 | + ) |
0 commit comments