Skip to content

compute

AsyncCompute

A compute resource.

description: Optional[str] = Field(None, title='Description') class-attribute instance-attribute

full_name: Optional[str] = Field(None, title='Full Name') class-attribute instance-attribute

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

notes: Optional[List[str]] = Field(None, title='Notes') class-attribute instance-attribute

status: StatusValue instance-attribute

system_type: Optional[str] = Field(None, title='System Type') class-attribute instance-attribute

updated_at: Optional[datetime] = 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)

submit_job(script) async

Parameters:

Name Type Description Default
script Union[str, AsyncRemotePath]

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

required

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]) -> AsyncJobSqueue:
    """Submit a job to the compute resource

    :param script: Path to file on the compute system, or script to run beginning with `#!`.
    :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}

    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)
    result = json.loads(task_result)
    if result.get("status") == "error":
        raise SfApiError(result["error"])

    jobid = result.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