Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove legacy units and option of dynamic units selection #2539

Merged
merged 25 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0317a81
No more dynamic or legacy units
alkino Sep 25, 2023
1509226
Update test rxd test data.
adamjhn Sep 26, 2023
2395d08
Formatting.
adamjhn Sep 26, 2023
639e916
use modern way of parsing
alkino Sep 26, 2023
092734a
Merge branch 'master' into cornu/simplify_units
alkino Sep 26, 2023
ad693fb
Merge branch 'master' into cornu/simplify_units
pramodk Sep 27, 2023
da0aba2
Merge branch 'master' into cornu/simplify_units
alkino Sep 28, 2023
60f44f5
Fix review by ioannis
alkino Sep 28, 2023
eacdf28
Keep the function 'nrnunit_use_legacy()'
alkino Sep 29, 2023
7e3e12b
Format
alkino Sep 30, 2023
384c778
Merge branch 'master' into cornu/simplify_units
alkino Sep 30, 2023
a804672
Update nrntest to follow last changes
alkino Oct 2, 2023
cd7d37f
Merge remote-tracking branch 'origin/cornu/simplify_units'
alkino Oct 2, 2023
98564a3
Fix declaration of nrnunit_use_legacy
iomaganaris Oct 3, 2023
ddc1a9a
Reduce sonarcloud warnings
alkino Oct 4, 2023
62daf4d
Merge remote-tracking branch 'origin/master'
alkino Oct 4, 2023
d44b3d4
Fix for review
alkino Oct 5, 2023
f8f02a6
Merge remote-tracking branch 'origin/master'
alkino Oct 5, 2023
1921c70
Fix all of them
alkino Oct 5, 2023
3cbd52f
Import things
alkino Oct 5, 2023
e882709
Merge branch 'master' into cornu/simplify_units
alkino Oct 5, 2023
1914e9f
review
alkino Oct 5, 2023
4df612a
Merge remote-tracking branch 'origin/cornu/simplify_units'
alkino Oct 5, 2023
b69138b
Fix failing test and nitpick on the error/warning message
pramodk Oct 6, 2023
db56d37
Merge branch 'master' into cornu/simplify_units
alkino Oct 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ option(NRN_AVOID_ABSOLUTE_PATHS
"Avoid embedding absolute paths in generated code (ccache optimisation)"
${NRN_AVOID_ABSOLUTE_PATHS_DEFAULT})
mark_as_advanced(NRN_AVOID_ABSOLUTE_PATHS)
option(NRN_DYNAMIC_UNITS_USE_LEGACY "Use legacy units as default for dynamic units"
${NRN_DYNAMIC_UNITS_USE_LEGACY_DEFAULT})
# note that if CoreNEURON is enabled then it is not necessary to enable this option
option(NRN_ENABLE_MOD_COMPATIBILITY "Enable CoreNEURON compatibility for MOD files"
${NRN_ENABLE_MOD_COMPATIBILITY_DEFAULT})
Expand Down Expand Up @@ -499,9 +497,6 @@ if(NRN_ENABLE_CORENEURON)
set(CORENRN_ENABLE_UNIT_TESTS
${NRN_ENABLE_TESTS}
CACHE BOOL "" FORCE)
set(CORENRN_ENABLE_LEGACY_UNITS
${NRN_DYNAMIC_UNITS_USE_LEGACY}
CACHE BOOL "" FORCE)
if(NRN_ENABLE_PROFILING)
if(NRN_PROFILER STREQUAL "caliper")
set(CORENRN_ENABLE_CALIPER_PROFILING ON)
Expand Down Expand Up @@ -960,11 +955,6 @@ message(STATUS "CXX COMPILER | ${CMAKE_CXX_COMPILER}")
message(STATUS "BUILD_TYPE | ${CMAKE_BUILD_TYPE} (allowed: ${allowableBuildTypes})")
message(STATUS "COMPILE FLAGS | ${COMPILER_FLAGS}")
message(STATUS "Shared | ${NRN_ENABLE_SHARED}")
if(NRN_DYNAMIC_UNITS_USE_LEGACY)
message(STATUS "Default units | legacy units")
else()
message(STATUS "Default units | modern units (2019 nist constants)")
endif()
message(STATUS "MPI | ${NRN_ENABLE_MPI}")
if(NRN_ENABLE_MPI)
message(STATUS " DYNAMIC | ${NRN_ENABLE_MPI_DYNAMIC}")
Expand Down Expand Up @@ -1035,9 +1025,6 @@ message(STATUS "CoreNEURON | ${NRN_ENABLE_CORENEURON}")
if(NRN_ENABLE_CORENEURON)
message(STATUS " PATH | ${CORENEURON_DIR}")
message(STATUS " LINK FLAGS | ${CORENRN_LIB_LINK_FLAGS}")
if(NOT coreneuron_FOUND)
message(STATUS " Legacy Units| ${CORENRN_ENABLE_LEGACY_UNITS}")
endif()
endif()
if(NRN_UNIVERSAL2_BUILD)
message(STATUS "CMAKE_OSX_ARCH| ${CMAKE_OSX_ARCHITECTURES}")
Expand Down
2 changes: 0 additions & 2 deletions cmake/BuildOptionDefaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ set(NRN_ENABLE_MPI_DYNAMIC_DEFAULT OFF)
set(NRN_ENABLE_MOD_COMPATIBILITY_DEFAULT OFF)
set(NRN_ENABLE_REL_RPATH_DEFAULT OFF)
set(NRN_AVOID_ABSOLUTE_PATHS_DEFAULT OFF)
set(NRN_DYNAMIC_UNITS_USE_LEGACY_DEFAULT OFF)
set(NRN_NMODL_CXX_FLAGS_DEFAULT "-O0")
set(NRN_SANITIZERS_DEFAULT "")

Expand Down Expand Up @@ -68,7 +67,6 @@ set(NRN_OPTION_NAME_LIST
NRN_MODULE_INSTALL_OPTIONS
NRN_PYTHON_DYNAMIC
NRN_MPI_DYNAMIC
NRN_DYNAMIC_UNITS_USE_LEGACY
NRN_RX3D_OPT_LEVEL
NRN_SANITIZERS
CMAKE_BUILD_TYPE
Expand Down
30 changes: 1 addition & 29 deletions cmake/ConfigFileSetting.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,6 @@ else()
set(DISCRETE_EVENT_OBSERVER 0)
endif()

# No longer a user option. Default modern units. Controlled at launch by the environment variable
# NRNUNIT_USE_LEGACY, and dynamically after launch by h.nrnunit_use_legacy(0or1). Left here solely
# to obtain a nrnunits.lib file for modlunit. Nmodl uses the nrnunits.lib.in file.
set(NRN_ENABLE_LEGACY_FR 0)
if(NRN_ENABLE_LEGACY_FR)
set(LegacyFR 1)
set(LegacyY "")
set(LegacyN "/")
set(LegacyYPy "")
set(LegacyNPy "#")
else()
set(LegacyFR 0)
set(LegacyY "/")
set(LegacyN "")
set(LegacyYPy "#")
set(LegacyNPy "")
endif()

if(NRN_ENABLE_MECH_DLL_STYLE)
set(NRNMECH_DLL_STYLE 1)
else()
Expand All @@ -126,12 +108,6 @@ if(NRN_ENABLE_PYTHON_DYNAMIC)
list(APPEND NRN_COMPILE_DEFS NRNPYTHON_DYNAMICLOAD)
endif()

if(NRN_DYNAMIC_UNITS_USE_LEGACY)
set(DYNAMIC_UNITS_USE_LEGACY_DEFAULT 1)
else()
unset(DYNAMIC_UNITS_USE_LEGACY_DEFAULT)
endif()

# =============================================================================
# Dependencies option
# =============================================================================
Expand Down Expand Up @@ -219,10 +195,8 @@ nrn_configure_file(nrnmpiuse.h src/oc)
nrn_configure_file(nrnconfigargs.h src/nrnoc)
nrn_configure_file(nrnneosm.h src/nrncvode)
nrn_configure_file(sundials_config.h src/sundials)
nrn_configure_dest_src(nrnunits.lib share/nrn/lib nrnunits.lib share/lib)
nrn_configure_dest_src(nrn.defaults share/nrn/lib nrn.defaults share/lib)
# NRN_DYNAMIC_UNITS requires nrnunits.lib.in be in same places as nrnunits.lib
file(COPY ${PROJECT_SOURCE_DIR}/share/lib/nrnunits.lib.in
file(COPY ${PROJECT_SOURCE_DIR}/share/lib/nrnunits.lib
DESTINATION ${PROJECT_BINARY_DIR}/share/nrn/lib)

if(NRN_MACOS_BUILD)
Expand All @@ -241,8 +215,6 @@ if(MINGW)
set(nrnskip_rebase "#")
nrn_configure_file(mknrndll.mak src/mswin/lib)
endif()
# TODO temporary workaround for mingw
file(COPY ${PROJECT_BINARY_DIR}/share/nrn/lib/nrnunits.lib.in DESTINATION ${PROJECT_BINARY_DIR}/lib)

# =============================================================================
# If Interviews is not provided, configure local files
Expand Down
3 changes: 0 additions & 3 deletions cmake_nrnconf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H

/* 1 for legacy, undef for NIST (as of 2017), for FARADAY and R */
#undef LegacyFR

/* define if using mingw */
#undef MINGW

Expand Down
14 changes: 0 additions & 14 deletions docs/cmake_doc/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -597,20 +597,6 @@ NRN_ENABLE_DISCRETE_EVENT_OBSERVER:BOOL=ON
Enable Observer to be a subclass of DiscreteEvent
Can save space but a lot of component destruction may not notify other components that are watching it to no longer use that component. Useful only if one builds a model without needing to eliminate pieces of the model.

NRN_DYNAMIC_UNITS_USE_LEGACY:BOOL=OFF
----------------------------
Default is to use modern faraday, R, etc. from 2019 nist constants.
When Off or ON, and in the absence of the ``NRNUNIT_USE_LEGACY=0or1``
environment variable, the default dynamic value of ``h.nrnunit_use_legacy()``
will be 0 or 1 respectively.

At launch time (or import neuron),
use of legacy or modern units can be specified with the
``NRNUNIT_USE_LEGACY=0or1`` environment variable. The use of legacy or
modern units can be dynamically specified after launch with the
``h.nrnunit_use_legacy(0or1)`` function (with no args, returns the
current use flag).

NRN_ENABLE_MECH_DLL_STYLE:BOOL=ON
---------------------------------
Dynamically load nrnmech shared library
Expand Down
7 changes: 1 addition & 6 deletions docs/hoc/modelspec/programmatic/mechanisms/nmodl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,7 @@ Description:
the UNIX units database. This can increase legibility and convenience, and is helpful both as a
reminder to the user and as a means for automating the process of checking for consistency of
units.
The UNIX units database taken into account is defined in the `nrnunits.lib file <https://github.com/neuronsimulator/nrn/blob/master/share/lib/nrnunits.lib.in>`_.
This file includes two versions of the units due to the updates in the values of their base
units. Currently there are legacy and modern units that contain the changes after the updates
introduced on 2019 to the nist constants. The selection between those two versions can be done
using the ``NRN_DYNAMIC_UNITS_USE_LEGACY`` CMake variable or a call to
``h.nrnunit_use_legacy(bool)`` during runtime.
The UNIX units database (based on the 2019 updated NIST constants) taken into account is defined in the `nrnunits.lib file <https://github.com/neuronsimulator/nrn/blob/master/share/lib/nrnunits.lib>`_.

New units can be defined in terms of default units and previously defined units by placing
definitions in the UNITS block. e.g.
Expand Down
23 changes: 0 additions & 23 deletions docs/python/envvariables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,3 @@ NEURON_MODULE_OPTIONS
os.environ["NEURON_MODULE_OPTIONS"] = nrn_options
from neuron import h
assert(nrn_options in h.nrnversion(7))



NRNUNIT_USE_LEGACY
------------------
When set to 1, legacy unit values for FARADAY, R, and a few other constants
are used. See ``nrn/share/lib/nrnunits.lib.in`` lines which begin with
``@LegacyY@``, ``nrn/src/oc/hoc_init.c`` in the code section
``static struct { /* Modern, Legacy units constants */``, and
``nrn/src/nrnoc/eion.c``.

When set to 0, (default), values from codata2018 are used.
See ``nrn/share/lib/nrnunits.lib.in`` lines that begin with
``@LegacyN@`` and ``nrn/src/oc/nrnunits_modern.h``.

Switching between legacy and modern units can also be done after launch
with the top level HOC function :func:`nrnunit_use_legacy`.

The purpose of allowing legacy unit values is to easily validate
results of old models (double precision identity).

This environment variable takes precedence over the CMake option
``NRN_DYNAMIC_UNITS_USE_LEGACY``.
7 changes: 1 addition & 6 deletions docs/python/modelspec/programmatic/mechanisms/nmodl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,7 @@ Description:
the UNIX units database. This can increase legibility and convenience, and is helpful both as a
reminder to the user and as a means for automating the process of checking for consistency of
units.
The UNIX units database taken into account is defined in the `nrnunits.lib file <https://github.com/neuronsimulator/nrn/blob/master/share/lib/nrnunits.lib.in>`_.
This file includes two versions of the units due to the updates in the values of their base
units. Currently there are legacy and modern units that contain the changes after the updates
introduced on 2019 to the nist constants. The selection between those two versions can be done
using the ``NRN_DYNAMIC_UNITS_USE_LEGACY`` CMake variable or a call to
``h.nrnunit_use_legacy(bool)`` during runtime.
The UNIX units database (based on the 2019 updated NIST constants) taken into account is defined in the `nrnunits.lib file <https://github.com/neuronsimulator/nrn/blob/master/share/lib/nrnunits.lib>`_.

New units can be defined in terms of default units and previously defined units by placing
definitions in the UNITS block. e.g.
Expand Down
9 changes: 0 additions & 9 deletions docs/python/programming/math/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ The following mathematical and physical constants are available through the ``h`

h.PHI 1.61803398874989484820 (golden ratio)

h.FARADAY 96484.56 (coulombs/mole) (legacy value)
h.FARADAY 96485.3321233100141 (modern value. derived from mole and electron charge)

h.R 8.31441 (molar gas constant, joules/mole/deg-K) (legacy value)
h.R 8.3144626181532395 (modern value. derived from boltzmann constant and mole)

h.Avogadro_constant 6.02214076e23 (codata2018 value, introduced version 8.0)

As of Version 8.0 (circa October, 2020) modern units are the default.
See :func:`nrnunit_use_legacy`

.. warning::
Constants are not treated specially by the interpreter and
Expand All @@ -37,10 +34,4 @@ See :func:`nrnunit_use_legacy`
If assignment takes
place due to execution of a hoc interpreter statement, the warning occurs
only once but cannot be avoided.

The legacy FARADAY is a bit different than the legacy faraday of the units database.
The legacy faraday in a :file:`.mod` mechanism is 96520.




16 changes: 0 additions & 16 deletions docs/python/simctrl/programmatic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,6 @@ Functions

----

.. function:: nrnunit_use_legacy

Syntax:
``bool = h.nrnunit_use_legacy(bool)``

Description:
| Return current units usage as 0 or 1.
| An argument is not required.
| Arg, False uses modern codata2018 units for FARADAY, R, etc. (default as of version 8.0)
| Arg, True uses legacy units (default prior to October, 2020)

.. seealso::
:ref:`NRNUNIT_USE_LEGACY` :ref:`CONSTANTS`

----

.. data:: secondorder


Expand Down
21 changes: 7 additions & 14 deletions share/lib/nrnunits.lib.in → share/lib/nrnunits.lib
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ pi 3.14159265358979323846
c 2.99792458+8 m/sec fuzz
g 9.80665 m/sec2
au 1.49597871+11 m fuzz
@LegacyY@mole 6.022169+23 fuzz
@LegacyN@mole 6.02214076+23 fuzz
@LegacyY@e 1.6021917-19 coul fuzz
@LegacyN@e 1.602176634-19 coul fuzz
mole 6.02214076+23 fuzz
e 1.602176634-19 coul fuzz
energy c2
force g
mercury 1.33322+5 kg/m2-sec2
Expand Down Expand Up @@ -394,8 +392,7 @@ ev e-volt
/ faraday 9.652000+04 coul
/ faraday from host: physics.nist.gov
/ path: /PhysRefData/fundconst/html/keywords.html
@LegacyY@faraday 9.6485309+4 coul
@LegacyN@faraday e-mole
faraday e-mole
fathom 6 ft
fermi 1-15 m
fifth 4|5 qt
Expand Down Expand Up @@ -431,8 +428,7 @@ hyl gm force sec2/m
hz /sec
imaginarycubicfoot 1.4 ft3
jeroboam 4|5 gal
@LegacyY@boltzmann 1.38064852-23 joule/K
@LegacyN@boltzmann 1.380649-23 joule/K
boltzmann 1.380649-23 joule/K
k boltzmann
karat 1|24
kcal kilocal
Expand Down Expand Up @@ -501,8 +497,7 @@ quarter 9 in
quartersection 1|4 mi2
quintal 100 kg
quire 25
@LegacyY@gasconstant 8.3144598 joule/K
@LegacyN@gasconstant k-mole
gasconstant k-mole
R gasconstant
rad 100 erg/gm
ream 500
Expand Down Expand Up @@ -571,10 +566,8 @@ tex .001 gram / m
englishell 45 inch
scottishell 37.2 inch
flemishell 27 inch
@LegacyY@planck 6.626-34 joule-sec
@LegacyN@planck 6.62607015-34 joule-sec
@LegacyY@hbar 1.055-34 joule-sec
@LegacyN@hbar planck/two-pi
planck 6.62607015-34 joule-sec
hbar planck/two-pi
electronmass 9.1095-31 kg
protonmass 1.6726-27 kg
neutronmass 1.6606-27 kg
Expand Down
8 changes: 4 additions & 4 deletions share/lib/python/neuron/expect_hocerr.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def expect_hocerr(callable, args, sec=None):

original_stderr = sys.stderr
sys.stderr = my_stderr = StringIO()
err = 0
err = False
pyerrmes = False
try:
if sec:
Expand All @@ -50,7 +50,7 @@ def expect_hocerr(callable, args, sec=None):
callable(*args)
printerr("expect_hocerr: no err for %s%s" % (str(callable), str(args)))
except Exception as e:
err = 1
err = True
errmes = my_stderr.getvalue()
if errmes:
errmes = errmes.splitlines()[0]
Expand All @@ -70,12 +70,12 @@ def expect_err(stmt):
"""
here = inspect.currentframe()
caller = here.f_back
err = 0
err = False
checking(stmt)
try:
exec(stmt, caller.f_globals, caller.f_locals)
printerr("expect_err: no err for-- " + stmt)
except Exception as e:
err = 1
err = True
printerr(e)
assert err
7 changes: 1 addition & 6 deletions share/lib/python/neuron/rxd/constants.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
# Avogadro's number (approximation before 2019 redefinition)
NA_legacy = 6.02214129e23
NA_modern = 6.02214076e23


def NA():
try:
from neuron import h

# val = NA_legacy if h.nrnunit_use_legacy() else NA_modern
val = h.Avogadro_constant
alkino marked this conversation as resolved.
Show resolved Hide resolved
# Note: h.Avogadro_constant is consistent with the above NA legacy and
# modern values.
except:
val = NA_modern
return val


def molecules_per_mM_um3():
# converting from mM um^3 to molecules
# = 6.02214129e23 * 1000. / 1.e18 / 1000
# = 6.02214076e23 * 1000. / 1.e18 / 1000
# = avogadro * (L / m^3) * (m^3 / um^3) * (mM / M)
return NA() / 1e18
6 changes: 1 addition & 5 deletions share/lib/python/neuron/rxd/rxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ def byeworld():

last_diam_change_cnt = None
last_structure_change_cnt = None
last_nrn_legacy_units = h.nrnunit_use_legacy()


_all_reactions = []

Expand Down Expand Up @@ -570,10 +568,8 @@ def _cxx_compile(formula):


def _setup_units(force=False):
global last_nrn_legacy_units
if initializer.is_initialized():
if force or last_nrn_legacy_units != h.nrnunit_use_legacy():
last_nrn_legacy_units = h.nrnunit_use_legacy()
if force:
clear_rates()
_setup_memb_currents()
_compile_reactions()
Expand Down
1 change: 0 additions & 1 deletion share/lib/python/neuron/rxdtests/do_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def do_test(test_to_run, results_location, num_record=10):

import itertools

h.nrnunit_use_legacy(True)
pramodk marked this conversation as resolved.
Show resolved Hide resolved
data = {"record_count": 0, "data": []}
do_test.data = data
record_count = 0
Expand Down
Loading
Loading