Skip to content

dataclasses

Classes for describing Task state and results.

Classes:

Name Description
TaskResult

Output of a specific analysis task.

TaskStatus

Enumeration of possible Task statuses (running, pending, failed, etc.).

DescribedAnalysis

Executor's description of a Task run (results, parameters, env).

DescribedAnalysis dataclass

Complete analysis description. Held by an Executor.

Source code in lute/tasks/dataclasses.py
148
149
150
151
152
153
154
155
156
157
@dataclass
class DescribedAnalysis:
    """Complete analysis description. Held by an Executor."""

    task_result: TaskResult
    task_parameters: Optional[TaskParameters]
    task_env: Dict[str, str]
    executor_name: str
    poll_interval: float
    communicator_desc: List[str]

ElogSummaryPlots dataclass

Holds a graphical summary intended for display in the eLog.

Converts figures to a byte stream of HTML data to be written out, so the eLog can properly display them.

Attributes:

Name Type Description
display_name str

This represents both a path and how the result will be displayed in the eLog. Can include "/" characters. E.g. display_name = "scans/my_motor_scan" will have plots shown on a "my_motor_scan" page, under a "scans" tab. This format mirrors how the file is stored on disk as well.

figures (Tabs, Image, Figure, bytes)

The figures to be displayed. Except panel/holoviews (bokeh backend) and matplotlib plots as well as a raw series of bytes for the HTML file. Figures from the plotting libraries will be converted to an HTML byte stream automatically.

Source code in lute/tasks/dataclasses.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@dataclass
class ElogSummaryPlots:
    """Holds a graphical summary intended for display in the eLog.

    Converts figures to a byte stream of HTML data to be written out, so the
    eLog can properly display them.

    Attributes:
        display_name (str): This represents both a path and how the result will be
            displayed in the eLog. Can include "/" characters. E.g.
            `display_name = "scans/my_motor_scan"` will have plots shown
            on a "my_motor_scan" page, under a "scans" tab. This format mirrors
            how the file is stored on disk as well.

        figures (pn.Tabs, hv.Image, plt.Figure, bytes): The figures to be
            displayed. Except panel/holoviews (bokeh backend) and matplotlib
            plots as well as a raw series of bytes for the HTML file. Figures from
            the plotting libraries will be converted to an HTML byte stream
            automatically.
    """

    display_name: str
    figures: Union[pn.Tabs, hv.Image, plt.Figure, bytes]  # type: ignore # noqa: F821

    def __post_init__(self) -> None:
        self._setup_figures()

    def _setup_figures(self) -> None:
        """Convert figures to an HTML file in a byte stream."""

        if hasattr(self.figures, "save"):
            f: io.BytesIO = io.BytesIO()
            self.figures.save(f)
            f.seek(0)
            self.figures = f.read()

_setup_figures()

Convert figures to an HTML file in a byte stream.

Source code in lute/tasks/dataclasses.py
138
139
140
141
142
143
144
145
def _setup_figures(self) -> None:
    """Convert figures to an HTML file in a byte stream."""

    if hasattr(self.figures, "save"):
        f: io.BytesIO = io.BytesIO()
        self.figures.save(f)
        f.seek(0)
        self.figures = f.read()

TaskParametersDBReference dataclass

Contains information about how to reconstruct a TaskParameters object.

Attributes:

Name Type Description
db_dir str

The path to the database containing the TaskParameters schema definition.

row_ids RowIds

The ids of the rows in the various tables required for reconstructing the TaskParameters object.

Source code in lute/tasks/dataclasses.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@dataclass
class TaskParametersDBReference:
    """Contains information about how to reconstruct a TaskParameters object.

    Attributes:
        db_dir (str): The path to the database containing the TaskParameters
            schema definition.

        row_ids (RowIds): The ids of the rows in the various tables required for
            reconstructing the TaskParameters object.
    """

    db_dir: str
    row_ids: RowIds

TaskResult dataclass

Class for storing the result of a Task's execution with metadata.

Attributes:

Name Type Description
task_name str

Name of the associated task which produced it.

task_status TaskStatus

Status of associated task.

summary Any

Short (usually text message) summary associated with the result.

payload Any

Actual result. May be data in any format.

impl_schemas Optional[str]

A string listing Task schemas implemented by the associated Task. Schemas define the category and expected output of the Task. An individual task may implement/conform to multiple schemas. Multiple schemas are separated by ';', e.g. * impl_schemas = "schema1;schema2"

Source code in lute/tasks/dataclasses.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
@dataclass
class TaskResult:
    """Class for storing the result of a Task's execution with metadata.

    Attributes:
        task_name (str): Name of the associated task which produced it.

        task_status (TaskStatus): Status of associated task.

        summary (Any): Short (usually text message) summary associated with the result.

        payload (Any): Actual result. May be data in any format.

        impl_schemas (Optional[str]): A string listing `Task` schemas implemented
            by the associated `Task`. Schemas define the category and expected
            output of the `Task`. An individual task may implement/conform to
            multiple schemas. Multiple schemas are separated by ';', e.g.
                * impl_schemas = "schema1;schema2"
    """

    task_name: str
    task_status: TaskStatus
    summary: Any
    payload: Any
    impl_schemas: Optional[str] = None

TaskStatus

Bases: Enum

Possible Task statuses.

Source code in lute/tasks/dataclasses.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class TaskStatus(Enum):
    """Possible Task statuses."""

    PENDING = 0
    """
    Task has yet to run. Is Queued, or waiting for prior tasks.
    """
    RUNNING = 1
    """
    Task is in the process of execution.
    """
    COMPLETED = 2
    """
    Task has completed without fatal errors.
    """
    FAILED = 3
    """
    Task encountered a fatal error.
    """
    STOPPED = 4
    """
    Task was, potentially temporarily, stopped/suspended.
    """
    CANCELLED = 5
    """
    Task was cancelled prior to completion or failure.
    """
    TIMEDOUT = 6
    """
    Task did not reach completion due to timeout.
    """

CANCELLED = 5 class-attribute instance-attribute

Task was cancelled prior to completion or failure.

COMPLETED = 2 class-attribute instance-attribute

Task has completed without fatal errors.

FAILED = 3 class-attribute instance-attribute

Task encountered a fatal error.

PENDING = 0 class-attribute instance-attribute

Task has yet to run. Is Queued, or waiting for prior tasks.

RUNNING = 1 class-attribute instance-attribute

Task is in the process of execution.

STOPPED = 4 class-attribute instance-attribute

Task was, potentially temporarily, stopped/suspended.

TIMEDOUT = 6 class-attribute instance-attribute

Task did not reach completion due to timeout.