Skip to content

Commit 991f7cd

Browse files
authored
Merge pull request #121 from OpenSourceBrain/test_xpp
Add XPP to engines; to v0.2.21
2 parents a3b5be8 + 1dcf15b commit 991f7cd

File tree

10 files changed

+287
-3
lines changed

10 files changed

+287
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
- pyNeuroML_validate_sbml
5252
- jNeuroML_Moose
5353
- MOOSE:3.1.5
54+
- XPP
5455

5556
steps:
5657
- uses: actions/checkout@v4

omv/common/inout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ def check_output(cmds, cwd=".", shell=False, verbosity=0, env=None):
121121

122122
except sp.CalledProcessError as err:
123123
inform(
124-
"Error running commands: %s in %s (return code: %s)"
125-
% (cmds, cwd, err.returncode),
124+
"CalledProcessError running commands: %s in %s (return code: %s), output:\n%s"
125+
% (cmds, cwd, err.returncode, err.output),
126126
indent=2,
127127
verbosity=verbosity,
128128
)

omv/engines/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# from omv.engines.brian1 import Brian1Engine
2424
from omv.engines.brian2_ import Brian2Engine
2525
from omv.engines.arbor_ import ArborEngine
26+
from omv.engines.xpp import XppEngine
2627
from omv.engines.eden_ import EdenEngine
2728
from omv.engines.nestsli import NestEngine
2829
from omv.engines.pynest import PyNestEngine

omv/engines/getxpp.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import os
2+
from omv.common.inout import inform, check_output
3+
4+
from omv.engines.utils.wdir import working_dir
5+
from sysconfig import get_paths
6+
import sys
7+
8+
import fileinput
9+
10+
11+
def install_xpp(version='latest'):
12+
13+
if version is None:
14+
version='latest'
15+
elif not version=='latest':
16+
raise Exception('Can currently only install the latest XPP version')
17+
18+
inform("Installing XPP", indent=2, verbosity=1)
19+
xppinstallpath = os.path.join(os.environ["HOME"])
20+
xpphomepath = os.path.join(xppinstallpath, 'xppaut')
21+
22+
inform(
23+
"Installing XPP to: %s" % (xpphomepath),
24+
indent=2,
25+
verbosity=1,
26+
)
27+
pypaths = get_paths()
28+
inform("Python lib info: %s" % (pypaths), indent=2, verbosity=1)
29+
30+
31+
with working_dir(xppinstallpath):
32+
print(
33+
check_output(
34+
[
35+
"git",
36+
"clone",
37+
"https://github.com/NeuroML/xppaut"
38+
]
39+
)
40+
)
41+
42+
with working_dir(xpphomepath):
43+
print(
44+
check_output(
45+
[
46+
"ls",
47+
"-alth"
48+
]
49+
)
50+
)
51+
52+
makefile = os.path.join(xpphomepath, 'Makefile')
53+
54+
print(' - Replacing text in %s'%makefile)
55+
with open(makefile, 'r') as file:
56+
filedata = file.read()
57+
58+
# Replace the target string
59+
filedata = filedata.replace("/usr/local/", "%s/"%xpphomepath)
60+
61+
# Write the file out again
62+
with open(makefile, 'w') as file:
63+
file.write(filedata)
64+
65+
print(
66+
check_output(
67+
[
68+
"make", "-j4"
69+
]
70+
)
71+
)
72+
print(
73+
check_output(
74+
[
75+
"make", "install"
76+
]
77+
)
78+
)
79+
80+
81+
82+
if __name__ == "__main__":
83+
install_nest()

omv/engines/xpp.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import os
2+
import sys
3+
4+
import subprocess as sp
5+
6+
from omv.common.inout import inform, trim_path, check_output, is_verbose
7+
from omv.engines.engine import OMVEngine, EngineExecutionError
8+
9+
10+
class XppEngine(OMVEngine):
11+
name = "XPP"
12+
13+
@staticmethod
14+
def get_xpp_environment():
15+
16+
# Default, if it was installed by omv...
17+
xpppath = os.path.join(os.environ["HOME"], "xppaut/bin")
18+
19+
if "XPP_HOME" in os.environ:
20+
xpppath = os.environ["XPP_HOME"] + "/"
21+
22+
environment_vars = {
23+
"XPP_HOME": xpppath,
24+
}
25+
26+
return environment_vars
27+
28+
@staticmethod
29+
def is_installed():
30+
ret = True
31+
environment_vars = XppEngine.get_xpp_environment()
32+
try:
33+
FNULL = open(os.devnull, "w")
34+
35+
r = check_output(
36+
[environment_vars["XPP_HOME"] + "/xppaut", "-version"], verbosity=2
37+
)
38+
if "Problem" in r:
39+
ret = 'v???'
40+
41+
else:
42+
ret = "%s" % r.split()[2]
43+
if not "v" in ret:
44+
ret = "v%s" % ret
45+
46+
inform("XPP %s is correctly installed..." % ret, indent=2, verbosity=1)
47+
48+
except OSError as err:
49+
if is_verbose():
50+
inform("Couldn't execute XPP: ", err, indent=1)
51+
ret = False
52+
return ret
53+
54+
@staticmethod
55+
def install(version):
56+
from omv.engines.getxpp import install_xpp
57+
58+
install_xpp(version)
59+
inform("Done...", indent=2)
60+
61+
def run(self):
62+
self.environment_vars = XppEngine.get_xpp_environment()
63+
self.set_environment()
64+
65+
try:
66+
inform(
67+
"Running file %s with %s" % (trim_path(self.modelpath), self.name),
68+
indent=1,
69+
)
70+
self.stdout = check_output(
71+
[self.environment_vars["XPP_HOME"] + "/xppaut", self.modelpath, '-silent'],
72+
cwd=os.path.dirname(self.modelpath),
73+
)
74+
self.returncode = 0
75+
except sp.CalledProcessError as err:
76+
self.returncode = err.returncode
77+
self.stdout = err.output
78+
raise EngineExecutionError
79+
except Exception as err:
80+
inform("Another error with running %s: " % self.name, err, indent=1)
81+
self.returncode = -1
82+
self.stdout = "???"

omv/omv_util.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ def _install_engine(eng):
279279

280280
install_arbor(engine_version)
281281

282+
elif eng.lower() == "XPP".lower():
283+
from omv.engines.xpp import XppEngine as ee
284+
285+
if ee.is_installed():
286+
already_installed = True
287+
else:
288+
from omv.engines.getxpp import install_xpp
289+
290+
install_xpp(engine_version)
291+
282292
elif eng.lower() == "EDEN".lower():
283293
from omv.engines.eden_ import EdenEngine as ee
284294

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = OSBModelValidation
3-
version = 0.2.20
3+
version = 0.2.21
44
author = Boris Marin, Padraig Gleeson
55
author_email = [email protected]
66
url = https://github.com/OpenSourceBrain/osb-model-validation
@@ -18,6 +18,7 @@ classifiers=
1818
Programming Language :: Python :: 3.9
1919
Programming Language :: Python :: 3.10
2020
Programming Language :: Python :: 3.11
21+
Programming Language :: Python :: 3.12
2122
Topic :: Scientific/Engineering
2223

2324
[options]

utilities/tests/.test.xpp.mep

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
system: Test XPP
2+
3+
experiments:
4+
spikes:
5+
expected:
6+
spike times: [32.25, 60.400002, 156.60001, 256.45001, 356.10001, 455.79999]
7+

utilities/tests/.test.xpp.omt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
target: nca.ode
2+
engine: XPP
3+
4+
mep: .test.xpp.mep
5+
experiments:
6+
spikes:
7+
observables:
8+
spike times:
9+
file:
10+
path: output.dat
11+
columns: [0,1]
12+
scaling: [1, 1]
13+
spike detection:
14+
method: threshold
15+
threshold: 0
16+
tolerance: 0.00
17+

utilities/tests/nca.ode

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Excitatory cortical neurons, normal [Ca].
2+
#
3+
number Cm=1.0
4+
number pms=3,pns=4
5+
number VNa=55.0,t_tauh=-40.5,t_taun=-27.0
6+
number thetaa=-50.0,sigmaa=20.0,thetab=-80.0,sigmab=-6.0,tauBs=15.0
7+
number thetam=-30.0,sigmam=9.5,sigmah=-7.0,sigman=10.0,sigmaz=5.0
8+
number VCa=120
9+
number thetar=-20.0,sigmar=10.0,thetac=-30,sigmac=7
10+
number pwrc=1,pwrq=4
11+
#
12+
p gNa=35.0,gKdr=6.0,gL=0.05,Iapp=1.0
13+
p gA=1.4,gNaP=0.2,gZ=1.0
14+
p thetaz=-39.0,tauZs=75.0
15+
p phi=10.0, thetah=-45.0
16+
p thetan=-35.0,thetap=-41.0,sigmap=3.0
17+
p VK=-90.0,VL=-70.0
18+
p gCa=0.08,gKCa=10.0,gKAHP=5
19+
p tauRs=1.0,aq=2,ac=6,tauq=450,tauCa=13,uuCa=0.13,tauKc=2
20+
#
21+
GAMMAF(VV,theta,sigma)=1.0/(1.0+exp(-(VV-theta)/sigma))
22+
ZFUNC(AA,CA,zz)=1/(1+(AA^zz/CA^zz))
23+
#
24+
VVs'=(-gL*(VVs-VL)-INa-INaP-IKdr-IA-Iz-ICa-IKC-IAHP+Iappx)/Cm
25+
hhs'=phi*(GAMMAF(VVs,thetah,sigmah)-hhs)/(1.0+7.5*GAMMAF(VVs,t_tauh,-6.0))
26+
nns'=phi*(GAMMAF(VVs,thetan,sigman)-nns)/(1.0+5.0*GAMMAF(VVs,t_taun,-15.0))
27+
bbs'=(GAMMAF(VVs,thetab,sigmab)-bbs)/tauBs
28+
zzs'=(GAMMAF(VVs,thetaz,sigmaz)-zzs)/tauZs
29+
rrs'=(GAMMAF(VVs,thetar,sigmar)-rrs)/tauRs
30+
ccs'=(GAMMAF(VVs,thetac,sigmac)-ccs)/tauKc
31+
qqs'=(ZFUNC(aq,Ca,pwrq)-qqs)/tauq
32+
Ca'=-uuCa*ICa-Ca/tauCa
33+
#
34+
Iappx=Iapp
35+
#if(t<=3.0)then(Iapp)else(0.0)
36+
Minfs=GAMMAF(VVs,thetam,sigmam)
37+
Pinfs=GAMMAF(VVs,thetap,sigmap)
38+
Ainfs=GAMMAF(VVs,thetaa,sigmaa)
39+
mKCa=ZFUNC(ac,Ca,pwrc)
40+
#
41+
INa=gNa*(Minfs^pms)*hhs*(VVs-VNa)
42+
INaP=gNaP*Pinfs*(VVs-VNa)
43+
IKdr=gKdr*(nns^pns)*(VVs-VK)
44+
IA=gA*Ainfs^3*bbs*(VVs-VK)
45+
Iz=gZ*zzs*(VVs-VK)
46+
ICa=gCa*rrs^2*(VVs-VCa)
47+
IKC=gKCa*mKCa*ccs*(VVs-VK)
48+
IAHP=gKAHP*qqs*(VVs-VK)
49+
#
50+
VVs(0)=-71.962
51+
hhs(0)=0.979199
52+
nns(0)=0.0242166
53+
bbs(0)=0.207565
54+
zzs(0)=0.0013689
55+
Ca[0]=0.000787
56+
rrs(0)=0.005507
57+
ccs(0)=0.002486
58+
qqs(0)=0.0
59+
#
60+
@ MAXSTOR=800000
61+
@ BACK=Black
62+
@ XP=T
63+
@ YP=VVs
64+
@ AXES=2
65+
@ TOTAL=500.0
66+
@ DT=0.05
67+
@ NJMP=1
68+
@ T0=0.0
69+
@ TRANS=0.0
70+
@ NMESH=40
71+
@ METH=rungekutta
72+
@ DTMIN=0.001
73+
@ DTMAX=1.0
74+
@ TOLER=0.00001
75+
@ BOUND=10000.0
76+
@ DELAY=0
77+
@ XLO=0.0, XHI=500.0, YLO=-90.0, YHI=30.0
78+
@ NTST=50,NMAX=2000,NPR=50
79+
@ DS=0.02,DSMIN=0.001,DSMAX=0.5
80+
@ PARMIN=-10,PARMAX=50,NORMMIN=0.0,NORMMAX=10000.0
81+
@ AUTOVAR=VVs1,AUTOXMIN=-10.0,AUTOXMAX=50.0,AUTOYMIN=-90.0,AUTOYMAX=50.0
82+
done

0 commit comments

Comments
 (0)