Registry.Job
A computational job managed by a Registry.
Usage
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
__repr__()Returns
str- Technical string representation.
__str__()
Return informal readable string representation.
Usage
__str__()Returns
str- Human-readbale string representation.
clear_log()
Clears the job’s log.
Usage
clear_log()get_id()
Return job identifier.
Usage
get_id()Returns
int- The job ID is returned.
get_log()
Read the job’s log.
Usage
get_log()Returns
str- The log file content as a single string.
get_output_path()
Return the output path.
Usage
get_output_path()Returns
str- File path to the output folder.
get_param_names()
Return list of parameter names.
Usage
get_param_names()get_params()
Return the job’s parameters.
Usage
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
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 toTrue.
get_status()
Return status.
Usage
get_status()is_done()
Has the job finished/done?
Usage
is_done()is_failed()
Has the job failed?
Usage
is_failed()is_initialised()
Is the job initialised?
Usage
is_initialised()is_running()
Is the job running?
Usage
is_running()log()
Write to the job’s log.
Usage
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
reset()Returns
Self- The callee itself (enables chaining).
set_done()
Set job status to finished/done.
Usage
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
set_failed()Returns
Self- The callee itself (enables chaining).
set_initialised()
Set job to initialised.
Usage
set_initialised()Returns
Self- The callee itself (enables chaining).
set_result()
Set job result.
Usage
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
set_running()Returns
Self- The callee itself (enables chaining).
tag()
Adds tags to jobs.
Usage
tag(tags)Parameters
tags: list[str]- list of tags. Each tag is a string.
Returns
Self- The callee itself (enables chaining).