## Registry.Job


A computational job managed by a [Registry](Registry.Registry.md#pyrallex.Registry.Registry).


Usage

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

------------------------------------------------------------------------


#### \_\_repr\_\_()


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


Usage

``` python
__repr__()
```


##### Returns


`str`  
Technical string representation.


------------------------------------------------------------------------


#### \_\_str\_\_()


Return informal readable string representation.


Usage

``` python
__str__()
```


##### Returns


`str`  
Human-readbale string representation.


------------------------------------------------------------------------


#### clear_log()


Clears the job's log.


Usage

``` python
clear_log()
```


------------------------------------------------------------------------


#### get_id()


Return job identifier.


Usage

``` python
get_id()
```


##### Returns


`int`  
The job ID is returned.


------------------------------------------------------------------------


#### get_log()


Read the job's log.


Usage

``` python
get_log()
```


##### Returns


`str`  
The log file content as a single string.


------------------------------------------------------------------------


#### get_output_path()


Return the output path.


Usage

``` python
get_output_path()
```


##### Returns


`str`  
File path to the output folder.


------------------------------------------------------------------------


#### get_param_names()


Return list of parameter names.


Usage

``` python
get_param_names()
```


------------------------------------------------------------------------


#### get_params()


Return the job's parameters.


Usage

``` python
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

``` python
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

``` python
get_status()
```


------------------------------------------------------------------------


#### has_tags()


Check if job contains certain tags.


Usage

``` python
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

``` python
is_done()
```


------------------------------------------------------------------------


#### is_failed()


Has the job failed?


Usage

``` python
is_failed()
```


------------------------------------------------------------------------


#### is_initialised()


Is the job initialised?


Usage

``` python
is_initialised()
```


------------------------------------------------------------------------


#### is_running()


Is the job running?


Usage

``` python
is_running()
```


------------------------------------------------------------------------


#### log()


Write to the job's log.


Usage

``` python
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

``` python
reset()
```


##### Returns


`Self`  
The callee itself (enables chaining).


------------------------------------------------------------------------


#### set_done()


Set job status to finished/done.


Usage

``` python
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

``` python
set_failed()
```


##### Returns


`Self`  
The callee itself (enables chaining).


------------------------------------------------------------------------


#### set_initialised()


Set job to initialised.


Usage

``` python
set_initialised()
```


##### Returns


`Self`  
The callee itself (enables chaining).


------------------------------------------------------------------------


#### set_result()


Set job result.


Usage

``` python
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

``` python
set_running()
```


##### Returns


`Self`  
The callee itself (enables chaining).


------------------------------------------------------------------------


#### tag()


Adds tags to jobs.


Usage

``` python
tag(tags)
```


##### Parameters


`tags: list[str]`  
list of tags. Each tag is a string.


##### Returns


`Self`  
The callee itself (enables chaining).
