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 (str) – code to execute when state is entered

  • on_exit (str) – code to execute when state is exited

class sismic.model.BasicState(name, on_entry=None, on_exit=None)

Bases: ContractMixin, StateMixin, ActionStateMixin, TransitionStateMixin

A basic state, with a name, transitions, actions, etc. but no child state.

Parameters:
  • name (str) – name of this state

  • on_entry (str) – code to execute when state is entered

  • on_exit (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: ContractMixin, StateMixin, ActionStateMixin, TransitionStateMixin, CompositeStateMixin

Compound states must have children states.

Parameters:
  • name (str) – name of this state

  • initial (str) – name of the initial state

  • on_entry (str) – code to execute when state is entered

  • on_exit (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: ContractMixin, StateMixin, ActionStateMixin, 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 (str) – code to execute when state is entered

  • on_exit (str) – code to execute when state is exited

  • memory (str) – name of the initial state

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 given 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.

class sismic.model.FinalState(name, on_entry=None, on_exit=None)

Bases: ContractMixin, StateMixin, ActionStateMixin

Final state has NO transition and is used to detect state machine termination.

Parameters:
  • name (str) – name of this state

  • on_entry (str) – code to execute when state is entered

  • on_exit (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 (str) – name of the initial state

class sismic.model.InternalEvent(name, **additional_parameters)

Bases: 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

property steps: List[MicroStep]

List of micro steps

property time: float

Time at which this step was executed.

property event: Event | None

Event (or None) that was consumed.

property transitions: List[Transition]

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

property entered_states: List[str]

List of the states names that were entered.

property exited_states: List[str]

List of the states names that were exited.

property sent_events: List[Event]

List of events that were sent during this step.

class sismic.model.MetaEvent(name, **additional_parameters)

Bases: 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 (Event) – Event or None in case of eventless transition

  • transition (Transition) – a Transition or None if no processed transition

  • entered_states (List[str]) – possibly empty list of entered states

  • exited_states (List[str]) – possibly empty list of exited states

  • sent_events (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: ContractMixin, StateMixin, ActionStateMixin, TransitionStateMixin, CompositeStateMixin

Orthogonal states run their children simultaneously.

Parameters:
  • name (str) – name of this state

  • on_entry (str) – code to execute when state is entered

  • on_exit (str) – code to execute when state is exited

class sismic.model.ShallowHistoryState(name, on_entry=None, on_exit=None, memory=None)

Bases: ContractMixin, StateMixin, ActionStateMixin, 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 (str) – code to execute when state is entered

  • on_exit (str) – code to execute when state is exited

  • memory (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 (str) – optional description

  • preamble (str) – code to execute to bootstrap the statechart

property root: str | None

Root state name

property preamble

Preamble code

property states

List of state names in lexicographic order.

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

parent_for(name)

Return the name of the parent of given state name.

Parameters:

name (str) – a state name

Return 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 name

Return 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 state

Return 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 state

Return 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 state

Return 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:
  • 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

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

property transitions

List of available transitions

add_transition(transition)

Register given transition and register it on the source state

Parameters:

transition (Transition) – transition to add

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

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

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

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, 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:
Raises:

StatechartError

Return type:

None

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

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

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

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

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: 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 (str) – name of the target state (if transition is not internal)

  • event (str) – event name (if any)

  • guard (str) – condition as code (if any)

  • action (str) – action as code (if any)

  • priority – priority (default to 0)

property internal

Boolean indicating whether this transition is an internal transition.

property eventless

Boolean indicating whether this transition is an eventless transition.

class sismic.model.TransitionStateMixin

Bases: object

A simple state can host transitions