LEMS / LEMS/jLEMS

Setting a property tag for a population of type population (not populationlist) causes jlems to throw an error

Open
#104 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help required
Dominant language
Java
Stars
11
Forks
11
Avg merge
8h 6m
Merged PRs (30d)
1

Description

Python script:

#!/usr/bin/env python3
"""
Create a simple network with two populations.
"""

import random
import numpy as np

from neuroml.utils import component_factory
from pyneuroml import pynml
from pyneuroml.lems import LEMSSimulation
import neuroml.writers as writers


nml_doc = component_factory("NeuroMLDocument", id="IzNet")
iz0 = nml_doc.add(
    "Izhikevich2007Cell",
    id="iz2007RS0",
    v0="-60mV",
    C="100pF",
    k="0.7nS_per_mV",
    vr="-60mV",
    vt="-40mV",
    vpeak="35mV",
    a="0.03per_ms",
    b="-2nS",
    c="-50.0mV",
    d="100pA",
)

# Inspect the component, also show all members:
iz0.info(True)

# Create a component of type ExpOneSynapse, and add it to the document
syn0 = nml_doc.add(
    "ExpOneSynapse", id="syn0", gbase="65nS", erev="0mV", tau_decay="3ms"
)
# Check what we have so far:
nml_doc.info(True)
# Also try:
print(nml_doc.summary())

# create the network: turned of validation because we will add populations next
net = nml_doc.add("Network", id="IzNet", validate=False)

# create the first population
size0 = 5
pop0 = component_factory("Population", id="IzPop0", component=iz0.id, size=size0)
# Set optional color property. Note: used later when generating plots
pop0.add("Property", tag="color", value="0 0 .8")
net.add(pop0)

# create the second population
size1 = 5
pop1 = component_factory("Population", id="IzPop1", component=iz0.id, size=size1)
pop1.add("Property", tag="color", value=".8 0 0")
net.add(pop1)

# network should be valid now that it contains populations
net.validate()

# create a projection from one population to another
proj = net.add(
    "Projection",
    id="proj",
    presynaptic_population=pop0.id,
    postsynaptic_population=pop1.id,
    synapse=syn0.id,
)

# We do two things in the loop:
# - add pulse generator inputs to population 1 to make neurons spike
# - create synapses between the two populations with a particular probability
random.seed(123)
prob_connection = 0.8
count = 0
for pre in range(0, size0):
    # pulse generator as explicit stimulus
    pg = nml_doc.add(
        "PulseGenerator",
        id="pg_%i" % pre,
        delay="0ms",
        duration="10000ms",
        amplitude="%f nA" % (0.1 + 0.1 * random.random()),
    )

    exp_input = net.add(
        "ExplicitInput", target="%s[%i]" % (pop0.id, pre), input=pg.id
    )

    # synapses between populations
    for post in range(0, size1):
        if random.random() <= prob_connection:
            syn = proj.add(
                "Connection",
                id=count,
                pre_cell_id="../%s[%i]" % (pop0.id, pre),
                post_cell_id="../%s[%i]" % (pop1.id, post),
            )
            count += 1

nml_doc.info(True)
print(nml_doc.summary())

# write model to file and validate
nml_file = "izhikevich2007_network.nml"
writers.NeuroMLWriter.write(nml_doc, nml_file)

print("Written network file to: " + nml_file)
pynml.validate_neuroml2(nml_file)

# Create simulation, and record data
simulation_id = "example_izhikevich2007network_sim"
simulation = LEMSSimulation(
    sim_id=simulation_id, duration=1000, dt=0.1, simulation_seed=123
)
simulation.assign_simulation_target(net.id)
simulation.include_neuroml2_file(nml_file)

simulation.create_event_output_file(
    "pop0", "%s.0.spikes.dat" % simulation_id, format="ID_TIME"
)
for pre in range(0, size0):
    simulation.add_selection_to_event_output_file(
        "pop0", pre, "IzPop0[{}]".format(pre), "spike"
    )

simulation.create_event_output_file(
    "pop1", "%s.1.spikes.dat" % simulation_id, format="ID_TIME"
)
for pre in range(0, size1):
    simulation.add_selection_to_event_output_file(
        "pop1", pre, "IzPop1[{}]".format(pre), "spike"
    )

lems_simulation_file = simulation.save_to_file()

# Run the simulation
pynml.run_lems_with_jneuroml(
    lems_simulation_file, max_memory="2G", nogui=True, plot=False
)

# Load the data from the file and plot the spike times
# using the pynml generate_plot utility function.
data_array_0 = np.loadtxt("%s.0.spikes.dat" % simulation_id)
data_array_1 = np.loadtxt("%s.1.spikes.dat" % simulation_id)
times_0 = data_array_0[:, 1]
times_1 = data_array_1[:, 1]
ids_0 = data_array_0[:, 0]
ids_1 = [id + size0 for id in data_array_1[:, 0]]
pynml.generate_plot(
    [times_0, times_1],
    [ids_0, ids_1],
    "Spike times",
    show_plot_already=False,
    save_figure_to="%s-spikes.png" % simulation_id,
    xaxis="time (s)",
    yaxis="cell ID",
    colors=["b", "r"],
    linewidths=["0", "0"],
    markers=[".", "."],
)

Output (failure):


pyNeuroML >>> INFO - Loading NeuroML2 file: /home/asinha/Documents/02_Code/00_mine/NeuroML/documentation/source/Userdocs/NML2_examples/izhikevich2007_network.nml
pyNeuroML >>> INFO - Loading LEMS file: LEMS_example_izhikevich2007network_sim.xml and running with jNeuroML
pyNeuroML >>> INFO - Executing: (java -Xmx2G  -Djava.awt.headless=true -jar  "/home/asinha/Documents/02_Code/00_mine/NeuroML/documentation/.venv/lib/python3.10/site-packages/pyneuroml/lib/jNeuroML-0.12.0-jar-with-dependencies.jar"  "LEMS_example_izhikevich2007network_sim.xml"  -nogui -I '') in directory: .
pyNeuroML >>> CRITICAL - *** Problem running command:
       Command 'java -Xmx2G  -Djava.awt.headless=true -jar  "/home/asinha/Documents/02_Code/00_mine/NeuroML/documentation/.venv/lib/python3.10/site-packages/pyneuroml/lib/jNeuroML-0.12.0-jar-with-dependencies.jar"  "LEMS_example_izhikevich2007network_sim.xml"  -nogui -I ''' returned non-zero exit status 1.
pyNeuroML >>> CRITICAL -  jNeuroML >>   jNeuroML v0.12.0
 jNeuroML >>  Loading: /home/asinha/Documents/02_Code/00_mine/NeuroML/documentation/source/Userdocs/NML2_examples/LEMS_example_izhikevich2007network_sim.xml with jLEMS, NO GUI mode...
 jNeuroML >>  org.lemsml.jlems.core.run.ConnectionError: Can't get predicate [0] from IzPop0[population], original path: ../IzPop0[0]
 jNeuroML >>  component has singeMI=false
 jNeuroML >>    at org.lemsml.jlems.core.sim.RunnableAccessor.getRelativeStateInstance(RunnableAccessor.java:140)
 jNeuroML >>    at org.lemsml.jlems.core.run.WithBuilder.postBuild(WithBuilder.java:37)
 jNeuroML >>    at org.lemsml.jlems.core.run.Builder.postBuild(Builder.java:25)
 jNeuroML >>    at org.lemsml.jlems.core.run.StateType.build(StateType.java:340)
 jNeuroML >>    at org.lemsml.jlems.core.run.StateInstance.checkBuilt(StateInstance.java:1187)
 jNeuroML >>    at org.lemsml.jlems.core.run.StateInstance.checkBuilt(StateInstance.java:1199)
 jNeuroML >>    at org.lemsml.jlems.core.run.StateInstance.checkBuilt(StateInstance.java:1199)
 jNeuroML >>    at org.lemsml.jlems.core.type.Lems.build(Lems.java:359)
 jNeuroML >>    at org.lemsml.jlems.core.sim.Sim.run(Sim.java:232)
 jNeuroML >>    at org.lemsml.jlems.core.sim.Sim.run(Sim.java:154)
 jNeuroML >>    at org.lemsml.jlems.core.sim.Sim.run(Sim.java:145)
 jNeuroML >>    at org.neuroml.export.utils.Utils.loadLemsFile(Utils.java:527)
 jNeuroML >>    at org.neuroml.export.utils.Utils.runLemsFile(Utils.java:493)
 jNeuroML >>    at org.neuroml.JNeuroML.main(JNeuroML.java:606)
 jNeuroML >>  INFO Oct 19,2022 13:17  (INFO) Loading LEMS file from: /home/asinha/Documents/02_Code/00_mine/NeuroML/documentation/source/Userdocs/NML2_examples/LEMS_example_izhikevich2007network_sim.xml
 jNeuroML >>  INFO Oct 19,2022 13:17  (INFO) Reading from: /home/asinha/Documents/02_Code/00_mine/NeuroML/documentation/source/Userdocs/NML2_examples/LEMS_example_izhikevich2007network_sim.xml
 jNeuroML >>
pyNeuroML >>> ERROR - execute_command_in_dir returned with output:  jNeuroML v0.12.0
Loading: /home/asinha/Documents/02_Code/00_mine/NeuroML/documentation/source/Userdocs/NML2_examples/LEMS_example_izhikevich2007network_sim.xml with jLEMS, NO GUI mode...
org.lemsml.jlems.core.run.ConnectionError: Can't get predicate [0] from IzPop0[population], original path: ../IzPop0[0]
component has singeMI=false
        at org.lemsml.jlems.core.sim.RunnableAccessor.getRelativeStateInstance(RunnableAccessor.java:140)
        at org.lemsml.jlems.core.run.WithBuilder.postBuild(WithBuilder.java:37)
        at org.lemsml.jlems.core.run.Builder.postBuild(Builder.java:25)
        at org.lemsml.jlems.core.run.StateType.build(StateType.java:340)
        at org.lemsml.jlems.core.run.StateInstance.checkBuilt(StateInstance.java:1187)
        at org.lemsml.jlems.core.run.StateInstance.checkBuilt(StateInstance.java:1199)
        at org.lemsml.jlems.core.run.StateInstance.checkBuilt(StateInstance.java:1199)
        at org.lemsml.jlems.core.type.Lems.build(Lems.java:359)
        at org.lemsml.jlems.core.sim.Sim.run(Sim.java:232)
        at org.lemsml.jlems.core.sim.Sim.run(Sim.java:154)
        at org.lemsml.jlems.core.sim.Sim.run(Sim.java:145)
        at org.neuroml.export.utils.Utils.loadLemsFile(Utils.java:527)
        at org.neuroml.export.utils.Utils.runLemsFile(Utils.java:493)
        at org.neuroml.JNeuroML.main(JNeuroML.java:606)
INFO Oct 19,2022 13:17  (INFO) Loading LEMS file from: /home/asinha/Documents/02_Code/00_mine/NeuroML/documentation/source/Userdocs/NML2_examples/LEMS_example_izhikevich2007network_sim.xml
INFO Oct 19,2022 13:17  (INFO) Reading from: /home/asinha/Documents/02_Code/00_mine/NeuroML/documentation/source/Userdocs/NML2_examples/LEMS_example_izhikevich2007network_sim.xml

It runs fine if one uses the NEURON simulation backend. To make it run in jneuroml/jlems, one needs to remove the property tag for the two populations.

Analysis (short!)

This is where the error message is generated:

https://github.com/LEMS/jLEMS/blob/master/src/main/java/org/lemsml/jlems/core/sim/RunnableAccessor.java#L139

The addition of the property tag to the population makes seems to set singleAMI to false. I think this is being his is being set here in countMIs on the basis of the size of multiA:

https://github.com/LEMS/jLEMS/blob/master/src/main/java/org/lemsml/jlems/core/run/StateInstance.java#L788

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the Python example in the issue, using the jNeuroML/jLEMS backend and population property tags. Read RunnableAccessor.java around line 139 and StateInstance.java around countMIs at line 788 to trace the singleAMI and multiA state. Done means the example runs in jLEMS without removing the property tags.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.