Skip to content

BaseDecoder

Bases: ABC

Simple base interface for quantum error correction decoders.

This is a pragmatic base class that provides a common interface for different decoding strategies without being overly abstract. Each decoder implementation handles its specific requirements while maintaining a consistent API.

Source code in src/color_code_stim/decoders/base.py
class BaseDecoder(ABC):
    """
    Simple base interface for quantum error correction decoders.

    This is a pragmatic base class that provides a common interface for
    different decoding strategies without being overly abstract. Each decoder
    implementation handles its specific requirements while maintaining a
    consistent API.
    """

    @abstractmethod
    def decode(self, detector_outcomes: np.ndarray, **kwargs) -> np.ndarray:
        """
        Decode detector outcomes to predict observables.

        Parameters
        ----------
        detector_outcomes : np.ndarray
            1D or 2D array of detector measurement outcomes.
            If 1D, interpreted as a single sample.
            If 2D, each row is a sample, each column a detector.

        **kwargs
            Additional decoder-specific parameters.

        Returns
        -------
        np.ndarray
            Predicted observable outcomes. Shape depends on the decoder
            implementation and input dimensions.
        """
        pass

    def supports_comparative_decoding(self) -> bool:
        """
        Check if this decoder supports comparative decoding.

        Returns
        -------
        bool
            True if the decoder can test multiple logical classes
            and return logical gaps for magic state distillation.
        """
        return False

    def supports_predecoding(self) -> bool:
        """
        Check if this decoder supports pre-decoding strategies.

        Returns
        -------
        bool
            True if the decoder supports erasure matching or
            belief propagation pre-decoding.
        """
        return False

decode(detector_outcomes, **kwargs) abstractmethod

Decode detector outcomes to predict observables.

Parameters:

Name Type Description Default
detector_outcomes ndarray

1D or 2D array of detector measurement outcomes. If 1D, interpreted as a single sample. If 2D, each row is a sample, each column a detector.

required
**kwargs

Additional decoder-specific parameters.

{}

Returns:

Type Description
ndarray

Predicted observable outcomes. Shape depends on the decoder implementation and input dimensions.

Source code in src/color_code_stim/decoders/base.py
@abstractmethod
def decode(self, detector_outcomes: np.ndarray, **kwargs) -> np.ndarray:
    """
    Decode detector outcomes to predict observables.

    Parameters
    ----------
    detector_outcomes : np.ndarray
        1D or 2D array of detector measurement outcomes.
        If 1D, interpreted as a single sample.
        If 2D, each row is a sample, each column a detector.

    **kwargs
        Additional decoder-specific parameters.

    Returns
    -------
    np.ndarray
        Predicted observable outcomes. Shape depends on the decoder
        implementation and input dimensions.
    """
    pass

supports_comparative_decoding()

Check if this decoder supports comparative decoding.

Returns:

Type Description
bool

True if the decoder can test multiple logical classes and return logical gaps for magic state distillation.

Source code in src/color_code_stim/decoders/base.py
def supports_comparative_decoding(self) -> bool:
    """
    Check if this decoder supports comparative decoding.

    Returns
    -------
    bool
        True if the decoder can test multiple logical classes
        and return logical gaps for magic state distillation.
    """
    return False

supports_predecoding()

Check if this decoder supports pre-decoding strategies.

Returns:

Type Description
bool

True if the decoder supports erasure matching or belief propagation pre-decoding.

Source code in src/color_code_stim/decoders/base.py
def supports_predecoding(self) -> bool:
    """
    Check if this decoder supports pre-decoding strategies.

    Returns
    -------
    bool
        True if the decoder supports erasure matching or
        belief propagation pre-decoding.
    """
    return False