Metadata-Version: 2.1
Name: NMODL-nightly
Version: 0.6.331
Summary: NEURON Modeling Language Source-to-Source Compiler Framework
Author-Email: Blue Brain Project <bbp-ou-hpc@groupes.epfl.ch>
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
Requires-Python: >=3.8
Requires-Dist: find_libpython
Requires-Dist: sympy>=1.3
Requires-Dist: importlib-metadata; python_version < "3.9"
Requires-Dist: importlib-resources; python_version < "3.9"
Requires-Dist: pytest>=3.3.0; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Requires-Dist: numpy; extra == "test"
Requires-Dist: scipy; extra == "test"
Requires-Dist: jupyter-client; extra == "docs"
Requires-Dist: jupyter; extra == "docs"
Requires-Dist: myst_parser<2.0.0; extra == "docs"
Requires-Dist: mistune<3; extra == "docs"
Requires-Dist: nbconvert; extra == "docs"
Requires-Dist: nbsphinx>=0.3.2; extra == "docs"
Requires-Dist: sphinxcontrib-applehelp<1.0.3; extra == "docs"
Requires-Dist: sphinxcontrib-htmlhelp<=2.0.0; extra == "docs"
Requires-Dist: sphinx<6; extra == "docs"
Requires-Dist: sphinx-rtd-theme; extra == "docs"
Requires-Dist: docutils<0.20; extra == "docs"
Provides-Extra: test
Provides-Extra: docs
Description-Content-Type: text/x-rst

The NMODL Framework
===================

|github workflow| |Build Status| |codecov| |CII Best Practices|

The NMODL Framework is a code generation engine for **N**\ EURON
**MOD**\ eling **L**\ anguage
(`NMODL <https://www.neuron.yale.edu/neuron/static/py_doc/modelspec/programmatic/mechanisms/nmodl.html>`__).
It is designed with modern compiler and code generation techniques to:

-  Provide **modular tools** for parsing, analysing and transforming
   NMODL
-  Provide **easy to use**, high level Python API
-  Generate **optimised code** for modern compute architectures
   including CPUs, GPUs
-  **Flexibility** to implement new simulator backends
-  Support for **full** NMODL specification

About NMODL
-----------

Simulators like `NEURON <https://www.neuron.yale.edu/neuron/>`__ use
NMODL as a domain specific language (DSL) to describe a wide range of
membrane and intracellular submodels. Here is an example of exponential
synapse specified in NMODL:

.. code::

   NEURON {
       POINT_PROCESS ExpSyn
       RANGE tau, e, i
       NONSPECIFIC_CURRENT i
   }
   UNITS {
       (nA) = (nanoamp)
       (mV) = (millivolt)
       (uS) = (microsiemens)
   }
   PARAMETER {
       tau = 0.1 (ms) <1e-9,1e9>
       e = 0 (mV)
   }
   ASSIGNED {
       v (mV)
       i (nA)
   }
   STATE {
       g (uS)
   }
   INITIAL {
       g = 0
   }
   BREAKPOINT {
       SOLVE state METHOD cnexp
       i = g*(v - e)
   }
   DERIVATIVE state {
       g' = -g/tau
   }
   NET_RECEIVE(weight (uS)) {
       g = g + weight
   }

Installation
------------

See
`INSTALL.rst <https://github.com/BlueBrain/nmodl/blob/master/INSTALL.rst>`__
for detailed instructions to build the NMODL from source.

Try NMODL with Docker
---------------------

To quickly test the NMODL Framework’s analysis capabilities we provide a
`docker <https://www.docker.com>`__ image, which includes the NMODL
Framework python library and a fully functional Jupyter notebook
environment. After installing
`docker <https://docs.docker.com/compose/install/>`__ and
`docker-compose <https://docs.docker.com/compose/install/>`__ you can
pull and run the NMODL image from your terminal.

To try Python interface directly from CLI, you can run docker image as:

::

   docker run -it --entrypoint=/bin/sh bluebrain/nmodl

And try NMODL Python API discussed later in this README as:

::

   $ python3
   Python 3.6.8 (default, Apr  8 2019, 18:17:52)
   >>> from nmodl import dsl
   >>> import os
   >>> examples = dsl.list_examples()
   >>> nmodl_string = dsl.load_example(examples[-1])
   ...

To try Jupyter notebooks you can download docker compose file and run it
as:

.. code:: sh

   wget "https://raw.githubusercontent.com/BlueBrain/nmodl/master/docker/docker-compose.yml"
   DUID=$(id -u) DGID=$(id -g) HOSTNAME=$(hostname) docker-compose up

If all goes well you should see at the end status messages similar to
these:

::

   [I 09:49:53.923 NotebookApp] The Jupyter Notebook is running at:
   [I 09:49:53.923 NotebookApp] http://(4c8edabe52e1 or 127.0.0.1):8888/?token=a7902983bad430a11935
   [I 09:49:53.923 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
       To access the notebook, open this file in a browser:
           file:///root/.local/share/jupyter/runtime/nbserver-1-open.html
       Or copy and paste one of these URLs:
           http://(4c8edabe52e1 or 127.0.0.1):8888/?token=a7902983bad430a11935

Based on the example above you should then open your browser and
navigate to the URL
``http://127.0.0.1:8888/?token=a7902983bad430a11935``.

You can open and run all example notebooks provided in the ``examples``
folder. You can also create new notebooks in ``my_notebooks``, which
will be stored in a subfolder ``notebooks`` at your current working
directory.

Using the Python API
--------------------

Once the NMODL Framework is installed, you can use the Python parsing
API to load NMOD file as:

.. code:: python

   from nmodl import dsl

   examples = dsl.list_examples() 
   nmodl_string = dsl.load_example(examples[-1])
   driver = dsl.NmodlDriver()
   modast = driver.parse_string(nmodl_string)

The ``parse_file`` API returns Abstract Syntax Tree
(`AST <https://en.wikipedia.org/wiki/Abstract_syntax_tree>`__)
representation of input NMODL file. One can look at the AST by
converting to JSON form as:

.. code:: python

   >>> print (dsl.to_json(modast))
   {
     "Program": [
       {
         "NeuronBlock": [
           {
             "StatementBlock": [
               {
                 "Suffix": [
                   {
                     "Name": [
                       {
                         "String": [
                           {
                             "name": "POINT_PROCESS"
                           }
                       ...

Every key in the JSON form represent a node in the AST. You can also use
visualization API to look at the details of AST as:

::

   from nmodl import ast
   ast.view(modast)

which will open AST view in web browser:

.. figure::
   https://user-images.githubusercontent.com/666852/57329449-12c9a400-7114-11e9-8da5-0042590044ec.gif
   :alt: ast_viz

   Vizualisation of the AST in the NMODL Framework

The central *Program* node represents the whole MOD file and each of
it’s children represent the block in the input NMODL file. Note that
this requires X-forwarding if you are using the Docker image.

Once the AST is created, one can use exisiting visitors to perform
various analysis/optimisations. One can also easily write his own custom
visitor using Python Visitor API. See `Python API
tutorial <docs/notebooks/nmodl-python-tutorial.ipynb>`__ for details.

The NMODL Framework also allows us to transform the AST representation back to
NMODL form as:

.. code:: python

   >>> print (dsl.to_nmodl(modast))
   NEURON {
       POINT_PROCESS ExpSyn
       RANGE tau, e, i
       NONSPECIFIC_CURRENT i
   }

   UNITS {
       (nA) = (nanoamp)
       (mV) = (millivolt)
       (uS) = (microsiemens)
   }

   PARAMETER {
       tau = 0.1 (ms) <1e-09,1000000000>
       e = 0 (mV)
   }
   ...

High Level Analysis and Code Generation
---------------------------------------

The NMODL Framework provides rich model introspection and analysis
capabilities using `various
visitors <https://bluebrain.github.io/nmodl/html/doxygen/group__visitor__classes.html>`__.
Here is an example of theoretical performance characterisation of
channels and synapses from rat neocortical column microcircuit
`published in
2015 <https://www.cell.com/cell/fulltext/S0092-8674%2815%2901191-5>`__:

.. figure::
   https://user-images.githubusercontent.com/666852/57336711-2cc0b200-7127-11e9-8053-8f662e2ec191.png
   :alt: nmodl-perf-stats

   Performance results of the NMODL Framework

To understand how you can write your own introspection and analysis
tool, see `this
tutorial <docs/notebooks/nmodl-python-tutorial.ipynb>`__.

Once analysis and optimization passes are performed, the NMODL Framework
can generate optimised code for modern compute architectures including
CPUs (Intel, AMD, ARM) and GPUs (NVIDIA, AMD) platforms. For example,
C++, OpenACC and OpenMP backends are implemented and one can choose
these backends on command line as:

::

   $ nmodl expsyn.mod sympy --analytic

To know more about code generation backends, `see
here <https://bluebrain.github.io/nmodl/html/doxygen/group__codegen__backends.html>`__.
NMODL Framework provides number of options (for code generation,
optimization passes and ODE solver) which can be listed as:

::

   $ nmodl -H
   NMODL : Source-to-Source Code Generation Framework [version]
   Usage: /path/<>/nmodl [OPTIONS] file... [SUBCOMMAND]

   Positionals:
     file TEXT:FILE ... REQUIRED           One or more MOD files to process

   Options:
     -h,--help                             Print this help message and exit
     -H,--help-all                         Print this help message including all sub-commands
     --verbose=info                        Verbose logger output (trace, debug, info, warning, error, critical, off)
     -o,--output TEXT=.                    Directory for backend code output
     --scratch TEXT=tmp                    Directory for intermediate code output
     --units TEXT=/path/<>/nrnunits.lib
                                           Directory of units lib file

   Subcommands:
   host
     HOST/CPU code backends
     Options:
       --c                                   C/C++ backend (true)

   acc
     Accelerator code backends
     Options:
       --oacc                                C/C++ backend with OpenACC (false)

   sympy
     SymPy based analysis and optimizations
     Options:
       --analytic                            Solve ODEs using SymPy analytic integration (false)
       --pade                                Pade approximation in SymPy analytic integration (false)
       --cse                                 CSE (Common Subexpression Elimination) in SymPy analytic integration (false)
       --conductance                         Add CONDUCTANCE keyword in BREAKPOINT (false)

   passes
     Analyse/Optimization passes
     Options:
       --inline                              Perform inlining at NMODL level (false)
       --unroll                              Perform loop unroll at NMODL level (false)
       --const-folding                       Perform constant folding at NMODL level (false)
       --localize                            Convert RANGE variables to LOCAL (false)
       --global-to-range                     Convert GLOBAL variables to RANGE (false)
       --localize-verbatim                   Convert RANGE variables to LOCAL even if verbatim block exist (false)
       --local-rename                        Rename LOCAL variable if variable of same name exist in global scope (false)
       --verbatim-inline                     Inline even if verbatim block exist (false)
       --verbatim-rename                     Rename variables in verbatim block (true)
       --json-ast                            Write AST to JSON file (false)
       --nmodl-ast                           Write AST to NMODL file (false)
       --json-perf                           Write performance statistics to JSON file (false)
       --show-symtab                         Write symbol table to stdout (false)

   codegen
     Code generation options
     Options:
       --layout TEXT:{aos,soa}=soa           Memory layout for code generation
       --datatype TEXT:{float,double}=soa    Data type for floating point variables
       --force                               Force code generation even if there is any incompatibility
       --only-check-compatibility            Check compatibility and return without generating code
       --opt-ionvar-copy                     Optimize copies of ion variables (false)

Documentation
-------------

We are working on user documentation, you can find current drafts of :

-  `User Documentation <https://bluebrain.github.io/nmodl/>`__
-  `Developer / API
   Documentation <https://bluebrain.github.io/nmodl/html/doxygen/index.html>`__

Citation
--------

If you would like to know more about the the NMODL Framework, see
following paper:

-  Pramod Kumbhar, Omar Awile, Liam Keegan, Jorge Alonso, James King,
   Michael Hines and Felix Schürmann. 2019. An optimizing multi-platform
   source-to-source compiler framework for the NEURON MODeling Language.
   In Eprint :
   `arXiv:1905.02241 <https://arxiv.org/pdf/1905.02241.pdf>`__

Support / Contribuition
-----------------------

If you see any issue, feel free to `raise a
ticket <https://github.com/BlueBrain/nmodl/issues/new>`__. If you would
like to improve this framework, see `open
issues <https://github.com/BlueBrain/nmodl/issues>`__ and `contribution
guidelines <CONTRIBUTING.rst>`__.

Examples / Benchmarks
---------------------

The benchmarks used to test the performance and parsing capabilities of
NMODL Framework are currently being migrated to GitHub. These benchmarks
will be published soon in following repositories:

-  `NMODL Benchmark <https://github.com/BlueBrain/nmodlbench>`__
-  `NMODL Database <https://github.com/BlueBrain/nmodldb>`__

Funding & Acknowledgment
------------------------

The development of this software was supported by funding to the Blue
Brain Project, a research center of the École polytechnique fédérale de
Lausanne (EPFL), from the Swiss government’s ETH Board of the Swiss
Federal Institutes of Technology. In addition, the development was
supported by funding from the National Institutes of Health (NIH) under
the Grant Number R01NS11613 (Yale University) and the European Union’s
Horizon 2020 Framework Programme for Research and Innovation under the
Specific Grant Agreement No. 785907 (Human Brain Project SGA2).

Copyright © 2017-2023 Blue Brain Project, EPFL

.. |github workflow| image:: https://github.com/BlueBrain/nmodl/actions/workflows/nmodl-ci.yml/badge.svg?branch=master
.. |Build Status| image:: https://dev.azure.com/pramodskumbhar/nmodl/_apis/build/status/BlueBrain.nmodl?branchName=master
   :target: https://dev.azure.com/pramodskumbhar/nmodl/_build/latest?definitionId=2&branchName=master
.. |codecov| image:: https://codecov.io/gh/BlueBrain/nmodl/branch/master/graph/badge.svg?token=A3NU9VbNcB
   :target: https://codecov.io/gh/BlueBrain/nmodl
.. |CII Best Practices| image:: https://bestpractices.coreinfrastructure.org/projects/4467/badge
   :target: https://bestpractices.coreinfrastructure.org/projects/4467
