pyiron_workflow.mixin.run module

A module to extract encapsulate for complex run mechanics, such as status, executor interaction, etc.

exception pyiron_workflow.mixin.run.NotInterpretableAsExecutorError[source]

Bases: TypeError

exception pyiron_workflow.mixin.run.ReadinessError[source]

Bases: ValueError

To be raised when Runnable calls run and requests a readiness check, but isn’t ready.

readiness_dict: dict[str, bool]
class pyiron_workflow.mixin.run.Runnable(*args, **kwargs)[source]

Bases: UsesState, HasLabel, HasRun, ABC

An abstract class for interfacing with executors, etc.

Child classes must define on_run() and Runnable.run_args, then the run() will invoke self.on_run(*run_args[0], **run_args[1]). The Runnable class then handles the status of the run, passing the call off for remote execution, handling any returned futures object, etc.

Child classes can optionally override process_run_result() to do something with the returned value of on_run(), but by default the returned value just passes cleanly through the function.

The run cycle is broken down into sub-steps: - _before_run: prior to the running status being set to True - _run: after the running status has been set to True - _finish_run: what is done to the results of running, and when running is

set to False

  • _run_exception: What to do if an encountered

  • _run_finally: What to do after _every_ run, regardless of whether an exception

    was encountered

Child classes can extend the behavior of these sub-steps, including introducing new keyword arguments.

property executor: Executor | tuple[Callable[[...], Executor], tuple, dict] | None
executor_shutdown(wait=True, *, cancel_futures=False)[source]

Invoke shutdown on the executor (if present).

abstractmethod on_run(*args, **kwargs) Any[source]

What the run() method actually does!

process_run_result(run_output: Any) Any[source]

What to _do_ with the results of on_run() once you have them.

By extracting this as a separate method, we allow the runnable to pass the actual execution off to another entity and release the python process to do other things. In such a case, this function should be registered as a callback so that the runnable can process the result of that process.

Parameters:

run_output – The results of a self.on_run(self.run_args) call.

property readiness_report: str

A human-readable summary of the readiness to run.

property ready: bool

Neither running nor failed

run(check_readiness: bool = True, raise_run_exceptions: bool = True, rerun: bool = False, before_run_kwargs: dict | None = None, run_kwargs: dict | None = None, run_exception_kwargs: dict | None = None, run_finally_kwargs: dict | None = None, finish_run_kwargs: dict | None = None) Any | tuple | Future[source]

Checks that the runnable is ready (if requested), then executes the functionality of defined in on_run() by passing it whatever is returned by run_args().

Can stop early if _before_run() called here returns True as its first argument.

Handles the status of the runnable, communicating with any remote computing resources, and processing the result.

Parameters:
  • check_readiness (bool) – Whether to raise a ReadinessError if not ready. (Default is True.)

  • raise_run_exceptions (bool) – Whether to raise exceptions encountered while running. (Default is True.)

  • rerun (bool) – Whether to proceed even if the running or

:param failed state is encountered before runnign.: :type failed state is encountered before runnign.: Default is False.

abstract property run_args: tuple[tuple, dict]

Any data needed for on_run(), will be passed as (*args, **kwargs).