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:
  • on_entry (Optional[str]) – code to execute when state is entered
  • on_exit (Optional[str]) – code to execute when state is exited
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:
  • name (str) – name of this state
  • on_entry (Optional[str]) – code to execute when state is entered
  • on_exit (Optional[str]) – code to execute when state is exited
class sismic.model.CompositeStateMixin

Bases: object

Composite state can have children states.

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:
  • name (str) – name of this state
  • initial (Optional[str]) – name of the initial state
  • on_entry (Optional[str]) – code to execute when state is entered
  • on_exit (Optional[str]) – code to execute when state is exited
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:
  • name (str) – name of this state
  • on_entry (Optional[str]) – code to execute when state is entered
  • on_exit (Optional[str]) – code to execute when state is exited
  • memory (Optional[str]) – name of the initial state
class sismic.model.Event(name, **additional_parameters)

Bases: object

Simple event with a name and (optionally) some data. Unless the attribute already exists, each key from data is exposed as an attribute of this class.

The list of defined attributes can be obtained using dir(event).

Parameters:
  • name (str) – Name of the event
  • data – additional data (mapping, dict-like)
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:
  • name (str) – name of this state
  • on_entry (Optional[str]) – code to execute when state is entered
  • on_exit (Optional[str]) – code to execute when state is exited
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
entered_states

List of the states names that were entered.

Return type:List[str]
event

Event (or None) that was consumed.

Return type:Optional[Event]
exited_states

List of the states names that were exited.

Return type:List[str]
sent_events

List of events that were sent during this step.

Return type:List[Event]
steps

List of micro steps

Return type:List[MicroStep]
time

Time at which this step was executed.

Return type:float
transitions

A (possibly empty) list of transitions that were triggered.

Return type:List[Transition]
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
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:
  • name (str) – name of this state
  • on_entry (Optional[str]) – code to execute when state is entered
  • on_exit (Optional[str]) – code to execute when state is exited
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:
  • name (str) – name of this state
  • on_entry (Optional[str]) – code to execute when state is entered
  • on_exit (Optional[str]) – code to execute when state is exited
  • memory (Optional[str]) – name of the initial state
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:
  • name (str) – Name of this statechart
  • description (Optional[str]) – optional description
  • preamble (Optional[str]) – code to execute to bootstrap the statechart
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:

StatechartError

Return type:

None

add_transition(transition)

Register given transition and register it on the source state

Parameters:transition (Transition) – transition to add
Raises:StatechartError
Return type:None
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 state
Return type:List[str]
Returns:state’s ancestors
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 name
Return type:List[str]
Returns:a (possibly empty) list of children
Raises:StatechartError – if state does not exist
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:
  • statechart (Statechart) – Source statechart from which states will be copied.
  • source (str) – Name of the source state.
  • replace (str) – Name of the target state. Should refer to a StateMixin with no child.
  • renaming_func (Callable[[str], str]) – Optional callable to resolve conflicting names.
Return type:

None

depth_for(name)

Return the depth of given state (1-indexed).

Parameters:name (str) – name of the state
Return type:int
Returns:state depth
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 state
Return type:List[str]
Returns:state’s descendants
Raises:StatechartError – if state does not exist
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
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 names
Return type:List[str]
Returns:the names of the leaves in names
Raises:StatechartError – if a 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:
  • name_first (str) – name of first state
  • name_second (str) – name of second state
Return type:

Optional[str]

Returns:

name of deepest common ancestor or None

Raises:

StatechartError – if state does not exist

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:
  • name (str) – name of the state to move
  • new_parent (str) – name of the new parent
Return type:

None

parent_for(name)

Return the name of the parent of given state name.

Parameters:name (str) – a state name
Return type:str
Returns:its parent name, or None.
Raises:StatechartError – if state does not exist
preamble

Preamble code

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 state
Raises:StatechartError
Return type:None
remove_transition(transition)

Remove given transitions.

Parameters:transition (Transition) – a Transition instance
Raises:StatechartError – if transition is not registered
Return type:None
rename_state(old_name, new_name)

Change state name, and adapt transitions, initial state, memory, etc.

Parameters:
  • old_name (str) – old name of the state
  • new_name (str) – new name of the state
Return type:

None

root

Root state name

Return type:Optional[str]
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:
  • transition (Transition) – a Transition instance
  • new_source (str) – a state name
  • new_target (Optional[str]) – a state name or None
Raises:

StatechartError – if given transition or a given state does not exist.

Return type:

None

state_for(name)

Return the state instance that has given name.

Parameters:name (str) – a state name
Return type:StateMixin
Returns:a StateMixin that has the same name or None
Raises:StatechartError – if state does not exist
states

List of state names in lexicographic order.

transitions

List of available transitions

transitions_from(source)

Return the list of transitions whose source is given name.

Parameters:source (str) – name of source state
Return 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 state
Return 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 event
Return type:List[Transition]
Returns:a list of Transition instances
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)

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)
eventless

Boolean indicating whether this transition is an eventless transition.

internal

Boolean indicating whether this transition is an internal transition.

class sismic.model.TransitionStateMixin

Bases: object

A simple state can host transitions