Skip to content

Commit cbc0a30

Browse files
committed
Merge branch 'experimental' of github.com:NeuroML/pyNeuroML into experimental
* 'experimental' of github.com:NeuroML/pyNeuroML: test(modchananalysis): test to check that nrnivmodl is run when required ooops, had forgotten to commit right logic handling near zero values Checking for compiled mod files. Fixes #165
2 parents 7425c58 + a668aac commit cbc0a30

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

pyneuroml/neuron/analysis/HHanalyse.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import argparse
1010
import re
11+
import subprocess
12+
import sys
1113
from math import log
1214
import neuron
1315
import matplotlib.pyplot as pylab
@@ -198,7 +200,21 @@ def main():
198200
states = get_states(modFileTxt)
199201
print("States found in mod file: " + str(states))
200202
assert chanToTest == get_suffix(modFileTxt), "Channel name could be wrong"
201-
sec.insert(str(chanToTest))
203+
try:
204+
sec.insert(str(chanToTest))
205+
except ValueError:
206+
print(f"{chanToTest} mechanism has not been compiled yet. Trying to run `nrnivmodl`.")
207+
try:
208+
subprocess.run("nrnivmodl", check=True, capture_output=True)
209+
except subprocess.CalledProcessError as e:
210+
print(f"Could not compile {modFileName}. nrivmodl returned {e.returncode}.")
211+
#print(e.stderr.decode())
212+
print("Try running nrnivmodl manually and checking its output.")
213+
print("Exiting...")
214+
return 1
215+
h.nrn_load_dll("x86_64/.libs/libnrnmech.so")
216+
sec.insert(str(chanToTest))
217+
202218

203219
for temperature in temperatures:
204220
h.celsius = temperature
@@ -388,15 +404,16 @@ def main():
388404
val = eval("sec(0.5)." + s + "_" + chanToTest)
389405

390406
if s not in foundInf:
391-
if abs((lastCheckVal[s] - val) / val) > tolerance:
407+
rel_dif = (lastCheckVal[s] - val) / val if val > sys.float_info.epsilon else lastCheckVal[s]
408+
if abs(rel_dif) > tolerance:
392409
if verbose:
393410
print(
394411
" State %s has failed at %f; lastCheckVal[s] = %f; fract = %f; tolerance = %f"
395412
% (
396413
s,
397414
val,
398415
lastCheckVal[s],
399-
((lastCheckVal[s] - val) / val),
416+
rel_dif,
400417
tolerance,
401418
)
402419
)
@@ -408,7 +425,7 @@ def main():
408425
s,
409426
val,
410427
lastCheckVal[s],
411-
((lastCheckVal[s] - val) / val),
428+
rel_dif,
412429
tolerance,
413430
)
414431
)

test-ghactions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ if [ "$run_neuron_examples" == true ]; then
146146
echo "################################################"
147147
echo "## Test analysis of channel in mod file"
148148

149-
nrnivmodl
149+
# do not run nrnivmodl, modchananalysis should run it if required
150150
pynml-modchananalysis -stepV 20 NaConductance -dt 0.01 -nogui
151151

152152

0 commit comments

Comments
 (0)