Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #28 from the-virtual-brain/NeuroML
Browse files Browse the repository at this point in the history
DSL2.0 for CUDA and python models
  • Loading branch information
sdiazpier authored Mar 4, 2020
2 parents 7ec6511 + dcb2e59 commit 38bcf78
Show file tree
Hide file tree
Showing 47 changed files with 10,754 additions and 33 deletions.
File renamed without changes.
183 changes: 183 additions & 0 deletions NeuroML/NeuroML/epileptor_2d_CUDA.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<Lems
xmlns="http://www.neuroml.org/lems/0.7.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.neuroml.org/lems/0.7.4 ../../LEMS/Schemas/LEMS/LEMS_v0.7.4.xsd"
description="A number of ComponentTypes for rate based/population models.
Base type of any cell/population which has a (dimensionless) rate _R.
Epileptor 2-D (phase plane) oscillator.">

<ComponentType name="Epileptor_2D"
description="Rate based 2D oscillator for TVB"
value="">

<Constant name="a" symbol="float32" dimension="" value="1.0" description="Coefficient of the cubic term in the first state-variable."/>
<Constant name="b" symbol="float32" dimension="" value="3.0" description="Coefficient of the squared term in the first state-variable."/>
<Constant name="c" symbol="float32" dimension="" value="1.0" description="Additive coefficient for the second state-variable x_{2}, called :math:`y_{0}` in Jirsa paper."/>
<Constant name="d" symbol="float32" dimension="" value="5.0" description="Coefficient of the squared term in the second state-variable x_{2}."/>
<Constant name="r" symbol="float32" dimension="lo=0.0, hi=0.001, step=0.00005" value="0.00035" description="Temporal scaling in the slow state-variable, called :math:`1\\tau_{0}` in Jirsa paper (see class Epileptor)."/>
<Constant name="s" symbol="float32" dimension="" value="4.0" description="Linear coefficient in the third state variable"/>
<Constant name="x0" symbol="float32" dimension="lo=-3.0, hi=-1.0, step=0.1" value="-1.6" description="Epileptogenicity parameter."/>
<Constant name="Iext" symbol="float32" dimension="lo=1.5, hi=5.0, step=0.1" value="3.1" description="External input current to the first state-variable."/>
<Constant name="slope" symbol="float32" dimension="lo=-16.0, hi=6.0, step=0.1" value="0." description="Linear coefficient in the first state-variable."/>
<Constant name="Iext2" symbol="float32" dimension="lo=0.0, hi=1.0, step=0.05" value="3.1" description="External input current to the first state-variable."/>
<Constant name="tau" symbol="float32" dimension="" value="10.0" description="Temporal scaling coefficient in fifth state variable."/>
<Constant name="aa" symbol="float32" dimension="" value="6.0" description="Linear coefficient in fifth state variable."/>
<Constant name="bb" symbol="float32" dimension="" value="2.0" description="Linear coefficient of lowpass excitatory coupling in fourth state variable."/>
<Constant name="Kvf" symbol="float32" dimension="lo=0.0, hi=4.0, step=0.5" value="0.0" description="Coupling scaling on a very fast time scale."/>
<Constant name="Kf" symbol="float32" dimension="lo=0.0, hi=4.0, step=0.5" value="0.0" description="Correspond to the coupling scaling on a fast time scale."/>
<Constant name="Ks" symbol="float32" dimension="lo=-4.0, hi=4.0, step=0.1" value="0.0" description="Permittivity coupling, that is from the fast time scale toward the slow time scale."/>
<Constant name="tt" symbol="float32" dimension="lo=0.001, hi=1.0, step=0.001" value="1.0" description="Time scaling of the whole system to the system in real time."/>
<Constant name="modification" symbol="bool" dimension="" value="1.0" description="When modification is True, then use nonlinear influence on z. The default value is False, i.e., linear influence."/>

<!-- Parameters will be assumed to be swept. sweep data will be matched by order of entry -->
<Parameter name="global_coupling" dimension="float" />
<Parameter name="global_speed" dimension="float" />
<Parameter name="x0" dimension="float" />

<Dynamics>
<StateVariable name="x1" dimension="-2., 1." exposure=""/>
<StateVariable name="y1" dimension="-20., 2."/>
<StateVariable name="z" dimension="-2.0, 5.0" exposure=""/>
<StateVariable name="x2" dimension="-2., 0."/>
<StateVariable name="y2" dimension="0., 2." exposure=""/>
<StateVariable name="g" dimension="-1, 1."/>

<!-- <DerivedVariable name="coupling_value" exposure="c_0" value="0.0" reduce="add"/>-->
<!-- Per state variable specifiable noise factor -->
<DerivedVariable name="sig_x1" exposure="float" value="sqrt(dt) * sqrt(2.0 * 1e-3)" reduce="add"/>
<DerivedVariable name="sig_y1" exposure="float" value="sqrt(dt) * sqrt(2.0 * 1e-3)" reduce="add"/>
<DerivedVariable name="sig_z" exposure="float" value="sqrt(dt) * sqrt(2.0 * 1e-3)" reduce="add"/>
<DerivedVariable name="sig_x2" exposure="float" value="sqrt(dt) * sqrt(2.0 * 1e-3)" reduce="add"/>
<DerivedVariable name="sig_y2" exposure="float" value="sqrt(dt) * sqrt(2.0 * 1e-3)" reduce="add"/>
<DerivedVariable name="sig_g" exposure="float" value="0" reduce="add"/>

<DerivedVariable name="rec_speed_dt" exposure="float" value="1.0f / global_speed / (dt)" reduce="add"/>
<!-- <DerivedVariable name="G" exposure="float" value="params" reduce="add"/>-->
<DerivedVariable name="lc_0" exposure="float" value="0.0"/>

<!-- For conditionals use &lt(=); or &gt;(=) for less- or greater then (equal to) -->
<!-- Population 1 -->
<ConditionalDerivedVariable name="if_ydot0" exposure="" dimension="(x1 &lt; 0) * (- a * powf(x1, 2) * b * x1)"/>
<ConditionalDerivedVariable name="else_ydot0" exposure="" dimension="(x1 &gt;= 0) * (slope - x2 + 0.6 * powf((z - 4.0), 2))"/>
<TimeDerivative variable="dx1" exposure="" value="tt * (y1 - z + Iext + Kvf * c_pop1 + (if_ydot0 + else_ydot0) )"/>
<TimeDerivative variable="dy1" exposure="" value="tt * (c - d * powf(x1, 2) - y1)"/>

<!-- Energy -->
<ConditionalDerivedVariable name="if_ydot1" exposure="" dimension="(y1 &lt; 0) * (- 0.1 * powf(Z, 7))"/>
<ConditionalDerivedVariable name="else_ydot1" exposure="" dimension="0"/>
<ConditionalDerivedVariable name="ifmod_h" exposure="" dimension="(modification==true)*(x0 + 3. / (1. + exp(-(x1 + 0.5) / 0.1)) "/>
<ConditionalDerivedVariable name="elsemod_h" exposure="" dimension="(modification==false)*(4 * (x1 - x0) + if_ydot1) )"/>
<TimeDerivative variable="dz" exposure="" value="tt * (r * ((ifmod_h + elsemod_h)) - z + Ks * c_pop1))"/>

<!-- Population 2 -->
<TimeDerivative variable="dx2" exposure="" value="tt * (-y2 + x2 - powf(x2, 3) + Iext2 + bb * g - 0.3 * (z - 3.5) + Kf * c_pop2)"/>
<ConditionalDerivedVariable name="if_ydot3" exposure="" dimension="0"/>
<ConditionalDerivedVariable name="else_ydot3" exposure="" dimension="(x2 &gt;= -0.25) * (aa * (x2 + 0.25))"/>
<TimeDerivative variable="dy2" exposure="" value="tt * (-y2 + else_ydot3) / tau"/>

<!-- Filter -->
<TimeDerivative variable="dg" exposure="" value="tt * (-0.01 * (g - 0.1 * x1) )"/>


</Dynamics>

<!-- Exposures are used for observables, for the name enter variable to be observed (usually states)
and for dimension enter the reduction functionality-->
<Exposure name="o_x1" dimension="x1"/>
<Exposure name="o_x2" dimension="x2"/>
<Exposure name="o_z" dimension="z"/>
<Exposure name="o_-x1+x2" dimension="-x1 + x2"/>

</ComponentType>

<ComponentType name="coupling_function_pop1">

<!-- Added function for pre and post synaptic activity. Fixed the power being **, however no parse checks for it-->

<Constant name="coupl_a" symbol="float32" dimension="lo=0.0, hi=10., step=0.1" value="1" description="Rescales the connection strength."/>

<!-- variable for pre synaptic function, only 1 param is allowed (and should be sufficient)) -->
<Parameter name="x1_j" dimension=''/>

<!-- variables for post synaptic function-->
<Requirement name="wij" dimension=''/>

<Function name="pre" value="sin(x1_j - x1)" description="pre synaptic function for coupling activity"/>
<Function name="post" value="a" description="post synaptic = a * pre"/>

<!-- Handle local coupling result, full expression is c_0 *= 'value'. Name option is hardcoded -->
<DerivedParameter name="c_pop1" value="global_coupling"/>

</ComponentType>

<ComponentType name="coupling_function_pop2">

<!-- Added function for pre and post synaptic activity. Fixed the power being **, however no parse checks for it-->

<Constant name="coupl_b" symbol="float32" dimension="lo=0.0, hi=10., step=0.1" value="0.1" description="Rescales the connection strength."/>

<!-- variables for pre synaptic function-->
<Parameter name="y1_j" dimension=''/>

<!-- variables for post synaptic function-->
<Requirement name="wij" dimension=''/>

<Function name="pre" value="" description = "pre synaptic function for coupling activity"/>
<Function name="post" value="" description = "post synaptic function for coupling activity"/>

<!-- Handle local coupling result, full expression is c_0 *= 'value'. Name option is hardcoded -->
<DerivedParameter name="c_pop2" value="g"/>

</ComponentType>

<ComponentType name="noise">

<!-- Param a-->
<!-- Related to exposures?-->

<!-- StateVariables for certain noises-->
<!-- parant noise of specific children-->
<!-- ScalingFunction GFUN; noisescaling-->

<!-- dimension field for Constant is being (mis)used for fields required for Float (True or False), domain for float32 (lo, hi, step) or field_type for Attr ('str') ) -->
<!-- is label more than a short description? -->

<Constant name="ntau" symbol="Float" dimension="True" value="0.1" description="The noise correlation time"/>
<Constant name="noise_seed" symbol="Int" dimension="" value="42" description="A random seed used to initialise the random_stream if it is missing."/>
<Constant name="random_stream" symbol="Attr" dimension="numpy.random.RandomState" value="0.0" description="An instance of numpy's RandomState associated with this
specific Noise object. Used when you need to resume a simulation from a state saved to disk"/>
<!-- <Requirement name="temperature" dimension="temperature"/>-->

</ComponentType>

<ComponentType name="additive" extends="noise">

<!-- specific child of noise-->
<Constant name="nsig" symbol="float32" dimension="lo=0.0, hi=10.0, step=0.1" value="1.0"
description="The noise dispersion, it is the standard deviation of the
distribution from which the Gaussian random variates are drawn. NOTE:
Sensible values are typically ~gt 1% of the dynamic range of a Model's
state variables."/>

</ComponentType>

<ComponentType name="multiplicative" extends="noise">

<!-- specific https://gitlab.version.fz-juelich.de/diaz1/tvb_dslchild of noise-->
<Constant name="nsig" symbol="float32" dimension="lo=0.0, hi=10.0, step=0.1" value="1.0"
description="The noise dispersion, it is the standard deviation of the
distribution from which the Gaussian random variates are drawn. NOTE:
Sensible values are typically ~gt 1% of the dynamic range of a Model's
state variables."/>

<Constant name="b" symbol="Attr" dimension="equations.TemporalApplicableEquation" value="0.0"
description="A function evaluated on the state-variables, the result of which enters as the diffusion coefficient."/>

</ComponentType>



</Lems>


<!--Look at vector representation in XML LEMS-->
101 changes: 101 additions & 0 deletions NeuroML/NeuroML/example10_Q10.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<Lems>

<Target component="simset"/>

<!--<Include file="ex2dims.xml"/>-->
<!--<Include file="hhchannel.xml"/> -->
<!--<Include file="hhcell.xml"/>-->
<!--<Include file="hhmodels.xml"/>-->
<!--<Include file="MultiRunSimulation.xml"/>-->


<ComponentType name="TemperatureDependency">
<Exposure name="rateFactor" dimension="none"/>
<Requirement name="temperature" dimension="temperature"/>
</ComponentType>



<ComponentType name="Q10TemperatureDependency" extends="TemperatureDependency" description="Provides a q10 value">
<Parameter name="Q10" dimension="none"/>
<Requirement name="velocity" dimension="speed"/>
<!-- <Parameter name="baseTemperature" dimension="temperature"/>-->
<!-- <Constant name="tenC" symbol="" dimension="temperature" value="10"/>-->
<!-- <Dynamics>-->
<!-- <DerivedVariable name="rateFactor" exposure="rateFactor" dimension="none"-->
<!-- value="Q10^((temperature - baseTemperature) / tenC)"/>-->
<!-- </Dynamics>-->
</ComponentType>



<!-- <ComponentType name="HHGateQ10" extends="HHGate">-->
<!-- <Child name="temperatureDependency" type="TemperatureDependency"/>-->
<!-- -->
<!-- <Dynamics simultaneous="false">-->
<!-- <StateVariable name="x" dimension="none"/>-->

<!-- <DerivedVariable name="rateFactor" dimension="none" select="temperatureDependency/rateFactor" -->
<!-- reduce="multiply" required="false"/>-->

<!-- <DerivedVariable name="rf" dimension="per_time" select="Forward/r"/>-->
<!-- <DerivedVariable name="rr" dimension="per_time" select="Reverse/r"/> -->
<!-- -->
<!-- <TimeDerivative variable="x" value="(1 + ex)^2 / ex * (rateFactor * rf * (1 - q) - rateFactor * rr * q)"/>-->
<!-- -->
<!-- <DerivedVariable name="ex" dimension="none" value="exp(x)"/>-->
<!-- <DerivedVariable name="q" dimension="none" value="ex / (1 + ex)"/>-->
<!-- <DerivedVariable name="fcond" exposure="fcond" value="q^power"/>-->
<!-- </Dynamics> -->
<!--</ComponentType>-->





<!--<HHChannel id="naq10" conductance="10pS">-->

<!-- <HHGateQ10 id="m" power="3">-->
<!-- <temperatureDependency type="Q10TemperatureDependency" Q10="3" baseTemperature="32degC" /> -->
<!-- <Forward type="HHExpLinearRate" rate="1per_ms" midpoint="-40mV" scale="10mV"/>-->
<!-- <Reverse type="HHExpRate" rate="4per_ms" midpoint="-65mV" scale="-18mV"/>-->
<!-- </HHGateQ10>-->

<!-- <HHGateQ10 id="h" power="1">-->
<!-- <Forward type="HHExpRate" rate="0.07per_ms" midpoint="-65mV" scale="-20mV"/>-->
<!-- <Reverse type="HHSigmoidRate" rate="1per_ms" midpoint="-35mV" scale="10mV"/>-->
<!-- </HHGateQ10>-->

<!--</HHChannel>-->


<!--<ComponentType name="HHCellT" extends="HHCell">-->
<!-- <Parameter name="temperature" dimension="temperature"/>-->

<!--</ComponentType>-->

<!--<HHCellT id="hhcell_1" capacitance="1pF" injection="4pA" v0="-60mV" temperature="22degC">-->
<!-- <ChannelPopulation id="NaPop" channel="naq10" number="8000" erev="50mV"/>-->
<!-- <ChannelPopulation id="KPop" channel="k" number="1100" erev="-77mV"/>-->
<!--</HHCellT>-->




<!--<SimulationSet id="simset">-->
<!-- <Display id="disp1" title="Example 10: Challen kinetics with Q10" xmin="0" xmax="80" ymin="-80" ymax="50"/>-->
<!-- -->
<!-- <Simulation id="sim1" length="80ms" step="0.05ms" target="hhcell_1" display="disp1">-->
<!-- <DisplayList timeScale="1ms" title="">-->
<!-- <Line id="V" quantity="v" scale="1mV" timeScale="1ms" color="#0000f0"/>-->
<!-- -->
<!-- <Line id="Na_q" quantity="NaPop/geff" scale="1nS" timeScale="1ms" color="#f00000"/>-->
<!-- <Line id="K_q" quantity="KPop/geff" scale="1nS" timeScale="1ms" color="#00f000"/>-->
<!-- -->
<!-- -->
<!-- </DisplayList>-->
<!-- </Simulation>-->
<!--</SimulationSet>-->


</Lems>
74 changes: 74 additions & 0 deletions NeuroML/NeuroML/kuramoto_CUDA.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<Lems
xmlns="http://www.neuroml.org/lems/0.7.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.neuroml.org/lems/0.7.4 ../../LEMS/Schemas/LEMS/LEMS_v0.7.4.xsd"
description="A number of ComponentTypes for rate based/population models">

<ComponentType name="Kuramoto"
description="Base type of any cell/population which has a (dimensionless) rate _R."
value="none">

<!-- Parameters will be assumed to be swept. sweep data will be matched by order of entry -->
<Parameter name="global_coupling" dimension='float'/>
<Parameter name="global_speed" dimension='float'/>

<Requirement name="MODEL_LIMIT" dimension="2_pi"/> <!-- put helping functions in util, select wrapping functions. -->

<Exposure name="V" dimension="sin(V)"/>

<Dynamics>
<StateVariable name="V" dimension="PI-V, PI"/>

<DerivedVariable name="rec_n" dimension="none" value="1.0f / n_node" />
<DerivedVariable name="rec_speed_dt" dimension="1/distance" value="1.0f / global_speed / (dt)" />
<DerivedVariable name="omega" dimension="MHz" value="60.0 * 2.0 * M_PI_F / 1e3" />
<DerivedVariable name="nsig" dimension="none" value="sqrt(dt) * sqrt(2.0 * 1e-5)" />

<TimeDerivative variable="dV" exposure="dV" value="omega * c_0"/>
</Dynamics>

</ComponentType>

<ComponentType name="coupling_function">

<!-- Added function for pre and post synaptic activity. Fixed the power being **, however no parse checks for it-->

<Constant name="a" symbol="NArray" dimension="lo=0.0, hi=10., step=0.1" value="0.1" description="Rescales the connection strength."/>

<!-- variables for pre synaptic function-->
<Parameter name="V" dimension=''/>
<Parameter name="V_j" dimension=''/>

<!-- variables for post synaptic function-->
<Requirement name="wij" dimension=''/>

<Function name="pre" value="sin(V_j - V)" description = "pre synaptic function for coupling activity"/>
<Function name="post" value="wij" description = "post synaptic function for coupling activity"/>

<!-- Handle local coupling result, full expression is c_0 *= 'value'. Name option is hardcoded -->
<DerivedParameter name="c_0" value="global_coupling * rec_n"/>

</ComponentType>

<ComponentType name="noise">

<!-- Param a-->
<!-- Related to exposures?-->

<!-- StateVariables for certain noises-->
<!-- parant noise of specific children-->
<!-- ScalingFunction GFUN; noisescaling-->

<!-- dimension field for Constant is being (mis)used for fields required for Float (True or False), domain for NArray (lo, hi, step) or field_type for Attr ('str') ) -->
<!-- is label more than a short description? -->

<Constant name="ntau" symbol="Float" dimension="True" value="0.1" description="The noise correlation time"/>
<Constant name="noise_seed" symbol="Int" dimension="" value="42" description="A random seed used to initialise the random_stream if it is missing."/>
<Constant name="random_stream" symbol="Attr" dimension="numpy.random.RandomState" value="0.0" description="An instance of numpy's RandomState associated with this
specific Noise object. Used when you need to resume a simulation from a state saved to disk"/>
<!-- <Requirement name="temperature" dimension="temperature"/>-->

</ComponentType>


</Lems>
Loading

0 comments on commit 38bcf78

Please sign in to comment.