tasks
CheckException
Bases: EnsembleException
For check failures
ProcessingException
Bases: EnsembleException
For general processing failures
TaskException
Bases: EnsembleException
For task processing failures
check(ctx, cmd, cwd=None, log=False, fail=False, shell=None)
async
Check: Call arbitrary command as a check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
cmd
|
str
|
See |
required |
cwd
|
str
|
See |
None
|
log
|
bool
|
See |
False
|
fail
|
bool
|
If true, then the check returning nonzero will raise an error rather than return false, meaning run abandonment rather than recheck will take place. |
False
|
shell
|
str
|
See |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if return code is zero, false otherwise. |
Raises:
| Type | Description |
|---|---|
FailureNotToleratedError
|
Error when fail is true and the check returns a nonzero code. |
Source code in model_ensembler/tasks/sys.py
execute(ctx, cmd, cwd=None, log=False, shell=None)
async
Process: Call arbitrary command as a processing task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
cmd
|
str
|
See |
required |
cwd
|
str
|
See |
None
|
log
|
bool
|
See |
False
|
shell
|
str
|
See |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if return code is zero, false otherwise. |
Source code in model_ensembler/tasks/sys.py
jobs(ctx, limit, match)
async
Check: Assert whether number of jobs in SLURM is under limit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
limit
|
int
|
Number of jobs to check for. |
required |
match
|
str
|
Prefix to match jobs by. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if number of jobs is less than limit, otherwise false. |
Source code in model_ensembler/tasks/hpc.py
move(ctx, dest, include=None, exclude=None, cwd=None)
async
Process: rsync current working directory contents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
dest
|
str
|
Path to copy ctx.id named directory to. |
required |
include
|
List[str]
|
rsync include specifiers. |
None
|
exclude
|
List[str]
|
rsync exclude specifiers, defaults to "*" when calling rsync if include specifiers are given and no exclude specifiers are provided. |
None
|
cwd
|
str
|
See |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
true if return code is zero, false otherwise. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If did not provide necessary context attribute for using this processing task. |
Source code in model_ensembler/tasks/sys.py
quota(ctx, atleast, mnt=None)
async
Check: Make sure quota is sufficient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
atleast
|
int
|
Amount in kB. |
required |
mnt
|
str
|
Path for mount to check quota on if explicitly required. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if available space is less than atleast, false otherwise. |
Raises:
| Type | Description |
|---|---|
IndexError / TypeError
|
If quota cannot be determined. |
Source code in model_ensembler/tasks/hpc.py
remove(ctx, directory=None)
async
Process: Remove directory using shutil.rmtree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
directory
|
str
|
Specify the directory to remove, otherwise this will use the path specified by ctx.dir. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if return code is zero, false otherwise. |
Raises:
| Type | Description |
|---|---|
OSError
|
If directory cannot be removed. |
Source code in model_ensembler/tasks/sys.py
submit(ctx, script=None)
async
Process: Submit a new job to SLURM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
script
|
str
|
Slurm submission script for sbatch. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Job identifier. |
Source code in model_ensembler/tasks/hpc.py
exceptions
Task Exceptions
Exceptions relating to tasks
CheckException
Bases: EnsembleException
For check failures
EnsembleException
FailureNotToleratedError
ProcessingException
Bases: EnsembleException
For general processing failures
TaskException
Bases: EnsembleException
For task processing failures
hpc
init_hpc_backend(backend)
Initialise cluster backend to use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
Cluster backed to use. |
required |
Raises:
| Type | Description |
|---|---|
ImportError / ModuleNotFoundError
|
If cluster backend cannot be imported. |
Source code in model_ensembler/tasks/hpc.py
jobs(ctx, limit, match)
async
Check: Assert whether number of jobs in SLURM is under limit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
limit
|
int
|
Number of jobs to check for. |
required |
match
|
str
|
Prefix to match jobs by. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if number of jobs is less than limit, otherwise false. |
Source code in model_ensembler/tasks/hpc.py
quota(ctx, atleast, mnt=None)
async
Check: Make sure quota is sufficient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
atleast
|
int
|
Amount in kB. |
required |
mnt
|
str
|
Path for mount to check quota on if explicitly required. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if available space is less than atleast, false otherwise. |
Raises:
| Type | Description |
|---|---|
IndexError / TypeError
|
If quota cannot be determined. |
Source code in model_ensembler/tasks/hpc.py
submit(ctx, script=None)
async
Process: Submit a new job to SLURM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
script
|
str
|
Slurm submission script for sbatch. |
None
|
Returns:
| Type | Description |
|---|---|
int
|
Job identifier. |
Source code in model_ensembler/tasks/hpc.py
sys
check(ctx, cmd, cwd=None, log=False, fail=False, shell=None)
async
Check: Call arbitrary command as a check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
cmd
|
str
|
See |
required |
cwd
|
str
|
See |
None
|
log
|
bool
|
See |
False
|
fail
|
bool
|
If true, then the check returning nonzero will raise an error rather than return false, meaning run abandonment rather than recheck will take place. |
False
|
shell
|
str
|
See |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if return code is zero, false otherwise. |
Raises:
| Type | Description |
|---|---|
FailureNotToleratedError
|
Error when fail is true and the check returns a nonzero code. |
Source code in model_ensembler/tasks/sys.py
execute(ctx, cmd, cwd=None, log=False, shell=None)
async
Process: Call arbitrary command as a processing task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
cmd
|
str
|
See |
required |
cwd
|
str
|
See |
None
|
log
|
bool
|
See |
False
|
shell
|
str
|
See |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if return code is zero, false otherwise. |
Source code in model_ensembler/tasks/sys.py
move(ctx, dest, include=None, exclude=None, cwd=None)
async
Process: rsync current working directory contents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
dest
|
str
|
Path to copy ctx.id named directory to. |
required |
include
|
List[str]
|
rsync include specifiers. |
None
|
exclude
|
List[str]
|
rsync exclude specifiers, defaults to "*" when calling rsync if include specifiers are given and no exclude specifiers are provided. |
None
|
cwd
|
str
|
See |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
true if return code is zero, false otherwise. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If did not provide necessary context attribute for using this processing task. |
Source code in model_ensembler/tasks/sys.py
remove(ctx, directory=None)
async
Process: Remove directory using shutil.rmtree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
object
|
Contextual configuration. |
required |
directory
|
str
|
Specify the directory to remove, otherwise this will use the path specified by ctx.dir. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if return code is zero, false otherwise. |
Raises:
| Type | Description |
|---|---|
OSError
|
If directory cannot be removed. |
Source code in model_ensembler/tasks/sys.py
utils
execute_command(cmd, cwd=None, log=False, shell=None)
async
Standard handling for calling external command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
The relative path of the command being called to cwd. |
required |
cwd
|
str
|
The current working directory to call the cmd from, passed to subprocess. |
None
|
log
|
bool
|
If true, output stdout/stderr to logfile in cwd. |
False
|
shell
|
str
|
Which shell to ask subprocess to invoke when processing the command, will default to bash internally. |
None
|
Returns:
| Type | Description |
|---|---|
object
|
Namespace containing the returncode, stdout and stderr from the process that was invoked. |
Source code in model_ensembler/tasks/utils.py
flight_task(func, check=True)
Decorator for making func as a task, providing context preprocessing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
Callable to wrap with context. |
required |
check
|
bool
|
Determine whether the func is to be treated as a check or another type of action (checks can be skipped). |
True
|
Returns:
| Type | Description |
|---|---|
func
|
The wrapped function that can process the context provided appropriately. |