crestdsl.model package

Domain Model

class crestdsl.model.Resource(unit, domain)

A resource is a value type for CREST models. Each port is initialised with a Resource that identifies the type of values it will hold. Note, that resouce objects should be centrally defined and reused, so that ports of the same resource can reference the same resource object.

Resources are created with a unit i.e. it’s name (e.g. Watt or Lumen) and a domain. The domain is either one of the crestdsl Datatypes or a list of discrete values.

class crestdsl.model.Entity(name='', parent=None)

Bases: crestdsl.model.meta.CrestObject

The base class of all CREST systems and components. It is meant to be subclassed.

To create a new entity, create from this class using e.g. class MyEntity(crest.Entity). Note, that you can implement (parameterized) constructors for your entities with __init__.

Communication Interface

class crestdsl.model.Input(resource=None, value=None, name=None, parent=None)

Bases: crestdsl.model.ports.Port

An input port of an entity. Its value can only be read from inside the entity and set only from the outside. This means you should never write an input from inside its own entity!

__init__(resource=None, value=None, name=None, parent=None)
Parameters
  • resource (Resource) – A resource that specifies the types of values the port can take.

  • value (object) – An initial value that matches the resource.

class crestdsl.model.Output(resource=None, value=None, name=None, parent=None)

Bases: crestdsl.model.ports.Port

An output port of an entity. Its value can only be set from inside the entity and read only from the outside. This means you should never read an output from inside its own entity!

__init__(resource=None, value=None, name=None, parent=None)
Parameters
  • resource (Resource) – A resource that specifies the types of values the port can take.

  • value (object) – An initial value that matches the resource.

class crestdsl.model.Local(resource=None, value=None, name=None, parent=None)

Bases: crestdsl.model.ports.Port

A local port of an entity. Its value can only be set and read from the entity itself.

__init__(resource=None, value=None, name=None, parent=None)
Parameters
  • resource (Resource) – A resource that specifies the types of values the port can take.

  • value (object) – An initial value that matches the resource.

Behaviour Automaton (Discrete Behaviour)

class crestdsl.model.State(name=None, parent=None)

Bases: crestdsl.model.meta.CrestObject

A state for the behaviour automaton. States don’t have much functionality, but are necessary for transtions. Don’t forget to declare one of the states as current.

__init__(name=None, parent=None)
class crestdsl.model.Transition(source=None, target=None, guard=None, name='', parent=None)

Bases: crestdsl.model.meta.CrestObject

A transition between behaviour automaton states. Note that the source and target states have to be defined for the same entity as the transition itself.

Note

Pro-tip: To avoid repetition, you can initialise it with a list of source/target states (or str-names). This will automatically create a transition from/to each. Be careful, because the transition’s name will be autoamtically numbered on inititialisation.

__init__(source=None, target=None, guard=None, name='', parent=None)
Parameters
  • source (State or str or list) – The starting state of a transition. Either a state object, or the name (str) of it.

  • target (State or str or list) – The target state of a transition. Either a state object, or the name (str) of it.

  • guard (lambda or func) – The guard function implementation. This can be either a lambda expression or the reference to a function/method. (The guard HAS to take exactly one parameter: self)

isenabled()

Evaluates whether the transition is currently enabled.

@crestdsl.model.transition(source='', target='')

A decorator for the definition of a Transition. Decorate any method to make it a guarded transition.

Don’t forget to specify the source and target states.

Parameters
  • source (State or str or list) – The starting state of a transition. Either a state object, or the name (str) of it.

  • target (State or str or list) – The target state of a transition. Either a state object, or the name (str) of it.

class crestdsl.model.Action(transition, target, function, name='', parent=None)

Bases: crestdsl.model.meta.CrestObject

An Action whose function is executed when a certain automaton transition is triggered.

Note

Pro-tip: To avoid repetition, you can initialise it with a list of transitions (or str-names). This will automatically create an action for each transition. Be careful, because the action’s name will be autoamtically numbered on inititialisation.

__init__(transition, target, function, name='', parent=None)
Parameters
  • source (Transition or str) – The transition at which the update should be triggered. Either a transition object, or the name (str) of it.

  • target (Port or str) – The target port of the action. Either a port object, or the name (str) of it.

  • function (lambda or func) – A conversion function that calculates the target port’s value. (The function HAS to take exactly one parameter: self)

@crestdsl.model.action(*args, **kwargs)

A decorator for the definition of an Action. Decorate any method to make it an action function.

Don’t forget to specify the transition and target port.

Parameters
  • source (Transition or str) – The transition at which the update should be triggered. Either a transition object, or the name (str) of it.

  • target (Port or str) – The target port of the action. Either a port object, or the name (str) of it.

Continuous Behaviour

class crestdsl.model.Influence(source, target, function=None, name='', parent=None)

Bases: crestdsl.model.meta.CrestObject

An influence between two ports. You can specify a conversiton function that modifies the source port’s value before writing it to the target port.

__init__(source, target, function=None, name='', parent=None)
Parameters
  • source (Port or str) – The starting port of the influence. Either a port object, or the name (str) of it.

  • target (Port or str) – The target port of the influence. Either a port object, or the name (str) of it.

  • function (lambda or func) – A conversion function that calculates the target port’s value. (The function HAS to take exactly one parameter value)

@crestdsl.model.influence(source='', target='')

A decorator for the definition of an Influence. Decorate any method to make it an influence between two ports.

Don’t forget to specify the source and target ports.

Parameters
  • source (Port or str) – The starting port of the influence. Either a port object, or the name (str) of it.

  • target (Port or str) – The target port of the influence. Either a port object, or the name (str) of it.

class crestdsl.model.Update(state, target, function, name='', parent=None)

Bases: crestdsl.model.meta.CrestObject

An Update whose function is continuously executed when the automaton is in a certain state.

Note

Pro-tip: To avoid repetition, you can initialise it with a list of states (or str-names). This will automatically create an update for each state to avoid repetition. Be careful, because the update’s name will be autoamtically numbered on inititialisation.

__init__(state, target, function, name='', parent=None)
Parameters
  • source (State or str) – The state in which the update should be executed. Either a state object, or the name (str) of it.

  • target (Port or str) – The target port of the update. Either a port object, or the name (str) of it.

  • function (lambda or func) – A conversion function that calculates the target port’s value. (The function HAS to take exactly two parameters: self and dt)

@crestdsl.model.update(*args, **kwargs)

A decorator for the definition of an Update. Decorate any method to make it an update function.

Don’t forget to specify the state and target port.

Parameters
  • source (State or str) – The state in which the update should be executed. Either a state object, or the name (str) of it.

  • target (Port or str) – The target port of the update. Either a port object, or the name (str) of it.

Input/Output Dependencies

class crestdsl.model.Dependency(source, target)

Bases: crestdsl.model.meta.CrestObject

A Dependency object specifies that an output depends on an input. This is necessary to resolve circular dependencies.

Don’t use this class directly. Use the @dependency class decorator instead.

__init__(source, target)
Parameters
  • source (Output or str (output portname)) – The dependency source (i.e. the output port).

  • target (Input or str (input portname)) – The dependency target (i.e. the input port).

@crestdsl.model.nodependencies

A class-decorator to declare that a class’ outputs don’t depend in its inputs.

No params!

@crestdsl.model.dependency(source, target)

A class-decorator to declare that a class’s output depends on an input. This is necessary to resolve circular dependencies.

Parameters
  • source (Output or str (output portname)) – The dependency source (i.e. the output port).

  • target (Input or str (input portname)) – The dependency target (i.e. the input port).