Skip to content

Commit

Permalink
Merge branch 'master' into magkanar/nrn_reg
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodk committed Feb 9, 2024
2 parents 450d9fa + d1290e0 commit d1167d4
Show file tree
Hide file tree
Showing 45 changed files with 2,701 additions and 451 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ jobs:
python3-dev python3-pip
shell: bash
- name: Set up Python3
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Install Python3 dependencies
Expand All @@ -48,7 +48,7 @@ jobs:
pip3 install -U pip setuptools
pip3 install --user -r requirements.txt
- name: Restore compiler cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
${{runner.workspace}}/ccache
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
lcov --capture --directory . --no-external --output-file build/coverage-run.info --exclude "*/ext/*"
(cd build; lcov --add-tracefile coverage-base.info --add-tracefile coverage-run.info --output-file coverage.info)
(cd build; lcov --list coverage.info)
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
files: ./build/coverage.info
fail_ci_if_error: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: C/C++, CMake and Python
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update submodule
working-directory: ${{runner.workspace}}/nmodl
run: git submodule update --init cmake/hpc-coding-conventions
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/nmodl-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ jobs:
shell: bash

- name: Set up Python3
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Python3 dependencies
working-directory: ${{runner.workspace}}/nmodl
Expand Down Expand Up @@ -141,14 +141,15 @@ jobs:
echo -----
- name: Restore compiler cache
uses: pat-s/always-upload-cache@v3
uses: actions/cache@v4
with:
path: |
${{runner.workspace}}/ccache
key: ${{hashfiles('matrix.json')}}-${{github.ref}}-${{github.sha}}
restore-keys: |
${{hashfiles('matrix.json')}}-${{github.ref}}-
${{hashfiles('matrix.json')}}-
save-always: true

- name: Build
shell: bash
Expand Down Expand Up @@ -183,7 +184,7 @@ jobs:
run: |
cmake --build . --target install
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ctest-results-${{hashfiles('matrix.json')}}
path: ${{runner.workspace}}/nmodl/build/Testing/*/Test.xml
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/nmodl-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ jobs:
shell: bash

- name: Set up Python3
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -68,7 +68,7 @@ jobs:
uses: mxschmitt/action-tmate@v3

- name: Restore compiler cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
${{runner.workspace}}/ccache
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/sonarsource.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
python3-dev python3-pip
shell: bash
- name: Set up Python3
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install Python3 dependencies
Expand All @@ -49,6 +49,7 @@ jobs:
run: |
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/
- name: Run sonar-scanner
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,4 @@ You can build the entire documentation simply by using sphinx from

.. code:: sh
python3 setup.py build_ext --inplace docs -G "Unix Makefiles"
python3 setup.py build_ext --inplace docs
109 changes: 109 additions & 0 deletions docs/contents/ions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
Ions
====

NEURON supports computing the ion currents and ion concentrations. For each segment
there can be separate current for separate ions, i.e. one for sodium ions and
another for calcium ions.

There are five variables associated with ions: the current (``ina``), the
concentration inside the segment adjacent to the membrane (``nai``), the
concentration outside the segment adjacent to the membrane (``nao``), the
reversal potential (``ena``) and the derivative if the current w.r.t. the
voltage (``dinadv``). The names should be split as ``i{na}`` and therefore
refer to the value for sodium, for calcium it would have been ``ica``.

These variables are physical properties of the segment. Therefore, there exists
one mechanism per ion. MOD files can include code to read or write these
variables.

NDMOL Keywords
--------------
A MOD file seeking to use ions should use ``USEION`` as follows:

.. code::
NEURON {
USEION na READ ina WRITE ena
}
ASSIGNED {
ena (mV)
ina (mA / cm2)
}
Multiple ions are expressed by one line of ``USEION`` per ion.

The ``{ion_name}`` is a string giving the ion a name. For sodium it's ``na``
and for calcium ``ca``. If the no other mechanisms have defined an ion with
this name a new ion mechanism is created.

Both ``READ`` and ``WRITE`` are optional and are followed by a comma separated
list of ion variable names, e.g. ``ina, ena``.

Keyword: WRITE
~~~~~~~~~~~~~~

Writing Ion Currents
^^^^^^^^^^^^^^^^^^^^

In MOD file one can set the value of ion variables.

.. code::
BREAKPOINT {
ina = gna*(v - ena)
}
Semantically, this states that the contribution of the Hodgkin-Huxley model to
the overall sodium current in that segment is ``gna*(v - ena)``. Since
everything is at the level of segment, we'll not keep repeating "for that
segment". Similarly, each mechanism computes a `local` contribution, i.e. the
contribution due to this mechanism to the actual `global` ion current.

Therefore, code for the following must be generated:

1. Compute the local contribution to the sodium current.
2. Increment the total, local, current contribution by ``ina``.
3. Increment the global sodium current by ``ina``.
4. Compute local derivative of ``ina`` w.r.t. the voltage.
5. Increment the global derivative of the sodium current w.r.t. the voltage.

The global current must also be updated as usual. However, this isn't ion
specific and hence omitted.


Storage
-------

Each mechanism that specifies ``USEION na`` contains a copy of all used ion
variables and pointers to the shared values in the ion mechanism, see Figure 1.

The pointer to the variable in the ion mechanism is prefixed with ``ion_``,
e.g. during initialization we might copy the shared value ``*ion_ena[i]`` to
``ena[i]`` (the copy local to the mechanism using the ion).

.. figure:: ../images/ion_storage.svg

Figure 1: Ion mechanism for sodium (``na``) and its use in the
Hodgkin-Huxley mechanism. This figure shows the NEURON memory layout.


Optimizing Storage
~~~~~~~~~~~~~~~~~~

Since the common pattern is to only access the values of a particular instance,
the local copy isn't needed. I might facilitate SIMD, but it could be replaces
by local variables, see Figure 2.

.. figure:: ../images/ion_storage-opt.svg

Figure 2: Optimized ion storage layout.


This optimization is implemented in NMODL. It can be activated on the CLI via

.. code:: sh
nmodl ... codegen --opt-ionvar-copy
30 changes: 30 additions & 0 deletions docs/contents/pointers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
NMODL "pointers"
================

Mechanisms can refer to values in other mechanisms, e.g. the sodium current
``ina``. Therefore, it supports a notion of "pointer", called ``Datum``. A datum
can store a pointer to a double, a stable pointer to a double, integers, or
pointers to anything else.

Integer Variables
-----------------
One important subset of Datum are pointers to RANGE variables. Meaning they are
pointers to parameters in other mechanisms or pointers to the parameters
associated with each node, e.g. the voltage. Since the storage of RANGE
variable is controlled by NEURON/CoreNEURON, these pointers have stronger
semantics than a ``double*``.

These make up the majority of usecases for Datum; and are considered the
well-mannered subset.

In CoreNEURON this subset of Datums are treated differently for other Datums.
Because CoreNEURON stores the values these Datums can point to in a single
contiguous array of doubles, the "pointers" can be expressed as indices into
this array.

Therefore, this subset of Datums is referred to as "integer variables".

In NEURON these pointers are a ``data_handle`` to the value they point to.
Before the simulation phase they are "resolved" and a cache stores a list of
``double*`` to the appropriate values.

Loading

0 comments on commit d1167d4

Please sign in to comment.