Skip to content

Commit

Permalink
Merge branch 'nml_examples' into keras_interface
Browse files Browse the repository at this point in the history
  • Loading branch information
pgleeson committed Sep 15, 2023
2 parents fec24cc + a397a81 commit 13d1c6e
Show file tree
Hide file tree
Showing 35 changed files with 2,062 additions and 22 deletions.
21 changes: 14 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,25 @@ Thumbs.db #thumbnail cache on Windows
/examples/TensorFlow/Keras/keras_to_MDF
/examples/NeuroML/PyNN/All*
/examples/NeuroML/PyNN/*dat
/examples/NeuroML/PyNN/*.png
/examples/NeuroML/PyNN/*1.png
/examples/NeuroML/PyNN/*.1
/examples/NeuroML/PyNN/InputWeights*
/examples/NeuroML/PyNN/OneCell*
/examples/NeuroML/PyNN/Sim*
/examples/NeuroML/PyNN/LEMS_Sim*
/examples/NeuroML/PyNN/HH*
/examples/NeuroML/PyNN/arm64
/examples/NeuroML/PyNN/*.pkl
/examples/NeuroML/PyNN/*.json
/examples/NeuroML/PyNN/*.mdf
/examples/NeuroML/PyNN/*.spikes
*_code.gen.c
/examples/NeuroML/PyNN/Net1*
examples/TensorFlow/Keras/Keras_to_MDF_IRIS/keras_to_MDF
examples/TensorFlow/Keras/keras_to_MDF
/examples/TensorFlow/Keras/Keras_MDF/Keras_to_MDF_IRIS/keras_to_MDF
/examples/TensorFlow/Keras/Keras_MDF/keras_to_MDF
/examples/NeuroML/PyNN/HH.yaml
/examples/NeuroML/PyNN/InputWeights.yaml
/examples/NeuroML/PyNN/Net1.yaml
/examples/NeuroML/PyNN/OneCell.yaml
/examples/NeuroML/PyNN/SimHH.yaml
/examples/NeuroML/PyNN/SimNet1.yaml
/examples/NeuroML/PyNN/SimOneCell.yaml
/examples/NeuroML/PyNN/SimSimpleNet.yaml
/examples/NeuroML/PyNN/SimpleNet.yaml
/examples/NeuroML/PyNN/SimInputWeights.yaml
6 changes: 6 additions & 0 deletions docs/sphinx/source/api/QuickStart.md

Large diffs are not rendered by default.

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.5",
"version": "NeuroMLlite v0.5.7",
"notes": "Example of a simplified network",
"parameters": {
"A_initial": 0.1,
Expand Down
2 changes: 1 addition & 1 deletion 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.3.xsd" id="ABCD">
<notes>Generated by NeuroMLlite v0.5.5
<notes>Generated by NeuroMLlite v0.5.7
Generated network: ABCD
Generation seed: 1234
NeuroMLlite parameters:
Expand Down
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.5",
"version": "NeuroMLlite v0.5.7",
"notes": "FitzHugh Nagumo cell model - originally specified in NeuroML/LEMS",
"parameters": {
"initial_w": 0.0,
Expand Down
2 changes: 1 addition & 1 deletion 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.3.xsd" id="FN">
<notes>Generated by NeuroMLlite v0.5.5
<notes>Generated by NeuroMLlite v0.5.7
Generated network: FN
Generation seed: 1234
NeuroMLlite parameters:
Expand Down
2 changes: 1 addition & 1 deletion examples/NeuroML/IzhikevichTest.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.3.xsd" id="IzhikevichTest">
<notes>Generated by NeuroMLlite v0.5.5
<notes>Generated by NeuroMLlite v0.5.7
Generated network: IzhikevichTest
Generation seed: 1234
NeuroMLlite parameters:
Expand Down
4 changes: 2 additions & 2 deletions examples/NeuroML/IzhikevichTest.nmllite.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IzhikevichTest:
version: NeuroMLlite v0.5.5
version: NeuroMLlite v0.5.7
notes: Example Izhikevich
parameters:
N: 1
Expand Down Expand Up @@ -47,5 +47,5 @@ IzhikevichTest:
stim:
input_source: iclamp_0
population: izhPop
percentage: 100.0
percentage: 100
weight: 1
2 changes: 1 addition & 1 deletion examples/NeuroML/LEMS_SimABCD.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--
This LEMS file has been automatically generated using PyNeuroML v1.0.8 (libNeuroML v0.5.1)
This LEMS file has been automatically generated using PyNeuroML v1.0.10 (libNeuroML v0.5.3)
-->

Expand Down
2 changes: 1 addition & 1 deletion examples/NeuroML/LEMS_SimFN.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--
This LEMS file has been automatically generated using PyNeuroML v1.0.8 (libNeuroML v0.5.1)
This LEMS file has been automatically generated using PyNeuroML v1.0.10 (libNeuroML v0.5.3)
-->

Expand Down
2 changes: 1 addition & 1 deletion examples/NeuroML/LEMS_SimIzhikevichTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--
This LEMS file has been automatically generated using PyNeuroML v1.0.8 (libNeuroML v0.5.1)
This LEMS file has been automatically generated using PyNeuroML v1.0.10 (libNeuroML v0.5.3)
-->

Expand Down
202 changes: 202 additions & 0 deletions examples/NeuroML/PyNN/Generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
from neuromllite import (
Network,
Cell,
InputSource,
Population,
Synapse,
RectangularRegion,
RandomLayout,
)
from neuromllite import Projection, RandomConnectivity, Input, Simulation
import sys


def generate(
ref,
num_pop0=2,
num_pop1=2,
conn_prob=1,
conn_weight=0.3,
input_percentage=50,
input_weight=".8",
pynn_cell="IF_curr_alpha",
):

################################################################################
### Build new network

net = Network(id=ref)
net.notes = "Example: %s" % ref
net.parameters = {"input_amp": 0.99}

cell = Cell(id="testcell", pynn_cell=pynn_cell)

cell.parameters = {"i_offset": 0.0}
if "IF_" in pynn_cell:
cell.parameters["tau_refrac"] = 5
else:
cell.parameters = {"i_offset": 0.05}
net.parameters = {"input_amp": 0}
net.cells.append(cell)

input_source = InputSource(
id="i_clamp",
pynn_input="DCSource",
parameters={"amplitude": "input_amp", "start": 200.0, "stop": 800.0},
)
net.input_sources.append(input_source)

r1 = RectangularRegion(
id="region1", x=0, y=0, z=0, width=1000, height=100, depth=1000
)
net.regions.append(r1)

p0 = Population(
id="pop0",
size=num_pop0,
component=cell.id,
properties={"color": "1 0 0", "radius": 20},
random_layout=RandomLayout(region=r1.id),
)
net.populations.append(p0)

if num_pop1 > 0:
p1 = Population(
id="pop1",
size=num_pop1,
component=cell.id,
properties={"color": "0 1 0", "radius": 20},
random_layout=RandomLayout(region=r1.id),
)
net.populations.append(p1)

"""p2 = Population(
id="pop2",
size=1,
component=cell2.id,
properties={"color": "0 0 1", "radius": 20},
random_layout=RandomLayout(region=r1.id),
)
net.populations.append(p2)"""

net.synapses.append(
Synapse(
id="ampaSyn",
pynn_receptor_type="excitatory",
pynn_synapse_type="curr_alpha",
parameters={"tau_syn": 20},
)
)
"""net.synapses.append(
Synapse(
id="gabaSyn",
pynn_receptor_type="inhibitory",
pynn_synapse_type="cond_alpha",
parameters={"e_rev": -80, "tau_syn": 10},
)
)"""

if num_pop1 > 0:
net.projections.append(
Projection(
id="proj0",
presynaptic=p0.id,
postsynaptic=p1.id,
synapse="ampaSyn",
delay=2,
weight=conn_weight,
)
)
net.projections[0].random_connectivity = RandomConnectivity(
probability=conn_prob
)

"""net.projections.append(
Projection(
id="proj1",
presynaptic=p0.id,
postsynaptic=p2.id,
synapse="gabaSyn",
delay=2,
weight=0.01,
)
)
net.projections[1].random_connectivity = RandomConnectivity(probability=1)"""

net.inputs.append(
Input(
id="stim",
input_source=input_source.id,
population=p0.id,
percentage=input_percentage,
weight=input_weight,
)
)

net_json_file = net.to_json_file("%s.json" % net.id)
net_yaml_file = net.to_yaml_file("%s.yaml" % net.id)

################################################################################
### Build Simulation object & save as JSON

sim = Simulation(
id="Sim%s" % net.id,
network=net_json_file,
duration="1000",
dt="0.01",
record_traces={"all": "*"},
record_spikes={"all": "*"} if "IF_" in pynn_cell else {},
)

sim.to_json_file()
sim.network = net_yaml_file
sim.to_yaml_file("%s.yaml" % sim.id)

sim.network = net_json_file # reverting, for call below...

return sim, net


if __name__ == "__main__":

if "-one" in sys.argv:
sim, net = generate("OneCell", num_pop0=1, num_pop1=0, input_percentage=100)
elif "-hh" in sys.argv:
sim, net = generate(
"HH", num_pop0=1, num_pop1=0, input_percentage=0, pynn_cell="HH_cond_exp"
)
elif "-input_weights" in sys.argv:
sim, net = generate(
"InputWeights",
num_pop0=4,
num_pop1=0,
input_percentage=62,
input_weight=".8*random()",
)
elif "-simple_net" in sys.argv:
sim, net = generate(
"SimpleNet",
num_pop0=1,
num_pop1=1,
input_percentage=100,
input_weight="1",
)
elif "-net1" in sys.argv:
sim, net = generate(
"Net1",
num_pop0=2,
num_pop1=3,
conn_weight="random()",
input_percentage=100,
input_weight="2*random()",
)
else:
sim, net = generate("All")

################################################################################
### Run in some simulators

from neuromllite.NetworkGenerator import check_to_generate_or_run

check_to_generate_or_run(sys.argv, sim)
Binary file added examples/NeuroML/PyNN/HH.mdf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 13d1c6e

Please sign in to comment.