Support for Random number generator as language constructs
- Proposal for Random number generators as language constructs (instead of VERBATIM blocks)
- Review use cases from BBP models as well as ModelDB
- Present this during next NEURON meeting
- Start this implement in NMODL (and also discuss with Michael Hines about NEURON implementation)
@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
There was a very early proposal described in an issue in neuronsimulator/nrn:
https://github.com/neuronsimulator/nrn/issues/239
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...
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
Some implementation notes for the discussion:
Considering the example:
RANDOM UNIFORM(0.0, 1.0) ur1, ur2
- The whole line represent RandomStatement.
- ur1 and ur2 are random variables.
- We add following AST nodes
- RandomStatement : Statement
- distribution_type : Name
- distribution_range : ExpressionVector; vector: True
- variables : RandomVarVector; vector : True
- RandomVar : Identifier
- name : Name; node_name: true
- RandomStatement : Statement
- Bison production will be something like
euron_statement RANDOM NAME_PTR "(" expression_list ")" random_var_list - In
RandomVarwe are not storing any information about the distribution type etc. - Arguments checking etc will be done in separate semantic check visitor
- we want to check if distributiob type and it's arguments are mathcing
- such checks can be added in separate semantic visitor instead of trying to achieve everything via Bison grammar. This way we don't need to check lexer/parser if we add new distribution type.
- During the code generation, we will need to know the information about distribution type etc
- Similar use cases we handle with CodegenInfo structure i.e. we can store information about different variables, their types, ranges etc. in some map or structure. we don't need to put all information in the AST nodes
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)
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...
Here's also a gist with example code the way it could look like when generated: https://gist.github.com/ohm314/1d47a6cfecc6f71d238161358aaf59d1
This has been implemented.