Registry.Job

A computational job managed by a Registry.

Usage

Source

Registry.Job(
    id,
    path,
    params=None,
    status=JobStatus.INITIALISED,
)

A job encapsulates the information required to execute a computation and stores its execution state and result.

Parameters

id: int

The job’s identifier (a natural number).

path: str

Path to the job’s storage folder.

params: dict[str, any] = None

A dictionary of job parameters.

status: JobStatus = JobStatus.INITIALISED

The job’s status. Default is ‘initialised’.

result
The job’s result.

Attributes

id: int

The job’s identifier.

params: dict[str, any]

A dictionary of hyper-parameters for the job.

status: str

The job’s status. One of ‘INITIALISED’, ‘RUNNING’, ‘FAILED’ or ‘DONE’.

tags: set[str]

A set of tags, i.e., keywords that characterise the job (e.g., ‘expensive’).

output_path: str

Path to folder where the jobs output and results shall be stored.

pickle_path: str

Path to file that stores the pickled job persistently.

result_path: str

Path to pickle file that stores the job functions result / return value.

log_path: str
Path to file that stores the logging.

Methods

Name Description
__repr__() Return official string representation, which is aimed at programmers as they develop and maintain a program.
__str__() Return informal readable string representation.
clear_log() Clears the job’s log.
get_id() Return job identifier.
get_log() Read the job’s log.
get_output_path() Return the output path.
get_param_names() Return list of parameter names.
get_params() Return the job’s parameters.
get_result() Return job result.
get_status() Return status.
has_tags() Check if job contains certain tags.
is_done() Has the job finished/done?
is_failed() Has the job failed?
is_initialised() Is the job initialised?
is_running() Is the job running?
log() Write to the job’s log.
reset() Resets the job to the ‘initialised’ state.
set_done() Set job status to finished/done.
set_failed() Set job status to failed.
set_initialised() Set job to initialised.
set_result() Set job result.
set_running() Set job status to running.
tag() Adds tags to jobs.

__repr__()

Return official string representation, which is aimed at programmers as they develop and maintain a program.

Usage

Source

__repr__()
Returns
str
Technical string representation.

__str__()

Return informal readable string representation.

Usage

Source

__str__()
Returns
str
Human-readbale string representation.

clear_log()

Clears the job’s log.

Usage

Source

clear_log()

get_id()

Return job identifier.

Usage

Source

get_id()
Returns
int
The job ID is returned.

get_log()

Read the job’s log.

Usage

Source

get_log()
Returns
str
The log file content as a single string.

get_output_path()

Return the output path.

Usage

Source

get_output_path()
Returns
str
File path to the output folder.

get_param_names()

Return list of parameter names.

Usage

Source

get_param_names()

get_params()

Return the job’s parameters.

Usage

Source

get_params()
Returns
dict[str, any]
A dictionary of parameters. The parameter names are the keys while the values are parameters.

get_result()

Return job result.

Usage

Source

get_result(simplify=False)
Parameters
simplify: bool = False
Should the result be returned as a single dictionary? Default is False.
Returns
tuple[int, dict[str, any], dict[str, any]] | dict[str, any]

The result of the job either as a 3-tuple (jobid, params, result) or a dictionary (dict[str, any])

if simplify is set to True.

get_status()

Return status.

Usage

Source

get_status()

has_tags()

Check if job contains certain tags.

Usage

Source

has_tags(tags)
Parameters
tags: list[str]
list of tags. Each tag is a string.
Returns
bool
A Boolean that is True if the job has all tags appended and False otherwise.

is_done()

Has the job finished/done?

Usage

Source

is_done()

is_failed()

Has the job failed?

Usage

Source

is_failed()

is_initialised()

Is the job initialised?

Usage

Source

is_initialised()

is_running()

Is the job running?

Usage

Source

is_running()

log()

Write to the job’s log.

Usage

Source

log(e)
Parameters
e: Exception
An exception object. The traceback is written to the job’s log-file.
Returns
Self
The callee itself (enables chaining).

reset()

Resets the job to the ‘initialised’ state.

Usage

Source

reset()
Returns
Self
The callee itself (enables chaining).

set_done()

Set job status to finished/done.

Usage

Source

set_done(runtime=None)
Parameters
runtime: float | None = None
Optional runtime of the job. Default is None.
Returns
Self
The callee itself (enables chaining).

set_failed()

Set job status to failed.

Usage

Source

set_failed()
Returns
Self
The callee itself (enables chaining).

set_initialised()

Set job to initialised.

Usage

Source

set_initialised()
Returns
Self
The callee itself (enables chaining).

set_result()

Set job result.

Usage

Source

set_result(result)
Parameters
result: any
Whatever the result is.
Returns
Self
The callee itself (enables chaining).

set_running()

Set job status to running.

Usage

Source

set_running()
Returns
Self
The callee itself (enables chaining).

tag()

Adds tags to jobs.

Usage

Source

tag(tags)
Parameters
tags: list[str]
list of tags. Each tag is a string.
Returns
Self
The callee itself (enables chaining).