| 1 |
<!-- must define a prefix for default namespace (fml) as soon as there is another prefix defined |
|---|
| 2 |
otherwise XPath expressions don't treat default namespace --> |
|---|
| 3 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
|---|
| 4 |
xmlns:fml="http://neuralensemble.org/FacetsML" |
|---|
| 5 |
xmlns:class="http://neuralensemble.org/FacetsML/cellclass" |
|---|
| 6 |
xmlns:rand="http://neuralensemble.org/FacetsML/randomNumberGenerator" |
|---|
| 7 |
version="1.0"> |
|---|
| 8 |
|
|---|
| 9 |
<xsl:strip-space elements="*"/> |
|---|
| 10 |
<xsl:output method="text" indent="no" omit-xml-declaration="yes"/> |
|---|
| 11 |
<xsl:template match="/"> |
|---|
| 12 |
|
|---|
| 13 |
<xsl:text disable-output-escaping="yes"> |
|---|
| 14 |
import sys |
|---|
| 15 |
from copy import copy |
|---|
| 16 |
|
|---|
| 17 |
if hasattr(sys,"argv"): # run using python |
|---|
| 18 |
if len(sys.argv) < 2: |
|---|
| 19 |
print "Usage: python VAbenchmarks.py <simulator> \n\n<simulator> is either neuron, nest1, nest2 or pcsim" |
|---|
| 20 |
sys.exit(1) |
|---|
| 21 |
simulator = sys.argv[-2] |
|---|
| 22 |
else: |
|---|
| 23 |
simulator = "oldneuron" # run using nrngui -python |
|---|
| 24 |
exec("from pyNN.%s import *" % simulator) |
|---|
| 25 |
|
|---|
| 26 |
from pyNN.random import NumpyRNG, RandomDistribution |
|---|
| 27 |
import pyNN.utility |
|---|
| 28 |
</xsl:text> |
|---|
| 29 |
|
|---|
| 30 |
<xsl:apply-templates/> |
|---|
| 31 |
|
|---|
| 32 |
</xsl:template> |
|---|
| 33 |
|
|---|
| 34 |
<xsl:template match="fml:network"> |
|---|
| 35 |
|
|---|
| 36 |
# === Build the network ======================================================== |
|---|
| 37 |
|
|---|
| 38 |
<xsl:if test="fml:extra"> |
|---|
| 39 |
extra = {<xsl:apply-templates select="fml:extra"/>} |
|---|
| 40 |
</xsl:if> |
|---|
| 41 |
|
|---|
| 42 |
node_id = setup(<xsl:apply-templates select="@*" mode="object"/><xsl:if test="fml:extra">**extra</xsl:if>) |
|---|
| 43 |
|
|---|
| 44 |
if extra.has_key('threads'): |
|---|
| 45 |
print "%d Initialising the simulator with %d threads..." %(node_id, extra['threads']) |
|---|
| 46 |
else: |
|---|
| 47 |
print "%d Initialising the simulator with single thread..." %(node_id) |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
print "%d Defining Random Number Generator object..." % node_id |
|---|
| 51 |
<xsl:apply-templates select="fml:rng"/> |
|---|
| 52 |
|
|---|
| 53 |
print "%d Defining cell types used..." % node_id |
|---|
| 54 |
<xsl:apply-templates select="fml:cells"/> |
|---|
| 55 |
|
|---|
| 56 |
print "%d Creating cell populations..." % node_id |
|---|
| 57 |
<xsl:apply-templates select="fml:populations"/> |
|---|
| 58 |
|
|---|
| 59 |
print "%d Connecting populations..." % node_id |
|---|
| 60 |
<xsl:apply-templates select="fml:projections"/> |
|---|
| 61 |
|
|---|
| 62 |
print "%d Setting weights..." % node_id |
|---|
| 63 |
<xsl:apply-templates select="/fml:network/fml:projections/fml:projection[@weight]" mode="setWeights"/> |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
# === Setup recording ========================================================== |
|---|
| 67 |
print "%d Setting up recording..." % node_id |
|---|
| 68 |
<xsl:for-each select="//fml:population"> |
|---|
| 69 |
<xsl:variable name="name" select="@name"/> |
|---|
| 70 |
<xsl:value-of select="$name"/>.record() |
|---|
| 71 |
vrecord_list = [<xsl:value-of select="$name"/>[0],<xsl:value-of select="$name"/>[1]] |
|---|
| 72 |
<xsl:value-of select="$name"/>.record_v(vrecord_list) |
|---|
| 73 |
</xsl:for-each> |
|---|
| 74 |
|
|---|
| 75 |
buildCPUTime = Timer.elapsedTime() |
|---|
| 76 |
|
|---|
| 77 |
# === Run simulation =========================================================== |
|---|
| 78 |
print "%d Running simulation..." % node_id |
|---|
| 79 |
Timer.reset() |
|---|
| 80 |
<xsl:variable name="tstop" select="/fml:network/@sim_duration"/> |
|---|
| 81 |
run(<xsl:value-of select="$tstop"/>) |
|---|
| 82 |
|
|---|
| 83 |
simCPUTime = Timer.elapsedTime() |
|---|
| 84 |
|
|---|
| 85 |
<xsl:for-each select="//fml:population"> |
|---|
| 86 |
<xsl:variable name="name" select="@name"/> |
|---|
| 87 |
<xsl:value-of select="$name"/>_rate = <xsl:value-of select="$name"/>.meanSpikeCount()*1000./<xsl:value-of select="$tstop"/><xsl:text> |
|---|
| 88 |
</xsl:text> |
|---|
| 89 |
</xsl:for-each> |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
# === Print results to file ==================================================== |
|---|
| 93 |
|
|---|
| 94 |
print "%d Writing data to file..." % node_id |
|---|
| 95 |
Timer.reset() |
|---|
| 96 |
<xsl:for-each select="//fml:population"> |
|---|
| 97 |
<xsl:variable name="name" select="@name"/> |
|---|
| 98 |
<xsl:value-of select="$name"/>.printSpikes("<xsl:value-of select="$name"/>.ras") |
|---|
| 99 |
<xsl:value-of select="$name"/>.print_v("<xsl:value-of select="$name"/>.v") |
|---|
| 100 |
</xsl:for-each> |
|---|
| 101 |
writeCPUTime = Timer.elapsedTime() |
|---|
| 102 |
</xsl:template> |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
<!-- |
|---|
| 109 |
<extra name="threads" value="2"/> -> extra = {'threads' : 2} |
|---|
| 110 |
--> |
|---|
| 111 |
<xsl:template match="fml:extra"><xsl:call-template name="dumpDictParam"/> |
|---|
| 112 |
</xsl:template> |
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
<!-- |
|---|
| 116 |
<rng name="rng" seed="98765" generator="NumPYRNG"/> -> rng = NumPYRNG(98765+node_id) |
|---|
| 117 |
--> |
|---|
| 118 |
<xsl:template match="fml:rng"> |
|---|
| 119 |
rng = <xsl:value-of select="@generator"/>(<xsl:value-of select="@seed"/>+node_id) |
|---|
| 120 |
</xsl:template> |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
<!-- |
|---|
| 124 |
<cells> |
|---|
| 125 |
<cell name="cellA"> |
|---|
| 126 |
<class:IF_cond_exp tau_m="20." tau_syn_E="5." tau_syn_I="10." |
|---|
| 127 |
v_rest="-60." v_reset="-60." v_thresh="-50." |
|---|
| 128 |
cm="1." tau_refrac="5." e_rev_E="0." |
|---|
| 129 |
e_rev_I="-80."/> |
|---|
| 130 |
</cell> |
|---|
| 131 |
</cells> |
|---|
| 132 |
|
|---|
| 133 |
-> |
|---|
| 134 |
|
|---|
| 135 |
cellclass['cellA'] = IF_cond_exp |
|---|
| 136 |
cellparams['cellA'] = { 'tau_m': 20., 'tau_syn_E': 5., 'tau_syn_I': 10., 'v_rest': -60., 'v_reset': -60., 'v_thresh': -50., 'cm': 1., 'tau_refrac': 5., 'e_rev_E': 0., 'e_rev_I': -80., } |
|---|
| 137 |
--> |
|---|
| 138 |
<xsl:template match="fml:cells"> |
|---|
| 139 |
cellclass = {} |
|---|
| 140 |
cellparams = {} |
|---|
| 141 |
<xsl:apply-templates/> |
|---|
| 142 |
</xsl:template> |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
<!-- |
|---|
| 146 |
<populations> |
|---|
| 147 |
<population name="exc_cells" label="Excitatory_Cells"> |
|---|
| 148 |
<dim size="4000"/> |
|---|
| 149 |
<cell_type name="cellA"/> |
|---|
| 150 |
<randomInit rng="rng"> |
|---|
| 151 |
<rand:uniform min="-60." max="-50."/> |
|---|
| 152 |
</randomInit> |
|---|
| 153 |
</population> |
|---|
| 154 |
</populations> |
|---|
| 155 |
|
|---|
| 156 |
-> |
|---|
| 157 |
|
|---|
| 158 |
exc_cells = Population((4000,), cellclass = cellclass['cellA'], cellparams = cellparams['cellA'], label="Excitatory_Cells", ) |
|---|
| 159 |
exc_cells.randomInit(RandomDistribution('uniform',[-60., -50., ], rng=rng)) |
|---|
| 160 |
--> |
|---|
| 161 |
<xsl:template match="fml:populations"> |
|---|
| 162 |
<xsl:apply-templates/> |
|---|
| 163 |
</xsl:template> |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
<!-- |
|---|
| 167 |
<projections> |
|---|
| 168 |
<projection name="e2e" |
|---|
| 169 |
presynaptic_population_name="exc_cells" |
|---|
| 170 |
postsynaptic_population_name="exc_cells" |
|---|
| 171 |
method="fixedProbability" |
|---|
| 172 |
weight="0.004" |
|---|
| 173 |
target="excitatory" |
|---|
| 174 |
rng="rng"> |
|---|
| 175 |
<methodParameter name="p_connect" value="0.02"/> |
|---|
| 176 |
</projection> |
|---|
| 177 |
</projections> |
|---|
| 178 |
|
|---|
| 179 |
-> |
|---|
| 180 |
|
|---|
| 181 |
e2e = Projection(exc_cells, exc_cells, method="fixedProbability", methodParameters=0.02, target="excitatory", rng=rng, ) |
|---|
| 182 |
--> |
|---|
| 183 |
<xsl:template match="fml:projections"> |
|---|
| 184 |
<xsl:apply-templates/> |
|---|
| 185 |
</xsl:template> |
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
<!-- |
|---|
| 189 |
weight="0.004" -> e2e.setWeights(0.004) |
|---|
| 190 |
--> |
|---|
| 191 |
<xsl:template match="fml:projection" mode="setWeights"> |
|---|
| 192 |
<xsl:value-of select="@name"/>.setWeights(<xsl:value-of select="@weight"/>) |
|---|
| 193 |
</xsl:template> |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
<!-- |
|---|
| 199 |
cell type definition |
|---|
| 200 |
--> |
|---|
| 201 |
<xsl:template match="fml:cell"> |
|---|
| 202 |
cellclass['<xsl:value-of select="@name"/>'] = <xsl:apply-templates select="class:*"> |
|---|
| 203 |
<xsl:with-param name="celltypeid" select="@name"/> |
|---|
| 204 |
</xsl:apply-templates> |
|---|
| 205 |
</xsl:template> |
|---|
| 206 |
|
|---|
| 207 |
<xsl:template match="class:*"><xsl:param name="celltypeid"/><xsl:value-of select="local-name(current())"/> |
|---|
| 208 |
<xsl:if test="attribute::node()"> |
|---|
| 209 |
cellparams['<xsl:value-of select="$celltypeid"/>'] = { <xsl:call-template name="dumpCellparams"/>} |
|---|
| 210 |
</xsl:if> |
|---|
| 211 |
</xsl:template> |
|---|
| 212 |
|
|---|
| 213 |
<xsl:template match="class:NonStandardCellType"><xsl:param name="celltypeid"/>"<xsl:value-of select="@name"/>" |
|---|
| 214 |
cellparams['<xsl:value-of select="$celltypeid"/>'] = { <xsl:apply-templates select="class:cellparams"/> } |
|---|
| 215 |
</xsl:template> |
|---|
| 216 |
|
|---|
| 217 |
<xsl:template match="class:cellparams"><xsl:call-template name="dumpDictParam"/> |
|---|
| 218 |
</xsl:template> |
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
<!-- |
|---|
| 222 |
population definition |
|---|
| 223 |
--> |
|---|
| 224 |
<xsl:template match="fml:population"> |
|---|
| 225 |
<xsl:value-of select="@name"/> = Population((<xsl:apply-templates select="fml:dim"/>), <xsl:apply-templates select="fml:cell_type"/><xsl:apply-templates select="@label"/>) |
|---|
| 226 |
<xsl:apply-templates select="fml:randomInit"> |
|---|
| 227 |
<xsl:with-param name="populationid" select="@name"/> |
|---|
| 228 |
</xsl:apply-templates> |
|---|
| 229 |
</xsl:template> |
|---|
| 230 |
|
|---|
| 231 |
<xsl:template match="fml:dim"><xsl:value-of select="@size"/>,</xsl:template> |
|---|
| 232 |
|
|---|
| 233 |
<xsl:template match="fml:cell_type">cellclass = cellclass['<xsl:value-of select="@name"/>'], cellparams = cellparams['<xsl:value-of select="@name"/>'], </xsl:template> |
|---|
| 234 |
|
|---|
| 235 |
<xsl:template match="fml:randomInit"> |
|---|
| 236 |
<xsl:param name="populationid"/> |
|---|
| 237 |
|
|---|
| 238 |
<xsl:value-of select="$populationid"/>.randomInit(<xsl:apply-templates select="rand:*"> |
|---|
| 239 |
<xsl:with-param name="rng" select="@rng"/> |
|---|
| 240 |
</xsl:apply-templates>) |
|---|
| 241 |
|
|---|
| 242 |
</xsl:template> |
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
<xsl:template match="rand:*"> |
|---|
| 246 |
<xsl:param name="rng"/>RandomDistribution('<xsl:value-of select="local-name(current())"/>',[<xsl:apply-templates select="@*" mode="value"/>], rng=rng)</xsl:template> |
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
<!-- |
|---|
| 250 |
projection definition |
|---|
| 251 |
--> |
|---|
| 252 |
<xsl:template match="fml:projection"><xsl:value-of select="@name"/> = Projection(<xsl:value-of select="@presynaptic_population_name"/>, <xsl:value-of select="@postsynaptic_population_name"/>, <xsl:apply-templates select="@method"/><xsl:apply-templates select="fml:methodParameter"/><xsl:apply-templates select="@source|@target|@label"/><xsl:apply-templates select="@rng" mode="object"/>) |
|---|
| 253 |
</xsl:template> |
|---|
| 254 |
|
|---|
| 255 |
<xsl:template match="fml:methodParameter">methodParameters=<xsl:choose> |
|---|
| 256 |
<xsl:when test="count(current())=1"><xsl:value-of select="@value"/> |
|---|
| 257 |
</xsl:when> |
|---|
| 258 |
<xsl:otherwise> |
|---|
| 259 |
{<xsl:call-template name="dumpDictParam"/>} |
|---|
| 260 |
</xsl:otherwise> |
|---|
| 261 |
</xsl:choose>, </xsl:template> |
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
<!-- |
|---|
| 265 |
functions to dump attributes as label="aLabel" or label=aLabel or just aLabel |
|---|
| 266 |
--> |
|---|
| 267 |
<xsl:template match="@*"><xsl:value-of select="local-name()"/>="<xsl:value-of select="current()"/>", </xsl:template> |
|---|
| 268 |
|
|---|
| 269 |
<xsl:template match="@*" mode="object"><xsl:value-of select="local-name()"/>=<xsl:value-of select="current()"/>, </xsl:template> |
|---|
| 270 |
|
|---|
| 271 |
<xsl:template match="@*" mode="value"><xsl:value-of select="current()"/>, </xsl:template> |
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
<!-- |
|---|
| 275 |
dump generic parameters as : <methodParameter name="p_connect" value="0.005"/> |
|---|
| 276 |
--> |
|---|
| 277 |
<xsl:template name="dumpDictParam">'<xsl:value-of select="@name"/>': <xsl:value-of select="@value"/>, </xsl:template> |
|---|
| 278 |
|
|---|
| 279 |
<!-- |
|---|
| 280 |
generically dump attributes as a dict : |
|---|
| 281 |
<class:IF_cond_exp tau_m="20." tau_syn_E="5." tau_syn_I="10." |
|---|
| 282 |
v_rest="-60." v_reset="-60." v_thresh="-50." |
|---|
| 283 |
cm="1." tau_refrac="5." e_rev_E="0." |
|---|
| 284 |
e_rev_I="-80."/> |
|---|
| 285 |
|
|---|
| 286 |
-> |
|---|
| 287 |
|
|---|
| 288 |
'tau_m': 20., 'tau_syn_E': 5., 'tau_syn_I': 10., 'v_rest': -60., 'v_reset': -60., 'v_thresh': -50., 'cm': 1., 'tau_refrac': 5., 'e_rev_E': 0., 'e_rev_I': -80., |
|---|
| 289 |
--> |
|---|
| 290 |
<xsl:template name="dumpCellparams"><xsl:for-each select="attribute::*">'<xsl:value-of select="local-name()"/>': <xsl:value-of select="current()"/>, </xsl:for-each> |
|---|
| 291 |
</xsl:template> |
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
</xsl:stylesheet> |
|---|