Module model¶
-
class
sismic.model.
ActionStateMixin
(on_entry=None, on_exit=None)¶ Bases:
object
State that can define actions on entry and on exit.
Parameters:
-
class
sismic.model.
BasicState
(name, on_entry=None, on_exit=None)¶ Bases:
sismic.model.elements.ContractMixin
,sismic.model.elements.StateMixin
,sismic.model.elements.ActionStateMixin
,sismic.model.elements.TransitionStateMixin
A basic state, with a name, transitions, actions, etc. but no child state.
Parameters:
-
class
sismic.model.
CompoundState
(name, initial=None, on_entry=None, on_exit=None)¶ Bases:
sismic.model.elements.ContractMixin
,sismic.model.elements.StateMixin
,sismic.model.elements.ActionStateMixin
,sismic.model.elements.TransitionStateMixin
,sismic.model.elements.CompositeStateMixin
Compound states must have children states.
Parameters:
-
class
sismic.model.
ContractMixin
¶ Bases:
object
Mixin with a contract: preconditions, postconditions and invariants.
-
class
sismic.model.
DeepHistoryState
(name, on_entry=None, on_exit=None, memory=None)¶ Bases:
sismic.model.elements.ContractMixin
,sismic.model.elements.StateMixin
,sismic.model.elements.ActionStateMixin
,sismic.model.elements.HistoryStateMixin
A deep history state resumes the execution of its parent, and of every nested active states in its parent.
Parameters:
-
class
sismic.model.
Event
(name, **additional_parameters)¶ Bases:
object
An event with a name and (optionally) some data passed as named parameters.
The list of parameters can be obtained using dir(event). Notice that name and data are reserved names. If a delay parameter is provided, then this event will be considered as a delayed event (and won’t be executed until delay has elapsed).
When two events are compared, they are considered equal if their names and their data are equal.
Parameters: - name (
str
) – name of the event. - data – additional data passed as named parameters.
- name (
-
class
sismic.model.
FinalState
(name, on_entry=None, on_exit=None)¶ Bases:
sismic.model.elements.ContractMixin
,sismic.model.elements.StateMixin
,sismic.model.elements.ActionStateMixin
Final state has NO transition and is used to detect state machine termination.
Parameters:
-
class
sismic.model.
HistoryStateMixin
(memory=None)¶ Bases:
object
History state has a memory that can be resumed.
Parameters: memory ( Optional
[str
]) – name of the initial state
-
class
sismic.model.
InternalEvent
(name, **additional_parameters)¶ Bases:
sismic.model.events.Event
Subclass of Event that represents an internal event.
-
class
sismic.model.
MacroStep
(time, steps)¶ Bases:
object
A macro step is a list of micro steps.
Parameters: - time (
float
) – the time at which this step was executed - steps (
List
[MicroStep
]) – a list of MicroStep instances
-
steps
¶ List of micro steps
Return type: List
[MicroStep
]
-
event
¶ Event (or None) that was consumed.
Return type: Optional
[Event
]
-
transitions
¶ A (possibly empty) list of transitions that were triggered.
Return type: List
[Transition
]
-
sent_events
¶ List of events that were sent during this step.
Return type: List
[Event
]
- time (
-
class
sismic.model.
MetaEvent
(name, **additional_parameters)¶ Bases:
sismic.model.events.Event
Subclass of Event that represents a MetaEvent, as used in property statecharts.
-
class
sismic.model.
MicroStep
(event=None, transition=None, entered_states=None, exited_states=None, sent_events=None)¶ Bases:
object
Create a micro step.
A step consider event, takes a transition and results in a list of entered_states and a list of exited_states. Order in the two lists is REALLY important!
Parameters: - event (
Optional
[Event
]) – Event or None in case of eventless transition - transition (
Optional
[Transition
]) – a Transition or None if no processed transition - entered_states (
Optional
[List
[str
]]) – possibly empty list of entered states - exited_states (
Optional
[List
[str
]]) – possibly empty list of exited states - sent_events (
Optional
[List
[Event
]]) – a possibly empty list of events that are sent during the step
- event (
-
class
sismic.model.
OrthogonalState
(name, on_entry=None, on_exit=None)¶ Bases:
sismic.model.elements.ContractMixin
,sismic.model.elements.StateMixin
,sismic.model.elements.ActionStateMixin
,sismic.model.elements.TransitionStateMixin
,sismic.model.elements.CompositeStateMixin
Orthogonal states run their children simultaneously.
Parameters:
-
class
sismic.model.
ShallowHistoryState
(name, on_entry=None, on_exit=None, memory=None)¶ Bases:
sismic.model.elements.ContractMixin
,sismic.model.elements.StateMixin
,sismic.model.elements.ActionStateMixin
,sismic.model.elements.HistoryStateMixin
A shallow history state resumes the execution of its parent. It activates the latest visited state of its parent.
Parameters:
-
class
sismic.model.
StateMixin
(name)¶ Bases:
object
State element with a name.
Parameters: name ( str
) – name of the state
-
class
sismic.model.
Statechart
(name, description=None, preamble=None)¶ Bases:
object
Python structure for a statechart
Parameters: -
preamble
¶ Preamble code
-
states
¶ List of state names in lexicographic order.
-
state_for
(name)¶ Return the state instance that has given name.
Parameters: name ( str
) – a state nameReturn type: StateMixin
Returns: a StateMixin that has the same name or None Raises: StatechartError – if state does not exist
-
parent_for
(name)¶ Return the name of the parent of given state name.
Parameters: name ( str
) – a state nameReturn type: Optional
[str
]Returns: its parent name, or None. Raises: StatechartError – if state does not exist
-
children_for
(name)¶ Return the names of the children of the given state.
Parameters: name ( str
) – a state nameReturn type: List
[str
]Returns: a (possibly empty) list of children Raises: StatechartError – if state does not exist
-
ancestors_for
(name)¶ Return an ordered list of ancestors for the given state. Ancestors are ordered by decreasing depth.
Parameters: name ( str
) – name of the stateReturn type: List
[str
]Returns: state’s ancestors Raises: StatechartError – if state does not exist
-
descendants_for
(name)¶ Return an ordered list of descendants for the given state. Descendants are ordered by increasing depth.
Parameters: name ( str
) – name of the stateReturn type: List
[str
]Returns: state’s descendants Raises: StatechartError – if state does not exist
-
depth_for
(name)¶ Return the depth of given state (1-indexed).
Parameters: name ( str
) – name of the stateReturn type: int
Returns: state depth Raises: StatechartError – if state does not exist
-
least_common_ancestor
(name_first, name_second)¶ Return the deepest common ancestor for s1 and s2, or None if there is no common ancestor except root (top-level) state.
Parameters: Return type: Optional
[str
]Returns: name of deepest common ancestor or None
Raises: StatechartError – if state does not exist
-
leaf_for
(names)¶ Return the leaves of names.
Considering the list of states names in names, return a list containing each element of names such that this element has no descendant in names.
Parameters: names ( Iterable
[str
]) – a list of state namesReturn type: List
[str
]Returns: the names of the leaves in names Raises: StatechartError – if a state does not exist
-
transitions
¶ List of available transitions
-
add_transition
(transition)¶ Register given transition and register it on the source state
Parameters: transition ( Transition
) – transition to addRaises: StatechartError – Return type: None
-
remove_transition
(transition)¶ Remove given transitions.
Parameters: transition ( Transition
) – a Transition instanceRaises: StatechartError – if transition is not registered Return type: None
-
rotate_transition
(transition, new_source='', new_target='')¶ Rotate given transition.
You MUST specify either new_source (a valid state name) or new_target (a valid state name or None) or both.
Parameters: Raises: StatechartError – if given transition or a given state does not exist.
Return type: None
-
transitions_from
(source)¶ Return the list of transitions whose source is given name.
Parameters: source ( str
) – name of source stateReturn type: List
[Transition
]Returns: a list of Transition instances Raises: StatechartError – if state does not exist
-
transitions_to
(target)¶ Return the list of transitions whose target is given name. Internal transitions are returned too.
Parameters: target ( str
) – name of target stateReturn type: List
[Transition
]Returns: a list of Transition instances Raises: StatechartError – if state does not exist
-
transitions_with
(event)¶ Return the list of transitions that can be triggered by given event name.
Parameters: event ( str
) – name of the eventReturn type: List
[Transition
]Returns: a list of Transition instances
-
events_for
(name_or_names=None)¶ Return a list containing the name of every event that guards a transition in this statechart.
If name_or_names is specified, it must be the name of a state (or a list of such names). Only transitions that have a source state from this list will be considered. By default, the list contains all the states.
Parameters: name_or_names ( Union
[str
,List
[str
],None
]) – None, a state name or a list of state names.Return type: List
[str
]Returns: A list of event names
-
add_state
(state, parent)¶ Add given state (a StateMixin instance) on given parent (its name as an str). If given state should be use as a root state, set parent to None.
Parameters: - state (
StateMixin
) – state to add - parent (
Optional
[str
]) – name of its parent, or None
Raises: Return type: None
- state (
-
remove_state
(name)¶ Remove given state.
The transitions that involve this state will also be removed. If the state is the target of an initial or memory property, their value will be set to None. If the state has children, they will be removed too.
Parameters: name ( str
) – name of a stateRaises: StatechartError – Return type: None
-
rename_state
(old_name, new_name)¶ Change state name, and adapt transitions, initial state, memory, etc.
Parameters: Return type: None
-
move_state
(name, new_parent)¶ Move given state (and its children) such that its new parent is new_parent.
Notice that a state cannot be moved inside itself or inside one of its descendants. If the state to move is the target of an initial or memory property of its parent, this property will be set to None. The same occurs if given state is an history state.
Parameters: Return type: None
-
copy_from_statechart
(statechart, *, source, replace, renaming_func=<function Statechart.<lambda>>)¶ Copy (a part of) given statechart into current one.
Copy source state, all its descendants and all involved transitions from statechart into current statechart. The source state will override replace state (but will be renamed to replace), and all its descendants in statechart will be copied into current statechart. All the transitions that are involved in the process must be fully contained in source state (ie. for all transition T: S->T, if S (resp. T) is a descendant-or-self of source, then T (resp. S) must be a descendant-or-self of source).
If necessary, callable renaming_func can be provided. This function should accept a (state) name and return a (new state) name. Use renaming_func to avoid conflicting names in target statechart.
Parameters: Return type: None
-
validate
()¶ Checks that every CompoundState’s initial state refer to one of its children Checks that every HistoryStateMixin’s memory refer to one of its parent’s children
Return type: bool
Returns: True Raises: StatechartError –
-
-
class
sismic.model.
Transition
(source, target=None, event=None, guard=None, action=None, priority=None)¶ Bases:
sismic.model.elements.ContractMixin
Represent a transition from a source state to a target state.
A transition can be eventless (no event) or internal (no target). A condition (code as string) can be specified as a guard.
Parameters: - source (
str
) – name of the source state - target (
Optional
[str
]) – name of the target state (if transition is not internal) - event (
Optional
[str
]) – event name (if any) - guard (
Optional
[str
]) – condition as code (if any) - action (
Optional
[str
]) – action as code (if any) - priority – priority (default to 0)
-
internal
¶ Boolean indicating whether this transition is an internal transition.
-
eventless
¶ Boolean indicating whether this transition is an eventless transition.
- source (