Skip to content

sunflare.model module

Model

Bases: PModel, Generic[MI]

A boilerplate base class for quick model development.

Users may subclass from this model and provide their custom sunflare.config.ModelInfo implementation.

Example usage:

from sunflare.model import Model
from sunflare.config import ModelInfo
from attrs import define


@define
class MyModelInfo(ModelInfo):
    str_param: str
    bool_param: bool
    # any other parameters...


class MyModel(Model[MyModelInfo]):
    def __init__(self, name: str, model_info: MyModelInfo) -> None:
        super().__init__(name, model_info)
        # any other initialization code...

Parameters:

Name Type Description Default
name ``str``

Name of the model. Serves as a unique identifier for the object created from it.

required
model_info ``MI``

Instance of sunflare.config.ModelInfo subclass.

required
Source code in src/sunflare/model/_base.py
class Model(PModel, Generic[MI]):
    """A boilerplate base class for quick model development.

    Users may subclass from this model and provide their custom
    `sunflare.config.ModelInfo` implementation.

    Example usage:

    ```python
    from sunflare.model import Model
    from sunflare.config import ModelInfo
    from attrs import define


    @define
    class MyModelInfo(ModelInfo):
        str_param: str
        bool_param: bool
        # any other parameters...


    class MyModel(Model[MyModelInfo]):
        def __init__(self, name: str, model_info: MyModelInfo) -> None:
            super().__init__(name, model_info)
            # any other initialization code...
    ```

    Parameters
    ----------
    name : ``str``
        Name of the model. Serves as a unique identifier for the object created from it.
    model_info : ``MI``
        Instance of `sunflare.config.ModelInfo` subclass.
    """

    def __init__(self, name: str, model_info: MI) -> None:
        self._name = name
        self._model_info = model_info

    def describe_configuration(self) -> SyncOrAsync[dict[str, Descriptor]]:
        """Provide a description of the model configuration.

        Inspects the local ``model_info`` object and
        returns a descriptor dictionary compatible
        with the Bluesky event model.

        Returns
        -------
        dict[``str``, `event_model.DataKey`]
            A dictionary with the description of each field of the model configuration.
        """
        return self._model_info.describe_configuration()

    def read_configuration(self) -> SyncOrAsync[dict[str, Reading[Any]]]:
        """Provide a description of the model configuration.

        Inspects the local ``model_info`` object and
        returns a reading dictionary compatible
        with the Bluesky event model.

        Returns
        -------
        dict[``str``, `bluesky.protocols.Descriptor`]
            A dictionary with the description of each field of the model configuration.
        """
        return self._model_info.read_configuration()

    @property
    def name(self) -> str:
        return self._name

    @property
    def model_info(self) -> MI:
        return self._model_info

    @property
    def parent(self) -> None:
        return None

describe_configuration

describe_configuration() -> SyncOrAsync[
    dict[str, Descriptor]
]

Provide a description of the model configuration.

Inspects the local model_info object and returns a descriptor dictionary compatible with the Bluesky event model.

Returns:

Type Description
dict[``str``, `event_model.DataKey`]

A dictionary with the description of each field of the model configuration.

Source code in src/sunflare/model/_base.py
def describe_configuration(self) -> SyncOrAsync[dict[str, Descriptor]]:
    """Provide a description of the model configuration.

    Inspects the local ``model_info`` object and
    returns a descriptor dictionary compatible
    with the Bluesky event model.

    Returns
    -------
    dict[``str``, `event_model.DataKey`]
        A dictionary with the description of each field of the model configuration.
    """
    return self._model_info.describe_configuration()

read_configuration

read_configuration() -> SyncOrAsync[
    dict[str, Reading[Any]]
]

Provide a description of the model configuration.

Inspects the local model_info object and returns a reading dictionary compatible with the Bluesky event model.

Returns:

Type Description
dict[``str``, `bluesky.protocols.Descriptor`]

A dictionary with the description of each field of the model configuration.

Source code in src/sunflare/model/_base.py
def read_configuration(self) -> SyncOrAsync[dict[str, Reading[Any]]]:
    """Provide a description of the model configuration.

    Inspects the local ``model_info`` object and
    returns a reading dictionary compatible
    with the Bluesky event model.

    Returns
    -------
    dict[``str``, `bluesky.protocols.Descriptor`]
        A dictionary with the description of each field of the model configuration.
    """
    return self._model_info.read_configuration()

PModel

Bases: HasName, HasParent, Configurable[Any], Protocol

Minimal required protocol for a recognizable device in Redsun.

Exposes the following Bluesky protocols:

Source code in src/sunflare/model/_protocols.py
@runtime_checkable
class PModel(HasName, HasParent, Configurable[Any], Protocol):  # pragma: no cover
    """Minimal required protocol for a recognizable device in Redsun.

    Exposes the following Bluesky protocols:

    - [`bluesky.protocols.HasName`]()
    - [`bluesky.protocols.HasParent`]()
    - [`bluesky.protocols.Configurable`]()
    """

    @property
    @abstractmethod
    def model_info(self) -> PModelInfo:
        """The associated model information.

        It can return a subclass of `sunflare.config.ModelInfo`.
        """
        ...

model_info abstractmethod property

model_info: PModelInfo

The associated model information.

It can return a subclass of sunflare.config.ModelInfo.