lems.model package

Submodules

lems.model.component module

Parameter, ComponentType and Component class definitions.

author:

Gautham Ganapathy

organization:

LEMS (https://github.com/organizations/LEMS)

class lems.model.component.Attachments(name, type_, description='')

Bases: LEMSBase

Stores an attachment type specification.

description

Description about the attachment.

Type:

str

name

Name of the attachment collection.

Type:

str

toxml()

Exports this object into a LEMS XML object

type

Type of attachment.

Type:

str

class lems.model.component.Children(name, type_, description='', multiple=False)

Bases: LEMSBase

Stores children specification.

description

Description of the children.

Type:

str

multiple

Single child / multiple children.

Type:

bool

name

Name of the children.

Type:

str

toxml()

Exports this object into a LEMS XML object

type

Component type of the children.

Type:

str

class lems.model.component.Component(id_, type_, **params)

Bases: LEMSBase

Stores a component instantiation.

add(child)

Adds a typed child object to the component.

Parameters:

child – Child object to be added.

add_child(child)

Adds a child component.

Parameters:

child (lems.model.component.Component) – Child component to be added.

children

List of child components.

Type:

list(lems.model.component.Component)

id

ID of the component.

Type:

str

parameters

Dictionary of parameter values.

Type:

str

parent_id

Optional id of parent

Type:

str

set_parameter(parameter, value)

Set a parameter.

Parameters:
  • parameter (str) – Parameter to be set.

  • value (str) – Value to be set to.

set_parent_id(parent_id)

Sets the id of the parent Component

Parameters:

parent_id (str) – id of the parent Component

toxml()

Exports this object into a LEMS XML object

type

Type of the component.

Type:

str

class lems.model.component.ComponentReference(name, type_, local=None)

Bases: LEMSBase

Stores a component reference.

local

???

Type:

str

name

Name of the component reference.

Type:

str

referenced_component

Component being referenced.

Type:

FatComponent

toxml()

Exports this object into a LEMS XML object

type

Type of the component reference.

Type:

str

class lems.model.component.ComponentRequirement(name, description='')

Bases: LEMSBase

Specifies a component that is required

description

Description of this ComponentRequirement.

Type:

str

name

Name of the Component required.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.component.ComponentType(name, description='', extends=None)

Bases: Fat

Stores a component type declaration.

description

Description of this component type.

Type:

str

extends

Base component type.

Type:

str

name

Name of the component type.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.component.Constant(name, value, dimension=None, symbol=None, description='')

Bases: LEMSBase

Stores a constant specification.

description

Description of the constant.

Type:

str

dimension

Physical dimensions of the constant.

Type:

str

name

Name of the constant.

Type:

str

numeric_value

Numeric value of the constant.

Type:

float

symbol

Symbol of the constant.

Type:

str

toxml()

Exports this object into a LEMS XML object

value

Value of the constant.

Type:

str

class lems.model.component.DerivedParameter(name, value, dimension=None, description='')

Bases: LEMSBase

Store the specification of a derived parameter.

description

Description of the derived parameter.

Type:

str

dimension

Physical dimensions of the derived parameter.

Type:

str

name

Name of the derived parameter.

Type:

str

toxml()

Exports this object into a LEMS XML object

value

Value of the derived parameter.

Type:

str

class lems.model.component.EventPort(name, direction, description='')

Bases: LEMSBase

Stores an event port specification.

description

Description of the event port.

Type:

str

direction

Direction - IN/OUT .

Type:

str

name

Name of the event port.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.component.Exposure(name, dimension, description='')

Bases: LEMSBase

Stores a exposure specification.

description

Description of this exposure.

Type:

str

dimension

Physical dimension of the exposure.

Type:

str

name

Name of the exposure.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.component.Fat

Bases: LEMSBase

Stores common elements for a component type / fat component.

add(child)

Adds a typed child object to the component type.

Parameters:

child – Child object to be added.

add_attachments(attachments)

Adds an attachments type specification to this component type.

Parameters:

attachments (lems.model.component.Attachments) – Attachments specification to be added.

add_children(children)

Adds children to this component type.

Parameters:

children (lems.model.component.Children) – Children to be added.

add_component_reference(component_reference)

Adds a component reference to this component type.

Parameters:

component_reference (lems.model.component.ComponentReference) – Component reference to be added.

add_component_requirement(component_requirement)

Adds a component requirement to this component type.

Parameters:

component_requirement (lems.model.component.ComponentRequirement) – ComponentRequirement to be added.

add_constant(constant)

Adds a paramter to this component type.

Parameters:

constant (lems.model.component.Constant) – Constant to be added.

add_derived_parameter(derived_parameter)

Adds a derived_parameter to this component type.

Parameters:

derived_parameter (lems.model.component.DerivedParameter) – Derived Parameter to be added.

add_event_port(event_port)

Adds a event port to this component type.

Parameters:

event_port (lems.model.component.EventPort) – Event port to be added.

add_exposure(exposure)

Adds a exposure to this component type.

Parameters:

exposure (lems.model.component.Exposure) – Exposure to be added.

add_index_parameter(index_parameter)

Adds an index_parameter to this component type.

Parameters:

index_parameter (lems.model.component.IndexParameter) – Index Parameter to be added.

add_instance_requirement(instance_requirement)

Adds an instance requirement to this component type.

Parameters:

instance_requirement (lems.model.component.InstanceRequirement) – InstanceRequirement to be added.

Adds a link to this component type.

Parameters:

link (lems.model.component.Link) – Link to be added.

add_parameter(parameter)

Adds a paramter to this component type.

Parameters:

parameter (lems.model.component.Parameter) – Parameter to be added.

add_path(path)

Adds a path to this component type.

Parameters:

path (lems.model.component.Path) – Path to be added.

add_property(property)

Adds a property to this component type.

Parameters:

property (lems.model.component.Property) – Property to be added.

add_requirement(requirement)

Adds a requirement to this component type.

Parameters:

requirement (lems.model.component.Requirement) – Requirement to be added.

add_text(text)

Adds a text to this component type.

Parameters:

text (lems.model.component.Text) – Text to be added.

attachments

Map of attachment type specifications.

Type:

Map(str, lems.model.component.Attachments)

children

Map of children.

Type:

Map(str, lems.model.component.Children)

component_references

Map of component references.

Type:

Map(str, lems.model.component.ComponentReference)

component_requirements

Map of component requirements.

Type:

Map(str, lems.model.component.ComponentRequirement)

constants

Map of constants in this component type.

Type:

Map(str, lems.model.component.Constant)

derived_parameters

Map of derived_parameters in this component type.

Type:

Map(str, lems.model.component.Parameter)

dynamics

Behavioural dynamics object.

Type:

lems.model.dynamics.Dynamics

event_ports

Map of event ports.

Type:

Map(str, lems.model.component.EventPort

exposures

Map of exposures in this component type.

Type:

Map(str, lems.model.component.Exposure)

index_parameters

Map of index_parameters in this component type.

Type:

Map(str, lems.model.component.IndexParameter)

instance_requirements

Map of instance requirements.

Type:

Map(str, lems.model.component.InstanceRequirement)

Map of links.

Type:

Map(str, lems.model.component.Link)

parameters

Map of parameters in this component type.

Type:

Map(str, lems.model.component.Parameter)

paths

Map of path entries.

Type:

Map(str, lems.model.component.Path)

properties

Map of properties in this component type.

Type:

Map(str, lems.model.component.Property)

requirements

Map of requirements.

Type:

Map(str, lems.model.component.Requirement)

simulation

Simulation attributes.

Type:

lems.model.simulation.Simulation

structure

Structural properties object.

Type:

lems.model.structure.Structure

texts

Map of text entries.

Type:

Map(str, lems.model.component.Text)

types

Set of compatible component types.

Type:

set(str)

class lems.model.component.FatComponent(id_, type_)

Bases: Fat

Stores a resolved component.

add(child)

Adds a typed child object to the component type.

Parameters:

child – Child object to be added.

add_child_component(child_component)

Adds a child component to this fat component.

Parameters:

child_component (lems.model.component.FatComponent) – Child component to be added.

child_components

List of child components.

Type:

lems.model.component.FatComponent

id

ID of the component.

Type:

str

parent_id

Optional id of parent

Type:

str

set_parent_id(parent_id)

Sets the id of the parent Component

Parameters:

parent_id (str) – id of the parent Component

type

Type of the component.

Type:

str

class lems.model.component.Fixed(parameter, value, description='')

Bases: Parameter

Stores a fixed parameter specification.

toxml()

Exports this object into a LEMS XML object

class lems.model.component.IndexParameter(name, description='')

Bases: LEMSBase

Stores a parameter which is an index (integer > 0).

description

Description of this parameter.

Type:

str

name

Name of the parameter.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.component.InstanceRequirement(name, type, description='')

Bases: LEMSBase

Stores an instance requirement specification.

description

Description of this InstanceRequirement.

Type:

str

name

Name of the instance requirement.

Type:

str

toxml()

Exports this object into a LEMS XML object

type

Type of the instance required.

Type:

str

Bases: LEMSBase

Stores a link specification.

description

Description of the link.

Type:

str

name

Name of the link entry.

Type:

str

toxml()

Exports this object into a LEMS XML object

type

Type of the link.

Type:

str

value

Value of the link.

Type:

str

class lems.model.component.Parameter(name, dimension, description='')

Bases: LEMSBase

Stores a parameter declaration.

description

Description of this parameter.

Type:

str

dimension

Physical dimension of the parameter.

Type:

str

fixed

Whether the parameter has been fixed or not.

Type:

bool

fixed_value

Value if fixed.

Type:

str

name

Name of the parameter.

Type:

str

numeric_value

Resolved numeric value.

Type:

float

toxml()

Exports this object into a LEMS XML object

value

Value of the parameter.

Type:

str

class lems.model.component.Path(name, description='')

Bases: LEMSBase

Stores a path entry specification.

description

Description of the path entry.

Type:

str

name

Name of the path entry.

Type:

str

toxml()

Exports this object into a LEMS XML object

value

Value of the path entry.

Type:

str

class lems.model.component.Property(name, dimension=None, default_value=None, description='')

Bases: LEMSBase

Store the specification of a property.

default_value

Default value of the property.

Type:

float

description

Description of the property.

Type:

str

dimension

Physical dimensions of the property.

Type:

str

name

Name of the property.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.component.Requirement(name, dimension, description='')

Bases: LEMSBase

Stores a requirement specification.

description

Description of this requirement.

Type:

str

dimension

Physical dimension of the requirement.

Type:

str

name

Name of the requirement.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.component.Text(name, description='')

Bases: LEMSBase

Stores a text entry specification.

description

Description of the text entry.

Type:

str

name

Name of the text entry.

Type:

str

toxml()

Exports this object into a LEMS XML object

value

Value of the text entry.

Type:

str

lems.model.dynamics module

Behavioral dynamics of component types.

author:

Gautham Ganapathy

organization:

LEMS (https://github.com/organizations/LEMS)

class lems.model.dynamics.Action

Bases: LEMSBase

Base class for event handler actions.

class lems.model.dynamics.Behavioral

Bases: LEMSBase

Store dynamic behavioral attributes.

add(child)

Adds a typed child object to the behavioral object.

Parameters:

child – Child object to be added.

add_conditional_derived_variable(cdv)

Adds a conditional derived variable to this behavior regime.

Parameters:

cdv (lems.model.dynamics.ConditionalDerivedVariable) – Conditional Derived variable.

add_derived_variable(dv)

Adds a derived variable to this behavior regime.

Parameters:

dv (lems.model.dynamics.DerivedVariable) – Derived variable.

add_event_handler(eh)

Adds an event handler to this behavior regime.

Parameters:

eh (lems.model.dynamics.EventHandler) – Event handler.

add_kinetic_scheme(ks)

Adds a kinetic scheme to this behavior regime.

Parameters:

ks (lems.model.dynamics.KineticScheme) – Kinetic scheme.

add_state_variable(sv)

Adds a state variable to this behavior regime.

Parameters:

sv (lems.model.dynamics.StateVariable) – State variable.

add_time_derivative(td)

Adds a time derivative to this behavior regime.

Parameters:

td (lems.model.dynamics.TimeDerivative) – Time derivative.

clear()

Clear behavioral entities.

conditional_derived_variables

Map of conditional derived variables in this behavior regime.

Type:

dict(str, lems.model.dynamics.ConditionalDerivedVariable

derived_variables

Map of derived variables in this behavior regime.

Type:

dict(str, lems.model.dynamics.DerivedVariable

event_handlers

List of event handlers in this behavior regime.

Type:

list(lems.model.dynamics.EventHandler)

has_content()
kinetic_schemes

Map of kinetic schemes in this behavior regime.

Type:

dict(str, lems.model.dynamics.KineticScheme)

parent_behavioral

Parent behavioral object.

Type:

lems.model.dynamics.Behavioral

state_variables

Map of state variables in this behavior regime.

Type:

dict(str, lems.model.dynamics.StateVariable

time_derivatives

Map of time derivatives in this behavior regime.

Type:

dict(str, lems.model.dynamics.TimeDerivative)

toxml()

Exports this object into a LEMS XML object

class lems.model.dynamics.Case(condition, value)

Bases: LEMSBase

Store the specification of a case for a Conditional Derived Variable.

condition

Condition for this case.

Type:

str

condition_expression_tree

Parse tree for the case condition expression.

Type:

lems.parser.expr.ExprNode

toxml()

Exports this object into a LEMS XML object

value

Value if the condition is true.

Type:

str

value_expression_tree

Parse tree for the case condition expression.

Type:

lems.parser.expr.ExprNode

class lems.model.dynamics.ConditionalDerivedVariable(name, dimension, exposure=None)

Bases: LEMSBase

Store the specification of a conditional derived variable.

add(child)

Adds a typed child object to the conditional derived variable.

Parameters:

child – Child object to be added.

add_case(case)

Adds a case to this conditional derived variable.

Parameters:

case (lems.model.dynamics.Case) – Case to be added.

cases

List of cases related to this conditional derived variable.

Type:

list(lems.model.dynamics.Case)

dimension

Dimension of the state variable.

Type:

str

exposure

Exposure name for the state variable.

Type:

str

name

Name of the derived variable.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.dynamics.DerivedVariable(name, **params)

Bases: LEMSBase

Store the specification of a derived variable.

dimension

Dimension of the derived variable or None if computed.

Type:

str

exposure

Exposure name for the derived variable.

Type:

str

expression_tree

Parse tree for the time derivative expression.

Type:

lems.parser.expr.ExprNode

name

Name of the derived variable.

Type:

str

reduce

Reduce method for the derived variable.

Type:

str

required

Requried or not.

Type:

str

select

Selection path/expression for the derived variable.

Type:

str

toxml()

Exports this object into a LEMS XML object

value

Value of the derived variable.

Type:

str

class lems.model.dynamics.Dynamics

Bases: Behavioral

Stores behavioral dynamics specification for a component type.

add(child)

Adds a typed child object to the dynamics object.

Parameters:

child – Child object to be added.

add_regime(regime)

Adds a behavior regime to this dynamics object.

Parameters:

regime (lems.model.dynamics.Regime) – Behavior regime to be added.

has_content()
regimes

Map of behavior regimes.

Type:

Map(str, lems.model.dynamics.Regime)

class lems.model.dynamics.EventHandler

Bases: LEMSBase

Base class for event handlers.

actions

List of actions to be performed in response to this event.

Type:

list(lems.model.dynamics.Action)

add(child)

Adds a typed child object to the event handler.

Parameters:

child – Child object to be added.

add_action(action)

Adds an action to this event handler.

Parameters:

action (lems.model.dynamics.Action) – Action to be added.

class lems.model.dynamics.EventOut(port)

Bases: Action

Event transmission specification.

port

Port on which the event comes in.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.dynamics.KineticScheme(name, nodes, state_variable, edges, edge_source, edge_target, forward_rate, reverse_rate)

Bases: LEMSBase

Kinetic scheme specifications.

edge_source

Attribute that defines the source of the transition.

Type:

str

edge_target

Attribute that defines the target of the transition.

Type:

str

edges

Edges to be used for the kinetic scheme.

Type:

str

forward_rate

Name of the forward rate exposure.

Type:

str

name

Name of the kinetic scheme.

Type:

str

nodes

Nodes to be used for the kinetic scheme.

Type:

str

reverse_rate

Name of the reverse rate exposure.

Type:

str

state_variable

State variable updated by the kinetic scheme.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.dynamics.OnCondition(test)

Bases: EventHandler

Specification for event handler called upon satisfying a given condition.

test

Condition to be tested for.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.dynamics.OnEntry

Bases: EventHandler

Specification for event handler called upon entry into a new behavior regime.

toxml()

Exports this object into a LEMS XML object

class lems.model.dynamics.OnEvent(port)

Bases: EventHandler

Specification for event handler called upon receiving en event sent by another component.

port

Port on which the event comes in.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.dynamics.OnStart

Bases: EventHandler

Specification for event handler called upon initialization of the component.

toxml()

Exports this object into a LEMS XML object

class lems.model.dynamics.Regime(name, parent_behavioral, initial=False)

Bases: Behavioral

Stores a single behavioral regime for a component type.

initial

Initial behavior regime.

Type:

bool

name

Name of this behavior regime.

Type:

str

parent_behavioral

Parent behavioral object.

Type:

lems.model.dynamics.Behavioral

class lems.model.dynamics.StateAssignment(variable, value)

Bases: Action

State assignment specification.

expression_tree

Parse tree for the time derivative expression.

Type:

lems.parser.expr.ExprNode

toxml()

Exports this object into a LEMS XML object

value

Derivative expression.

Type:

str

variable

Name of the variable for which the time derivative is being specified.

Type:

str

class lems.model.dynamics.StateVariable(name, dimension, exposure=None)

Bases: LEMSBase

Store the specification of a state variable.

dimension

Dimension of the state variable.

Type:

str

exposure

Exposure name for the state variable.

Type:

str

name

Name of the state variable.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.dynamics.TimeDerivative(variable, value)

Bases: LEMSBase

Store the specification of a time derivative specifcation.

expression_tree

Parse tree for the time derivative expression.

Type:

lems.parser.expr.ExprNode

toxml()

Exports this object into a LEMS XML object

value

Derivative expression.

Type:

str

variable

Name of the variable for which the time derivative is being specified.

Type:

str

class lems.model.dynamics.Transition(regime)

Bases: Action

Regime transition specification.

regime

Regime to transition to.

Type:

str

toxml()

Exports this object into a LEMS XML object

lems.model.fundamental module

Dimension and Unit definitions in terms of the fundamental SI units.

author:

Gautham Ganapathy

organization:

LEMS (https://github.com/organizations/LEMS)

class lems.model.fundamental.Dimension(name, description='', **params)

Bases: LEMSBase

Stores a dimension in terms of the seven fundamental SI units.

description

Description of this dimension.

Type:

str

i

Power for the electic current dimension.

Type:

int

j

Power for the luminous intensity dimension.

Type:

int

k

Power for the temperature dimension.

Type:

int

l

Power for the length dimension.

Type:

int

m

Power for the mass dimension.

Type:

int

n

Power for the quantity dimension.

Type:

int

name

Name of the dimension.

Type:

str

t

Power for the time dimension.

Type:

int

toxml()

Exports this object into a LEMS XML object

class lems.model.fundamental.Include(filename)

Bases: LEMSBase

Include another LEMS file.

file

Name of the file.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.fundamental.Unit(name, symbol, dimension, power=0, scale=1.0, offset=0.0, description='')

Bases: LEMSBase

Stores a unit definition.

description

Description of this unit.

Type:

str

dimension

Dimension for the unit.

Type:

str

name

Name of the unit.

Type:

str

offset

Offset for non-zero units.

Type:

float

power

Scaling by power of 10.

Type:

int

scale

Scaling.

Type:

float

symbol

Symbol for the unit.

Type:

str

toxml()

Exports this object into a LEMS XML object

lems.model.model module

Model storage.

author:

Gautham Ganapathy

organization:

LEMS (https://github.com/organizations/LEMS)

class lems.model.model.Model(include_includes=True, fail_on_missing_includes=True)

Bases: LEMSBase

Stores a model.

add(child)

Adds a typed child object to the model.

Parameters:

child – Child object to be added.

add_component(component)

Adds a component to the model.

Parameters:

component (lems.model.fundamental.Component) – Component to be added.

add_component_type(component_type)

Adds a component type to the model.

Parameters:

component_type (lems.model.fundamental.ComponentType) – Component type to be added.

add_constant(constant)

Adds a paramter to the model.

Parameters:

constant (lems.model.component.Constant) – Constant to be added.

add_dimension(dimension)

Adds a dimension to the model.

Parameters:

dimension (lems.model.fundamental.Dimension) – Dimension to be added.

add_fat_component(fat_component)

Adds a fattened component to the model.

Parameters:

fat_component (lems.model.fundamental.Fat_component) – Fattened component to be added.

add_include(include)

Adds an include to the model.

Parameters:

include (lems.model.fundamental.Include) – Include to be added.

add_include_directory(path)

Adds a directory to the include file search path.

Parameters:

path (str) – Directory to be added.

add_target(target)

Adds a simulation target to the model.

Parameters:

target (str) – Name of the component to be added as a simulation target.

add_unit(unit)

Adds a unit to the model.

Parameters:

unit (lems.model.fundamental.Unit) – Unit to be added.

comp_ref_map

A map of the component references in the model, generated by self.get_comp_reference_map

Type:

None or Map

component_types

Map of component types defined in the model.

Type:

dict(str, lems.model.component.ComponentType)

components

Map of root components defined in the model.

Type:

dict(str, lems.model.component.Component)

constants

Map of constants in this component type.

Type:

dict(str, lems.model.component.Constant)

construct_path(pathlist: list[str], skip: str | None = None) str

Construct path from a list.

Parameters:
  • vec (list(str)) – list of text strings to generate path from

  • skip (str) – text strings to skip

Returns:

generated path string

debug = False
description

Short description of contents of LEMS file

Type:

str

dimensions

Dictionary of dimensions defined in the model.

Type:

dict(str, lems.model.fundamental.Dimension

export_to_dom()

Exports this model to a DOM.

export_to_file(filepath, level_prefix='  ')

Exports this model to a file.

Parameters:

filepath (str) – File to be exported to.

fail_on_missing_includes

Whether to raise an Exception when a file in an <Include> element is not found

Type:

boolean

fat_components

Map of root fattened components defined in the model.

Type:

dict(str, lems.model.component.FatComponent)

fatten_component(c)

Fatten a component but resolving all references into the corresponding component type.

Parameters:

c (lems.model.component.Component) – Lean component to be fattened.

Returns:

Fattened component.

Return type:

lems.model.component.FatComponent

get_comp_ref_map() Map

Get a Map of ComponentReferences in the model.

Returns:

Map with target -> [source] entries

get_component_list(substring: str = '') dict[str, Component]

Get all components whose id matches the given substring.

Note that in PyLEMS, if a component does not have an id attribute, PyLEMS uses the name of the component as its ID. See the parser methods in LEMSFileParser.

This function is required because the component and fat_component attribute of the model class only holds lists of the top level components and not its child/children elements. So we need to manually fetch them.

Parameters:

substring (str) – substring to match components against

Returns:

Dict of components matching the substring of the form {‘id’ : Component }

get_fattened_component_list(substring: str = '') Map

Get a list of fattened components whose ids include the substring.

A “fattened component” is one where all elements of the components have been resolved. See lems.model.component.FatComponent.

Parameters:

substring (str) – substring to match components against

Returns:

Map of fattened components matching the substring

get_full_comp_paths_with_comp_refs(comp: FatComponent, comptext: str | None = None)

Get list of component paths with all component references also resolved for the given component comp.

This does not return a value, but fills in self.temp_vec with all the possible paths as individual lists. These can then be passed to the construct_path method to construct string paths.

Additionally, note that this generates paths from the model declaration, not from a built simulation instance of the model. Therefore, it does not find paths that are constructed during build time.

XXX: should this be converted to a private method?

Parameters:
  • comp (Component) – Component to get all paths for

  • comptext (str) – text to use for component (used for generation of path strings)

get_nested_components(comp: Component) dict[str, Component]

Get all nested (child/children) components in the comp component

Parameters:

comp (Component) – component to get all nested (child/children) components for

Returns:

list of components

get_numeric_value(value_str, dimension=None)

Get the numeric value for a parameter value specification.

Parameters:
  • value_str (str) – Value string

  • dimension (str) – Dimension of the value

get_parent_component(fc)

TODO: Replace with more efficient way to do this…

import_from_file(filepath)

Import a model from a file.

Parameters:

filepath (str) – File to be imported.

include_directories

List of include directories to search for included LEMS files.

Type:

list(str)

include_file(path, include_dirs=[])

Includes a file into the current model.

Parameters:
  • path (str) – Path to the file to be included.

  • include_dirs (list(str)) – Optional alternate include search path.

include_includes

Whether to include LEMS definitions in <Include> elements

Type:

boolean

included_files

List of files already included.

Type:

list(str)

includes

Dictionary of includes defined in the model.

Type:

dict(str, lems.model.fundamental.Include

list_exposures(substring: str = '') dict[FatComponent, Map]

Get exposures from model belonging to components which contain the given substring.

Parameters:

substring (str) – substring to match for in component names

Returns:

dictionary of components and their exposures

The returned dictionary is of the form:

{
    "component": ["exp1", "exp2"]
}
list_recording_paths_for_exposures(substring: str = '', target: str = '') list[str]

List recording paths for exposures in the model for components matching the given substring, and for the given simulation target.

This is a helper method that will generate all recording paths for exposures in the provided LEMS model. Since a detailed model may include many paths, it is suggested to use the substring parameter to limit the list to necessary components only.

Please note that this uses only the declared model, and not a built instance of the model. Therefore, it returns a subset of all possible paths.

Parameters:
  • substring (str) – substring to match component IDs against

  • target (str) – simulation target whose components are to be analysed

Returns:

list of generated path strings

merge_component_types(ct, base_ct)

Merge various maps in the given component type from a base component type.

Parameters:
resolve() lems.model.Model

Resolves references in this model and returns resolved model.

Returns:

resolved Model

resolve_component_type(component_type)

Resolves references in the specified component type.

Parameters:

component_type (lems.model.component.ComponentType) – Component type to be resolved.

resolve_simulation(fc, ct)

Resolve simulation specifications.

resolve_structure(fc, ct)

Resolve structure specifications.

resolved_model

A resolved version of the model, generated by self.resolve()

Type:

None or Model

schema_location = 'https://raw.githubusercontent.com/LEMS/LEMS/development/Schemas/LEMS/LEMS_v0.7.6.xsd'
target_lems_version = '0.7.6'
targets

List of targets to be run on startup.

Type:

list(str)

units

Map of units defined in the model.

Type:

dict(str, lems.model.fundamental.Unit

lems.model.simulation module

Simulation specification classes.

author:

Gautham Ganapathy

organization:

LEMS (https://github.com/organizations/LEMS)

class lems.model.simulation.DataDisplay(title, data_region)

Bases: DataOutput

Stores specification for a data display.

data_region

Display position

Type:

string

time_scale

Time scale

Type:

Number

title

Title for the display.

Type:

string

toxml()

Exports this object into a LEMS XML object

class lems.model.simulation.DataOutput

Bases: LEMSBase

Generic data output specification class.

class lems.model.simulation.DataWriter(path, file_name)

Bases: DataOutput

Stores specification for a data writer.

file_name

Text parameter to be used for the file name

Type:

string

path

Path to the quantity to be saved to file.

Type:

string

toxml()

Exports this object into a LEMS XML object

class lems.model.simulation.EventRecord(quantity, eventPort)

Bases: LEMSBase

Stores the parameters of an <EventRecord> statement.

eventPort

eventPort to be used for the event record

Type:

str

id

Id of the quantity

Type:

str

quantity

Path to the quantity to be recorded.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.simulation.EventWriter(path, file_name, format)

Bases: DataOutput

Stores specification for an event writer.

file_name

Text parameter to be used for the file name

Type:

string

format

Text parameter to be used for the format

Type:

string

path

Path to the quantity to be saved to file.

Type:

string

toxml()

Exports this object into a LEMS XML object

class lems.model.simulation.Record(quantity, scale=None, color=None, id=None)

Bases: LEMSBase

Stores the parameters of a <Record> statement.

color

Text parameter to be used to specify the color for display.

Type:

str

id

Text parameter to be used to specify an id for the record

Type:

str

quantity

Path to the quantity to be recorded.

Type:

str

scale

Text parameter to be used for scaling the quantity before display.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.simulation.Run(component, variable, increment, total)

Bases: LEMSBase

Stores the description of an object to be run according to an independent variable (usually time).

component

Name of the target component to be run according to the specification given for an independent state variable.

Type:

str

increment

Increment of the state variable on each step.

Type:

str

total

Final value of the state variable.

Type:

str

toxml()

Exports this object into a LEMS XML object

variable

The name of an independent state variable according to which the target component will be run.

Type:

str

class lems.model.simulation.Simulation

Bases: LEMSBase

Stores the simulation-related attributes of a component-type.

add(child)

Adds a typed child object to the simulation spec.

Parameters:

child – Child object to be added.

add_data_display(data_display)

Adds a data display to this simulation section.

Parameters:

data_display (lems.model.simulation.DataDisplay) – Data display to be added.

add_data_writer(data_writer)

Adds a data writer to this simulation section.

Parameters:

data_writer (lems.model.simulation.DataWriter) – Data writer to be added.

add_event_record(event_record)

Adds an eventrecord object to the list of event_record objects in this dynamics regime.

Parameters:

event_record (lems.model.simulation.EventRecord) – EventRecord object to be added.

add_event_writer(event_writer)

Adds an event writer to this simulation section.

Parameters:

event_writer (lems.model.simulation.EventWriter) – event writer to be added.

add_record(record)

Adds a record object to the list of record objects in this dynamics regime.

Parameters:

record (lems.model.simulation.Record) – Record object to be added.

add_run(run)

Adds a runnable target component definition to the list of runnable components stored in this context.

Parameters:

run (lems.model.simulation.Run) – Run specification

data_displays

Map of data displays mapping titles to regions.

Type:

Map(string, string)

data_writers

Map of recorded variables to data writers.

Type:

Map(string, lems.model.simulation.DataWriter

event_records

Map of recorded events in this dynamics regime.

Type:

Map(string, lems.model.simulation.EventRecord

event_writers

Map of recorded variables to event writers.

Type:

Map(string, lems.model.simulation.EventWriter

records

Map of recorded variables in this dynamics regime.

Type:

Map(string, lems.model.simulation.Record

runs

Map of runs in this dynamics regime.

Type:

Map(string, lems.model.simulation.Run)

toxml()

Exports this object into a LEMS XML object

lems.model.structure module

Structural properties of component types.

author:

Gautham Ganapathy

organization:

LEMS (https://github.com/organizations/LEMS)

class lems.model.structure.Assign(property, value)

Bases: LEMSBase

Stores a child assign specification.

property_

Name of the property reference to be used for instantiation.

Type:

str

toxml()

Exports this object into a LEMS XML object

value

Value of the property.

Type:

str

class lems.model.structure.ChildInstance(component, referenced_component=None)

Bases: LEMSBase

Stores a child instantiation specification.

component

Name of the component reference to be used for instantiation.

Type:

str

referenced_component

Target component being referenced after resolution.

Type:

lems.model.component.FatComponent

toxml()

Exports this object into a LEMS XML object

class lems.model.structure.EventConnection(from_, to, source_port, target_port, receiver, receiver_container)

Bases: LEMSBase

Stores an event connection specification.

from_

Name of the source component for event.

Type:

str

receiver

Proxy receiver component attached to the target component that actually receiving the event.

Type:

Component

receiver_container

Name of the child component grouping to add the receiver to.

Type:

str

source_port

Source port name.

Type:

str

target_port

Target port name.

Type:

str

to

Name of the target component for the event.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.structure.ForEach(instances, as_)

Bases: LEMSBase

ForEach specification.

add_event_connection(ec)

Adds an event conenction to the structure.

Parameters:

ec (lems.model.structure.EventConnection) – Event connection.

add_for_each(fe)

Adds a for-each specification.

Parameters:

fe (lems.model.structure.ForEach) – For-each specification.

event_connections

List of event connections.

Type:

list(lems.model.structure.EventConnection)

for_eachs

List of for each specs.

Type:

list(lems.model.structure.ForEach)

toxml()

Exports this object into a LEMS XML object

class lems.model.structure.MultiInstantiate(component=None, number=None, component_type=None)

Bases: LEMSBase

Stores a child multi-instantiation specification.

add(child)

Adds a typed child object to the structure object.

Parameters:

child – Child object to be added.

add_assign(assign)

Adds an Assign to the structure.

Parameters:

assign (lems.model.structure.Assign) – Assign structure.

assignments

List of assignments included in MultiInstantiate.

Type:

list(Assign)

component

Name of the component reference to be used for instantiation.

Type:

str

component_type

Name of the component type reference to be used for instantiation.

Type:

str

number

Name of the paramter specifying the number of times the component reference is to be instantiated.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.structure.Structure

Bases: LEMSBase

Stores structural properties of a component type.

add(child)

Adds a typed child object to the structure object.

Parameters:

child – Child object to be added.

add_child_instance(ci)

Adds a child instantiation specification.

Parameters:

ci (lems.model.structure.ChildInstance) – Child instantiation specification.

add_event_connection(ec)

Adds an event conenction to the structure.

Parameters:

ec (lems.model.structure.EventConnection) – Event connection.

add_for_each(fe)

Adds a for-each specification.

Parameters:

fe (lems.model.structure.ForEach) – For-each specification.

add_multi_instantiate(mi)

Adds a child multi-instantiation specification.

Parameters:

mi (lems.model.structure.MultiInstantiate) – Child multi-instantiation specification.

add_tunnel(tunnel)

Adds a tunnel specification to the structure.

Parameters:

tunnel (lems.model.structure.Tunnel) – tunnel specification.

add_with(with_)

Adds a with-as specification to the structure.

Parameters:

with (lems.model.structure.With) – With-as specification.

child_instances

List of child instantations.

Type:

list(lems.model.structure.ChildInstance)

event_connections

List of event connections.

Type:

list(lems.model.structure.EventConnection)

for_eachs

List of for each specs.

Type:

list(lems.model.structure.ForEach)

has_content()
multi_instantiates

List of child multi-instantiations.

Type:

list(lems.model.structure.MultiInstantiate)

toxml()

Exports this object into a LEMS XML object

tunnels

Map of tunnel statements.

Type:

Map(str, lems.model.structure.Tunnel)

withs

Map of With statements.

Type:

Map(str, lems.model.structure.With)

class lems.model.structure.Tunnel(name, end_a, end_b, component_a, component_b)

Bases: LEMSBase

Stores a Tunnel.

component_a

Component to create at A.

Type:

str

component_b

Component to create at B.

Type:

str

end_a

‘A’ end of Tunnel.

Type:

str

end_b

‘B’ end of Tunnel.

Type:

str

name

name of Tunnel.

Type:

str

toxml()

Exports this object into a LEMS XML object

class lems.model.structure.With(instance, as_, list=None, index=None)

Bases: LEMSBase

Stores a with-as statement.

as_

Alternative name.

Type:

str

index

index in list to be referenced.

Type:

str

instance

Instance to be referenced.

Type:

str

list

list of components, e.g. population

Type:

str

toxml()

Exports this object into a LEMS XML object

Module contents

author:

Gautham Ganapathy

organization:

LEMS (https://github.com/organizations/LEMS)