Ex13: Population Instances

Instance-based population with explicit cell placement — 3 iafCells, 2 projections, pulse input

Model: Instance-Based Network

Three iafCell instances with explicit 3D placement. Cell 0 receives a pulse input and connects to cells 1 and 2 via two different expOneSynapse connections.

Reference: NML2_InstanceBasedNetwork.nml


1. Define Network in TVBO

from tvbo import SimulationExperiment

exp = SimulationExperiment.from_string("""
label: "NeuroML Ex13: Instance-Based Network"
dynamics:
  name: iaf
  iri: neuroml:iafCell
  parameters:
    leakReversal:    { value: -60, unit: mV }
    thresh:          { value: -55, unit: mV }
    reset:           { value: -62, unit: mV }
    C:               { value: 1.0, unit: nF }
    leakConductance: { value: 0.05, unit: uS }

network:
  number_of_nodes: 4
  dynamics:
    iaf:
      name: iaf
      iri: neuroml:iafCell
      parameters:
        leakReversal:    { value: -60, unit: mV }
        thresh:          { value: -55, unit: mV }
        reset:           { value: -62, unit: mV }
        C:               { value: 1.0, unit: nF }
        leakConductance: { value: 0.05, unit: uS }
    pulseGen1:
      name: pulseGen1
      iri: neuroml:pulseGenerator
      parameters:
        delay:     { value: 100, unit: ms }
        duration:  { value: 100, unit: ms }
        amplitude: { value: 0.3, unit: nA }
  nodes:
    - id: 0
      dynamics: iaf
    - id: 1
      dynamics: iaf
    - id: 2
      dynamics: iaf
    - id: 100
      dynamics: pulseGen1
  edges:
    - source: 100
      target: 0
    - source: 0
      target: 1
      coupling: expOneSynapse
      parameters:
        gbase:    { value: 5, unit: nS }
        erev:     { value: 0, unit: mV }
        tauDecay: { value: 3, unit: ms }
    - source: 0
      target: 2
      coupling: expOneSynapse
      parameters:
        gbase:    { value: 10, unit: nS }
        erev:     { value: 0, unit: mV }
        tauDecay: { value: 2, unit: ms }

integration:
  method: euler
  step_size: 0.05
  duration: 300.0
  time_scale: ms
""")
print(f"Model: {exp.dynamics.name if exp.dynamics else 'network'}")
print(f"Network nodes: {len(exp.network.nodes)}")
Model: iaf
Network nodes: 4

2. Render LEMS XML

xml = exp.render("lems")
print(xml[:2000])
<Lems>

  <!-- Tell jLEMS/jNeuroML which component is the simulation entry point. -->
  <Target component="sim_NeuroML_Ex13__Instance_Based_Network"/>

  <!-- ════════════════════════════════════════════════════════════════
       Standard NeuroML2 type includes for network mode.
       Provides all standard dimensions, units, synapse types, input
       types, network infrastructure, and simulation types.
       ════════════════════════════════════════════════════════════════ -->
  <Include file="Cells.xml"/>
  <Include file="Networks.xml"/>
  <Include file="Simulation.xml"/>

  <!-- ════════════════════════════════════════════════════════════════
       Dynamics ComponentType & Component instances
       ════════════════════════════════════════════════════════════════ -->


  <!-- ── ComponentType: iaf ── -->
  <ComponentType name="iaf" extends="baseCellMembPot">
    <Parameter name="tau" dimension="none"/>
    <Parameter name="leakReversal" dimension="voltage"/>
    <Parameter name="thresh" dimension="voltage"/>
    <Parameter name="reset" dimension="voltage"/>
    <Parameter name="C" dimension="capacitance"/>
    <Parameter name="leakConductance" dimension="conductance"/>
    <Parameter name="refract" dimension="time"/>
    <Parameter name="v_0" dimension="none" />
    <!-- Dynamically attached synapses/inputs from network connections -->
    <Attachments name="synapses" type="basePointCurrent"/>

    <Dynamics>
      <StateVariable name="v" dimension="none" exposure="v"/>
      <StateVariable name="lastSpikeTime" dimension="time"/>
      <ConditionalDerivedVariable name="I_ext" dimension="none">
        <Case condition="t .geq. 0.1 .and. t .lt. 0.2" value="0.300000000000000"/>
        <Case value="0.0"/>
      </ConditionalDerivedVariable>
      <!-- ── Regime-based dynamics (spike model) ── -->
      <OnStart>
        <StateAssignment variable="v" value="v_0"/>
      </OnStart>

      <Regime name="integrating" initial="true">
        <TimeDerivative variable=
/Users/leonmartin_bih/tools/tvbo/tvbo/adapters/neuroml.py:2787: UserWarning: synapse 'expOneSynapse' is used with more than one set of parameters; emitting the additional one as 'expOneSynapse_2'. Give each parameterisation its own entry in the dynamics library to choose the names yourself.
  syn_id = _unique_component_id(syn_type, assigned_syn_ids, kind="synapse")

3. Run Reference

from tvbo.adapters.neuroml import run_lems_example

ref_outputs = run_lems_example("LEMS_NML2_Ex13_Instances.xml")
for name, arr in ref_outputs.items():
    print(f"  {name}: shape={arr.shape}")
  auto.dat: shape=(6001, 4)

4. Run TVBO

result = exp.run("neuroml")
da = result.integration.data
print(f"TVBO: {da.dims}, shape={da.shape}")
pyNeuroML >>> 16:48:11 - INFO - Loading LEMS file: tvbo_lems_sim.xml and running with jNeuroML
pyNeuroML >>> 16:48:11 - INFO - Executing: (java -Xmx400M  -Djava.awt.headless=true -jar  "/Users/leonmartin_bih/tools/tvbo/.venv/lib/python3.12/site-packages/pyneuroml/utils/./../lib/jNeuroML-0.14.0-jar-with-dependencies.jar"  tvbo_lems_sim.xml  -nogui -I '') in directory: /var/folders/ym/9kw1g21j1nd7kwfn8c0z3st40000gn/T/tmp79ax0r7x
pyNeuroML >>> 16:48:12 - INFO - Command completed successfully!
TVBO: ('time', 'quantity'), shape=(6001, 3)

5. Compare & Plot

from tvbo.adapters.neuroml import plot_lems_comparison
plot_lems_comparison("LEMS_NML2_Ex13_Instances.xml", ref_outputs, result.integration.data, title_prefix="Ex13")