lems.sim package¶
Submodules¶
lems.sim.build module¶
Simulation builder.
- author:
Gautham Ganapathy
- organization:
- class lems.sim.build.SimulationBuilder(model)¶
Bases:
LEMSBase
Simulation builder class.
- add_dynamics_1(component, runnable, regime, dynamics)¶
Adds dynamics to a runnable component based on the dynamics specifications in the component model.
This method builds dynamics necessary for building child components.
- Parameters:
component (lems.model.component.FatComponent) – Component model containing dynamics specifications.
runnable (lems.sim.runnable.Runnable) – Runnable component to which dynamics is to be added.
regime (lems.model.dynamics.Regime) – The dynamics regime to be used to generate dynamics code in the runnable component.
dynamics (lems.model.dynamics.Regime) – Shared dynamics specifications.
- Raises:
SimBuildError – Raised when a time derivative expression refers to an undefined variable.
SimBuildError – Raised when there are invalid time specifications for the <Run> statement.
SimBuildError – Raised when the component reference for <Run> cannot be resolved.
- add_dynamics_2(component, runnable, regime, dynamics)¶
Adds dynamics to a runnable component based on the dynamics specifications in the component model.
This method builds dynamics dependent on child components.
- Parameters:
component (lems.model.component.FatComponent) – Component model containing dynamics specifications.
runnable (lems.sim.runnable.Runnable) – Runnable component to which dynamics is to be added.
regime (lems.model.dynamics.Regime) – The dynamics regime to be used to generate dynamics code in the runnable component.
dynamics (lems.model.dynamics.Regime) – Shared dynamics specifications.
- Raises:
SimBuildError – Raised when a time derivative expression refers to an undefined variable.
SimBuildError – Raised when there are invalid time specifications for the <Run> statement.
SimBuildError – Raised when the component reference for <Run> cannot be resolved.
- add_recording_behavior(component, runnable)¶
Adds recording-related dynamics to a runnable component based on the dynamics specifications in the component model.
- Parameters:
component (lems.model.component.FatComponent runnable: Runnable component to which dynamics is to be added.) – Component model containing dynamics specifications.
- Raises:
SimBuildError – Raised when a target for recording could not be found.
- build()¶
Build the simulation components from the model.
- Returns:
A runnable simulation object
- Return type:
- build_action(runnable, regime, action)¶
Build event handler action code.
- Parameters:
action (lems.model.dynamics.Action) – Event handler action object
- Returns:
Generated action code
- Return type:
string
- build_conditional_derived_var_code(runnable, regime, dv)¶
- build_event_connections(component, runnable, structure)¶
Adds event connections to a runnable component based on the structure specifications in the component model.
- Parameters:
component (lems.model.component.FatComponent) – Component model containing structure specifications.
runnable (lems.sim.runnable.Runnable) – Runnable component to which structure is to be added.
structure (lems.model.structure.Structure) – The structure object to be used to add structure code in the runnable component.
- build_event_handler(runnable, regime, event_handler)¶
Build event handler code.
- Parameters:
event_handler (lems.model.dynamics.EventHandler) – Event handler object
- Returns:
Generated event handler code.
- Return type:
list(string)
- build_event_out(event_out)¶
Build event out code.
- Parameters:
event_out (lems.model.dynamics.EventOut) – event out object
- Returns:
Generated event out code
- Return type:
string
- build_expression_from_tree(runnable, regime, tree_node)¶
Recursively builds a Python expression from a parsed expression tree.
- Parameters:
runnable (lems.sim.runnable.Runnable) – Runnable object to which this expression would be added.
regime (lems.model.dynamics.Regime) – Dynamics regime being built.
tree_node (lems.parser.expr.ExprNode) – Root node for the tree from which the expression is to be built.
- Returns:
Generated Python expression.
- Return type:
string
- build_foreach(component, runnable, foreach, name_mappings={})¶
Iterate over ForEach constructs and process nested elements.
- Parameters:
component (lems.model.component.FatComponent) – Component model containing structure specifications.
runnable (lems.sim.runnable.Runnable) – Runnable component to which structure is to be added.
foreach (lems.model.structure.ForEach) – The ForEach structure object to be used to add structure code in the runnable component.
- build_on_condition(runnable, regime, on_condition)¶
Build OnCondition event handler code.
- Parameters:
on_condition (lems.model.dynamics.OnCondition) – OnCondition event handler object
- Returns:
Generated OnCondition code
- Return type:
list(string)
- build_on_entry(runnable, regime, on_entry)¶
Build OnEntry start handler code.
- Parameters:
on_entry (lems.model.dynamics.OnEntry) – OnEntry start handler object
- Returns:
Generated OnEntry code
- Return type:
list(string)
- build_on_event(runnable, regime, on_event)¶
Build OnEvent event handler code.
- Parameters:
on_event (lems.model.dynamics.OnEvent) – OnEvent event handler object
- Returns:
Generated OnEvent code
- Return type:
list(string)
- build_on_start(runnable, regime, on_start)¶
Build OnStart start handler code.
- Parameters:
on_start (lems.model.dynamics.OnStart) – OnStart start handler object
- Returns:
Generated OnStart code
- Return type:
list(string)
- build_reduce_code(result, select, reduce)¶
Builds a reduce operation on the selected target range.
- build_runnable(component, parent=None, id_=None)¶
Build a runnable component from a component specification and add it to the simulation.
- Parameters:
component (lems.model.component.FatComponent) – Component specification
parent (lems.sim.runnable.Runnable) – Parent runnable component.
id – Optional id for therunnable. If it’s not passed in, the runnable will inherit the id of the component.
- Raises:
SimBuildError – Raised when a component reference cannot be resolved.
- build_state_assignment(runnable, regime, state_assignment)¶
Build state assignment code.
- Parameters:
state_assignment (lems.model.dynamics.StateAssignment) – State assignment object
- Returns:
Generated state assignment code
- Return type:
string
- build_structure(component, runnable, structure)¶
Adds structure to a runnable component based on the structure specifications in the component model.
- Parameters:
component (lems.model.component.FatComponent) – Component model containing structure specifications.
runnable (lems.sim.runnable.Runnable) – Runnable component to which structure is to be added.
structure (lems.model.structure.Structure) – The structure object to be used to add structure code in the runnable component.
- build_transition(transition)¶
Build regime transition code.
- Parameters:
transition (lems.model.dynamics.Transition) – Transition object
- Returns:
Generated transition code
- Return type:
string
- convert_func(func)¶
Converts NeuroML arithmetic/logical functions to python equivalents.
- Parameters:
func (string) – NeuroML function
- Returns:
Python operator
- Return type:
string
- convert_op(op)¶
Converts NeuroML arithmetic/logical operators to python equivalents.
- Parameters:
op (string) – NeuroML operator
- Returns:
Python operator
- Return type:
string
- debug = False¶
- model¶
Model to be used for constructing the simulation.
- Type:
- process_simulation_specs(component, runnable, simulation)¶
Process simulation-related aspects to a runnable component based on the dynamics specifications in the component model.
- Parameters:
component (lems.model.component.FatComponent) – Component model containing dynamics specifications.
runnable (lems.sim.runnable.Runnable) – Runnable component to which dynamics is to be added.
simulation (lems.model.simulation.Simulation) – The simulation-related aspects to be implemented in the runnable component.
- Raises:
SimBuildError – Raised when a time derivative expression refers to an undefined variable
SimBuildError – Raised when there are invalid time specifications for the <Run> statement.
SimBuildError – Raised when the component reference for <Run> cannot be resolved.
- sim¶
Simulation built from the model.
- Type:
- lems.sim.build.is_var_in_exp_tree(var, exp_tree)¶
- lems.sim.build.order_derived_parameters(component)¶
Finds ordering of derived_parameters.
- Parameters:
component (lems.model.component.Component) – Component containing derived parameters.
- Returns:
Returns ordered list of derived parameters.
- Return type:
list(string)
- Raises:
SimBuildError – Raised when a proper ordering of derived parameters could not be found.
- lems.sim.build.order_derived_variables(regime)¶
Finds ordering of derived_variables.
- Parameters:
regime (lems.model.dynamics.regime) – Dynamics Regime containing derived variables.
- Returns:
Returns ordered list of derived variables.
- Return type:
list(string)
- Raises:
SimBuildError – Raised when a proper ordering of derived variables could not be found.
lems.sim.recording module¶
Recording class(es).
- author:
Gautham Ganapathy
- organization:
lems.sim.runnable module¶
Base class for runnable components.
- author:
Gautham Ganapathy
- organization:
- class lems.sim.runnable.Reflective¶
Bases:
LEMSBase
- add_derived_variable(variable)¶
- add_instance_variable(variable, initial_value)¶
- add_method(method_name, parameter_list, statements)¶
- add_text_variable(variable, value)¶
- debug = False¶
- class lems.sim.runnable.Regime(name)¶
Bases:
object
- class lems.sim.runnable.Runnable(id_, component, parent=None)¶
Bases:
Reflective
- add_attachment(runnable, container=None)¶
- add_child(id_, runnable)¶
- add_child_to_group(group_name, child)¶
- add_child_typeref(typename, runnable)¶
- add_event_in_port(port)¶
- add_event_out_port(port)¶
- add_regime(regime)¶
- add_variable_recorder(data_output, recorder)¶
- add_variable_recorder2(data_output, recorder, path, full_path)¶
- configure_time(time_step, time_total)¶
- copy()¶
Make a copy of this runnable.
- Returns:
Copy of this runnable.
- Return type:
- do_startup()¶
- inc_event_in(port)¶
- make_attachment(type_, name)¶
- pop_state()¶
- push_state()¶
- record_variables()¶
- register_event_out_callback(port, callback)¶
- register_event_out_link(port, runnable, remote_port)¶
- reset_time()¶
- resolve_path(path)¶
- single_step(dt)¶
- single_step2(dt)¶
- uid_count = 0¶
- update_shadow_variables()¶
lems.sim.sim module¶
Simulation.
- author:
Gautham Ganapathy
- organization:
- class lems.sim.sim.Event(from_id, to_id)¶
Bases:
object
Stores data associated with an event.
- from_id¶
ID of the source runnable for this event.
- Type:
Integer
- to_id¶
ID of the destination runnable for this event.
- Type:
Integer
- class lems.sim.sim.Simulation¶
Bases:
LEMSBase
Simulation class.
- add_runnable(runnable)¶
Adds a runnable component to the list of runnable components in this simulation.
- Parameters:
runnable (lems.sim.runnable.Runnable) – A runnable component
- debug = False¶
- disable_plasticity()¶
- dump(prefix='')¶
- dump_runnable(runnable, prefix='.')¶
- enable_plasticity()¶
- event_queue¶
List of posted events.
- Type:
list(lems.sim.sim.Event)
- init_run()¶
- pop_state()¶
- push_state()¶
- run()¶
Runs the simulation.
- run_queue¶
Priority of pairs of (time-to-next run, runnable).
- Type:
list((Integer, lems.sim.runnable.Runnable))
- runnables¶
Dictionary of runnable components in this simulation.
- Type:
dict(string, lems.sim.runnable.Runnable)
- step()¶
Module contents¶
- author:
Gautham Ganapathy
- organization: