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 5 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 @@ -96,24 +96,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 @@ -130,12 +112,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 @@ -269,10 +245,8 @@ nrn_configure_file(nrnconfigargs.h src/nrnoc)
nrn_configure_file(bbsconf.h src/parallel)
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 @@ -291,8 +265,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 @@ -239,9 +239,6 @@
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#undef LT_OBJDIR

/* 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 @@ -537,20 +537,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 taken into account is defined in the `nrnunits.lib file <https://github.com/neuronsimulator/nrn/blob/master/share/lib/nrnunits.lib>`_.
alkino marked this conversation as resolved.
Show resolved Hide resolved

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 taken into account is defined in the `nrnunits.lib file <https://github.com/neuronsimulator/nrn/blob/master/share/lib/nrnunits.lib>`_.
alkino marked this conversation as resolved.
Show resolved Hide resolved

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
1 change: 0 additions & 1 deletion share/lib/python/neuron/rxd/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def NA():
try:
from neuron import h

# val = NA_legacy if h.nrnunit_use_legacy() else NA_modern
alkino marked this conversation as resolved.
Show resolved Hide resolved
val = h.Avogadro_constant
# Note: h.Avogadro_constant is consistent with the above NA legacy and
# modern values.
Expand Down
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
13 changes: 0 additions & 13 deletions src/coreneuron/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ option(CORENRN_ENABLE_CUDA_UNIFIED_MEMORY "Enable CUDA unified memory support" O
option(CORENRN_ENABLE_UNIT_TESTS "Enable unit tests execution" ON)
option(CORENRN_ENABLE_GPU "Enable GPU support using OpenACC or OpenMP" OFF)
option(CORENRN_ENABLE_SHARED "Enable shared library build" ON)
option(CORENRN_ENABLE_LEGACY_UNITS "Enable legacy FARADAY, R, etc" OFF)
option(CORENRN_ENABLE_PRCELLSTATE "Enable NRN_PRCELLSTATE debug feature" OFF)

set(CORENRN_NMODL_DIR
Expand Down Expand Up @@ -244,17 +243,6 @@ if(CORENRN_ENABLE_REPORTING)
include_directories(${sonatareport_INCLUDE_DIR})
endif()

if(CORENRN_ENABLE_LEGACY_UNITS)
set(CORENRN_USE_LEGACY_UNITS 1)
else()
set(CORENRN_USE_LEGACY_UNITS 0)
endif()
list(APPEND CORENRN_COMPILE_DEFS CORENEURON_USE_LEGACY_UNITS=${CORENRN_USE_LEGACY_UNITS})
# Propagate Legacy Units flag to backends.
set(NMODL_ENABLE_LEGACY_UNITS
${CORENRN_ENABLE_LEGACY_UNITS}
CACHE BOOL "" FORCE)

if(CORENRN_ENABLE_PRCELLSTATE)
set(CORENRN_NRN_PRCELLSTATE 1)
else()
Expand Down Expand Up @@ -800,7 +788,6 @@ if(NRN_ENABLE_MPI)
endif()
endif()
message(STATUS "OpenMP | ${CORENRN_ENABLE_OPENMP}")
message(STATUS "Use legacy units | ${CORENRN_ENABLE_LEGACY_UNITS}")
message(STATUS "NMODL PATH | ${CORENRN_NMODL_BINARY}")
message(STATUS "NMODL FLAGS | ${CORENRN_NMODL_FLAGS}")
message(STATUS "GPU Support | ${CORENRN_ENABLE_GPU}")
Expand Down
5 changes: 0 additions & 5 deletions src/coreneuron/apps/main1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ const char* corenrn_version() {
return coreneuron::bbcore_write_version;
}

// the CORENEURON_USE_LEGACY_UNITS determined by CORENRN_ENABLE_LEGACY_UNITS
bool corenrn_units_use_legacy() {
return CORENEURON_USE_LEGACY_UNITS;
}

void (*nrn2core_part2_clean_)();

/**
Expand Down
Loading
Loading