Skip to content

Commit c6f37e6

Browse files
committed
Initial simple nml api example...
1 parent b7f7444 commit c6f37e6

10 files changed

+346
-1
lines changed

examples/neuroml2/NeuroML2.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
## NeuroML
2+
Some description...
3+
4+
### Allowed parameters
5+
<table>
6+
<tr>
7+
<td><b>id</b></td>
8+
<td>str</td>
9+
<td><i>The id of the NeuroML 2 document</i></td>
10+
</tr>
11+
12+
13+
</table>
14+
15+
### Allowed children
16+
<table>
17+
<tr>
18+
<td><b>networks</b></td>
19+
<td><a href="#network">Network</a></td>
20+
<td><i>The networks present</i></td>
21+
</tr>
22+
23+
24+
</table>
25+
26+
## Network
27+
Some description...
28+
29+
### Allowed parameters
30+
<table>
31+
<tr>
32+
<td><b>id</b></td>
33+
<td>str</td>
34+
<td><i>The id of the network</i></td>
35+
</tr>
36+
37+
38+
</table>
39+
40+
### Allowed children
41+
<table>
42+
<tr>
43+
<td><b>populations</b></td>
44+
<td><a href="#population">Population</a></td>
45+
<td><i>the pops in the net</i></td>
46+
</tr>
47+
48+
49+
</table>
50+
51+
## Population
52+
Some description...
53+
54+
### Allowed parameters
55+
<table>
56+
<tr>
57+
<td><b>id</b></td>
58+
<td>str</td>
59+
<td><i>The id of the population</i></td>
60+
</tr>
61+
62+
63+
<tr>
64+
<td><b>component</b></td>
65+
<td>str</td>
66+
<td><i>the component to use in the population</i></td>
67+
</tr>
68+
69+
70+
<tr>
71+
<td><b>size</b></td>
72+
<td>int</td>
73+
<td><i>the size of the population</i></td>
74+
</tr>
75+
76+
77+
</table>

examples/neuroml2/NeuroML2.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
=======
2+
NeuroML
3+
=======
4+
Some description...
5+
6+
**Allowed parameters**
7+
8+
=============== =========== ================================
9+
Allowed field Data Type Description
10+
=============== =========== ================================
11+
**id** str The id of the NeuroML 2 document
12+
=============== =========== ================================
13+
14+
**Allowed children**
15+
16+
=============== ====================== ====================
17+
Allowed child Data Type Description
18+
=============== ====================== ====================
19+
**networks** `Network <#network>`__ The networks present
20+
=============== ====================== ====================
21+
22+
=======
23+
Network
24+
=======
25+
Some description...
26+
27+
**Allowed parameters**
28+
29+
=============== =========== =====================
30+
Allowed field Data Type Description
31+
=============== =========== =====================
32+
**id** str The id of the network
33+
=============== =========== =====================
34+
35+
**Allowed children**
36+
37+
=============== ============================ ===================
38+
Allowed child Data Type Description
39+
=============== ============================ ===================
40+
**populations** `Population <#population>`__ the pops in the net
41+
=============== ============================ ===================
42+
43+
==========
44+
Population
45+
==========
46+
Some description...
47+
48+
**Allowed parameters**
49+
50+
=============== =========== ======================================
51+
Allowed field Data Type Description
52+
=============== =========== ======================================
53+
**id** str The id of the population
54+
**component** str the component to use in the population
55+
**size** int the size of the population
56+
=============== =========== ======================================
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"NeuroML": {
3+
"definition": "Some description... ",
4+
"allowed_parameters": {
5+
"id": {
6+
"type": "str",
7+
"description": "The id of the NeuroML 2 document"
8+
}
9+
},
10+
"allowed_children": {
11+
"networks": {
12+
"type": "Network",
13+
"description": "The networks present"
14+
}
15+
}
16+
},
17+
"Network": {
18+
"definition": "Some description... ",
19+
"allowed_parameters": {
20+
"id": {
21+
"type": "str",
22+
"description": "The id of the network"
23+
}
24+
},
25+
"allowed_children": {
26+
"populations": {
27+
"type": "Population",
28+
"description": "the pops in the net"
29+
}
30+
}
31+
},
32+
"Population": {
33+
"definition": "Some description... ",
34+
"allowed_parameters": {
35+
"id": {
36+
"type": "str",
37+
"description": "The id of the population"
38+
},
39+
"component": {
40+
"type": "str",
41+
"description": "the component to use in the population"
42+
},
43+
"size": {
44+
"type": "int",
45+
"description": "the size of the population"
46+
}
47+
}
48+
}
49+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
NeuroML:
2+
definition: 'Some description... '
3+
allowed_parameters:
4+
id:
5+
type: str
6+
description: The id of the NeuroML 2 document
7+
allowed_children:
8+
networks:
9+
type: Network
10+
description: The networks present
11+
Network:
12+
definition: 'Some description... '
13+
allowed_parameters:
14+
id:
15+
type: str
16+
description: The id of the network
17+
allowed_children:
18+
populations:
19+
type: Population
20+
description: the pops in the net
21+
Population:
22+
definition: 'Some description... '
23+
allowed_parameters:
24+
id:
25+
type: str
26+
description: The id of the population
27+
component:
28+
type: str
29+
description: the component to use in the population
30+
size:
31+
type: int
32+
description: the size of the population

examples/neuroml2/TestNeuroML.bson

114 Bytes
Binary file not shown.

examples/neuroml2/TestNeuroML.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"TestNeuroML": {
3+
"networks": {
4+
"net0": {
5+
"populations": {
6+
"pop0": {
7+
"component": "izh2007RS0",
8+
"size": 1
9+
}
10+
}
11+
}
12+
}
13+
}
14+
}

examples/neuroml2/TestNeuroML.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
TestNeuroML:
2+
networks:
3+
net0:
4+
populations:
5+
pop0:
6+
component: izh2007RS0
7+
size: 1

examples/neuroml2/hello_world_neuroml.net.nml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
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="IzhNeuron">
1+
<neuroml
2+
xmlns="http://www.neuroml.org/schema/neuroml2"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2 https://raw.github.com/NeuroML/NeuroML2/development/Schemas/NeuroML2/NeuroML_v2.3.xsd"
6+
id="IzhNeuron">
27
<izhikevich2007Cell id="izh2007RS0" C="100pF" v0="-60mV" k="0.7nS_per_mV" vr="-60mV" vt="-40mV" vpeak="35mV" a="0.03per_ms" b="-2nS" c="-50.0mV" d="100pA"/>
38
<pulseGenerator id="pulseGen_0" delay="100ms" duration="800ms" amplitude="0.07 nA"/>
49
<network id="IzNet">

examples/neuroml2/neuroml2_spec.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import modelspec
2+
from modelspec import field, instance_of, optional
3+
from modelspec.base_types import Base
4+
from typing import List
5+
6+
# Example showing ...
7+
8+
9+
@modelspec.define
10+
class Population(Base):
11+
"""
12+
Some description...
13+
14+
Args:
15+
id: The id of the population
16+
component: the component to use in the population
17+
size: the size of the population
18+
"""
19+
20+
id: str = field(validator=instance_of(str))
21+
component: str = field(default=None, validator=optional(instance_of(str)))
22+
size: int = field(default=None, validator=optional(instance_of(int)))
23+
24+
@modelspec.define
25+
class Network(Base):
26+
"""
27+
Some description...
28+
29+
Args:
30+
id: The id of the network
31+
populations: the pops in the net
32+
"""
33+
34+
id: str = field(validator=instance_of(str))
35+
36+
populations: List[Population] = field(factory=list)
37+
38+
39+
@modelspec.define
40+
class NeuroML(Base):
41+
"""
42+
Some description...
43+
44+
Args:
45+
id: The id of the NeuroML 2 document
46+
networks: The networks present
47+
"""
48+
49+
id: str = field(validator=instance_of(str))
50+
51+
networks: List[Network] = field(factory=list)
52+
53+
54+
if __name__ == '__main__':
55+
56+
nml_doc = NeuroML(id="TestNeuroML")
57+
net = Network(id="net0")
58+
nml_doc.networks.append(net)
59+
60+
net.populations.append(Population("pop0", component="izh2007RS0", size=1))
61+
62+
print(nml_doc)
63+
print(nml_doc.id)
64+
65+
nml_doc.to_json_file("%s.json"%nml_doc.id)
66+
nml_doc.to_yaml_file("%s.yaml"%nml_doc.id)
67+
nml_doc.to_bson_file("%s.bson"%nml_doc.id)
68+
#nml_doc.to_xml_file("%s.xml"%nml_doc.id)
69+
70+
print(" >> Full document details in YAML format:\n")
71+
72+
print(nml_doc.to_yaml())
73+
74+
75+
doc_md = nml_doc.generate_documentation(format="markdown")
76+
77+
with open("NeuroML2.md", "w") as d:
78+
d.write(doc_md)
79+
80+
81+
doc_rst = nml_doc.generate_documentation(format="rst")
82+
83+
with open("NeuroML2.rst", "w") as d:
84+
d.write(doc_rst)
85+
86+
87+
print("\n >> Generating specification in dict form...")
88+
doc_dict = nml_doc.generate_documentation(format="dict")
89+
90+
import json
91+
import yaml
92+
93+
with open("NeuroML2.specification.json", "w") as d:
94+
d.write(json.dumps(doc_dict, indent=4))
95+
96+
print(" >> Generating specification in YAML...\n")
97+
98+
with open("NeuroML2.specification.yaml", "w") as d:
99+
yy = yaml.dump(doc_dict, indent=4, sort_keys=False)
100+
print(yy)
101+
d.write(yy)
102+

test_all.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ python document.py
99
cd test
1010
python test.py
1111

12+
cd ../neuroml2
13+
python neuroml2_spec.py
14+
1215
cd ../..
1316

1417
pytest tests -v

0 commit comments

Comments
 (0)