Skip to content

WIP: Support for RANDOM construct in NMODL#2597

Closed
pramodk wants to merge 15 commits into
masterfrom
pramodk/random
Closed

WIP: Support for RANDOM construct in NMODL#2597
pramodk wants to merge 15 commits into
masterfrom
pramodk/random

Conversation

@pramodk

@pramodk pramodk commented Oct 30, 2023

Copy link
Copy Markdown
Member

Summary of what has been done until now and how/why/where::

  • Addition of src/nrnoc/netstim_rng.mod

This is the same as netstim.mod but with the removal of all VERBATIM and save state-related features. This should replace netstim.mod once all the implementation is
finished. I didn't modify netstim.mod because I didn't want to break existing
tests. It uses new RANDOM construct and methods like sample, init, setseq.

  • Changes in src/nmodl/noccout.cpp

print_functions_for_random_construct() emits all code related to helper+wrapper functions
that we need in the generated code. As mentioned in the code comment, code like
_get_random_var_by_name() should be removed once we support proper syntax like
netstim.r.init_rng(id1,id2,id3).

  • Changes in src/nmodl/parsact.cpp

Has changes to replace sample, init, setseq functions with corresponding Random123 equivalent.

  • Changes in src/nmodl/parse1.ypp

Parser changes to parse RANDOM specification in NEURON block. This can be further
improved with error handling etc.

  • Changes in src/nmodl/random_construct.*

Store random variables and supplementary methods to support code generation

  • src/oc/nrnran123.cpp

Changes to support distributions including NORMAL and UNIFORM.

  • test
  • test/coreneuron/test_rng.py : is an old test from hackathon to discuss the syntax
  • test/nmodl/test_random.py : new test which tests the APIs and overall functionality

Next Steps

  • Changes on the NEURON side to support access to RANDOM variables via interpreter
cell.r.init_rng(gid, 2, 3)

instead of

cell.init_rng("r", gid, 2, 3)
  • Handle random semantic type in NEURON

Currently, we are registering a random semantic but that is being treated the same as POINTER.

  • Handle bbsavestate and transfer of this type to CoreNEURON
  • NMODL code generation changes similar to nocmodl

Comments for Discussion

  • A way to use parameters instead of constant vars
 RANDOM NEGEXP(1.0) r

to

 RANDOM NEGEXP(X) r

where X is PARAMETER variable

Improvements

  • Error handling
  • Through testing
  • NMODL code generation and GPU usage

@bbpbuildbot

This comment has been minimized.

@bbpbuildbot

This comment has been minimized.

@ohm314 ohm314 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some first comments

Comment thread src/nmodl/parse1.ypp

// TODO: keep track of arguments for RANDOM
// could be removed by fixing production rules?
static std::vector<std::string> numbers;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit astonished this is necessary - you don't have argument lists anywhere else?

Comment thread src/nmodl/noccout.cpp
Comment on lines +158 to +164
auto args_with_comma = [](const std::string& acc, const std::string& str) {
return acc.empty() ? str : acc + ", " + str;
};
std::string result = std::accumulate(var.arguments.begin(),
var.arguments.end(),
std::string(),
args_with_comma);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused why this is done here and not in random_construct.cpp ? It's just nitpicking, but just wondering.

Comment thread src/nmodl/noccout.cpp
}
}

std::vector<std::string> nrnlist_to_string(Item* begin, Item* qlist) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's that for? I don't see its use here?

@bbpbuildbot

This comment has been minimized.

pramodk and others added 15 commits November 20, 2023 15:58
cp ../external/coding-conventions/cpp/clang-format-10 ../.clang-format
clang-format-11 -i ./src/nrnoc/netstim.cpp
cp ../external/coding-conventions/cpp/clang-format-10 ../.clang-format
clang-format-11 -i ./src/nrnoc/netstim.cpp
1. variables are properly declared and registered
2. necessary functions are declared, defined and registered
3. able to call the functions from python world
4. add unit test to the same
- added src/nrnoc/netstim_rng.mod so that existing tests
  can work and we have a "cleaned" MOD file for RANDOM
- have basic support implemented for setseq, init, sample
  methods with RANDOM variable
- RANDOM variables are registered with "random" semantics
  but they are now treated as POINTER variables
- revert src/nrnoc/netstim.mod to origin/master
- remove temporary generated file cmake-build-debug/src/nrnoc/netstim.cpp
@sonarqubecloud

Copy link
Copy Markdown

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 1 Security Hotspot
Code Smell A 30 Code Smells

No Coverage information No Coverage information
6.6% 6.6% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@pramodk

pramodk commented Jan 27, 2024

Copy link
Copy Markdown
Member Author

superseded by #2627

@pramodk pramodk closed this Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants