Skip to content

resource

ResourceCreate = Annotated[Annotated[ValidResourceLocal, Tag(ResourceType.LOCAL)] | Annotated[ValidResourceSlurmSudo, Tag(ResourceType.SLURM_SUDO)] | Annotated[ValidResourceSlurmSSH, Tag(ResourceType.SLURM_SSH)], Discriminator(get_discriminator_value)] module-attribute

Schema for resources in API request bodies.

ResourceRead

Bases: BaseModel

Schema for resources in API response bodies.

Source code in fractal_server/app/schemas/v2/resource.py
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
class ResourceRead(BaseModel):
    """
    Schema for resources in API response bodies.
    """

    id: int
    name: str
    type: str
    prevent_new_submissions: bool
    timestamp_created: AwareDatetime

    host: str | None

    jobs_local_dir: str
    jobs_runner_config: dict[str, Any]
    jobs_slurm_python_worker: str | None
    jobs_poll_interval: int

    tasks_local_dir: str
    tasks_python_config: dict[str, Any]
    tasks_pixi_config: dict[str, Any]

ResourceType

Bases: StrEnum

Enum for the possible resource types.

Source code in fractal_server/app/schemas/v2/resource.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class ResourceType(StrEnum):
    """
    Enum for the possible resource types.
    """

    SLURM_SUDO = "slurm_sudo"
    """
    Enum entry for resource type `slurm_sudo`.
    """

    SLURM_SSH = "slurm_ssh"
    """
    Enum entry for resource type `slurm_ssh`.
    """

    LOCAL = "local"
    """
    Enum entry for resource type `local`.
    """

LOCAL = 'local' class-attribute instance-attribute

Enum entry for resource type local.

SLURM_SSH = 'slurm_ssh' class-attribute instance-attribute

Enum entry for resource type slurm_ssh.

SLURM_SUDO = 'slurm_sudo' class-attribute instance-attribute

Enum entry for resource type slurm_sudo.

ValidResourceBase

Bases: BaseModel

Base resource schema.

Source code in fractal_server/app/schemas/v2/resource.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
84
85
86
87
88
89
90
class ValidResourceBase(BaseModel):
    """
    Base resource schema.
    """

    type: ResourceType
    name: NonEmptyStr

    # Tasks
    tasks_python_config: TasksPythonSettings
    tasks_pixi_config: Annotated[
        dict[NonEmptyStr, Any],
        AfterValidator(cast_serialize_pixi_settings),
    ]
    tasks_local_dir: AbsolutePathStr

    # Jobs
    jobs_local_dir: AbsolutePathStr
    jobs_runner_config: dict[NonEmptyStr, Any]
    jobs_poll_interval: int = 5

    prevent_new_submissions: bool = False

    @model_validator(mode="after")
    def _pixi_slurm_config(self) -> Self:
        if (
            self.tasks_pixi_config != {}
            and self.type == ResourceType.SLURM_SSH
            and self.tasks_pixi_config["SLURM_CONFIG"] is None
        ):
            raise ValueError("`tasks_pixi_config` must include `SLURM_CONFIG`.")
        return self

ValidResourceLocal

Bases: ValidResourceBase

Valid local resource.

ATTRIBUTE DESCRIPTION
name

Resource name.

TYPE: NonEmptyStr

type

Resource type.

TYPE: Literal[LOCAL]

prevent_new_submissions

When set to true: Prevent new job submissions and stop execution of ongoing jobs as soon as the current task is complete.

TYPE: bool

tasks_python_config

Configuration of Python interpreters used for task collection.

TYPE: TasksPythonSettings

tasks_pixi_config

Configuration of pixi interpreters used for task collection.

TYPE: Annotated[dict[NonEmptyStr, Any], AfterValidator(cast_serialize_pixi_settings)]

tasks_local_dir

Local base folder for task environments.

TYPE: AbsolutePathStr

jobs_local_dir

Local base folder for job folders.

TYPE: AbsolutePathStr

jobs_runner_config

Runner configuration.

TYPE: JobRunnerConfigLocal

Source code in fractal_server/app/schemas/v2/resource.py
 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
class ValidResourceLocal(ValidResourceBase):
    """
    Valid local resource.

    Attributes:
        name: Resource name.
        type: Resource type.
        prevent_new_submissions:
            When set to true: Prevent new job submissions and stop execution of
            ongoing jobs as soon as the current task is complete.
        tasks_python_config:
            Configuration of Python interpreters used for task collection.
        tasks_pixi_config:
            Configuration of `pixi` interpreters used for task collection.
        tasks_local_dir:
            Local base folder for task environments.
        jobs_local_dir:
            Local base folder for job folders.
        jobs_runner_config:
            Runner configuration.
    """

    type: Literal[ResourceType.LOCAL]
    jobs_runner_config: JobRunnerConfigLocal
    jobs_slurm_python_worker: None = None
    host: None = None

ValidResourceSlurmSSH

Bases: ValidResourceBase

Valid SLURM-SSH resource.

ATTRIBUTE DESCRIPTION
name

Resource name

TYPE: NonEmptyStr

type

Resource type.

TYPE: Literal[SLURM_SSH]

prevent_new_submissions

When set to true: Prevent new job submissions and stop execution of ongoing jobs as soon as the current task is complete.

TYPE: bool

tasks_python_config

Configuration of Python interpreters used for task collection.

TYPE: TasksPythonSettings

tasks_pixi_config

Configuration of pixi interpreters used for task collection.

TYPE: Annotated[dict[NonEmptyStr, Any], AfterValidator(cast_serialize_pixi_settings)]

tasks_local_dir

Local base folder for task environments.

TYPE: AbsolutePathStr

jobs_local_dir

Local base folder for job folders.

TYPE: AbsolutePathStr

jobs_runner_config

Runner configuration.

TYPE: JobRunnerConfigSLURM

jobs_poll_interval

squeue polling interval.

TYPE: int

jobs_slurm_python_worker

Python worker to be used in SLURM jobs.

TYPE: AbsolutePathStr

host

Hostname or IP address of remote SLURM cluster.

TYPE: NonEmptyStr

Source code in fractal_server/app/schemas/v2/resource.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
class ValidResourceSlurmSSH(ValidResourceBase):
    """
    Valid SLURM-SSH resource.

    Attributes:
        name: Resource name
        type: Resource type.
        prevent_new_submissions:
            When set to true: Prevent new job submissions and stop execution of
            ongoing jobs as soon as the current task is complete.
        tasks_python_config:
            Configuration of Python interpreters used for task collection.
        tasks_pixi_config:
            Configuration of `pixi` interpreters used for task collection.
        tasks_local_dir:
            Local base folder for task environments.
        jobs_local_dir:
            Local base folder for job folders.
        jobs_runner_config:
            Runner configuration.
        jobs_poll_interval:
            `squeue` polling interval.
        jobs_slurm_python_worker:
            Python worker to be used in SLURM jobs.
        host:
            Hostname or IP address of remote SLURM cluster.
    """

    type: Literal[ResourceType.SLURM_SSH]
    host: NonEmptyStr
    jobs_slurm_python_worker: AbsolutePathStr
    jobs_runner_config: JobRunnerConfigSLURM

ValidResourceSlurmSudo

Bases: ValidResourceBase

Valid SLURM-sudo resource.

ATTRIBUTE DESCRIPTION
name

Resource name.

TYPE: NonEmptyStr

type

Resource type.

TYPE: Literal[SLURM_SUDO]

prevent_new_submissions

When set to true: Prevent new job submissions and stop execution of ongoing jobs as soon as the current task is complete.

TYPE: bool

tasks_python_config

Configuration of Python interpreters used for task collection.

TYPE: TasksPythonSettings

tasks_pixi_config

Configuration of pixi interpreters used for task collection.

TYPE: Annotated[dict[NonEmptyStr, Any], AfterValidator(cast_serialize_pixi_settings)]

tasks_local_dir

Local base folder for task environments.

TYPE: AbsolutePathStr

jobs_local_dir

Local base folder for job folders.

TYPE: AbsolutePathStr

jobs_runner_config

Runner configuration.

TYPE: JobRunnerConfigSLURM

jobs_poll_interval

squeue polling interval.

TYPE: int

jobs_slurm_python_worker

Python worker to be used in SLURM jobs.

TYPE: AbsolutePathStr

Source code in fractal_server/app/schemas/v2/resource.py
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
146
147
148
149
150
class ValidResourceSlurmSudo(ValidResourceBase):
    """
    Valid SLURM-sudo resource.

    Attributes:
        name: Resource name.
        type: Resource type.
        prevent_new_submissions:
            When set to true: Prevent new job submissions and stop execution of
            ongoing jobs as soon as the current task is complete.
        tasks_python_config:
            Configuration of Python interpreters used for task collection.
        tasks_pixi_config:
            Configuration of `pixi` interpreters used for task collection.
        tasks_local_dir:
            Local base folder for task environments.
        jobs_local_dir:
            Local base folder for job folders.
        jobs_runner_config:
            Runner configuration.
        jobs_poll_interval:
            `squeue` polling interval.
        jobs_slurm_python_worker:
            Python worker to be used in SLURM jobs.
    """

    type: Literal[ResourceType.SLURM_SUDO]
    jobs_slurm_python_worker: AbsolutePathStr
    jobs_runner_config: JobRunnerConfigSLURM
    host: None = None

cast_serialize_pixi_settings(value)

Cast/serialize round trip for tasks_pixi_config through the TasksPixiSettings schema.

PARAMETER DESCRIPTION
value

Current tasks_pixi_config value.

TYPE: dict[NonEmptyStr, Any]

Source code in fractal_server/app/schemas/v2/resource.py
44
45
46
47
48
49
50
51
52
53
54
55
56
def cast_serialize_pixi_settings(
    value: dict[NonEmptyStr, Any],
) -> dict[NonEmptyStr, Any]:
    """
    Cast/serialize round trip for `tasks_pixi_config` through the
    `TasksPixiSettings` schema.

    Arguments:
        value: Current `tasks_pixi_config` value.
    """
    if value != {}:
        value = TasksPixiSettings(**value).model_dump()
    return value

cast_serialize_resource(_data)

Cast/serialize round-trip for Resource data.

We use @validate_call because ResourceCreate is a Union type and it cannot be instantiated directly.

PARAMETER DESCRIPTION
_data

TYPE: ResourceCreate

Return

Serialized version of a valid resource object.

Source code in fractal_server/app/schemas/v2/resource.py
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
@validate_call
def cast_serialize_resource(_data: ResourceCreate) -> dict[str, Any]:
    """
    Cast/serialize round-trip for `Resource` data.

    We use `@validate_call` because `ResourceCreate` is a `Union` type and it
    cannot be instantiated directly.

    Args:
        _data:

    Return:
        Serialized version of a valid resource object.
    """
    return _data.model_dump()