If the component name has "-" in them, they need to be replaced because the digraph ...
line in dot cannot include "-".
MWE:
#!/usr/bin/env python3
"""
Create a simple network with two populations.
"""
from neuroml import NeuroMLDocument
from neuroml import Izhikevich2007Cell
from neuroml import Network
from neuroml import ExpOneSynapse
from neuroml import Population
from neuroml import PulseGenerator
from neuroml import ExplicitInput
from neuroml import SynapticConnection
import neuroml.writers as writers
import random
from pyneuroml import pynml
from pyneuroml.lems import LEMSSimulation
import numpy as np
nml_doc = NeuroMLDocument(id="IzNet")
iz0 = 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")
nml_doc.izhikevich2007_cells.append(iz0)
syn0 = ExpOneSynapse(id="syn0", gbase="65nS", erev="0mV", tau_decay="3ms")
nml_doc.exp_one_synapses.append(syn0)
net = Network(id="IzNet")
nml_doc.networks.append(net)
size0 = 5
pop0 = Population(id="IzPop0", component=iz0.id, size=size0)
net.populations.append(pop0)
size1 = 5
pop1 = Population(id="IzPop1", component=iz0.id, size=size1)
net.populations.append(pop1)
random.seed(42)
prob_connection = 0.5
for pre in range(0, size0):
pg = PulseGenerator(
id="pulseGen_%i" % pre, delay="0ms", duration="10000ms",
amplitude="%f nA" % (0.1 * random.random())
)
nml_doc.pulse_generators.append(pg)
exp_input = ExplicitInput(target="%s/%i" % (pop0.id, pre), input=pg.id)
net.explicit_inputs.append(exp_input)
for post in range(0, size1):
# 'from_' is used since 'from' is Python keyword
if random.random() <= prob_connection:
syn = SynapticConnection(from_="%s/%i" % (pop0.id, pre),
synapse=syn0.id,
to="%s/%i" % (pop1.id, post))
net.synaptic_connections.append(syn)
nml_file = 'izhikevich2007_network.nml'
writers.NeuroMLWriter.write(nml_doc, nml_file)
print("Written network file to: " + nml_file)
pynml.validate_neuroml2(nml_file)
simulation_id = "example-izhikevich2007network-sim"
simulation = LEMSSimulation(sim_id=simulation_id,
duration=10000, 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.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')
lems_simulation_file = simulation.save_to_file()
pynml.run_lems_with_jneuroml_neuron(
lems_simulation_file, max_memory="20G", nogui=True, plot=False
)
# Load the data from the file and plot the spike times
# using the pynml generate_plot utility function.
data_array = np.loadtxt("%s.spikes.dat" % simulation_id)
pynml.generate_plot(
[data_array[:, 1]], [data_array[:, 0]],
"Spike times", show_plot_already=False,
save_figure_to="%s-spikes.png" % simulation_id,
xaxis="time (s)", yaxis="cell ID",
linestyles='', linewidths='0', markers=['.'],
)
This generates this LEMS file:
<Lems>
<!--
This LEMS file has been automatically generated using PyNeuroML v0.5.6 (libNeuroML v0.2.52)
-->
<!-- Specify which component to run -->
<Target component="example-izhikevich2007network-sim"/>
<!-- Include core NeuroML2 ComponentType definitions -->
<Include file="Cells.xml"/>
<Include file="Networks.xml"/>
<Include file="Simulation.xml"/>
<Include file="izhikevich2007_network.nml"/>
<Simulation id="example-izhikevich2007network-sim" length="10000ms" step="0.1ms" target="IzNet" seed="123"> <!-- Note seed: ensures same random numbers used every run -->
<EventOutputFile id="pop0" fileName="example-izhikevich2007network-sim.spikes.dat" format="ID_TIME">
<EventSelection id="0" select="IzPop0/0" eventPort="spike"/>
<EventSelection id="1" select="IzPop0/1" eventPort="spike"/>
<EventSelection id="2" select="IzPop0/2" eventPort="spike"/>
<EventSelection id="3" select="IzPop0/3" eventPort="spike"/>
<EventSelection id="4" select="IzPop0/4" eventPort="spike"/>
</EventOutputFile>
</Simulation>
</Lems>
Exporting it to graphviz fails with this error:
jnml LEMS_example-izhikevich2007network-sim.xml -graph
jNeuroML v0.10.1
(INFO) Reading from: /home/asinha/Documents/02_Code/00_mine/2020-OSB/NeuroML-Documentation/source/Userdocs/NML2_examples/LEMS_example-izhikevich2007network-sim.xml
(INFO) simCpt: Component(id=example-izhikevich2007network-sim type=Simulation)
Writing to: /home/asinha/Documents/02_Code/00_mine/2020-OSB/NeuroML-Documentation/source/Userdocs/NML2_examples/LEMS_example-izhikevich2007network-sim.gv
----Error: /home/asinha/Documents/02_Code/00_mine/2020-OSB/NeuroML-Documentation/source/Userdocs/NML2_examples/LEMS_example-izhikevich2007network-sim.gv: syntax error in line 3 near '-'
Line 3 is the digraph
line where the component ID has "-" in it:
# GraphViz compliant export for:IzNet (Type: network)
digraph example-izhikevich2007network-sim {
fontsize=10;
subgraph cluster_network {
style=filled;
color="#D6eeEA";
node [style=filled,color=white];
label = "Network to be simulated";
node [shape=rectangle]; IzNet;
# Population IzPop0 contains components of: Component(id=iz2007RS0 type=izhikevich2007Cell)
node [shape=ellipse,color="white",fontcolor="black"]; IzPop0;
IzNet -> IzPop0 [len=1.00, arrowhead=diamond]
# Population IzPop1 contains components of: Component(id=iz2007RS0 type=izhikevich2007Cell)
node [shape=ellipse,color="white",fontcolor="black"]; IzPop1;
IzNet -> IzPop1 [len=1.00, arrowhead=diamond]
}
subgraph cluster_comps {
style=filled;
color="#CCFFCC";
node [style=filled,color=white];
label = "Components";
node [shape=ellipse label=<<table border="0" cellborder="0"><tr><td>iz2007RS0 (izhikevich2007Cell)</td></tr><tr><td><font color="#666666">v0 = -0.06 V, k = 7.0E-7 kg^-2 m^-4 s^6 A^3, vr = -0.06 V, <br/>vt = -0.04 V, vpeak = 0.035 V, a = 30 s^-1, <br/>b = -2.0E-9 S, c = -0.05 V, d = 1.0E-10 A, <br/>C = 1.0E-10 F</font></td></tr></table>>]; "iz2007RS0 (izhikevich2007Cell)";
"IzPop0" -> "iz2007RS0 (izhikevich2007Cell)" [label="5",len=1.00, arrowhead=diamond]
node [shape=ellipse label=<<table border="0" cellborder="0"><tr><td>iz2007RS0 (izhikevich2007Cell)</td></tr><tr><td><font color="#666666">v0 = -0.06 V, k = 7.0E-7 kg^-2 m^-4 s^6 A^3, vr = -0.06 V, <br/>vt = -0.04 V, vpeak = 0.035 V, a = 30 s^-1, <br/>b = -2.0E-9 S, c = -0.05 V, d = 1.0E-10 A, <br/>C = 1.0E-10 F</font></td></tr></table>>]; "iz2007RS0 (izhikevich2007Cell)";
"IzPop1" -> "iz2007RS0 (izhikevich2007Cell)" [label="5",len=1.00, arrowhead=diamond]
}
subgraph cluster_compTypes {
style=filled;
color="#D6E0EA";
node [style="rounded, filled",color=white];
label = "Component Types";
node [style="rounded, filled",color=white];
node [shape=box label=<<table border="0" cellborder="0"><tr><td>izhikevich2007Cell</td></tr><tr><td><font color="#669999">Params: v0 (voltage), k (conductance_per_voltage), vr (voltage), <br/>vt (voltage), vpeak (voltage), a (per_time), <br/>b (conductance), c (voltage), d (current) </font></td></tr><tr><td><font color="#FF9966">State vars: v (voltage), u (current) </font></td></tr><tr><td><font color="#99CC00">iSyn = SUM OF: synapses[*]/i</font></td></tr><tr><td><font color="#99CC00">iMemb = k * (v-vr) * (v-vt) + iSyn - u</font></td></tr><tr><td><font color="#666633">v' = iMemb / C</font></td></tr><tr><td><font color="#666633">u' = a * (b * (v-vr) - u)</font></td></tr><tr><td><font color="#996633">IF v .gt. vpeak THEN </font></td></tr><tr><td><font color="#996633">(v = c) <br/>AND (u = u + d) <br/>AND (EVENT: spike)</font></td></tr><tr><td><font color="#666666">Exposures: u (current), iSyn (current), iMemb (current), <br/>v (voltage) </font></td></tr></table>>]; izhikevich2007Cell;
node [shape=box label=<<table border="0" cellborder="0"><tr><td>baseCellMembPotCap</td></tr><tr><td><font color="#669999">Params: C (capacitance) </font></td></tr><tr><td><font color="#666666">Exposures: iSyn (current), iMemb (current), v (voltage) </font></td></tr></table>>]; baseCellMembPotCap;
izhikevich2007Cell -> baseCellMembPotCap [len=1.00, arrowhead=onormal]
node [shape=box label=<<table border="0" cellborder="0"><tr><td>baseCellMembPot</td></tr><tr><td><font color="#666666">Exposures: v (voltage) </font></td></tr></table>>]; baseCellMembPot;
baseCellMembPotCap -> baseCellMembPot [len=1.00, arrowhead=onormal]
node [shape=box label=<<table border="0" cellborder="0"><tr><td>baseSpikingCell</td></tr></table>>]; baseSpikingCell;
baseCellMembPot -> baseSpikingCell [len=1.00, arrowhead=onormal]
node [shape=box label=<<table border="0" cellborder="0"><tr><td>baseCell</td></tr></table>>]; baseCell;
baseSpikingCell -> baseCell [len=1.00, arrowhead=onormal]
node [shape=box label=<<table border="0" cellborder="0"><tr><td>baseStandalone</td></tr></table>>]; baseStandalone;
baseCell -> baseStandalone [len=1.00, arrowhead=onormal]
node [shape=box label=<<table border="0" cellborder="0"><tr><td>izhikevich2007Cell</td></tr><tr><td><font color="#669999">Params: v0 (voltage), k (conductance_per_voltage), vr (voltage), <br/>vt (voltage), vpeak (voltage), a (per_time), <br/>b (conductance), c (voltage), d (current) </font></td></tr><tr><td><font color="#FF9966">State vars: v (voltage), u (current) </font></td></tr><tr><td><font color="#99CC00">iSyn = SUM OF: synapses[*]/i</font></td></tr><tr><td><font color="#99CC00">iMemb = k * (v-vr) * (v-vt) + iSyn - u</font></td></tr><tr><td><font color="#666633">v' = iMemb / C</font></td></tr><tr><td><font color="#666633">u' = a * (b * (v-vr) - u)</font></td></tr><tr><td><font color="#996633">IF v .gt. vpeak THEN </font></td></tr><tr><td><font color="#996633">(v = c) <br/>AND (u = u + d) <br/>AND (EVENT: spike)</font></td></tr><tr><td><font color="#666666">Exposures: u (current), iSyn (current), iMemb (current), <br/>v (voltage) </font></td></tr></table>>]; izhikevich2007Cell;
node [shape=box label=<<table border="0" cellborder="0"><tr><td>baseCellMembPotCap</td></tr><tr><td><font color="#669999">Params: C (capacitance) </font></td></tr><tr><td><font color="#666666">Exposures: iSyn (current), iMemb (current), v (voltage) </font></td></tr></table>>]; baseCellMembPotCap;
node [shape=box label=<<table border="0" cellborder="0"><tr><td>baseCellMembPot</td></tr><tr><td><font color="#666666">Exposures: v (voltage) </font></td></tr></table>>]; baseCellMembPot;
node [shape=box label=<<table border="0" cellborder="0"><tr><td>baseSpikingCell</td></tr></table>>]; baseSpikingCell;
node [shape=box label=<<table border="0" cellborder="0"><tr><td>baseCell</td></tr></table>>]; baseCell;
node [shape=box label=<<table border="0" cellborder="0"><tr><td>baseStandalone</td></tr></table>>]; baseStandalone;
}
"iz2007RS0 (izhikevich2007Cell)" -> izhikevich2007Cell [len=1.00]
}