BlueBrain / nmodl

Code Generation Framework For NEURON MODeling Language
https://bluebrain.github.io/nmodl/
Apache License 2.0
52 stars 15 forks source link

Support for Random number generator as language constructs #383

Open pramodk opened 4 years ago

pramodk commented 4 years ago

@ohm314 : During Yale visit last year we put together a draft PR (or temporary branch). Could you link that here?

Also ping Sam Yates on this topic as well

ohm314 commented 4 years ago

There was a very early proposal described in an issue in neuronsimulator/nrn: https://github.com/neuronsimulator/nrn/issues/239

nrnhines commented 4 years ago

To my shame I was unaware of neuronsimulator/nrn#239 . It looks very good and very clean. No VERBATIM blocks remain! And I think similar things could be done with

VECTOR vec

This could be implemented in nocmodl but if new nmodl is coming to NEURON sooner rather than later...

ohm314 commented 3 years ago

The ticket on the neuron repo has been quite a bit extended with lots of details towards having a complete specification.

As a first step I will try to add the parsing of such declarations

RANDOM DISTRIBUTION(param_1, ..., param_n) varname_1, ..., varname_m
pramodk commented 3 years ago

Some implementation notes for the discussion:

Considering the example:

RANDOM UNIFORM(0.0, 1.0) ur1, ur2
nrnhines commented 3 years ago

Seems sufficient to begin an implementation. Note that I presume this will NOT make use of the interpreter Random. Currently, nrnran123.h supports

DiscreteUniform( 0 to 2**32 - 1)
Uniform(0.0 to 1.0)  (I'm not sure but I think there are either  2**32  or (2**32 - 1)distinct values)
    /* nrnran123_dblpick minimum value is 2.3283064e-10 and max value is 1-min */
NegExp (mean 1.0)
   /* nrnran123_negexp min value is 2.3283064e-10, max is 22.18071 */
Normal (mean 0.0, stddev 1.0)
ohm314 commented 3 years ago

Correct, this will not use interpreter random, but the distribution arguments can be set via parameters. Thanks for sharing the available distributions in random123, then we'll make sure to support those directly. Actually a start of an implementation is already in a branch. Will report back when this gets a bit further along...

ohm314 commented 12 months ago

Here's also a gist with example code the way it could look like when generated: https://gist.github.com/ohm314/1d47a6cfecc6f71d238161358aaf59d1