Skip to content

Commit 93fe21c

Browse files
authored
(#284) Small Test editions
* Now tests check if CUDA is installed. * Set energy tolerance to 1kcal/mol. * Changed dipole output so that INTEL does not break things. * Now travis makes some tests.
1 parent 97b7c89 commit 93fe21c

File tree

6 files changed

+112
-21
lines changed

6 files changed

+112
-21
lines changed

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: cpp
22
sudo: required
33
before_install:
4-
- sudo apt-get install gfortran liblapack-dev libblas-dev
5-
script: ./configure && make -j cpu=1 cuda=0
4+
- sudo apt-get install gfortran liblapack-dev libblas-dev python2.7
5+
before_script: ./configure && make -j cpu=1 cuda=0 && cd test
6+
script: travis_wait ./run_travis_test.py

lioamber/fileio/output_others.f90

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ subroutine write_dipole(dipxyz, u, uid, header)
4949
double precision, intent(in) :: dipxyz(3), u
5050
integer , intent(in) :: uid
5151
logical , intent(in) :: header
52+
character(len=40) :: out_fmt = '(4(2x,F13.9))'
5253

5354
open(unit = uid, file = "dipole_moment")
5455
if (style) then
@@ -64,10 +65,10 @@ subroutine write_dipole(dipxyz, u, uid, header)
6465
else
6566
if (header) then
6667
write(UID,*)
67-
write(UID,*) '#DIPOLE MOMENT, X Y Z COMPONENTS AND NORM (DEBYES)'
68+
write(UID,'(A)') '#DIPOLE MOMENT, X Y Z COMPONENTS AND NORM (DEBYES)'
6869
write(UID,*)
6970
else
70-
write(UID,*) dipxyz(1), dipxyz(2), dipxyz(3), u
71+
write(UID,out_fmt) dipxyz(1), dipxyz(2), dipxyz(3), u
7172
endif
7273
endif
7374

test/compile.py

+26-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def set_options(flag):
1111
return options
1212

1313

14-
def compilar(options):
14+
def compile_lio(options):
1515
liodir = os.path.abspath("../")
1616
devnull = open(os.devnull, "w")
1717
cmd = ["tests_engine/build.sh", liodir, options]
@@ -26,23 +26,45 @@ def run_lio():
2626
process.wait()
2727
return process.returncode
2828

29+
# Verifies if CUDA is installed. Returns
30+
def cuda_is_installed():
31+
devnull = open(os.devnull, 'wb')
32+
process = subprocess.Popen(["nvcc --version"], shell=True, stdout=devnull, stderr=devnull)
33+
try:
34+
stdout, stderr = process.communicate()
35+
except:
36+
process.kill()
37+
process.wait()
38+
raise
39+
retcode = process.poll()
40+
41+
is_installed = False
42+
if (retcode == 0):
43+
is_installed = True
44+
45+
return is_installed
2946

3047
if __name__ == "__main__":
31-
comp = ["cuda","intel","precision"]
48+
if (cuda_is_installed()):
49+
print "CUDA Libraries detected."
50+
comp = ["cuda","intel","precision"]
51+
else:
52+
print "CUDA libraries not detected. Will attempt CPU-only compilations."
53+
comp = ["intel","precision"]
3254
seq = list(itertools.product(["0","1"],repeat=len(comp)))
3355
all_sets = []
3456

3557
for cases in seq:
3658
compile_opts = dict([(comp[i],cases[i]) for i in xrange(0,len(comp))])
3759
if compile_opts["cuda"] == "1":
38-
compile_opts["cuda"] = "2"
60+
compile_opts["cuda"] = "2"
3961

4062
all_sets.append(compile_opts)
4163

4264
for flag_set in all_sets:
4365
opts = set_options(flag_set)
4466
print "Compiling LIO with Options: %s" % opts.rstrip()
45-
error = compilar(opts)
67+
error = compile_lio(opts)
4668
if not error:
4769
print "\tSuccessfully compiled."
4870
else:

test/new_tests.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66
import subprocess
77

88
def lio_env():
9-
""""
10-
Sets lio enviroment variables, adding g2g and
11-
lioamber to LD_LIBRARY_PATH.
12-
"""
13-
14-
lioenv = os.environ.copy()
15-
lioenv["LIOBIN"] = os.path.abspath("../liosolo/liosolo")
16-
prev = lioenv["LD_LIBRARY_PATH"]
17-
dirs = ["../g2g", "../lioamber"]
18-
lioenv["LD_LIBRARY_PATH"] = ":".join([prev] + [os.path.abspath(p) for p in dirs])
19-
lioenv["LIOHOME"] = os.path.abspath("../")
20-
return lioenv
9+
""""
10+
Sets lio enviroment variables, adding g2g and
11+
lioamber to LD_LIBRARY_PATH.
12+
"""
13+
14+
lioenv = os.environ.copy()
15+
lioenv["LIOBIN"] = os.path.abspath("../liosolo/liosolo")
16+
dirs = ["../g2g", "../lioamber"]
17+
try:
18+
prev = lioenv["LD_LIBRARY_PATH"]
19+
except:
20+
prev = ""
21+
lioenv["LD_LIBRARY_PATH"] = ":".join([prev] + [os.path.abspath(p) for p in dirs])
22+
lioenv["LIOHOME"] = os.path.abspath("../")
23+
return lioenv
2124

2225

2326
def run_lio(dirs_with_tests):

test/run_travis_test.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python2.7
2+
3+
import re
4+
import os
5+
import argparse
6+
import subprocess
7+
8+
def lio_env():
9+
""""
10+
Sets lio enviroment variables, adding g2g and
11+
lioamber to LD_LIBRARY_PATH.
12+
"""
13+
14+
lioenv = os.environ.copy()
15+
lioenv["LIOBIN"] = os.path.abspath("../liosolo/liosolo")
16+
dirs = ["../g2g", "../lioamber"]
17+
try:
18+
prev = lioenv["LD_LIBRARY_PATH"]
19+
except:
20+
prev = ""
21+
lioenv["LD_LIBRARY_PATH"] = ":".join([prev] + [os.path.abspath(p) for p in dirs])
22+
lioenv["LIOHOME"] = os.path.abspath("../")
23+
return lioenv
24+
25+
26+
def run_lio(dirs_with_tests):
27+
"Runs all Tests"
28+
lioenv = lio_env()
29+
30+
for dir in dirs_with_tests:
31+
is_file = os.path.isfile(os.path.abspath(dir) + "/run.sh")
32+
print "Running LIO in",dir
33+
34+
if is_file:
35+
execpath = ["./run.sh"]
36+
process = subprocess.Popen(execpath, env=lioenv, cwd=os.path.abspath(dir))
37+
process.wait()
38+
if process.returncode != 0:
39+
print "Error in this folder."
40+
continue
41+
else:
42+
execpath = ["./check_test.py"]
43+
check = subprocess.Popen(execpath, env=lioenv, cwd=os.path.abspath(dir))
44+
check.wait()
45+
else:
46+
print("Nothing to do.")
47+
48+
49+
if __name__ == "__main__":
50+
parser = argparse.ArgumentParser()
51+
parser.add_argument("--filter_rx", help="RegExp used to filter which tests are run.", default=".*")
52+
args = parser.parse_args()
53+
filterrx = args.filter_rx
54+
55+
# This obtain tests folder
56+
subdirs = list(os.walk('LIO_test/'))[0][1]
57+
dirs_with_tests = sorted([d for d in subdirs if re.search(filterrx,d)])
58+
test_folders = [0,1,3,4,6]
59+
for i in test_folders:
60+
dirs_with_tests[i] = "LIO_test/" + dirs_with_tests[i]
61+
62+
# Run lio
63+
filed = run_lio(dirs_with_tests)
64+

test/tests_engine/energy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def error(ene,ene_ok):
5353
value = abs(ene[num] - ene_ok[num])
5454
thre = 1e-2
5555
if tipo[num] == "Total energy":
56-
thre = 1e-4
56+
thre = 1.5e-4
5757
if value > thre:
5858
scr = -1
5959
print "Error in",tipo[num]

0 commit comments

Comments
 (0)