{"id":20956561,"url":"https://github.com/bluebrain/nmodl","last_synced_at":"2025-04-04T11:09:46.155Z","repository":{"id":37819016,"uuid":"170517431","full_name":"BlueBrain/nmodl","owner":"BlueBrain","description":"Code Generation Framework For NEURON MODeling Language ","archived":false,"fork":false,"pushed_at":"2024-10-29T09:34:33.000Z","size":151036,"stargazers_count":55,"open_issues_count":195,"forks_count":15,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-10-29T09:52:27.876Z","etag":null,"topics":["code-generation","compilers","dsl","hpc","neuron-simulator","neuroscience","nmodl"],"latest_commit_sha":null,"homepage":"https://bluebrain.github.io/nmodl/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BlueBrain.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.txt","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-13T14:01:13.000Z","updated_at":"2024-10-28T14:22:00.000Z","dependencies_parsed_at":"2023-09-27T20:09:11.426Z","dependency_job_id":"49f89c35-8b08-4f4b-945c-31c7deb9b661","html_url":"https://github.com/BlueBrain/nmodl","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueBrain%2Fnmodl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueBrain%2Fnmodl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueBrain%2Fnmodl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueBrain%2Fnmodl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlueBrain","download_url":"https://codeload.github.com/BlueBrain/nmodl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166168,"owners_count":20894654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generation","compilers","dsl","hpc","neuron-simulator","neuroscience","nmodl"],"created_at":"2024-11-19T01:26:43.987Z","updated_at":"2025-04-04T11:09:46.132Z","avatar_url":"https://github.com/BlueBrain.png","language":"C++","readme":"The NMODL Framework\n===================\n\nWARNING\n_______\n\n**NMODL has been fully integrated into the NEURON repository.**\nThere will be no further development efforts on NMODL as an independent project.\n\nAll future development will happen at:\n`https://github.com/neuronsimulator/nrn \u003chttps://github.com/neuronsimulator/nrn\u003e`_.\n\n---------------------\n\nThe NMODL Framework is a code generation engine for **N**\\ EURON\n**MOD**\\ eling **L**\\ anguage\n(`NMODL \u003chttps://www.neuron.yale.edu/neuron/static/py_doc/modelspec/programmatic/mechanisms/nmodl.html\u003e`__).\nIt is designed with modern compiler and code generation techniques to:\n\n-  Provide **modular tools** for parsing, analysing and transforming\n   NMODL\n-  Provide **easy to use**, high level Python API\n-  Generate **optimised code** for modern compute architectures\n   including CPUs, GPUs\n-  **Flexibility** to implement new simulator backends\n-  Support for **full** NMODL specification\n\nAbout NMODL\n-----------\n\nSimulators like `NEURON \u003chttps://www.neuron.yale.edu/neuron/\u003e`__ use\nNMODL as a domain specific language (DSL) to describe a wide range of\nmembrane and intracellular submodels. Here is an example of exponential\nsynapse specified in NMODL:\n\n.. code::\n\n   NEURON {\n       POINT_PROCESS ExpSyn\n       RANGE tau, e, i\n       NONSPECIFIC_CURRENT i\n   }\n   UNITS {\n       (nA) = (nanoamp)\n       (mV) = (millivolt)\n       (uS) = (microsiemens)\n   }\n   PARAMETER {\n       tau = 0.1 (ms) \u003c1e-9,1e9\u003e\n       e = 0 (mV)\n   }\n   ASSIGNED {\n       v (mV)\n       i (nA)\n   }\n   STATE {\n       g (uS)\n   }\n   INITIAL {\n       g = 0\n   }\n   BREAKPOINT {\n       SOLVE state METHOD cnexp\n       i = g*(v - e)\n   }\n   DERIVATIVE state {\n       g' = -g/tau\n   }\n   NET_RECEIVE(weight (uS)) {\n       g = g + weight\n   }\n\nInstallation\n------------\n\nSee\n`INSTALL.rst \u003chttps://github.com/BlueBrain/nmodl/blob/master/INSTALL.rst\u003e`__\nfor detailed instructions to build the NMODL from source.\n\nTry NMODL with Docker\n---------------------\n\nTo quickly test the NMODL Framework’s analysis capabilities we provide a\n`docker \u003chttps://www.docker.com\u003e`__ image, which includes the NMODL\nFramework python library and a fully functional Jupyter notebook\nenvironment. After installing\n`docker \u003chttps://docs.docker.com/compose/install/\u003e`__ and\n`docker-compose \u003chttps://docs.docker.com/compose/install/\u003e`__ you can\npull and run the NMODL image from your terminal.\n\nTo try Python interface directly from CLI, you can run docker image as:\n\n::\n\n   docker run -it --entrypoint=/bin/sh bluebrain/nmodl\n\nAnd try NMODL Python API discussed later in this README as:\n\n::\n\n   $ python3\n   Python 3.6.8 (default, Apr  8 2019, 18:17:52)\n   \u003e\u003e\u003e from nmodl import dsl\n   \u003e\u003e\u003e import os\n   \u003e\u003e\u003e examples = dsl.list_examples()\n   \u003e\u003e\u003e nmodl_string = dsl.load_example(examples[-1])\n   ...\n\nTo try Jupyter notebooks you can download docker compose file and run it\nas:\n\n.. code:: sh\n\n   wget \"https://raw.githubusercontent.com/BlueBrain/nmodl/master/docker/docker-compose.yml\"\n   DUID=$(id -u) DGID=$(id -g) HOSTNAME=$(hostname) docker-compose up\n\nIf all goes well you should see at the end status messages similar to\nthese:\n\n::\n\n   [I 09:49:53.923 NotebookApp] The Jupyter Notebook is running at:\n   [I 09:49:53.923 NotebookApp] http://(4c8edabe52e1 or 127.0.0.1):8888/?token=a7902983bad430a11935\n   [I 09:49:53.923 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).\n       To access the notebook, open this file in a browser:\n           file:///root/.local/share/jupyter/runtime/nbserver-1-open.html\n       Or copy and paste one of these URLs:\n           http://(4c8edabe52e1 or 127.0.0.1):8888/?token=a7902983bad430a11935\n\nBased on the example above you should then open your browser and\nnavigate to the URL\n``http://127.0.0.1:8888/?token=a7902983bad430a11935``.\n\nYou can open and run all example notebooks provided in the ``examples``\nfolder. You can also create new notebooks in ``my_notebooks``, which\nwill be stored in a subfolder ``notebooks`` at your current working\ndirectory.\n\nUsing the Python API\n--------------------\n\nOnce the NMODL Framework is installed, you can use the Python parsing\nAPI to load NMOD file as:\n\n.. code:: python\n\n   from nmodl import dsl\n\n   examples = dsl.list_examples()\n   nmodl_string = dsl.load_example(examples[-1])\n   driver = dsl.NmodlDriver()\n   modast = driver.parse_string(nmodl_string)\n\nThe ``parse_file`` API returns Abstract Syntax Tree\n(`AST \u003chttps://en.wikipedia.org/wiki/Abstract_syntax_tree\u003e`__)\nrepresentation of input NMODL file. One can look at the AST by\nconverting to JSON form as:\n\n.. code:: python\n\n   \u003e\u003e\u003e print (dsl.to_json(modast))\n   {\n     \"Program\": [\n       {\n         \"NeuronBlock\": [\n           {\n             \"StatementBlock\": [\n               {\n                 \"Suffix\": [\n                   {\n                     \"Name\": [\n                       {\n                         \"String\": [\n                           {\n                             \"name\": \"POINT_PROCESS\"\n                           }\n                       ...\n\nEvery key in the JSON form represent a node in the AST. You can also use\nvisualization API to look at the details of AST as:\n\n::\n\n   from nmodl import ast\n   ast.view(modast)\n\nwhich will open AST view in web browser:\n\n.. figure::\n   https://user-images.githubusercontent.com/666852/57329449-12c9a400-7114-11e9-8da5-0042590044ec.gif\n   :alt: ast_viz\n\n   Vizualisation of the AST in the NMODL Framework\n\nThe central *Program* node represents the whole MOD file and each of\nit’s children represent the block in the input NMODL file. Note that\nthis requires X-forwarding if you are using the Docker image.\n\nOnce the AST is created, one can use exisiting visitors to perform\nvarious analysis/optimisations. One can also easily write his own custom\nvisitor using Python Visitor API. See `Python API\ntutorial \u003cdocs/notebooks/nmodl-python-tutorial.ipynb\u003e`__ for details.\n\nThe NMODL Framework also allows us to transform the AST representation back to\nNMODL form as:\n\n.. code:: python\n\n   \u003e\u003e\u003e print (dsl.to_nmodl(modast))\n   NEURON {\n       POINT_PROCESS ExpSyn\n       RANGE tau, e, i\n       NONSPECIFIC_CURRENT i\n   }\n\n   UNITS {\n       (nA) = (nanoamp)\n       (mV) = (millivolt)\n       (uS) = (microsiemens)\n   }\n\n   PARAMETER {\n       tau = 0.1 (ms) \u003c1e-09,1000000000\u003e\n       e = 0 (mV)\n   }\n   ...\n\nHigh Level Analysis and Code Generation\n---------------------------------------\n\nThe NMODL Framework provides rich model introspection and analysis\ncapabilities using `various\nvisitors \u003chttps://bluebrain.github.io/nmodl/html/doxygen/group__visitor__classes.html\u003e`__.\nHere is an example of theoretical performance characterisation of\nchannels and synapses from rat neocortical column microcircuit\n`published in\n2015 \u003chttps://www.cell.com/cell/fulltext/S0092-8674%2815%2901191-5\u003e`__:\n\n.. figure::\n   https://user-images.githubusercontent.com/666852/57336711-2cc0b200-7127-11e9-8053-8f662e2ec191.png\n   :alt: nmodl-perf-stats\n\n   Performance results of the NMODL Framework\n\nTo understand how you can write your own introspection and analysis\ntool, see `this\ntutorial \u003cdocs/notebooks/nmodl-python-tutorial.ipynb\u003e`__.\n\nOnce analysis and optimization passes are performed, the NMODL Framework\ncan generate optimised code for modern compute architectures including\nCPUs (Intel, AMD, ARM) and GPUs (NVIDIA, AMD) platforms. For example,\nC++, OpenACC and OpenMP backends are implemented and one can choose\nthese backends on command line as:\n\n::\n\n   $ nmodl expsyn.mod sympy --analytic\n\nTo know more about code generation backends, `see\nhere \u003chttps://bluebrain.github.io/nmodl/html/doxygen/group__codegen__backends.html\u003e`__.\nNMODL Framework provides number of options (for code generation,\noptimization passes and ODE solver) which can be listed as:\n\n::\n\n   $ nmodl -H\n   NMODL : Source-to-Source Code Generation Framework [version]\n   Usage: /path/\u003c\u003e/nmodl [OPTIONS] file... [SUBCOMMAND]\n\n   Positionals:\n     file TEXT:FILE ... REQUIRED           One or more MOD files to process\n\n   Options:\n     -h,--help                             Print this help message and exit\n     -H,--help-all                         Print this help message including all sub-commands\n     --verbose=info                        Verbose logger output (trace, debug, info, warning, error, critical, off)\n     -o,--output TEXT=.                    Directory for backend code output\n     --scratch TEXT=tmp                    Directory for intermediate code output\n     --units TEXT=/path/\u003c\u003e/nrnunits.lib\n                                           Directory of units lib file\n\n   Subcommands:\n   host\n     HOST/CPU code backends\n     Options:\n       --c                                   C/C++ backend (true)\n\n   acc\n     Accelerator code backends\n     Options:\n       --oacc                                C/C++ backend with OpenACC (false)\n\n   sympy\n     SymPy based analysis and optimizations\n     Options:\n       --analytic                            Solve ODEs using SymPy analytic integration (false)\n       --pade                                Pade approximation in SymPy analytic integration (false)\n       --cse                                 CSE (Common Subexpression Elimination) in SymPy analytic integration (false)\n       --conductance                         Add CONDUCTANCE keyword in BREAKPOINT (false)\n\n   passes\n     Analyse/Optimization passes\n     Options:\n       --inline                              Perform inlining at NMODL level (false)\n       --unroll                              Perform loop unroll at NMODL level (false)\n       --const-folding                       Perform constant folding at NMODL level (false)\n       --localize                            Convert RANGE variables to LOCAL (false)\n       --global-to-range                     Convert GLOBAL variables to RANGE (false)\n       --localize-verbatim                   Convert RANGE variables to LOCAL even if verbatim block exist (false)\n       --local-rename                        Rename LOCAL variable if variable of same name exist in global scope (false)\n       --verbatim-inline                     Inline even if verbatim block exist (false)\n       --verbatim-rename                     Rename variables in verbatim block (true)\n       --json-ast                            Write AST to JSON file (false)\n       --nmodl-ast                           Write AST to NMODL file (false)\n       --json-perf                           Write performance statistics to JSON file (false)\n       --show-symtab                         Write symbol table to stdout (false)\n\n   codegen\n     Code generation options\n     Options:\n       --layout TEXT:{aos,soa}=soa           Memory layout for code generation\n       --datatype TEXT:{float,double}=soa    Data type for floating point variables\n       --force                               Force code generation even if there is any incompatibility\n       --only-check-compatibility            Check compatibility and return without generating code\n       --opt-ionvar-copy                     Optimize copies of ion variables (false)\n\nDocumentation\n-------------\n\nWe are working on user documentation, you can find current drafts of :\n\n-  `User Documentation \u003chttps://bluebrain.github.io/nmodl/\u003e`__\n-  `Developer / API\n   Documentation \u003chttps://bluebrain.github.io/nmodl/html/doxygen/index.html\u003e`__\n\nCitation\n--------\n\nIf you would like to know more about the the NMODL Framework, see\nthe following paper:\n\n- Pramod Kumbhar, Omar Awile, Liam Keegan, Jorge Blanco Alonso, James King,\n  Michael Hines, and Felix Schürmann. 2020. An optimizing multi-platform\n  source-to-source compiler framework for the NEURON MODeling Language.\n  In *Computational Science – ICCS 2020*, Springer, Cham, 45–58.\n  DOI: `10.1007/978-3-030-50371-0_4 \u003chttps://doi.org/10.1007/978-3-030-50371-0_4\u003e`__\n\nSome additional details are covered in the pre-print:\n\n-  Pramod Kumbhar, Omar Awile, Liam Keegan, Jorge Alonso, James King,\n   Michael Hines and Felix Schürmann. 2019. An optimizing multi-platform\n   source-to-source compiler framework for the NEURON MODeling Language.\n   In Eprint :\n   `arXiv:1905.02241 \u003chttps://arxiv.org/pdf/1905.02241.pdf\u003e`__\n\nSupport / Contribuition\n-----------------------\n\nIf you see any issue, feel free to `raise a\nticket \u003chttps://github.com/BlueBrain/nmodl/issues/new\u003e`__. If you would\nlike to improve this framework, see `open\nissues \u003chttps://github.com/BlueBrain/nmodl/issues\u003e`__ and `contribution\nguidelines \u003cCONTRIBUTING.rst\u003e`__.\n\nExamples / Benchmarks\n---------------------\n\nThe benchmarks used to test the performance and parsing capabilities of\nNMODL Framework are currently being migrated to GitHub. These benchmarks\nwill be published soon in following repositories:\n\n-  `NMODL Benchmark \u003chttps://github.com/BlueBrain/nmodlbench\u003e`__\n-  `NMODL Database \u003chttps://github.com/BlueBrain/nmodldb\u003e`__\n\nFunding \u0026 Acknowledgment\n------------------------\n\nThe development of this software was supported by funding to the Blue\nBrain Project, a research center of the École polytechnique fédérale de\nLausanne (EPFL), from the Swiss government’s ETH Board of the Swiss\nFederal Institutes of Technology. In addition, the development was\nsupported by funding from the National Institutes of Health (NIH) under\nthe Grant Number R01NS11613 (Yale University) and the European Union’s\nHorizon 2020 Framework Programme for Research and Innovation under the\nSpecific Grant Agreement No. 785907 (Human Brain Project SGA2).\n\nCopyright © 2017-2024 Blue Brain Project, EPFL\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluebrain%2Fnmodl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbluebrain%2Fnmodl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluebrain%2Fnmodl/lists"}