Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sanjayankur31 opened this issue Oct 19, 2022 · 0 comments

Comments

@sanjayankur31
Copy link
Contributor

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

sanjayankur31 added a commit to NeuroML/Documentation that referenced this issue Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant