States: states
¶
barrier_concurrency¶
- class rafcon.core.states.barrier_concurrency_state.BarrierConcurrencyState(name=None, state_id=None, input_data_ports=None, output_data_ports=None, income=None, outcomes=None, states=None, transitions=None, data_flows=None, start_state_id=None, scoped_variables=None, decider_state=None, load_from_storage=False, safe_init=True)¶
Bases:
ConcurrencyState
The barrier concurrency holds a list of states that are executed in parallel. It waits until all states finished their execution before it returns.
Note: In the backward execution case the decider state does not have to be backward executed, as it only decides the outcome of the barrier concurrency state. In a backward execution the logic flow obviously already exists.
The order of history items for the concurrency state is: Call - Concurrency - Return and for the backward case: Return - Concurrency - Call
For the children of the concurrency state the history items are: In the forward case: - Call: Before calling the child - Return: After executing the child In the backward case: - Pop Return: Before backward executing the child - Pop Call: After backward executing the child
The decider state is not considered in the backward execution case.
- add_state(state, storage_load=False)¶
Overwrite the parent class add_state method
Add automatic transition generation for the decider_state.
- Parameters:
state – The state to be added
- Returns:
- classmethod from_dict(dictionary)¶
An abstract method each state has to implement.
- Parameters:
dictionary – the dictionary of parameters a state can be created from
- Raises:
exceptions.NotImplementedError – in any case
- remove_state(state_id, recursive=True, force=False, destroy=True)¶
Overwrite the parent class remove state method by checking if the user tries to delete the decider state
- Parameters:
state_id – the id of the state to remove
recursive – a flag to indicate a recursive disassembling of all substates
force – a flag to indicate forcefully deletion of all states (important of the decider state in the barrier concurrency state)
destroy – a flag which indicates if the state should not only be disconnected from the state but also destroyed, including all its state elements
- Raises:
exceptions.AttributeError – if the state_id parameter is the decider state
- run()¶
This defines the sequence of actions that are taken when the barrier concurrency state is executed
- Returns:
- run_decider_state(decider_state, child_errors, final_outcomes_dict)¶
Runs the decider state of the barrier concurrency state. The decider state decides on which outcome the barrier concurrency is left.
- Parameters:
decider_state – the decider state of the barrier concurrency state
child_errors – error of the concurrent branches
final_outcomes_dict – dictionary of all outcomes of the concurrent branches
- Returns:
- property states¶
Property for the _states field
The setter-method substitute ContainerState.states which is a dict. The method checks if the elements are of the right type or will cancel the operation and recover old outcomes. The method does check validity of the elements by calling the parent-setter.
- class rafcon.core.states.barrier_concurrency_state.DeciderState(name=None, state_id=None, input_data_ports=None, output_data_ports=None, income=None, outcomes=None, path=None, filename=None, safe_init=True)¶
Bases:
ExecutionState
A class to represent a state for deciding the exit of barrier concurrency state.
This type of ExecutionState has initial always the UNIQUE_DECIDER_STATE_ID.
- get_errors_for_state_name(name)¶
Returns the error message of the child state specified by name.
Note: This is utility function that is used by the programmer to make a decision based on the final outcome of its child states. A state is not uniquely specified by the name, but as the programmer normally does not want to use state-ids in his code this utility function was defined.
- Parameters:
name – The name of the state to get the error message for
- Returns:
- get_outcome_for_state_id(state_id)¶
Returns the final outcome of the child state specified by the state_id.
- Parameters:
state_id – The id of the state to get the final outcome for.
- Returns:
- get_outcome_for_state_name(name)¶
Returns the final outcome of the child state specified by name.
Note: This is utility function that is used by the programmer to make a decision based on the final outcome of its child states. A state is not uniquely specified by the name, but as the programmer normally does not want to use state-ids in his code this utility function was defined.
- Parameters:
name – The name of the state to get the final outcome for.
- Returns:
concurrency_state¶
- class rafcon.core.states.concurrency_state.ConcurrencyState(name=None, state_id=None, input_keys=None, output_keys=None, income=None, outcomes=None, states=None, transitions=None, data_flows=None, start_state_id=None, scoped_variables=None, safe_init=True)¶
Bases:
ContainerState
A class to represent a concurrency state for the state machine
The concurrency state holds several child states, that can be container states again
- finalize_backward_execution()¶
Utility function to finalize the backward execution of the concurrency state.
- Returns:
- finalize_concurrency_state(outcome)¶
Utility function to finalize the forward execution of the concurrency state.
- Parameters:
outcome –
- Returns:
- join_state(state, history_index, concurrency_history_item)¶
a utility function to join a state
- Parameters:
state – the state to join
history_index – the index of the execution history stack in the concurrency history item for the given state
concurrency_history_item – the concurrency history item that stores the execution history stacks of all children
- Returns:
- run(*args, **kwargs)¶
The abstract run method that has to be implemented by all concurrency states.
- Parameters:
args – list of optional arguments
kwargs – optional keyword arguments
- Raises:
exceptions.AttributeError – if this method was not implemented by the subclass
- setup_forward_or_backward_execution()¶
Sets up the execution of the concurrency states dependent on if the state is executed forward of backward.
- Returns:
- start_child_states(concurrency_history_item, do_not_start_state=None)¶
Utility function to start all child states of the concurrency state.
- Parameters:
concurrency_history_item – each concurrent child branch gets an execution history stack of this concurrency history item
do_not_start_state – optionally the id of a state can be passed, that must not be started (e.g. in the case of the barrier concurrency state the decider state)
- Returns:
container_state¶
- class rafcon.core.states.container_state.ContainerState(name=None, state_id=None, input_data_ports=None, output_data_ports=None, income=None, outcomes=None, states=None, transitions=None, data_flows=None, start_state_id=None, scoped_variables=None, missing_library_meta_data=None, is_dummy=False, safe_init=True)¶
Bases:
State
A class for representing a state in the state machine
Only the variables are listed that are not already contained in the state base class
- Variables:
ContainerState.states (dict) – the child states of the container state of the state
ContainerState.transitions (dict) – transitions between all child states
ContainerState.data_flows (dict) – data flows between all child states
ContainerState.start_state_id (str) – the state to start with when the hierarchy state is executed
ContainerState.scoped_variables (dict) – the scoped variables of the container
- add_data_flow(**kwargs)¶
- add_default_values_of_scoped_variables_to_scoped_data()¶
Add the scoped variables default values to the scoped_data dictionary
- add_input_data_to_scoped_data(dictionary)¶
Add a dictionary to the scoped data
As the input_data dictionary maps names to values, the functions looks for the proper data_ports keys in the input_data_ports dictionary
- Parameters:
dictionary – The dictionary that is added to the scoped data
state – The state to which the input_data was passed (should be self in most cases)
- add_scoped_variable(**kwargs)¶
- add_state(**kwargs)¶
- add_state_execution_output_to_scoped_data(dictionary, state)¶
Add a state execution output to the scoped data
- Parameters:
dictionary – The dictionary that is added to the scoped data
state – The state that finished execution and provide the dictionary
- add_transition(**kwargs)¶
- change_state_id(state_id=None)¶
Changes the id of the state to a new id. This functions replaces the old state_id with the new state_id in all data flows and transitions.
- Parameters:
state_id – The new state if of the state
- change_state_type(**kwargs)¶
- check_child_validity(child)¶
Check validity of passed child object
The method is called by state child objects (transitions, data flows) when these are initialized or changed. The method checks the type of the child and then checks its validity in the context of the state.
- Parameters:
child (object) – The child of the state that is to be tested
- Return bool validity, str message:
validity is True, when the child is valid, False else. message gives more information especially if the child is not valid
- check_data_flow_id(data_flow_id)¶
Check the data flow id and calculate a new one if its None
- Parameters:
data_flow_id – The data flow id to check
- Returns:
The new data flow id
- Raises:
exceptions.AttributeError – if data_flow.data_flow_id already exists
- check_data_port_connection(check_data_port)¶
Checks the connection validity of a data port
The method is called by a child state to check the validity of a data port in case it is connected with data flows. The data port does not belong to ‘self’, but to one of self.states. If the data port is connected to a data flow, the method checks, whether these connect consistent data types of ports.
- Parameters:
check_data_port (rafcon.core.data_port.DataPort) – The port to check
- Returns:
valid, message
- check_transition_id(transition_id)¶
Check the transition id and calculate a new one if its None
- Parameters:
transition_id – The transition-id to check
- Returns:
The new transition id
- Raises:
exceptions.AttributeError – if transition.transition_id already exists
- property data_flows¶
Property for the _data_flows field
The setter-method substitute ContainerState._data_flows with handed dictionary. The method checks if the elements are of the right type and the keys consistent (DataFlow.data_flow_id==key). The method does check validity of the elements by calling the parent-setter and in case of failure cancel the operation and recover old _data_flows dictionary.
- Returns:
Dictionary data_flows[data_flow_id] of
rafcon.core.data_flow.DataFlow
- Return type:
- destroy(recursive)¶
Removes all the state elements.
- Parameters:
recursive – Flag whether to destroy all state elements which are removed
- classmethod from_dict(dictionary)¶
An abstract method each state has to implement.
- Parameters:
dictionary – the dictionary of parameters a state can be created from
- Raises:
exceptions.NotImplementedError – in any case
- get_connections_for_state(state_id)¶
The method generates two dictionaries with related transitions and data flows for the given state_id
The method creates dictionaries for all ‘internal’ and ‘external’ (first dict-key) connections of the state. Both dictionaries contain sub dicts with 3 (external)/4 (internal) fields ‘enclosed’, ‘ingoing’, ‘outgoing’ and ‘self’. - ‘enclosed’ means the handed state.states cover origin and target of those linkage - ‘ingoing’ means the handed state is target of those linkage - ‘outgoing’ means the handed state is origin of those linkage - ‘self’ (corner case) single state that has linkage with it self and is thereby also origin and target at the same time
- Parameters:
state_id – State taken into account.
- Return type:
- Returns:
related_transitions, related_data_flows
- get_connections_for_state_and_scoped_variables(state_ids, scoped_variables)¶
The method generates two dictionaries with transitions and data flows for the given state ids and scoped vars
The method creates dictionaries with connections for a set of states and scoped variables. Both dictionaries have 3 fields (as first dict-key), ‘enclosed’, ‘ingoing’ and ‘outgoing’ - ‘enclosed’ means the given sets cover origin and target of those linkage - ‘ingoing’ means the given sets is target of those linkage - ‘ingoing’ means the given sets is origin of those linkage
- Parameters:
state_ids – List of states taken into account.
scoped_variables – List of scoped variables taken into account
- Return type:
- Returns:
related_transitions, related_data_flows
- get_data_port(state_id, port_id)¶
Searches for a data port
The data port specified by the state id and data port id is searched in the state itself and in its children.
- get_data_port_by_id(data_port_id)¶
Search for the given data port id in the data ports of the state
The method tries to find a data port in the input and output data ports as well as in the scoped variables.
- Parameters:
data_port_id – the unique id of the data port
- Returns:
the data port with the searched id or None if not found
- get_data_port_ids()¶
- get_inputs_for_state(state)¶
Retrieves all input data of a state. If several data flows are connected to an input port the most current data is used for the specific input port.
- Parameters:
state – the state of which the input data is determined
- Returns:
the input data of the target state
- get_number_of_data_flows()¶
Returns the number of data flows :return:
- get_number_of_transitions()¶
Returns the number of transitions :return:
- get_outcome(state_id, outcome_id)¶
- get_scoped_variable_from_name(name)¶
Get the scoped variable for a unique name
- Parameters:
name – the unique name of the scoped variable
- Returns:
the scoped variable specified by the name
- Raises:
exceptions.AttributeError – if the name is not in the the scoped_variables dictionary
- get_start_state(set_final_outcome=False)¶
Get the start state of the container state
- Parameters:
set_final_outcome – if the final_outcome of the state should be set if the income directly connects to an outcome
- Returns:
the start state
- get_state_for_transition(transition)¶
Calculate the target state of a transition
- Parameters:
transition – The transition of which the target state is determined
- Returns:
the to-state of the transition
- Raises:
exceptions.TypeError – if the transition parameter is of wrong type
- get_states_statistics(hierarchy_level)¶
Returns the numer of child states :return:
- get_transition_for_outcome(state, outcome)¶
Determines the next transition of a state.
- Parameters:
state – The state for which the transition is determined
outcome – The outcome of the state, that is given in the first parameter
- Returns:
the transition specified by the the state and the outcome
- Raises:
exceptions.TypeError – if the types of the passed parameters are incorrect
- group_states(**kwargs)¶
- handle_no_start_state()¶
Handles the situation, when no start state exists during execution
The method waits, until a transition is created. It then checks again for an existing start state and waits again, if this is not the case. It returns the None state if the the state machine was stopped.
- handle_no_transition(state)¶
This function handles the case that there is no transition for a specific outcome of a sub-state.
The method waits on a condition variable to a new transition that will be connected by the programmer or GUI-user.
- Parameters:
state – The sub-state to find a transition for
- Returns:
The transition for the target state.
- Raises:
exceptions.RuntimeError – if the execution engine is stopped (this will be caught at the end of the run method)
- property is_dummy¶
Property for the _is_dummy field
- property missing_library_meta_data¶
Property for the _missing_library_meta_data field
- recursively_pause_states()¶
Pause the state and all of it child states.
- recursively_preempt_states()¶
Preempt the state and all of it child states.
- recursively_resume_states()¶
Resume the state and all of it child states.
- remove(state_element, recursive=True, force=False, destroy=True)¶
Remove item from state
- Parameters:
state_element (StateElement) – State or state element to be removed
recursive (bool) – Only applies to removal of state and decides whether the removal should be called recursively on all child states
force (bool) – if the removal should be forced without checking constraints
destroy (bool) – a flag that signals that the state element will be fully removed and disassembled
- remove_data_flow(**kwargs)¶
- remove_data_flows_with_data_port_id(data_port_id)¶
Remove an data ports whose from_key or to_key equals the passed data_port_id
- Parameters:
data_port_id (int) – the id of a data_port of which all data_flows should be removed, the id can be a input or output data port id
- remove_outcome_hook(outcome_id)¶
Removes internal transition going to the outcome
- remove_scoped_variable(**kwargs)¶
- remove_state(**kwargs)¶
- remove_transition(**kwargs)¶
- run(*args, **kwargs)¶
Implementation of the abstract run() method of the
threading.Thread
Should be filled with code, that should be executed for each container_state derivative. :raises exceptions.NotImplementedError: in every case
- property scoped_data¶
Property for the _scoped_data field
- property scoped_variables¶
Property for the _scoped_variables field
The setter-method ContainerState._scoped_variables with a handed dictionary. The method checks if the elements are of the right type and the keys consistent (Transition.transition_id==key). The method does check validity of the elements by calling the parent-setter and in case of failure cancel the operation and recover old _scoped_variables dictionary.
- Returns:
Dictionary scoped_variables[data_port_id] of
rafcon.core.scope.ScopedVariable
- Return type:
- set_start_state(state)¶
Sets the start state of a container state
- Parameters:
state – The state_id of a state or a direct reference ot he state (that was already added to the container) that will be the start state of this container state.
- setup_run()¶
Executes a generic set of actions that has to be called in the run methods of each derived state class.
- Returns:
- property start_state_id¶
The start state is the state to which the first transition goes to.
The setter-method creates a unique first transition to the state with the given id. Existing first transitions are removed. If the given state id is None, the first transition is removed.
- Returns:
The id of the start state
- static state_to_dict(state)¶
- property states¶
Property for the _states field
The setter-method substitute ContainerState.states which is a dict. The method checks if the elements are of the right type or will cancel the operation and recover old outcomes. The method does check validity of the elements by calling the parent-setter.
- substitute_state(**kwargs)¶
- property transitions¶
Property for the _transitions field
The setter-method substitute ContainerState._transitions with a handed dictionary. The method checks if the elements are of the right type and the keys consistent (Transition.transition_id==key). The method does check validity of the elements by calling the parent-setter and in case of failure cancel the operation and recover old _transitions dictionary.
- Returns:
Dictionary transitions[transition_id] of
rafcon.core.transition.Transition
- Return type:
- ungroup_state(**kwargs)¶
- update_hash(obj_hash)¶
Should be implemented by derived classes to update the hash with their data fields
- Parameters:
obj_hash – The hash object (see Python hashlib)
- update_scoped_variables_with_output_dictionary(dictionary, state)¶
Update the values of the scoped variables with the output dictionary of a specific state.
- Param:
the dictionary to update the scoped variables with
- Param:
the state the output dictionary belongs to
- write_output_data(specific_output_dictionary=None)¶
Write the scoped data to the output of the state. Called before exiting the container state.
- Parameters:
specific_output_dictionary – an optional dictionary to write the output data in
- Returns:
execution_state¶
- class rafcon.core.states.execution_state.ExecutionState(name=None, state_id=None, input_data_ports=None, output_data_ports=None, income=None, outcomes=None, path=None, filename=None, check_path=True, safe_init=True)¶
Bases:
State
A class to represent a state for executing arbitrary functions
This kind of state does not have any child states.
- classmethod from_dict(dictionary)¶
An abstract method each state has to implement.
- Parameters:
dictionary – the dictionary of parameters a state can be created from
- Raises:
exceptions.NotImplementedError – in any case
- run()¶
This defines the sequence of actions that are taken when the execution state is executed
- Returns:
- property script¶
Returns the property for the _script field.
- property script_text¶
- update_hash(obj_hash)¶
Should be implemented by derived classes to update the hash with their data fields
- Parameters:
obj_hash – The hash object (see Python hashlib)
hierarchy_state¶
- class rafcon.core.states.hierarchy_state.HierarchyState(name=None, state_id=None, input_data_ports=None, output_data_ports=None, income=None, outcomes=None, states=None, transitions=None, data_flows=None, start_state_id=None, scoped_variables=None, missing_library_meta_data=None, is_dummy=False, safe_init=True)¶
Bases:
ContainerState
A class to represent a hierarchy state for the state machine
The hierarchy state holds several child states, that can be container states on their own
- check_if_child_state_was_modified()¶
- run()¶
This defines the sequence of actions that are taken when the hierarchy is executed. A hierarchy state executes all its child states recursively. Principally this code collects all input data for the next child state, executes it, stores its output data and determines the next state based on the outcome of the child state. :return:
library_state¶
- class rafcon.core.states.library_state.LibraryState(library_path=None, library_name=None, version=None, name=None, state_id=None, income=None, outcomes=None, input_data_port_runtime_values=None, use_runtime_value_input_data_ports=None, output_data_port_runtime_values=None, use_runtime_value_output_data_ports=None, allow_user_interaction=True, safe_init=True, skip_runtime_data_initialization=False)¶
Bases:
State
A class to represent a library state for the state machine
Only the variables are listed that are not already contained in the state base class.
The constructor uses an exceptions.AttributeError if the passed version of the library and the version found in the library paths do not match.
- Variables:
library_path (str) – the path of the library relative to a certain library path (e.g. lwr/gripper/)
library_name (str) – the name of the library between all child states: (e.g. open, or close)
State.name (str) – the name of the library state
State.state_id (str) – the id of the library state
input_data_port_runtime_values (dict) – a dict to store all the runtime values for the input data ports
use_runtime_value_input_data_ports (dict) – flags to indicate if the runtime or the default value should be used for a specific input data port
output_data_port_runtime_values (dict) – a dict to store all the runtime values for the output data ports
use_runtime_value_output_data_ports (dict) – flags to indicate if the runtime or the default value should be used for a specific output data port
allow_user_interaction (dict) – flag to indicate if the user can support in localizing moved libraries
skip_runtime_data_initialization – flag to indicate if the runtime-data data structures have to be initialized, this is not needed e.g. in the case of a copy
- add_input_data_port(name, data_type=None, default_value=None, data_port_id=None)¶
Overwrites the add_input_data_port method of the State class. Prevents user from adding a output data port to the library state.
For further documentation, look at the State class. :raises exceptions.NotImplementedError: in any case
- add_outcome(name, outcome_id=None)¶
Overwrites the add_outcome method of the State class. Prevents user from adding a outcome to the library state.
For further documentation, look at the State class.
- Raises:
exceptions.NotImplementedError – in any case
- add_output_data_port(name, data_type, default_value=None, data_port_id=None)¶
Overwrites the add_output_data_port method of the State class. Prevents user from adding a output data port to the library state.
For further documentation, look at the State class. :raises exceptions.NotImplementedError: in any case
- destroy(recursive=True)¶
Removes all the state elements.
- Parameters:
recursive – Flag wether to destroy all state elements which are removed
- classmethod from_dict(dictionary)¶
An abstract method each state has to implement.
- Parameters:
dictionary – the dictionary of parameters a state can be created from
- Raises:
exceptions.NotImplementedError – in any case
- get_number_of_data_flows()¶
Return the number of data flows for a state. Per default states do not have data flows. :return:
- get_number_of_transitions()¶
Return the number of transitions for a state. Per default states do not have transitions. :return:
- get_states_statistics(hierarchy_level)¶
Returns the numer of child states. As per default states do not have child states return 1. :return:
- get_storage_path(appendix=None)¶
Recursively create the storage path of the state.
The path is generated in bottom up method i.e. from the nested child states to the root state. The method concatenates the concatenation of (State.name and State.state_id) as state identifier for the path.
- property input_data_port_runtime_values¶
Property for the _input_data_port_runtime_values field
- property library_hierarchy_depth¶
Calculates the library hierarchy depth
Counting starts at the current library state. So if the there is no upper library state the depth is one.
- Returns:
library hierarchy depth
- Return type:
- property library_name¶
Property for the _library_name field
- property library_path¶
Property for the _library_path field
- property output_data_port_runtime_values¶
Property for the _output_data_port_runtime_values field
- recursively_pause_states()¶
Pause the state and all of it child states.
- recursively_preempt_states()¶
Preempt the state and all of it child states.
- recursively_resume_states()¶
Resume the state and all of it child states.
- remove_input_data_port(data_port_id, force=False, destroy=True)¶
Overwrites the remove_input_data_port method of the State class. Prevents user from removing a input data port from the library state.
For further documentation, look at the State class.
- Parameters:
force (bool) – True if the removal should be forced
- Raises:
exceptions.NotImplementedError – in the removal is not forced
- remove_outcome(outcome_id, force=False, destroy=True)¶
Overwrites the remove_outcome method of the State class. Prevents user from removing a outcome from the library state.
For further documentation, look at the State class.
- Raises:
exceptions.NotImplementedError – in any case
- remove_output_data_port(data_port_id, force=False, destroy=True)¶
Overwrites the remove_output_data_port method of the State class. Prevents user from removing a output data port from the library state.
For further documentation, look at the State class. :param bool force: True if the removal should be forced :raises exceptions.NotImplementedError: in the removal is not forced
- run()¶
This defines the sequence of actions that are taken when the library state is executed
It basically just calls the run method of the container state :return:
- set_input_runtime_value(**kwargs)¶
- set_output_runtime_value(**kwargs)¶
- set_use_input_runtime_value(**kwargs)¶
- set_use_output_runtime_value(**kwargs)¶
- property state_copy¶
Property for the _state_copy field
- static state_to_dict(state)¶
- update_hash(obj_hash)¶
Should be implemented by derived classes to update the hash with their data fields
- Parameters:
obj_hash – The hash object (see Python hashlib)
- property use_runtime_value_input_data_ports¶
Property for the _use_runtime_value_input_data_ports field
- property use_runtime_value_output_data_ports¶
Property for the _use_runtime_value_output_data_ports field
- property version¶
Property for the _version field
preemptive_concurrency¶
- class rafcon.core.states.preemptive_concurrency_state.PreemptiveConcurrencyState(name=None, state_id=None, input_data_ports=None, output_data_ports=None, income=None, outcomes=None, states=None, transitions=None, data_flows=None, start_state_id=None, scoped_variables=None, safe_init=True)¶
Bases:
ConcurrencyState
The preemptive concurrency state has a set of substates which are started when the preemptive concurrency state executes. The execution of preemptive concurrency state waits for the first substate to return, preempts all other substates and finally returns self.
- run()¶
This defines the sequence of actions that are taken when the preemptive concurrency state is executed
- Returns:
state¶
- class rafcon.core.states.state.State(name=None, state_id=None, input_data_ports=None, output_data_ports=None, income=None, outcomes=None, parent=None, safe_init=True)¶
Bases:
Observable
,YAMLObject
,JSONObject
,Hashable
A class for representing a state in the state machine
It inherits from Observable to make a change of its fields observable.
- Variables:
State.name (str) – the name of the state
State.state_id (str) – the id of the state
State.input_data_ports (dict) – holds the input data ports of the state
State.output_data_ports (dict) – holds the output data ports of the state
State.outcomes (dict) – holds the state outcomes, which are the connection points for transitions
State.parent (rafcon.core.states.container_state.ContainerState) – a reference to the parent state or None
State.state_element_attrs (list) – List of strings/attribute names that point on state element type specific dictionaries which the state hold’s as attributes.
- property active¶
Property for the _active field
- add_input_data_port(**kwargs)¶
- add_outcome(**kwargs)¶
- add_output_data_port(**kwargs)¶
- add_semantic_data(**kwargs)¶
- change_state_id(state_id=None)¶
Changes the id of the state to a new id
If no state_id is passed as parameter, a new state id is generated.
- Parameters:
state_id (str) – The new state id of the state
- Returns:
- check_child_validity(child)¶
Check validity of passed child object
The method is called by state child objects (outcomes, data ports) when these are initialized or changed. The method checks the type of the child and then checks its validity in the context of the state.
- Parameters:
child (object) – The child of the state that is to be tested
- Return bool validity, str message:
validity is True, when the child is valid, False else. message gives more information especially if the child is not valid
- check_input_data_type()¶
Check the input data types of the state
Checks all input data ports if the handed data is not of the specified type and generate an error logger message with details of the found type conflict.
- check_output_data_type()¶
Check the output data types of the state
Checks all output data ports if the handed data is not of the specified type and generate an error logger message with details of the found type conflict.
- property concurrency_queue¶
Property for the _concurrency_queue field
- property core_element_id¶
- static create_output_dictionary_for_state(state)¶
Return empty output dictionary for a state
- Parameters:
state – the state of which the output data is determined
- Returns:
the output data of the target state
- property description¶
Property for the _description field
- destroy(recursive)¶
Removes all the state elements.
- Parameters:
recursive – Flag wether to destroy all state elements which are removed
- property file_system_path¶
Provides the path in the file system where the state is stored
The method returns None if the state was not stored, before,
- Return type:
- Returns:
the path on the file system where the state is stored
- property final_outcome¶
Property for the _final_outcome field
- finalize(outcome=None)¶
Finalize state
This method is called when the run method finishes
- Parameters:
outcome (rafcon.core.logical_port.Outcome) – final outcome of the state
- Returns:
Nothing for the moment
- classmethod from_dict(dictionary)¶
An abstract method each state has to implement.
- Parameters:
dictionary – the dictionary of parameters a state can be created from
- Raises:
exceptions.NotImplementedError – in any case
- generate_run_id()¶
- get_data_port_by_id(data_port_id)¶
Search for the given data port id in the data ports of the state
The method tries to find a data port in the input and output data ports. :param int data_port_id: the unique id of the data port :return: the data port with the searched id or None if it is not found
- get_data_port_ids()¶
- get_default_input_values_for_state(state)¶
Computes the default input values for a state
- Parameters:
state (State) – the state to get the default input values for
- get_io_data_port_id_from_name_and_type(name, data_port_type, throw_exception=True)¶
Returns the data_port_id of a data_port with a certain name and data port type
- Parameters:
name – the name of the target data_port
data_port_type – the data port type of the target data port
throw_exception – throw an exception when the data port does not exist
- Returns:
the data port specified by the name and the type
- Raises:
exceptions.AttributeError – if the specified data port does not exist in the input or output data ports
- get_next_upper_library_root_state()¶
Get next upper library root state
The method recursively checks state parent states till finding a StateMachine as parent or a library root state. If self is a LibraryState the next upper library root state is searched and it is not handed self.state_copy.
:return library root state (Execution or ContainerState) or None if self is not a library root state or inside of such :rtype rafcon.core.states.library_state.State:
- get_number_of_data_flows()¶
Generate the number of data flows
- Return type:
- Returns:
The number of data flows for a state. Per default states do not have data flows.
- get_number_of_transitions()¶
Generate the number of transitions
- Return type:
- Returns:
The number of transitions for a state. Per default states do not have transitions.
- get_path(appendix=None, by_name=False)¶
Recursively create the path of the state.
The path is generated in bottom up method i.e. from the nested child states to the root state. The method concatenates either State.state_id (always unique) or State.name (maybe not unique but human readable) as state identifier for the path.
- get_previously_executed_state()¶
Calculates the state that was executed before this state
- Returns:
The last state in the execution history
- get_semantic_data(path_as_list)¶
Retrieves an entry of the semantic data.
- Parameters:
path_as_list (list) – The path in the vividict to retrieve the value from
- Returns:
- get_state_machine()¶
Get a reference of the state_machine the state belongs to
:rtype rafcon.core.state_machine.StateMachine :return: respective state machine
- get_states_statistics(hierarchy_level)¶
Get states statistic tuple
- Return type:
- Returns:
The number of child states. As per default states do not have child states return 1.
- get_storage_path(appendix=None)¶
Recursively create the storage path of the state.
The path is generated in bottom up method i.e. from the nested child states to the root state. The method concatenates the concatenation of (State.name and State.state_id) as state identifier for the path.
- get_temp_file_system_path()¶
Provides a temporary path
The path is not fully secure because the all state ids are not globally unique.
- get_uppermost_library_root_state()¶
Find state_copy of uppermost LibraryState
Method checks if there is a parent library root state and assigns it to be the current library root state till there is no further parent library root state.
- id()¶
- property input_data¶
Property for the _input_data field
- property input_data_ports¶
Property for the _input_data_ports field
See Property.
- Parameters:
input_data_ports (dict) – Dictionary that maps
int
data_port_ids onto values of typerafcon.core.state_elements.data_port.InputDataPort
- Raises:
exceptions.TypeError – if the input_data_ports parameter has the wrong type
exceptions.AttributeError – if the key of the input dictionary and the id of the data port do not match
- property is_root_state¶
- property is_root_state_of_library¶
If self is the attribute LibraryState.state_copy of a LibraryState its the library root state and its parent is a LibraryState :return True or False :rtype bool
- join()¶
Waits until the state finished execution.
- property outcomes¶
Property for the _outcomes field
The setter-method substitute State._outcomes with a handed dictionary. The method checks if the elements are of the right type and the keys consistent (Outcome.outcome_id==key). The method does check validity of the elements by calling the parent-setter and in case of failure cancel the operation and recover old outcomes.
- Returns:
Dictionary outcomes[
int
,rafcon.core.state_elements.logical_port.Outcome
] that mapsint
outcome_ids onto values of type Outcome- Return type:
- property output_data¶
Property for the _output_data field
- property output_data_ports¶
Property for the _output_data_ports field
The setter-method substitute State._output_data_ports with a handed dictionary. The method checks if the elements are of the right type and the keys consistent (DataPort.data_port_id==key). The method does check validity of the elements by calling the parent-setter and in case of failure cancel the operation and recover old _output_data_ports.
- Returns:
Dictionary output_data_ports[
int
,rafcon.core.state_elements.data_port.OutputDataPort
] that mapsint
data_port_ids onto values of type OutputDataPort- Return type:
- property parent¶
Property for the _parent field
- Return type:
- Returns:
A ContainState or value None if there is no parent or the parent is
rafcon.core.state_machine.StateMachine
- property paused¶
Checks, whether the paused event is set
- property preempted¶
Checks, whether the preempted event is set
- preemptive_wait(time=None)¶
Waiting method which can be preempted
Use this method if you want a state to pause. In contrast to time.sleep(), the pause can be preempted. This method can also be used if you want to have a daemon thread within a preemptive concurrency state. In this case, time has to be set to None and the method waits indefinitely or until it is preempted from outside. :param time: The time in seconds to wait or None (default) for infinity :return: True, if the wait was preempted, False else
- recursively_pause_states()¶
Pause the state
- recursively_preempt_states()¶
Preempt the state
- recursively_resume_states()¶
Resume the state
- remove(state_element, recursive=True, force=False, destroy=True)¶
Remove item from state
- Parameters:
state_element (StateElement) – State element to be removed
recursive (bool) – Only applies to removal of state and decides whether the removal should be called recursively on all child states
force (bool) – if the removal should be forced without checking constraints
destroy (bool) – a flag that signals that the state element will be fully removed and disassembled
- remove_data_flows_with_data_port_id(data_port_id)¶
Remove all data flows whose from_key or to_key equals the passed data_port_id
- Parameters:
data_port_id – the id of a data_port of which all data_flows should be removed, the id can be a input or output data port id
- remove_income(**kwargs)¶
- remove_input_data_port(**kwargs)¶
- remove_outcome(**kwargs)¶
- remove_outcome_hook(outcome_id)¶
Hook for adding more logic when removing an outcome
This hook is intended for the use of inherited classed, which can add more functionality if needed. A container state would remove its transitions going the removed outcome here.
- Parameters:
outcome_id – The id of the outcome that is removed
- remove_output_data_port(**kwargs)¶
- remove_semantic_data(**kwargs)¶
- run(*args, **kwargs)¶
Implementation of the abstract run() method of the
threading.Thread
- Raises:
exceptions.NotImplementedError – in any case
- property run_id¶
Property for the _run_id field
- property semantic_data¶
Property for the _semantic_data field
- setup_backward_run()¶
- setup_run()¶
Executes a generic set of actions that has to be called in the run methods of each derived state class.
- Raises:
exceptions.TypeError – if the input or output data are not of type dict
- start(execution_history, backward_execution=False, generate_run_id=True)¶
Starts the execution of the state in a new thread.
- Returns:
- property started¶
Checks, whether the started event is set
- state_element_attrs = ['income', 'outcomes', 'input_data_ports', 'output_data_ports']¶
- property state_execution_status¶
Property for the _state_execution_status field
- property state_id¶
Property for the _state_id field
- static state_to_dict(state)¶
- to_dict()¶
Abstract method
This method must be implemented by the deriving classes. It must return a Python dict with all parameters of self, which are needed to create a copy of self.
- Returns:
A Python dict with all needed parameters of self
- Return type:
- update_hash(obj_hash)¶
Should be implemented by derived classes to update the hash with their data fields
- Parameters:
obj_hash – The hash object (see Python hashlib)
- wait_for_interruption(timeout=None)¶
Wait for any of the events paused or preempted to be set
- rafcon.core.states.state.StateExecutionStatus¶
alias of
STATE_EXECUTION_STATE
- rafcon.core.states.state.StateType¶
alias of
STATE_TYPE