Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# RateML model generation\n",
"\n",
"### Using RateML to generate the Python or CUDA models"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Building rate based models in RateML, starts by creating an XML model file. To understand which constructs can be used to build the model, one should take a closer look at the README file. The cell below will prints the latest README file from the repository. Every construct which can be used, is explained."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# set root\n",
"ROOT = \"/opt/app-root/src/drive/My Libraries/main/tvb-root/tvb_library/tvb/rateML/\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import Markdown, display, Code\n",
"\n",
"mdfile = open(ROOT + \"README.md\",\"r\")\n",
"model = mdfile.read()\n",
"display(Markdown(model))\n",
"mdfile.close()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Generate a model\n",
"After reading the README, one should be able to build an XML model file. Lets use the relatively small Kuramoto model as an example. \n",
"Your model should look like similar to the Kuramoto python file and define some constants, an exposure and dynamics behavior. The dynamics for the Kuramoto consist of a state variable, a derived variable and a time derivative. Except for the derived variable, there are the construct that a RateML XML model file should contain. The template: tvb-root/scientific_library/tvb/rateML/XMLmodels/model_template.xml is an empty template which can be used to create a model XML file."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Open the model template\n",
"from IPython.display import Markdown, display, Code\n",
"\n",
"model_location = ROOT + \"XMLmodels/model_template.xml\"\n",
"xmlfile = open(model_location,\"r\")\n",
"model = xmlfile.read()\n",
"display(Markdown(model))\n",
"xmlfile.close()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Generating the model code\n",
"\n",
"We will use an existing xml model file to generate a model called \"inifite_theta\". This model relates the biophysically relevant macroscopic quantities, namely the firing rate and the membrane potential, which govern the evolution of the neuronal network. These equations describe exaclty all possible macroscopical dynamical states of the network. (Montbrió, E., Pazó, D., and Roxin, A. (2015). Macroscopic Description for Networks of Spiking Neurons. Phys. Rev. X 5, 1–15. doi:10.1103/PhysRevX. 5.021028). \n",
"\n",
"#### Please open: \"tvb-root/tvb_library/tvb/rateML/XMLmodels/montbrio.xml\"\n",
"\n",
"If you are satified with the pre set time derivates properties, save the file. \n",
"\n",
"We will call the templating function in order to automatically generate the model code.\n",
"In XML2model.py the class \n",
"```python\n",
"RateML('model_filename', language=('python' | 'cuda'), 'path/to/your/XMLmodels', 'path/to/your/generatedModels')\n",
"``` \n",
"will start the code generation.\n",
"\n",
"If you get an error this might be that either the first 3 steps from the '0_Install_TVB.ipynb' need to be done or that you havent restarted this kernel. Kernel > Restart Kernel ..."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2022-09-28 13:05:49,187 - INFO - tvb.rateML.XML2model - True validation of /opt/app-root/src/drive/My Libraries/main/tvb-root/tvb_library/tvb/rateML/XMLmodels/montbrio.xml against /opt/app-root/src/.local/lib/python3.8/site-packages/tvb/rateML/rML_v0.xsd\n",
"2022-09-28 13:05:49,199 - INFO - tvb.rateML.XML2model - model file generated montbrio\n"
]
},
{
"data": {
"text/plain": [
"<tvb.rateML.XML2model.RateML at 0x7f221c3639a0>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from tvb.rateML.XML2model import RateML\n",
"\n",
"# put here the name of the xml file\n",
"# model_filename = 'oscillator'\n",
"model_filename = 'montbrio'\n",
"\n",
"language = \"python\"\n",
"# language = \"cuda\"\n",
"XMLin = ROOT + \"XMLmodels\"\n",
"GenModOut = ROOT + \"generatedModels\"\n",
"RateML(model_filename, language, XMLin, GenModOut)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}