Task API#

Tasks, in ENOSLIB, enable iterative development of the artifact. They are designed to allow experimenters to repeat their executions until a desired state is reached. By using tasks an experimenter can leave the python runtime and come back later (e.g. after fixing the code). Tasks act as checkpoint of the experimental workflow. The states of the experiment is stored in the Environment and itโ€™s the artifactโ€™s responsibility to determine the relevant states to store.

Tasks definition comes as a function decorator. Once decorated a function will first load the environment and make it available through a keyword argument. Environment is a dict-like data structure that is restored (resp. saved) at the beginning of a task (resp. at the end of a task).

These operations rely on pickling the object stored in the environment.

Classes:

Environment(env_name)

An environment is a kv-store used to keep track of the experimental context.

Functions:

enostask([new,ย symlink])

Decorator for an EnOSlib Task.

get_or_create_env(new,ย env_name[,ย symlink])

Loads an environment in various situations.

class enoslib.task.Environment(env_name: Path)#

An environment is a kv-store used to keep track of the experimental context.

Build a new environment backed by a file.

Parameters:

env_name โ€“ name of the environment. This corresponds to the place where the environment will be saved.

dump()#

Dump the environment in a file (env_name).

dumps()#

Return the dumped object of the environment.

classmethod load_from_file(env_file: Path)#

Create an Environment from a file.

Parameters:

env_file โ€“ path to the file to load.

reload_config()#

Reload a config file if any in the store.

enoslib.task.enostask(new: bool = False, symlink: bool = True)#

Decorator for an EnOSlib Task.

This decorator lets you define a new Enos task and helps you manage the environment. It injects the environment in the function called.

Parameters:
  • new (bool) โ€“ indicates if a new environment must be created. Usually this is set on the first task of the workflow.

  • symlink (bool) โ€“ indicates if the env in use must be symlinked (ignored if new=False)

Examples

@enostask(new=True)
def foo(env=None, **kwargs):
    # The key resultdir is available once the env is created
    print(env["resultdir"])

@enostask()
def myfunction(env=None, **kwargs):
    # saving a new key
    env['foo'] = 'bar'
enoslib.task.get_or_create_env(new: bool, env_name: Environment | Path | str | None, symlink: bool = True) Environment#

Loads an environment in various situations.

Parameters:
  • new โ€“ indicates if a new env must be created (and all its parents directories)

  • env_name โ€“ an environment specifier. May be a pathlib.Path object to an existing environment, a string (representing a path to an environment) or an already crafted Environment.

  • symlink โ€“ if an environment is created (new=True), a symlink can be created in the current directory to point to this environment if symlink=True.