Skip to content

Commit

Permalink
Merge pull request #318 from ModECI/nml_examples
Browse files Browse the repository at this point in the history
Updates to NeuroML examples
  • Loading branch information
pgleeson authored Aug 18, 2022
2 parents ee7dd60 + 34fcb8b commit 1ad3139
Show file tree
Hide file tree
Showing 37 changed files with 384 additions and 153 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

# Rely on latest release of modelspec...
# Rely on version of modelspec from PyPI as set by setup.cfg...
#- name: Install modelspec
# run: python -m pip install git+https://github.com/ModECI/modelspec.git@main

# Rely on version of NeuroMLlite from PyPI as set by setup.py...
# - name: Install NeuroMLlite
# run: python -m pip install NeuroMLlite>=0.5.0

- name: Install GPy (py3.9)
if: ${{ matrix.python-version == '3.9' }}
run: python -m pip install git+https://github.com/SheffieldML/GPy.git@devel

- name: Install specific PsyNeuLink branch
run: python -m pip install git+https://github.com/ModECI/PsyNeuLink@devel
# Rely on version of PsyNeuLink from PyPI as set by setup.py...
#- name: Install specific PsyNeuLink branch
# run: python -m pip install git+https://github.com/ModECI/PsyNeuLink@devel

- name: Install core package
run: python -m pip install .[dev]
Expand Down
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,10 @@ Thumbs.db #thumbnail cache on Windows
/examples/NeuroML/Izh.png
/examples/NeuroML/Izh_multi
/examples/NeuroML/Izh_multi.png
/examples/NeuroML/Izh_run.png
/examples/NeuroML/IzhikevichTest.mdf.json
/examples/NeuroML/IzhikevichTest.net.nml
/examples/NeuroML/IzhikevichTest.nmllite.yaml
/examples/NeuroML/LEMS_SimIzhikevichTest.xml
/examples/NeuroML/SimIzhikevichTest.json
/examples/NeuroML/SimIzhikevichTest.yaml
/examples/AB
/examples/AB.png
/examples/states
Expand All @@ -272,3 +269,10 @@ Thumbs.db #thumbnail cache on Windows
/examples/MDF/params_funcs_example_3
/examples/MDF/params_funcs_example_3.png
/examples/MDF/params_funcs_example.png
/examples/NeuroML/LEMS_SimFN_nrn.py
/examples/MDF/RNN/*.gv.png
/examples/MDF/RNN/*.dat
/examples/MDF/RNN/LEMS_Simiaf_example.xml
/examples/MDF/RNN/iaf_example.net.nml
/examples/MDF/RNN/iaf_example__lems.xml
/examples/MDF/RNN/iaf_example_lems_definitions.xml
9 changes: 3 additions & 6 deletions examples/MDF/RNN/IAFs.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"nodes": {
"input_node": {
"parameters": {
"t": {
"time": {
"default_initial_value": 0,
"time_derivative": "1"
},
Expand All @@ -25,12 +25,12 @@
"conditions": [
{
"id": "on",
"test": "t > start and t < start + duration",
"test": "time > start and time < start + duration",
"value": "amplitude"
},
{
"id": "off",
"test": "t > start + duration",
"test": "time > start + duration",
"value": 0
}
]
Expand All @@ -39,9 +39,6 @@
"output_ports": {
"out_port": {
"value": "level"
},
"t_out_port": {
"value": "t"
}
}
},
Expand Down
53 changes: 53 additions & 0 deletions examples/MDF/RNN/IAFs.nmllite.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"iaf_example": {
"version": "NeuroMLlite v0.5.2",
"notes": "NeuroMLlite export of MDF graph: iaf_example",
"cells": {
"input_node__instance": {
"lems_source_file": "iaf_example_lems_definitions.xml"
},
"iaf_node__instance": {
"lems_source_file": "iaf_example_lems_definitions.xml"
}
},
"synapses": {
"rsDL": {
"lems_source_file": "iaf_example_lems_definitions.xml"
},
"silentSyn_proj_input_edge": {
"lems_source_file": "iaf_example_lems_definitions.xml"
}
},
"populations": {
"input_node": {
"size": 1,
"component": "input_node__instance",
"properties": {
"color": "0.2 0.2 0.2",
"radius": 3
}
},
"iaf_node": {
"size": 1,
"component": "iaf_node__instance",
"properties": {
"color": "0.2 0.2 0.2",
"radius": 3
}
}
},
"projections": {
"proj_input_edge": {
"presynaptic": "input_node",
"postsynaptic": "iaf_node",
"synapse": "rsDL",
"pre_synapse": "silentSyn_proj_input_edge",
"type": "continuousProjection",
"weight": 1,
"random_connectivity": {
"probability": 1
}
}
}
}
}
8 changes: 3 additions & 5 deletions examples/MDF/RNN/IAFs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ IAFs:
nodes:
input_node:
parameters:
t:
time:
default_initial_value: 0
time_derivative: '1'
start:
Expand All @@ -19,16 +19,14 @@ IAFs:
value: 0
conditions:
- id: 'on'
test: t > start and t < start + duration
test: time > start and time < start + duration
value: amplitude
- id: 'off'
test: t > start + duration
test: time > start + duration
value: 0
output_ports:
out_port:
value: level
t_out_port:
value: t
iaf_node:
input_ports:
input: {}
Expand Down
Binary file added examples/MDF/RNN/LEMS_Simiaf_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions examples/MDF/RNN/Simiaf_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"Simiaf_example": {
"version": "NeuroMLlite v0.5.2",
"network": "IAFs.nmllite.json",
"duration": 100000.0,
"dt": 10.0,
"seed": 123,
"record_variables": {
"time": {
"input_node": 0
},
"out_port": {
"input_node": 0,
"iaf_node": 0
},
"input": {
"iaf_node": 0
},
"v": {
"iaf_node": 0
}
}
}
}
23 changes: 17 additions & 6 deletions examples/MDF/RNN/generate_iaf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def main():
## Counter node
input_node = Node(id="input_node")

t_param = Parameter(id="t", default_initial_value=0, time_derivative="1")
t_param = Parameter(id="time", default_initial_value=0, time_derivative="1")
input_node.parameters.append(t_param)

start = Parameter(id="start", value=20)
Expand All @@ -30,20 +30,20 @@ def main():

level.conditions.append(
ParameterCondition(
id="on", test="t > start and t < start + duration", value=amp.id
id="on", test="time > start and time < start + duration", value=amp.id
)
)
level.conditions.append(
ParameterCondition(id="off", test="t > start + duration", value=0)
ParameterCondition(id="off", test="time > start + duration", value=0)
)

input_node.parameters.append(level)

op1 = OutputPort(id="out_port", value=level.id)
input_node.output_ports.append(op1)

op2 = OutputPort(id="t_out_port", value=t_param.id)
input_node.output_ports.append(op2)
# op2 = OutputPort(id="t_out_port", value=t_param.id)
# input_node.output_ports.append(op2)

mod_graph.nodes.append(input_node)

Expand Down Expand Up @@ -118,7 +118,7 @@ def main():
eg.evaluate(time_increment=dt)

i.append(eg.enodes["input_node"].evaluable_outputs["out_port"].curr_value)
t.append(eg.enodes["input_node"].evaluable_outputs["t_out_port"].curr_value)
t.append(eg.enodes["input_node"].evaluable_parameters["time"].curr_value)
s.append(eg.enodes["iaf_node"].evaluable_outputs["out_port"].curr_value)
t_ext += dt

Expand All @@ -144,6 +144,17 @@ def main():
only_warn_on_fail=True, # Makes sure test of this doesn't fail on Windows on GitHub Actions
)

if "-neuroml" in sys.argv:
from modeci_mdf.interfaces.neuroml.exporter import mdf_to_neuroml

net, sim = mdf_to_neuroml(
mod_graph, save_to="%s.nmllite.json" % mod.id, run_duration_sec=100
)

from neuromllite.NetworkGenerator import generate_and_run

generate_and_run(sim, simulator="jNeuroML")

return mod_graph


Expand Down
Binary file modified examples/MDF/RNN/iaf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions examples/MDF/RNN/regenerate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ python generate_rnn.py -run -nogui

python generate_iaf.py -graph
python generate_iaf.py -run -nogui
python generate_iaf.py -neuroml
pynml LEMS_Simiaf_example.xml -lems-graph
2 changes: 1 addition & 1 deletion examples/NeuroML/ABCD.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ABCD": {
"version": "NeuroMLlite v0.5.1",
"version": "NeuroMLlite v0.5.2",
"notes": "Example of a simplified network",
"parameters": {
"A_initial": 0.1,
Expand Down
4 changes: 2 additions & 2 deletions examples/NeuroML/ABCD.net.nml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<neuroml xmlns="http://www.neuroml.org/schema/neuroml2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2 https://raw.github.com/NeuroML/NeuroML2/development/Schemas/NeuroML2/NeuroML_v2.2.xsd" id="ABCD">
<notes>Generated by NeuroMLlite v0.5.1
<neuroml xmlns="http://www.neuroml.org/schema/neuroml2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2 https://raw.github.com/NeuroML/NeuroML2/development/Schemas/NeuroML2/NeuroML_v2.3.xsd" id="ABCD">
<notes>Generated by NeuroMLlite v0.5.2
Generated network: ABCD
Generation seed: 1234
NeuroMLlite parameters:
Expand Down
Binary file modified examples/NeuroML/FN.gv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/NeuroML/FN.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"FN": {
"version": "NeuroMLlite v0.5.1",
"version": "NeuroMLlite v0.5.2",
"notes": "FitzHugh Nagumo cell model - originally specified in NeuroML/LEMS",
"parameters": {
"initial_w": 0.0,
Expand Down
6 changes: 3 additions & 3 deletions examples/NeuroML/FN.mdf.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"time_constant_w": {
"value": 12.5
},
"threshold": {
"threshold_exc": {
"value": -1.0
},
"mode": {
Expand All @@ -68,7 +68,7 @@
},
"V": {
"default_initial_value": "initial_v",
"time_derivative": "(a_v*V*V*V + (1+threshold)*b_v*V*V + (-1*threshold)*c_v*V + d_v + e_v*W + f_v*Iext + INPUT) / (time_constant_v*MSEC)"
"time_derivative": "(a_v*V*V*V + (1+threshold_exc)*b_v*V*V + (-1*threshold_exc)*c_v*V + d_v + e_v*W + f_v*Iext + INPUT) / (time_constant_v*MSEC)"
},
"W": {
"default_initial_value": "initial_w",
Expand All @@ -86,7 +86,7 @@
"value": "W"
}
},
"notes": "Cell: [Cell(notes=None, id='fn', parameters={'initial_w': 'initial_w', 'initial_v': 'initial_v', 'a_v': 'a_v', 'b_v': 'b_v', 'c_v': 'c_v', 'd_v': 'd_v', 'e_v': 'e_v', 'f_v': 'f_v', 'time_constant_v': 'time_constant_v', 'a_w': 'a_w', 'b_w': 'b_w', 'c_w': 'c_w', 'time_constant_w': 'time_constant_w', 'threshold': 'threshold', 'mode': 'mode', 'uncorrelated_activity': 'uncorrelated_activity', 'Iext': 'Iext'}, neuroml2_source_file=None, lems_source_file='FN_Definitions.xml', neuroml2_cell=None, pynn_cell=None, arbor_cell=None, bindsnet_node=None)] is defined in FN_Definitions.xml and in Lems is: Component, id: fn, type: fnCell,\n parameters: {'initial_w': '0.0', 'initial_v': '-1', 'a_v': '-0.3333333333333333', 'b_v': '0.0', 'c_v': '1.0', 'd_v': '1', 'e_v': '-1.0', 'f_v': '1.0', 'time_constant_v': '1.0', 'a_w': '1.0', 'b_w': '-0.8', 'c_w': '0.7', 'time_constant_w': '12.5', 'threshold': '-1.0', 'mode': '1.0', 'uncorrelated_activity': '0.0', 'Iext': '0'}\n parent: None\n"
"notes": "Cell: [Cell(notes=None, id='fn', parameters={'initial_w': 'initial_w', 'initial_v': 'initial_v', 'a_v': 'a_v', 'b_v': 'b_v', 'c_v': 'c_v', 'd_v': 'd_v', 'e_v': 'e_v', 'f_v': 'f_v', 'time_constant_v': 'time_constant_v', 'a_w': 'a_w', 'b_w': 'b_w', 'c_w': 'c_w', 'time_constant_w': 'time_constant_w', 'threshold': 'threshold', 'mode': 'mode', 'uncorrelated_activity': 'uncorrelated_activity', 'Iext': 'Iext'}, neuroml2_source_file=None, lems_source_file='FN_Definitions.xml', neuroml2_cell=None, pynn_cell=None, arbor_cell=None, bindsnet_node=None)] is defined in FN_Definitions.xml and in Lems is: Component, id: fn, type: fnCell,\n parameters: {'initial_w': '0.0', 'initial_v': '-1', 'a_v': '-0.3333333333333333', 'b_v': '0.0', 'c_v': '1.0', 'd_v': '1', 'e_v': '-1.0', 'f_v': '1.0', 'time_constant_v': '1.0', 'a_w': '1.0', 'b_w': '-0.8', 'c_w': '0.7', 'time_constant_w': '12.5', 'threshold_exc': '-1.0', 'mode': '1.0', 'uncorrelated_activity': '0.0', 'Iext': '0'}\n parent: None\n"
}
},
"edges": {}
Expand Down
14 changes: 7 additions & 7 deletions examples/NeuroML/FN.mdf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ FN:
value: 0.7
time_constant_w:
value: 12.5
threshold:
threshold_exc:
value: -1.0
mode:
value: 1.0
Expand All @@ -48,9 +48,9 @@ FN:
value: 0.001
V:
default_initial_value: initial_v
time_derivative: (a_v*V*V*V + (1+threshold)*b_v*V*V +
(-1*threshold)*c_v*V + d_v + e_v*W + f_v*Iext + INPUT)
/ (time_constant_v*MSEC)
time_derivative: (a_v*V*V*V + (1+threshold_exc)*b_v*V*V
+ (-1*threshold_exc)*c_v*V + d_v + e_v*W + f_v*Iext
+ INPUT) / (time_constant_v*MSEC)
W:
default_initial_value: initial_w
time_derivative: (mode*a_w*V + b_w*W + c_w + (1-mode)*uncorrelated_activity)
Expand All @@ -76,7 +76,7 @@ FN:
\ 'initial_v': '-1', 'a_v': '-0.3333333333333333', 'b_v':\
\ '0.0', 'c_v': '1.0', 'd_v': '1', 'e_v': '-1.0', 'f_v': '1.0',\
\ 'time_constant_v': '1.0', 'a_w': '1.0', 'b_w': '-0.8', 'c_w':\
\ '0.7', 'time_constant_w': '12.5', 'threshold': '-1.0', 'mode':\
\ '1.0', 'uncorrelated_activity': '0.0', 'Iext': '0'}\n \
\ parent: None\n"
\ '0.7', 'time_constant_w': '12.5', 'threshold_exc': '-1.0',\
\ 'mode': '1.0', 'uncorrelated_activity': '0.0', 'Iext': '0'}\n\
\ parent: None\n"
edges: {}
4 changes: 2 additions & 2 deletions examples/NeuroML/FN.net.nml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<neuroml xmlns="http://www.neuroml.org/schema/neuroml2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2 https://raw.github.com/NeuroML/NeuroML2/development/Schemas/NeuroML2/NeuroML_v2.2.xsd" id="FN">
<notes>Generated by NeuroMLlite v0.5.1
<neuroml xmlns="http://www.neuroml.org/schema/neuroml2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2 https://raw.github.com/NeuroML/NeuroML2/development/Schemas/NeuroML2/NeuroML_v2.3.xsd" id="FN">
<notes>Generated by NeuroMLlite v0.5.2
Generated network: FN
Generation seed: 1234
NeuroMLlite parameters:
Expand Down
8 changes: 4 additions & 4 deletions examples/NeuroML/FN_Definitions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Parameter name="b_w" dimension="none"/>
<Parameter name="c_w" dimension="none"/>
<Parameter name="time_constant_w" dimension="none"/>
<Parameter name="threshold" dimension="none"/>
<Parameter name="threshold_exc" dimension="none" description="Note: renamed temporarily from threshold to allow testing in NEURON, where threshold is reserved word"/>
<Parameter name="mode" dimension="none"/>
<Parameter name="uncorrelated_activity" dimension="none"/>
<!-- Initial Conditions -->
Expand Down Expand Up @@ -46,7 +46,7 @@

<DerivedVariable name="INPUT" dimension="none" exposure="INPUT" select="synapses[*]/I" reduce="add" />

<TimeDerivative variable="V" value="(a_v*V*V*V + (1+threshold)*b_v*V*V + (-1*threshold)*c_v*V + d_v + e_v*W + f_v*Iext + INPUT) / (time_constant_v*MSEC)"/>
<TimeDerivative variable="V" value="(a_v*V*V*V + (1+threshold_exc)*b_v*V*V + (-1*threshold_exc)*c_v*V + d_v + e_v*W + f_v*Iext + INPUT) / (time_constant_v*MSEC)"/>
<TimeDerivative variable="W" value="(mode*a_w*V + b_w*W + c_w + (1-mode)*uncorrelated_activity) / (time_constant_w*MSEC)"/>

<OnStart>
Expand All @@ -64,14 +64,14 @@
<fnCell id="fn0" initial_w="-0.62" initial_v="-1.2" a_v="-0.3333333333333333" b_v="0.0"
c_v="1.0" d_v="0" e_v="-1.0" f_v="1.0"
time_constant_v="1.0" a_w="1.0" b_w="-0.8" c_w="0.7"
time_constant_w="12.5" threshold="-1.0"
time_constant_w="12.5" threshold_exc="-1.0"
mode="1.0" uncorrelated_activity="0.0"
Iext="0" />

<fnCell id="fn" initial_w="0.0" initial_v="-1" a_v="-0.3333333333333333" b_v="0.0"
c_v="1.0" d_v="1" e_v="-1.0" f_v="1.0"
time_constant_v="1.0" a_w="1.0" b_w="-0.8" c_w="0.7"
time_constant_w="12.5" threshold="-1.0"
time_constant_w="12.5" threshold_exc="-1.0"
mode="1.0" uncorrelated_activity="0.0"
Iext="0" />

Expand Down
Loading

0 comments on commit 1ad3139

Please sign in to comment.