SimulationRunner#

class SimulationRunner(
network: Network,
models: dict[str, Any],
step_callback: Callable[[Any], Any],
model_outputs: dict[str, list[str] | None] | None = None,
temperature__celsius: float = 36.0,
)[source]#

Bases: object

Manages NEURON simulation execution with automated setup, initialization, and result collection for neuromuscular simulations.

Provides a clean interface for running complex neuromuscular simulations while maintaining full user control over populations, connections, and step-by-step simulation logic. Automatically handles NEURON environment setup, voltage initialization, and structured result collection.

Separates simulation control from plotting and analysis concerns.

Initialize SimulationRunner with network, models, and step callback.

Parameters:
  • network (Network) – Configured Network instance with populations and connections.

  • models (Dict[str, Any]) – Physiological models (e.g., {“hill”: hill_model, “spin”: spindle_model}).

  • step_callback (Callable) – User-defined function called at each simulation timestep.

  • model_outputs (Optional[Dict[str, Union[List[str], None]]], optional) – Explicit model output attributes to collect. None uses smart defaults. Format: {“model_name”: [“attr1”, “attr2”]} or {“model_name”: None} for defaults, by default None.

  • temperature__celsius (float, optional) – NEURON simulation temperature, by default 36.0.

Methods

__init__

Initialize SimulationRunner with network, models, and step callback.

get_model_outputs

Get the list of output attributes that will be collected for a model.

run

Execute NEURON simulation with automated setup and result collection.

set_model_outputs

Override the output attributes for a specific model.

run(
duration__ms: Quantity__ms,
timestep__ms: Quantity__ms,
membrane_recording: dict[str, list[int]] | None = None,
) Block[source]#

Execute NEURON simulation with automated setup and result collection.

Parameters:
  • duration__ms (Quantity__ms) – Total simulation duration in milliseconds.

  • timestep__ms (Quantity__ms) – Integration timestep in milliseconds.

  • membrane_recording (Optional[Dict[str, List[int]]], optional) – Populations and cell indices for membrane potential recording. Format: {“population_name”: [cell_id1, cell_id2, …]}, by default None.

Returns:

Structured simulation results containing: - spikes: Spike timing and ID data for all populations - membrane: Membrane potential traces (if requested) - models: Output data from all physiological models - simulation: Time vector and simulation metadata

Return type:

Block

Raises:
  • ValueError – If model output attributes don’t exist on model instances.

  • RuntimeError – If NEURON simulation fails to complete.

get_model_outputs(model_name: str) list[str][source]#

Get the list of output attributes that will be collected for a model.

Parameters:

model_name (str) – Name of the model as specified in the models dictionary.

Returns:

List of attribute names that will be collected from this model.

Return type:

List[str]

set_model_outputs(model_name: str, output_attrs: list[str]) None[source]#

Override the output attributes for a specific model.

Parameters:
  • model_name (str) – Name of the model as specified in the models dictionary.

  • output_attrs (List[str]) – List of attribute names to collect from this model.

Raises:

ValueError – If model_name is not found in the models dictionary.

Return type:

None