Skip to content

resource

CLASS DESCRIPTION
Resource

Resource table.

Classes

Resource

Bases: Base

Resource table.

ATTRIBUTE DESCRIPTION
host

Address for ssh connections, when type="slurm_ssh".

TYPE: Mapped[str | None]

jobs_local_dir

Base local folder for job subfolders (containing artifacts and logs).

TYPE: Mapped[str]

jobs_poll_interval

On SLURM resources: the interval to wait before new squeue calls.

TYPE: Mapped[int]

jobs_runner_config

Runner configuration, matching one of JobRunnerConfigLocal or

TYPE: Mapped[dict[str, Any]]

jobs_slurm_python_worker

On SLURM deloyments, this is the Python interpreter that runs the

TYPE: Mapped[str | None]

name

Resource name.

TYPE: Mapped[str]

pip_cache_dir_arg

If pip_cache_dir is set (in self.tasks_python_config), then

TYPE: str

prevent_new_submissions

When set to true: Prevent new job submissions and stop execution of

TYPE: Mapped[bool]

tasks_local_dir

Base local folder for task-package subfolders.

TYPE: Mapped[str]

tasks_pixi_config

Pixi configuration for task collection. Basic example:

TYPE: Mapped[dict[str, Any]]

tasks_python_config

Python configuration for task collection. Example:

TYPE: Mapped[dict[str, Any]]

timestamp_created

Creation timestamp (autogenerated).

TYPE: Mapped[datetime]

type

One of local, slurm_sudo or slurm_ssh - matching with

TYPE: Mapped[str]

Source code in fractal_server/app/models/v2/resource.py
class Resource(Base):
    """
    Resource table.
    """

    __tablename__ = "resource"

    id: Mapped[int] = mapped_column(primary_key=True)

    type: Mapped[str]
    """
    One of `local`, `slurm_sudo` or `slurm_ssh` - matching with
    `settings.FRACTAL_RUNNER_BACKEND`.
    """

    name: Mapped[str] = mapped_column(unique=True)
    """
    Resource name.
    """

    timestamp_created: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )
    """
    Creation timestamp (autogenerated).
    """

    host: Mapped[str | None] = mapped_column(default=lambda: None)
    """
    Address for ssh connections, when `type="slurm_ssh"`.
    """

    prevent_new_submissions: Mapped[bool] = mapped_column(
        BOOLEAN,
        server_default="false",
        nullable=False,
    )
    """
    When set to true: Prevent new job submissions and stop execution of
    ongoing jobs as soon as the current task is complete.
    """

    jobs_local_dir: Mapped[str]
    """
    Base local folder for job subfolders (containing artifacts and logs).
    """

    jobs_runner_config: Mapped[dict[str, Any]] = mapped_column(
        JSONB, nullable=False, server_default="{}"
    )
    """
    Runner configuration, matching one of `JobRunnerConfigLocal` or
    `JobRunnerConfigSLURM` schemas.
    """

    jobs_slurm_python_worker: Mapped[str | None] = mapped_column(
        default=lambda: None
    )
    """
    On SLURM deloyments, this is the Python interpreter that runs the
    `fractal-server` worker from within the SLURM jobs.
    """

    jobs_poll_interval: Mapped[int]
    """
    On SLURM resources: the interval to wait before new `squeue` calls.
    On local resources: ignored.
    """

    # task_settings
    tasks_local_dir: Mapped[str]
    """
    Base local folder for task-package subfolders.
    """

    tasks_python_config: Mapped[dict[str, Any]] = mapped_column(
        JSONB, nullable=False, server_default="{}"
    )
    """
    Python configuration for task collection. Example:
    ```json
    {
      "default_version": "3.10",
      "versions:{
        "3.10": "/xxx/venv-3.10/bin/python",
        "3.11": "/xxx/venv-3.11/bin/python",
        "3.12": "/xxx/venv-3.12/bin/python"
       }
    }
    ```
    """

    tasks_pixi_config: Mapped[dict[str, Any]] = mapped_column(
        JSONB, nullable=False, server_default="{}"
    )
    """
    Pixi configuration for task collection. Basic example:
    ```json
    {
        "default_version": "0.41.0",
        "versions": {
            "0.40.0": "/xxx/pixi/0.40.0/",
            "0.41.0": "/xxx/pixi/0.41.0/"
        },
    }
    ```
    """

    @property
    def pip_cache_dir_arg(self: Self) -> str:
        """
        If `pip_cache_dir` is set (in `self.tasks_python_config`), then
        return `--cache_dir /something`; else return `--no-cache-dir`.
        """
        _pip_cache_dir = self.tasks_python_config.get("pip_cache_dir", None)
        if _pip_cache_dir is not None:
            return f"--cache-dir {_pip_cache_dir}"
        else:
            return "--no-cache-dir"

    # Check constraints
    __table_args__ = (
        # `type` column must be one of "local", "slurm_sudo" or "slurm_ssh"
        CheckConstraint(
            "type IN ('local', 'slurm_sudo', 'slurm_ssh')",
            name="correct_type",
        ),
        # If `type` is not "local", `jobs_slurm_python_worker` must be set
        CheckConstraint(
            "(type = 'local') OR (jobs_slurm_python_worker IS NOT NULL)",
            name="jobs_slurm_python_worker_set",
        ),
    )

Attributes

host = mapped_column(default=lambda: None) class-attribute instance-attribute

Address for ssh connections, when type="slurm_ssh".

jobs_local_dir instance-attribute

Base local folder for job subfolders (containing artifacts and logs).

jobs_poll_interval instance-attribute

On SLURM resources: the interval to wait before new squeue calls. On local resources: ignored.

jobs_runner_config = mapped_column(JSONB, nullable=False, server_default='{}') class-attribute instance-attribute

Runner configuration, matching one of JobRunnerConfigLocal or JobRunnerConfigSLURM schemas.

jobs_slurm_python_worker = mapped_column(default=lambda: None) class-attribute instance-attribute

On SLURM deloyments, this is the Python interpreter that runs the fractal-server worker from within the SLURM jobs.

name = mapped_column(unique=True) class-attribute instance-attribute

Resource name.

pip_cache_dir_arg property

If pip_cache_dir is set (in self.tasks_python_config), then return --cache_dir /something; else return --no-cache-dir.

prevent_new_submissions = mapped_column(BOOLEAN, server_default='false', nullable=False) class-attribute instance-attribute

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

tasks_local_dir instance-attribute

Base local folder for task-package subfolders.

tasks_pixi_config = mapped_column(JSONB, nullable=False, server_default='{}') class-attribute instance-attribute

Pixi configuration for task collection. Basic example:

1
2
3
4
5
6
7
{
    "default_version": "0.41.0",
    "versions": {
        "0.40.0": "/xxx/pixi/0.40.0/",
        "0.41.0": "/xxx/pixi/0.41.0/"
    },
}

tasks_python_config = mapped_column(JSONB, nullable=False, server_default='{}') class-attribute instance-attribute

Python configuration for task collection. Example:

1
2
3
4
5
6
7
8
{
  "default_version": "3.10",
  "versions:{
    "3.10": "/xxx/venv-3.10/bin/python",
    "3.11": "/xxx/venv-3.11/bin/python",
    "3.12": "/xxx/venv-3.12/bin/python"
   }
}

timestamp_created = mapped_column(DateTime(timezone=True), nullable=False, default=get_timestamp) class-attribute instance-attribute

Creation timestamp (autogenerated).

type instance-attribute

One of local, slurm_sudo or slurm_ssh - matching with settings.FRACTAL_RUNNER_BACKEND.

Functions: