Belle II Software  release-05-02-19
AlgorithmMachine Class Reference
Inheritance diagram for AlgorithmMachine:
Collaboration diagram for AlgorithmMachine:

Public Member Functions

def __init__ (self, algorithm=None, initial_state="init")
 
def setup_from_dict (self, params)
 
def is_valid (self)
 
def initial_state (self)
 
def initial_state (self, state)
 
def state (self)
 
def state (self, state)
 
def add_state (self, state, enter=None, exit=None)
 
def add_transition (self, trigger, source, dest, conditions=None, before=None, after=None)
 
def __getattr__ (self, name, **kwargs)
 
def get_transitions (self, source)
 
def get_transition_dict (self, state, transition)
 
def save_graph (self, filename, graphname)
 

Static Public Member Functions

def default_condition (**kwargs)
 

Public Attributes

 default_states
 Default states for the AlgorithmMachine.
 
 algorithm
 Algorithm() object whose state we are modelling.
 
 input_files
 Collector output files, will contain all files retured by the output patterns.
 
 dependent_databases
 CAF created local databases from previous calibrations that this calibration/algorithm depends on.
 
 database_chain
 Assigned database chain to the overall Calibration object, or to the 'default' Collection. More...
 
 output_dir
 The algorithm output directory which is mostly used to store the stdout file.
 
 output_database_dir
 The output database directory for the localdb that the algorithm will commit to.
 
 result
 IoV_Result object for a single execution, will be reset upon a new execution.
 
 states
 Valid states for this machine.
 
 initial_state
 Pointless docstring since it's a property.
 
 transitions
 Allowed transitions between states.
 
 state
 Current State of machine.
 

Static Public Attributes

list required_attrs
 Required attributes that must exist before the machine can run properly. More...
 
list required_true_attrs
 Attributes that must have a value that returns True when tested. More...
 

Private Member Functions

def _create_output_dir (self, **kwargs)
 
def _setup_database_chain (self, **kwargs)
 
def _setup_logging (self, **kwargs)
 
def _change_working_dir (self, **kwargs)
 
def _pre_algorithm (self, **kwargs)
 
def _execute_over_iov (self, **kwargs)
 
def _set_input_data (self, **kwargs)
 
def _trigger (self, transition_name, transition_dict, **kwargs)
 

Static Private Member Functions

def _callback (func, **kwargs)
 

Private Attributes

 _initial_state
 Actual attribute holding initial state for this machine.
 
 _state
 Actual attribute holding the Current state. More...
 

Detailed Description

A state machine to handle the logic of running the algorithm on the overall runs contained in the data.

Definition at line 914 of file state_machines.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  algorithm = None,
  initial_state = "init" 
)
Takes an Algorithm object from the caf framework and defines the transitions.

Reimplemented from Machine.

Definition at line 936 of file state_machines.py.

936  def __init__(self, algorithm=None, initial_state="init"):
937  """
938  Takes an Algorithm object from the caf framework and defines the transitions.
939  """
940 
941  self.default_states = [State("init"),
942  State("ready"),
943  State("running_algorithm"),
944  State("completed"),
945  State("failed")]
946 
947  super().__init__(self.default_states, initial_state)
948 
949 
950  self.algorithm = algorithm
951 
952  self.input_files = []
953 
954  self.dependent_databases = []
955 
957  self.database_chain = []
958 
959  self.output_dir = ""
960 
961  self.output_database_dir = ""
962 
963  self.result = None
964 
965  self.add_transition("setup_algorithm", "init", "ready",
966  before=[self._setup_logging,
967  self._change_working_dir,
968  self._setup_database_chain,
969  self._set_input_data,
970  self._pre_algorithm])
971  self.add_transition("execute_runs", "ready", "running_algorithm",
972  after=self._execute_over_iov)
973  self.add_transition("complete", "running_algorithm", "completed")
974  self.add_transition("fail", "running_algorithm", "failed")
975  self.add_transition("fail", "ready", "failed")
976  self.add_transition("setup_algorithm", "completed", "ready")
977  self.add_transition("setup_algorithm", "failed", "ready")
978 

Member Function Documentation

◆ __getattr__()

def __getattr__ (   self,
  name,
**  kwargs 
)
inherited
Allows us to create a new method for each trigger on the fly.
If there is no trigger name in the machine to match, then the normal
AttributeError is called.

Definition at line 295 of file state_machines.py.

◆ _callback()

def _callback (   func,
**  kwargs 
)
staticprivateinherited
Calls a condition/before/after.. function using arguments passed (or not).

Definition at line 330 of file state_machines.py.

◆ _change_working_dir()

def _change_working_dir (   self,
**  kwargs 
)
private
 

Definition at line 1059 of file state_machines.py.

◆ _create_output_dir()

def _create_output_dir (   self,
**  kwargs 
)
private
Create working/output directory of algorithm. Any old directory is overwritten.

Definition at line 1005 of file state_machines.py.

◆ _execute_over_iov()

def _execute_over_iov (   self,
**  kwargs 
)
private
Does the actual execute of the algorithm on an IoV and records the result.

Definition at line 1075 of file state_machines.py.

◆ _pre_algorithm()

def _pre_algorithm (   self,
**  kwargs 
)
private
Call the user defined algorithm setup function.

Definition at line 1065 of file state_machines.py.

◆ _setup_database_chain()

def _setup_database_chain (   self,
**  kwargs 
)
private
Apply all databases in the correct order.

Definition at line 1011 of file state_machines.py.

◆ _setup_logging()

def _setup_logging (   self,
**  kwargs 
)
private
 

Definition at line 1049 of file state_machines.py.

◆ _trigger()

def _trigger (   self,
  transition_name,
  transition_dict,
**  kwargs 
)
privateinherited
Runs the transition logic. Callbacks are evaluated in the order:
conditions -> before -> <new state set here> -> after.

Definition at line 307 of file state_machines.py.

◆ add_state()

def add_state (   self,
  state,
  enter = None,
  exit = None 
)
inherited
Adds a single state to the list of possible ones.
Should be a unique string or a State object with a unique name.

Definition at line 182 of file state_machines.py.

◆ add_transition()

def add_transition (   self,
  trigger,
  source,
  dest,
  conditions = None,
  before = None,
  after = None 
)
inherited
Adds a single transition to the dictionary of possible ones.
Trigger is the method name that begins the transtion between the
source state and the destination state.

The condition is an optional function that returns True or False
depending on the current state/input.

Definition at line 253 of file state_machines.py.

◆ default_condition()

def default_condition ( **  kwargs)
staticinherited
Method to always return True.

Definition at line 247 of file state_machines.py.

◆ get_transition_dict()

def get_transition_dict (   self,
  state,
  transition 
)
inherited
Returns the transition dictionary for a state and transition out of it.

Definition at line 347 of file state_machines.py.

◆ get_transitions()

def get_transitions (   self,
  source 
)
inherited
Returns allowed transitions from a given state.

Definition at line 336 of file state_machines.py.

◆ initial_state() [1/2]

def initial_state (   self)
inherited
The initial state of the machine. Needs a special property to prevent trying to run on_enter callbacks when set.

Definition at line 198 of file state_machines.py.

◆ initial_state() [2/2]

def initial_state (   self,
  state 
)
inherited
 

Definition at line 205 of file state_machines.py.

◆ is_valid()

def is_valid (   self)
Returns:
    bool: Whether or not this machine has been set up correctly with all its necessary attributes.

Definition at line 987 of file state_machines.py.

◆ save_graph()

def save_graph (   self,
  filename,
  graphname 
)
inherited
Does a simple dot file creation to visualise states and transiitons.

Definition at line 358 of file state_machines.py.

◆ setup_from_dict()

def setup_from_dict (   self,
  params 
)
Parameters:
    params (dict): Dictionary containing values to be assigned to the machine's attributes of the same name.

Definition at line 979 of file state_machines.py.

◆ state() [1/2]

def state (   self)
inherited
The current state of the machine. Actually a `property` decorator. It will call the exit method of the
current state and enter method of the new one. To get around the behaviour e.g. for setting initial states,
either use the `initial_state` property or directly set the _state attribute itself (at your own risk!).

Definition at line 216 of file state_machines.py.

◆ state() [2/2]

def state (   self,
  state 
)
inherited
 

Definition at line 225 of file state_machines.py.

Member Data Documentation

◆ _state

_state
privateinherited

Actual attribute holding the Current state.

Current state (private)

Definition at line 178 of file state_machines.py.

◆ database_chain

database_chain

Assigned database chain to the overall Calibration object, or to the 'default' Collection.

Database chains for manually created Collections have no effect here.

Definition at line 957 of file state_machines.py.

◆ required_attrs

list required_attrs
static
Initial value:
= ["algorithm",
"dependent_databases",
"database_chain",
"output_dir",
"output_database_dir",
"input_files"
]

Required attributes that must exist before the machine can run properly.

Some are allowed be values that return False whe tested e.g. "" or []

Definition at line 921 of file state_machines.py.

◆ required_true_attrs

list required_true_attrs
static
Initial value:
= ["algorithm",
"output_dir",
"output_database_dir",
"input_files"
]

Attributes that must have a value that returns True when tested.

Definition at line 930 of file state_machines.py.


The documentation for this class was generated from the following file: