Skip to content

compute

AsyncCompute

A compute resource.

description = Field(None, title='Description') class-attribute instance-attribute

full_name = Field(None, title='Full Name') class-attribute instance-attribute

name = Field(..., title='Name') class-attribute instance-attribute

notes = Field(None, title='Notes') class-attribute instance-attribute

status instance-attribute

system_type = Field(None, title='System Type') class-attribute instance-attribute

updated_at = Field(None, title='Updated At') class-attribute instance-attribute

Source code in sfapi_client/_async/compute.py
def __init__(self, **kwargs):
    super().__init__(**kwargs)
    self._monitor = AsyncJobMonitor(self)

run_task(args) async

Parameters:

Name Type Description Default
args Union[str, AsyncRemotePath, List[str]]

Command to execute.

required

Returns:

Type Description
AsyncCommandTask

Task object that can be awaited ( async version ), updated, or cancelled.

Source code in sfapi_client/_async/compute.py
@check_auth
async def run_task(
    self, args: Union[str, AsyncRemotePath, List[str]]
) -> AsyncCommandTask:
    """
    Submit a command to the compute resource and return a task.

    :param args: Command to execute.
    :return: Task object that can be awaited ( async version ), updated, or cancelled.
    """
    return await self._run_task(args)

submit_job(script, args=None) async

Parameters:

Name Type Description Default
script Union[str, AsyncRemotePath]

Path to file on the compute system, or script to run beginning with #!.

required
args Optional[List[str]]

An optional list of command line arguments to pass to the script.

None

Returns:

Type Description
AsyncJobSqueue

Object containing information about the job, its job id, and status on the system.

Source code in sfapi_client/_async/compute.py
@check_auth
async def submit_job(
    self, script: Union[str, AsyncRemotePath], args: Optional[List[str]] = None
) -> AsyncJobSqueue:
    """Submit a job to the compute resource

    :param script: Path to file on the compute system, or script to run beginning with `#!`.
    :param args: An optional list of command line arguments to pass to the script.
    :return: Object containing information about the job, its job id, and status on the system.
    """

    is_path: bool = True

    # If it's a remote path we've already checked so just continue
    if isinstance(script, AsyncRemotePath):
        pass
    # If the string input looks like a script we'll set is_path to false
    elif script.startswith("#!") and "\n" in script:
        # If it starts with shebang and has multiple lines
        is_path = False
    else:
        # If we're given a path make sure it exists
        script_path = await self.ls(script)
        is_file = await script_path[0].is_file()
        if len(script_path) != 1 or not is_file:
            raise SfApiError(f"Script path not present or is not a file, {script}")

    data = {"job": script, "isPath": is_path}
    if args is not None:
        if not is_path:
            raise ValueError(
                "Command line arguments cannot be passed when the script is not a file."
            )
        data["args"] = args

    r = await self.client.post(f"compute/jobs/{self.name}", data)
    r.raise_for_status()

    json_response = r.json()
    job_response = SubmitJobResponse.model_validate(json_response)

    if job_response.status == SubmitJobResponseStatus.ERROR:
        raise SfApiError(job_response.error)

    task_id = job_response.task_id

    # We now need waiting for the task to complete!
    task_result = await self._wait_for_task(task_id)
    if task_result.status == "error":
        raise SfApiError(task_result.error)

    # Get the jobid from the extra fields of the result
    jobid = task_result.__pydantic_extra__.get("jobid")
    if jobid is None:
        raise SfApiError(f"Unable to extract jobid if for task: {task_id}")

    job = AsyncJobSqueue(jobid=jobid, compute=self)

    return job

Machine

The possible compute resources.

Bases: str, Enum

dtn01 = 'dtn01' class-attribute instance-attribute

dtns = 'dtns' class-attribute instance-attribute

perlmutter = 'perlmutter' class-attribute instance-attribute