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
123
124
125
126
127
128
129
130
131
@dataclass
class DescribedAnalysis:
    """Complete analysis description. Held by an Executor."""

    task_result: TaskResult
    task_parameters: Optional[TaskParameters]
    task_env: Dict[str, 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
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@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]

    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
113
114
115
116
117
118
119
120
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()

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 str

Short 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@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 (str): Short 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: str
    payload: Any
    impl_schemas: Optional[str] = None

TaskStatus

Bases: Enum

Possible Task statuses.

Source code in lute/tasks/dataclasses.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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.