hein_control.sequencing package¶
Tools for managing sequences of actions (execution) or linked chains of actions (automation).
For linear sequences of actions, it is recommended to use the .sequencing.execution module. For linked actions which are linked by .next_action attributes use the .sequencing.automation module.
hein_control.sequencing.automation module¶
Tools for executing a series of actions where the next action is determined by the previous one (linked by next_action). Automation sequences may include conditional next actions governed by DecisionActions.
-
class
hein_control.sequencing.automation.Automation(configuration: Union[str, hein_control.sequencing.automation.ConfiguredAutomation], **kwargs)¶ Bases:
hein_control.action.configured.ThreadedTrackedActionAn Automation is used to run a sequence of Steps. For an Automation, you need to specify what the first step torun is.
An Automation instance is callable. When called, it will run the first Step, get the next_step from that first step, and loop through running and retrieving the next Step to run, until there are no more Steps to run.
The IfStep enables decision making in an Automation
The Automation class is also important, because all the arguments for all the Steps must be passed into the Automation on instantiation, and these arguments may potentially be updated by the Steps. All these arguments for the CustomSteps must be passed into an Automation sequence as a dictionary, where the keys are the argument names and the values are the initial values for these arguments. These arguments get stored as self.kwargs in the Automation instance, and self.kwargs gets used as the arguments to run the CustomSteps. If the CustomStep run function has a return value, it MUST be a dictionary, where the keys are argument names (that must correspond to a key in the self.kwargs dictionary of the Automation instance), and the values are the new values for the arguments; and in this way the arguments for the Automation instance can be updated.
In short for using the Automation and Steps classes: * An Automation instantiation MUST include a dictionary of arguments and initial values to be used by the Steps
in the Automation, unless no variables need to be passed between/used by multiple Steps- The parameter names for all the functions of CustomSteps must be identical to the keys in the kwargs
- dictionary that get passed into an Automation instance on instantiation
- The return value of any CustomStep must be a dictionary, with the keys being identical to the keys in the
- kwargs dictionary of the Automation instance, and the values are the updated values
- All these functions for the CustomSteps must also have a **kwargs parameter, to catch arguments that get passed
- through that are not actually required by the functions.
- An Automation instance must know what the first step to run is
- Steps need to be ‘chained’ to each other
Parameters: - first_action (Step,) – first step in the automation to run
- kwargs (dict,) – all the entry keys need to be identical to the parameter names for the callable actions for all the Steps in the automation
-
UUID_PREFIX= 'auto-'¶
-
configuration¶ the configured sequence associated with the instance
-
copy_configuration() → hein_control.sequencing.automation.Automation¶ Copies the configuration of a Automation instance.
Returns: Automation instance with identical configuration
-
executed_actions¶ executed actions of the automation run
-
first_step¶ The first step in the Automation run
-
run_automation(**kwargs)¶ Run the first step in the automation, and get the next step that results from it. then loop, running the next step after that and so on, until the end of the automation has been reached. Will get called when an Automation instance is called.
Parameters: kwargs (dict,) – dictionary of arguments to run the Steps in the automation. Nothing should need to be passed in here for this because the kwargs should have been passed in when the Automation instance was instantiated, but if they were not or need to be updated, they can be passed here Returns:
-
class
hein_control.sequencing.automation.ConfiguredAutomation(first_action: Union[Callable, hein_control.action.basic.Action, str, hein_control.action.configured.ConfiguredAction], automation_name: str = None, **kwargs)¶ Bases:
hein_control.action.configured.ConfiguredActionA class for configuring an automation run
Parameters: - first_action – first action to run
- automation_name – name for the automation
- kwargs –
-
UUID_PREFIX= 'cauto-'¶
-
first_action¶ the first action in the automation run
-
get_tracked_from_config(**kwargs) → hein_control.sequencing.automation.Automation¶ Gets an automation instance from the configured automation
Parameters: kwargs – additional kwargs that differ from the instance configuration Returns: automation instance
-
hein_control.sequencing.automation.build_automation_sequence(*actions) → hein_control.action.configured.ConfiguredActionList¶ Builds an automation sequence of actions based on the order provided.
Parameters: actions – actions to link Returns: built automation sequence of actions
hein_control.sequencing.execution module¶
Tools for executing a predefined (linear) series of actions.
-
class
hein_control.sequencing.execution.ConfiguredSequence(*actions, sequence_name: str = None, next_action: Union[str, ConfiguredAction] = None, **kwargs)¶ Bases:
hein_control.action.configured.ConfiguredActionA class for configuring the execution of a sequence of actions
Parameters: - actions – actions to execute in sequence
- sequence_name – name for the sequence
- next_action – next action to perform after completion of the sequence
- kwargs – kwargs for the actions
-
action_sequence¶ sequence of actions for the configuration
-
duplicate_configuration(new_name: str = None) → hein_control.sequencing.execution.ConfiguredSequence¶ Duplicates the configuration of the sequence
Parameters: new_name – optional name for the new sequence Returns:
-
get_tracked_from_config(**kwargs) → hein_control.sequencing.execution.ExecutionSequence¶ Gets an execution sequence instance based on the configured sequence.
Parameters: kwargs – additional kwargs that differ from the instance configuration Returns: execution sequence
-
class
hein_control.sequencing.execution.ExecutionSequence(configuration: Union[str, hein_control.sequencing.execution.ConfiguredSequence], **kwargs)¶ Bases:
hein_control.action.configured.ThreadedTrackedActionExecutor class for a sequence of actions.
Parameters: actions – actions to execute when called (base actions or configured actions) -
UUID_PREFIX= 'seq-'¶
-
action_completion_times¶ times when the prescribed actions were completed
-
action_durations¶ execution durations for the prescribed actions
-
action_returns¶ retrieves the returned values from the actions. Only actions which have completed will have return values
-
action_start_times¶ times when the prescribed actions were started
-
actions_status¶ status of the actions of the instance
-
as_dict() → dict¶ extra type cast for arguments
-
classmethod
build_from_first_action(first_action: hein_control.action.configured.ConfiguredAction) → hein_control.sequencing.execution.ExecutionSequence¶ Builds an execution sequence from a first action and its linked action
Parameters: first_action – first action to reference Returns: execution sequence
-
configuration¶ the configured sequence associated with the instance
-
copy_configuration() → hein_control.sequencing.execution.ExecutionSequence¶ Copies the configuration of a ExecutionSequence instance.
Returns: ExecutionSequence instance with identical configuration
-
started_timestamps¶ timestamps for when actions were started
-