Skip to content

Commit

Permalink
Activate usecases during CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Dec 11, 2023
1 parent 9c98519 commit 62ee1d2
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/nmodl-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
# Hyphens here will be replaced with commas before the value is
# passed to NMODL_SANITIZERS
sanitizer: address-leak
- config:
os: ubuntu-22.04
enable_usecases: On
- config:
flag_warnings: ON
os: ubuntu-22.04
Expand Down Expand Up @@ -80,6 +83,11 @@ jobs:
python3 -m pip install -U pip setuptools
python3 -m pip install --user -r requirements.txt
- name: Install neuron-nightly
if: ${{matrix.config.enable_usecases == 'On'}}
run: |
python3 -m pip install neuron-nightly
- name: Register compiler warning problem matcher
if: ${{matrix.config.flag_warnings == 'ON'}}
run: echo "::add-matcher::.github/problem-matchers/gcc.json"
Expand All @@ -104,6 +112,9 @@ jobs:
-Wno-sign-compare \
-Wno-overloaded-virtual")
fi
if [[ -n "${{matrix.config.enable_usecases}}" ]]; then
cmake_args+=(-DNMODL_ENABLE_USECASES=${{matrix.config.enable_usecases}})
fi
if [[ -n "${{matrix.config.sanitizer}}" ]]; then
cmake_args+=(-DCMAKE_BUILD_TYPE=Custom \
-DCMAKE_CXX_FLAGS="-O1 -g" \
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
# =============================================================================
option(NMODL_ENABLE_PYTHON_BINDINGS "Enable pybind11 based python bindings" ON)
option(NMODL_ENABLE_TESTS "Enable build of tests" ON)
option(NMODL_ENABLE_USECASES
"If building tests, additionally enable build of usecase tests. Requires neuron." OFF)
set(NMODL_EXTRA_CXX_FLAGS
""
CACHE STRING "Add extra compile flags for NMODL sources")
Expand Down Expand Up @@ -207,6 +209,10 @@ if(NOT NMODL_AS_SUBPROJECT AND NMODL_ENABLE_TESTS)
include(CTest)
add_subdirectory(test/unit)
add_subdirectory(test/integration)

if(NMODL_ENABLE_USECASES)
add_subdirectory(test/usecases)
endif()
endif()

# =============================================================================
Expand Down
7 changes: 7 additions & 0 deletions test/usecases/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(NMODL_USECASE_DIRS leonhard)

foreach(usecase ${NMODL_USECASE_DIRS})
add_test(NAME usecase_${usecase}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run_test.sh ${CMAKE_BINARY_DIR}/bin/nmodl
${CMAKE_CURRENT_SOURCE_DIR}/${usecase})
endforeach()
16 changes: 16 additions & 0 deletions test/usecases/leonhard/leonhard.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
NEURON {
SUFFIX leonhard
}

STATE { x }

INITIAL {
x = 42
}

BREAKPOINT {
SOLVE dX METHOD cnexp
}

DERIVATIVE dX { x' = -x }

31 changes: 31 additions & 0 deletions test/usecases/leonhard/simulate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os

print(f"{os.environ['NEURON_MODULE_OPTIONS'] = }")

import numpy as np

from neuron import h, gui
from neuron.units import ms

nseg = 1

s = h.Section()
s.insert("leonhard")
s.nseg = nseg

x_hoc = h.Vector().record(s(0.5)._ref_x_leonhard)
t_hoc = h.Vector().record(h._ref_t)

h.stdinit()
h.tstop = 5.0 * ms
h.run()

x = np.array(x_hoc.as_numpy())
t = np.array(t_hoc.as_numpy())

x0 = 42.0
x_exact = 42.0 * np.exp(-t)
rel_err = np.abs(x - x_exact) / x_exact

assert np.all(rel_err < 1e-12)
print("leonhard: success")
14 changes: 14 additions & 0 deletions test/usecases/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#! /usr/bin/env bash
set -e

nmodl="$1"
usecase_dir="$2"

pushd "${usecase_dir}"

rm -r x86_64 tmp || true

nrnivmodl -nmodl "${nmodl}"
x86_64/special simulate.py

popd

0 comments on commit 62ee1d2

Please sign in to comment.