The Runner class
Abstract class for derived [1] classes that run an algorithm.
Many of the classes in libsemigroups_pybind11 implementing the algorithms,
that are the reason for the existence of this package, are derived from
Runner. The Runner class exists to collect various common tasks
required by such a derived class with a possibly long running run. These
common tasks include:
running for a given amount of time (
run_for)running until a nullary predicate is true (
run_until)checking the status of the algorithm: has it
started?finished? been killed by another thread (dead)? has it timed out (timed_out)? has itstoppedfor any reason?permit the function
runto be killed from another thread (kill).
Because Runner is an abstract class it is not possible to create instances of Runner except via a derived class.
This class inherits from Reporter.
Important
The classes that we claim derive from Runner in this documentation
have all the methods of the Runner class but, for boring technical
reasons, are not formally subclasses of Runner. If thing is an
instance of a class derived from Runner, then you can use thing
as if it were an instance of Runner but isinstance(thing, Runner)
will return False.
Footnotes
Contents
Abstract class for derived [1] classes that run an algorithm. |
|
Return the current state. |
|
|
Check if the runner is dead. |
Check if run has been run to completion or not. |
|
|
Initialize an existing Runner object. |
|
Stop run from running (thread-safe). |
Report why run stopped. |
|
|
Run until finished. |
Run for a specified amount of time. |
|
Run until a nullary predicate returns true or finished. |
|
Check if currently running. |
|
Check if the runner is currently running for a particular length of time. |
|
Check if the runner is currently running until a nullary predicate returns true. |
|
Check if run has been called at least once before. |
|
Check if the runner is stopped. |
|
Check if the runner was stopped, or should stop, because of the argument last passed to run_until. |
|
Check if run has been run to completion successfully. |
|
Check if the amount of time passed to run_for has elapsed. |
Full API
- class Runner
- current_state(self: Runner) Runner.state
Return the current state.
This function returns the current state of the
Runneras given bystate.- Returns:
A value of type
state.- Return type:
- Complexity:
Constant.
- dead(self: Runner) bool
Check if the runner is dead. This function can be used to check if we should terminate
run()because it has been killed by another thread.- Returns:
A
bool.- Return type:
See also
- finished(self: Runner) bool
Check if run has been run to completion or not.
This function returns
Trueifrun()has been run to completion. For this to work, the implementation ofrun()in a derived class ofRunnermust implement a specialisation offinished_impl.- Returns:
A
bool.- Return type:
See also
- init(self: Runner) Runner
Initialize an existing Runner object.
This function puts a
Runnerobject back into the same state as if it had been newly default constructed.- Returns:
self.
- Return type:
See also
- kill(self: Runner) None
Stop run from running (thread-safe). This function can be used to terminate
run()from another thread. Afterkill()has been called theRunnermay no longer be in a valid state, but will returnTruefromdead().See also
- report_why_we_stopped(self: Runner) None
Report why run stopped. Reports whether
run()was stopped because it isfinished(),timed_out(), ordead().
- run(self: Runner) None
Run until finished. Run the main algorithm implemented by a derived class of
Runner.
- run_for(self: Runner, t: datetime.timedelta) None
Run for a specified amount of time.
For this to work it is necessary to periodically check if
timed_out()returnsTrue, and to stop if it is, in therun()member function of any derived class ofRunner.- Parameters:
t (datetime.timedelta) – the time to run for.
See also
- run_until(self: Runner, func: collections.abc.Callable[[], bool]) None
Run until a nullary predicate returns true or finished.
- Parameters:
func (collections.abc.Callable[[], bool]) – a nullary function that will be used to determine when to stop running.
- running(self: Runner) bool
Check if currently running.
This function returns
Trueifrun()is in the process of running andFalseit is not.- Returns:
Whether or not the runner is running.
- Return type:
See also
- running_for(self: Runner) bool
Check if the runner is currently running for a particular length of time. If the
Runneris currently running because its member functionrun_forhas been invoked, then this function returnsTrue. Otherwise,Falseis returned.- Returns:
A
bool.- Return type:
- Complexity:
Constant.
- running_until(self: Runner) bool
Check if the runner is currently running until a nullary predicate returns true. If the
Runneris currently running because its member functionrun_untilhas been invoked, then this function returnsTrue. Otherwise,Falseis returned.- Returns:
A
bool.- Return type:
- Complexity:
Constant.
- started(self: Runner) bool
Check if run has been called at least once before.
This function returns
Trueifrun()has started to run (it can be running or not).- Returns:
A
bool.- Return type:
See also
- stopped(self: Runner) bool
Check if the runner is stopped. This function can be used to check whether or not
run()has been stopped for whatever reason. In other words, it checks iftimed_out(),finished(), ordead().- Returns:
A
bool.- Return type:
- stopped_by_predicate(self: Runner) bool
Check if the runner was stopped, or should stop, because of the argument last passed to run_until. If self is running, then the nullary predicate is called and its return value is returned. If self is not running, then
Trueis returned if and only if the last time self was running it was stopped by a call to the nullary predicate passed torun_until().- Returns:
A
bool.- Return type:
- Complexity:
Constant.