pylbo.automation.runner

Classes

LegolasRunner

Handles running legolas.

Functions

_validate_executable(executable)

Validates the given executable, then returns it. If the argument passed is

_validate_nb_cpus(cpus)

Validates the number of cpus passed to the multiprocessing pool.

_validate_parfiles(files)

Validates a list of parfiles.

Module Contents

pylbo.automation.runner._validate_executable(executable)

Validates the given executable, then returns it. If the argument passed is None, defaults to the executable in the legolas home directory.

Parameters:

executable (str, PathLike) – The path to the legolas executable to use.

Raises:

FileNotFoundError – If the executable was not found.

Returns:

executable – The (resolved) path to the executable to use.

Return type:

PathLike

pylbo.automation.runner._validate_nb_cpus(cpus)

Validates the number of cpus passed to the multiprocessing pool. Defaults to the maximum available number if exceeded.

Parameters:

cpus (int) – The number of cpus to use.

Returns:

cpus – The number of cpus to use, limited to the maximum number available.

Return type:

int

pylbo.automation.runner._validate_parfiles(files)

Validates a list of parfiles.

Parameters:

files ((list of) str, (list of) PathLike) – Paths to the parfiles.

Raises:

FileNotFoundError – If one of the parfiles is not found.

Returns:

files_list – A list of resolved filepaths for the parfiles.

Return type:

list

class pylbo.automation.runner.LegolasRunner(parfiles, remove_parfiles, nb_cpus, executable=None)

Handles running legolas.

Parameters:
  • parfiles (list, numpy.ndarray) – A list or array containing the names or paths to the parfiles.

  • remove_parfiles (bool) – If True, removes the parfiles after running Legolas. This will also remove the containing folder if it turns out to be empty after the parfiles are removed. If there are other files still in the folder it remains untouched.

  • nb_cpus (int) – The number of CPUs to use when running Legolas. If equal to 1 then parallelisation is disabled. Defaults to the maximum number of CPUs available if a number larger than the available number is specified.

  • executable (str, PathLike) – The path to the legolas executable.

parfiles
parfile_dir
executable
nb_cpus
remove_parfiles
static _init_worker()

Worker initialisation for the multiprocessing module.

_activate_worker(parfile)

Worker activation for the multiprocessing module. Calls the legolas executable as a subprocess with the parfile as argument.

Parameters:

parfile (str, PathLike) – The path to the parfile

Returns:

call – A call to a subprocess to run legolas.

Return type:

subprocess.call()

static _terminate_workers()

Terminates the multiprocessing workers after a forced interruption. Simply giving an interrupt terminates only the Python processes, but still keeps the Legolas calls running since those are subprocesses. This method first terminates all child processes (legolas), then the parents (workers).

execute()

Executes the legolas executables and initialises the multiprocessing pool if requested.