Improvements to TestHarness for #402

Now using openmc.executor.  Plot tests use hashed results.
This commit is contained in:
Sterling Harper 2015-06-28 13:23:24 -06:00
parent f13351f2ee
commit 647d39f41e
17 changed files with 541 additions and 88 deletions

View file

@ -253,15 +253,14 @@ foreach(test ${TESTS})
# Preform a parallel test
add_test(NAME ${TEST_NAME}
WORKING_DIRECTORY ${TEST_PATH}
COMMAND ${PYTHON_EXECUTABLE} ${TEST_NAME} --exe $<TARGET_FILE:openmc>
--mpi_exec $ENV{MPI_DIR}/bin/mpiexec)
COMMAND ${PYTHON_EXECUTABLE} ${TEST_NAME} --mpi_exec)
else(${MPI_ENABLED})
# Perform a serial test
add_test(NAME ${TEST_NAME}
WORKING_DIRECTORY ${TEST_PATH}
COMMAND ${PYTHON_EXECUTABLE} ${TEST_NAME} --exe $<TARGET_FILE:openmc>)
COMMAND ${PYTHON_EXECUTABLE} ${TEST_NAME})
endif(${MPI_ENABLED})

View file

@ -27,6 +27,9 @@ class Executor(object):
if line == '' and p.poll() != None:
break
# Return the returncode (integer, zero if no problems encountered)
return p.returncode
@property
def working_directory(self):
@ -50,7 +53,7 @@ class Executor(object):
def plot_geometry(self, output=True):
self._run_openmc('openmc -p', output)
return self._run_openmc('openmc -p', output)
def run_simulation(self, particles=None, threads=None,
@ -80,4 +83,4 @@ class Executor(object):
command = pre_args + 'openmc ' + post_args
self._run_openmc(command, output)
return self._run_openmc(command, output)

View file

@ -1 +1 @@
4ad951a83e28329502830b4161d2b78173768b6d7c8906e5c97aaaa4c3f6e8266762d72fe133a380aa8fae2d2ef85b7cb20be94597b99a72736f9f5c8152555e
f5873c6ca03a2c75f5094b7297059285788bb93c450466606914805cdb24fd2664c3872ed42a8c6665a272070ab6b08b0a53b02612bcd993e10329aec2f1d313

View file

@ -20,15 +20,14 @@ class DistribcellTestHarness(TestHarness):
try:
dirs = ('case-1', '../case-2', '../case-3')
sps = ('statepoint.1.*', 'statepoint.1.*', 'statepoint.3.*')
tallies_present = (True, True, False)
tallies_out_present = (True, True, False)
hash_out = (False, False, True)
for i in range(len(dirs)):
os.chdir(dirs[i])
self._sp_name = sps[i]
self._tallies = tallies_present[i]
self._run_openmc()
self._test_output_created()
self._test_output_created(tallies_out_present[i])
results = self._get_results(hash_out[i])
self._write_results(results)
self._compare_results()
@ -38,6 +37,18 @@ class DistribcellTestHarness(TestHarness):
os.chdir(dirs[i])
self._cleanup()
def _test_output_created(self, tallies_out_present):
"""Make sure statepoint.* and tallies.out have been created."""
statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))
assert len(statepoint) == 1, 'Either multiple or no statepoint files ' \
'exist.'
assert statepoint[0].endswith('binary') \
or statepoint[0].endswith('h5'), \
'Statepoint file is not a binary or hdf5 file.'
if tallies_out_present:
assert os.path.exists(os.path.join(os.getcwd(), 'tallies.out')), \
'Tally output file does not exist.'
if __name__ == '__main__':
harness = DistribcellTestHarness()

View file

@ -0,0 +1 @@
d0a8c3cd2eb2b73430e0fcac2f5249c012ba678d08add40fc43563332e71873977b2271d1e93ba42b3c1298f987f7d01406f60115d2f1c0879d140a11b909598

View file

@ -6,5 +6,5 @@ from testing_harness import PlotTestHarness
if __name__ == '__main__':
harness = PlotTestHarness('statepoint.10.*', True)
harness = PlotTestHarness(('1_plot.ppm', ))
harness.execute_test()

View file

@ -0,0 +1 @@
8953968071de7c660f8ce07a28b11bb7c37d7150dd2bfd800483e0f76e021d279b100560faf1fb0cd9b8398a1f86b6166ea21f331f265fcf8662b35e70359cad

View file

@ -6,5 +6,5 @@ from testing_harness import PlotTestHarness
if __name__ == '__main__':
harness = PlotTestHarness('statepoint.10.*', True)
harness = PlotTestHarness(('1_plot.ppm', '2_plot.ppm', '3_plot.ppm'))
harness.execute_test()

View file

@ -0,0 +1 @@
32acbbd7b0f777589b108333e4928b6ecd93bc9e553b04cc611da4079ff8738a03dd0667e7e17161708fde86180532f19907272356d23e8a827a736a5b4a697a

View file

@ -6,5 +6,5 @@ from testing_harness import PlotTestHarness
if __name__ == '__main__':
harness = PlotTestHarness('statepoint.10.*', True)
harness = PlotTestHarness(('1_plot.ppm', ))
harness.execute_test()

View file

@ -0,0 +1 @@
a32df9c5ab026c40d1b81e303da38cad9a1a6263165087539520d892d0a9cb40193f94f2f5f4d9c94e7e9208121847099bf0c47694d3fc1d01c9e4f57555208b

View file

@ -6,5 +6,5 @@ from testing_harness import PlotTestHarness
if __name__ == '__main__':
harness = PlotTestHarness('statepoint.10.*', True)
harness = PlotTestHarness(('1_plot.ppm', '2_plot.ppm', '3_plot.ppm'))
harness.execute_test()

View file

@ -1 +1,448 @@
0683f96913bb317c6179de78ecb8fafee5aa12cf5bfc6026c25be0728d691cb9ed388280a57724a961877d4779cd3d382d759ba1c8246cc1015c42a7bc252bd9
k-combined:
1.093844E+00 1.626801E-02
tally 1:
3.403102E+01
2.393236E+02
1.143060E+01
2.704386E+01
5.691243E+01
6.685581E+02
2.924945E+01
1.782032E+02
9.965051E+00
2.067319E+01
4.931805E+01
5.050490E+02
tally 2:
3.403102E+01
2.393236E+02
-3.055588E-01
3.594044E-02
3.171128E-01
3.805380E-01
-7.374877E-01
2.391349E-01
-1.621986E-01
5.578051E-02
4.710459E-01
1.850595E-01
-4.839599E-01
2.440735E-01
1.124798E-01
8.640649E-02
-4.976706E-01
8.943606E-02
1.323704E-01
6.713903E-02
-6.954103E-02
7.876989E-02
1.343675E-01
2.569171E-02
-5.205013E-01
7.985579E-02
2.037295E-01
1.501360E-01
-1.290735E-01
5.069422E-02
-2.045060E-01
2.197889E-01
1.307603E-01
5.938649E-02
-3.317004E-01
1.359233E-01
-4.347480E-01
7.528253E-02
7.685982E-02
4.559715E-02
-4.668783E-02
4.065614E-02
1.447872E-01
5.538956E-02
-2.027337E-01
7.095051E-02
-4.673353E-01
1.235371E-01
-3.321732E-01
6.905624E-02
-3.028859E-01
3.382353E-02
-2.320613E-01
2.845905E-02
8.038034E-02
3.466746E-02
1.766484E-01
9.996559E-02
3.385184E-02
5.510769E-02
6.952638E-02
2.741119E-02
3.630715E-01
5.336447E-02
2.876222E-01
9.938256E-02
-3.473240E-02
1.031412E-01
1.280013E-01
2.331384E-02
1.550774E-01
3.881493E-02
1.143060E+01
2.704386E+01
-1.955516E-01
9.789273E-03
4.070150E-02
3.530892E-02
-1.446334E-01
3.374966E-02
-4.072015E-02
1.407320E-02
1.056190E-01
2.144988E-02
-1.491728E-01
1.699068E-02
3.130539E-02
4.945783E-03
-1.706770E-01
6.943395E-03
6.278466E-02
4.522701E-03
-6.491915E-02
1.218265E-02
-6.226375E-02
8.920919E-03
-2.647477E-01
2.028918E-02
-9.179913E-03
1.186941E-02
-8.959288E-02
9.826050E-03
-4.800079E-02
3.500548E-02
9.919028E-02
1.278789E-02
-1.274511E-01
9.357942E-03
-9.037073E-02
4.686665E-03
-7.895199E-03
8.526809E-03
-2.071828E-02
5.844892E-03
-1.422877E-02
2.008170E-03
-7.787500E-02
9.642363E-03
-6.105504E-02
7.600775E-03
-1.249117E-01
1.314509E-02
-9.183605E-02
7.513215E-03
-9.171222E-02
4.220465E-03
8.798390E-02
5.037482E-03
4.366496E-02
8.411743E-03
1.605678E-02
6.994512E-03
-2.179875E-02
1.352098E-03
1.116755E-01
7.354423E-03
9.995739E-02
9.710025E-03
3.010324E-02
1.179938E-02
2.175816E-02
1.281441E-03
2.374886E-02
6.943432E-03
5.691243E+01
6.685581E+02
-7.130295E-01
1.971869E-01
1.138602E+00
1.071873E+00
-1.436194E+00
7.200870E-01
-2.384966E-01
1.129688E-01
8.003085E-01
5.809429E-01
-3.499868E-01
3.310435E-01
2.580763E-01
2.238385E-01
-3.576056E-01
1.437071E-01
2.560747E-01
4.492224E-02
-4.006295E-01
2.456809E-01
8.176054E-02
3.924768E-01
-8.105689E-01
2.397175E-01
3.777117E-01
4.811523E-01
-4.932440E-01
1.789106E-01
-3.705747E-02
5.517840E-01
7.049764E-01
4.243943E-01
-4.833188E-01
2.014189E-01
-5.420278E-01
1.201572E-01
7.606098E-02
1.451071E-01
2.244026E-01
7.628680E-02
2.495758E-01
1.882655E-01
-1.373888E-01
1.958724E-01
-3.799191E-01
2.258678E-01
-5.909625E-01
2.940322E-01
-6.336238E-01
1.272552E-01
-5.544697E-01
9.027652E-02
4.161023E-01
1.084744E-01
5.550548E-01
1.838427E-01
3.060033E-01
8.542356E-02
3.623817E-01
4.245612E-02
4.779023E-01
8.081477E-02
1.089872E-01
1.402042E-01
-1.107440E-01
3.140479E-01
2.333168E-01
1.035674E-01
-5.959476E-02
2.482914E-01
2.924945E+01
1.782032E+02
5.986907E-01
4.163713E-01
3.376452E-01
1.744277E-01
1.272993E-01
1.526084E-01
-2.551267E-01
7.284601E-02
4.755790E-02
6.832796E-02
-3.425133E-01
7.756266E-02
3.823240E-01
1.789133E-01
-3.767347E-01
1.676013E-01
1.655399E-01
1.153056E-01
1.432265E-01
2.956364E-02
-2.989439E-01
5.066565E-02
-3.226047E-02
5.960686E-02
-9.968550E-02
4.039270E-02
-1.235292E-02
2.805714E-01
-7.494860E-02
2.838999E-02
3.042503E-02
7.425538E-02
-1.849034E-01
8.599532E-02
-5.209242E-01
1.174277E-01
-2.314402E-01
4.065974E-02
-4.179560E-01
1.382716E-01
1.026654E-01
1.611177E-02
-2.270386E-01
5.157513E-02
7.884296E-02
2.677093E-02
7.284620E-01
1.871262E-01
1.360134E-01
9.437336E-03
-3.088199E-01
2.292832E-02
-2.543226E-01
1.264440E-01
6.256788E-02
7.604299E-02
-3.478518E-01
6.632508E-02
2.842847E-01
4.906462E-02
1.546241E-01
3.362908E-02
-2.247690E-01
1.912574E-02
-3.459210E-02
1.248892E-01
-2.204075E-01
4.281299E-02
2.145675E-01
5.593188E-02
9.965051E+00
2.067319E+01
2.381967E-01
4.786935E-02
-1.924307E-02
4.029344E-02
3.179175E-02
2.098033E-02
-1.652307E-02
9.391525E-03
-5.733037E-02
1.788394E-02
4.942155E-02
1.206623E-03
1.874859E-02
1.917059E-02
-1.179838E-01
2.185564E-02
-9.270518E-03
1.659002E-02
7.496510E-02
6.849931E-03
-1.004441E-01
4.570271E-03
-9.899603E-02
1.027435E-02
-9.963859E-02
4.686519E-03
-1.740638E-02
3.936514E-02
2.520348E-02
5.900520E-03
1.227791E-03
6.173783E-03
-3.068441E-02
6.867403E-03
-7.765653E-02
1.399383E-02
7.333551E-02
4.139444E-03
-3.508914E-02
1.421599E-02
4.334120E-02
4.918888E-03
-1.106116E-01
1.143785E-02
7.254492E-03
1.337966E-03
2.365948E-01
2.473485E-02
5.176646E-02
1.514750E-03
-8.723609E-02
2.395099E-03
-1.010207E-01
1.081070E-02
-5.113298E-02
6.053279E-03
-1.601115E-01
8.304230E-03
-5.105346E-03
5.079654E-03
-8.894549E-02
2.505026E-03
-1.023874E-01
4.311776E-03
7.972835E-02
1.178305E-02
-2.560943E-02
4.101793E-03
2.312203E-02
3.036209E-03
4.931805E+01
5.050490E+02
1.513494E+00
1.676567E+00
6.650656E-01
1.400732E+00
4.934620E-01
7.673322E-01
-2.964444E-02
2.262500E-01
-2.225956E-01
4.872938E-01
2.498269E-01
9.442256E-02
-1.454141E-01
2.683171E-01
-3.720260E-01
2.266316E-01
2.473591E-01
3.624408E-01
2.096941E-01
6.664835E-02
-4.700220E-01
9.789465E-02
-1.626165E-01
1.315362E-01
3.519966E-01
1.140516E-01
-1.185342E-01
5.708362E-01
-1.333083E-01
1.352294E-01
1.375803E-01
1.572243E-01
-6.099544E-02
2.042264E-01
-3.664336E-01
1.762506E-01
-1.717957E-01
5.864778E-02
-5.153204E-01
2.484316E-01
-2.258513E-01
8.839687E-02
-9.307566E-01
4.802462E-01
1.108577E-01
4.451362E-02
1.118965E+00
5.173979E-01
4.314600E-01
5.176751E-02
-2.864060E-01
9.159895E-02
-4.471918E-01
1.743046E-01
-7.850808E-02
1.317732E-01
-7.445394E-01
1.479808E-01
7.480873E-01
2.696289E-01
1.731449E-01
5.301367E-02
-3.663464E-01
3.430563E-02
3.553351E-01
2.051544E-01
-4.312304E-01
2.164291E-01
2.436515E-01
8.025128E-02

View file

@ -2,9 +2,9 @@
import sys
sys.path.insert(0, '..')
from testing_harness import HashedTestHarness
from testing_harness import TestHarness
if __name__ == '__main__':
harness = HashedTestHarness('statepoint.10.*', True)
harness = TestHarness('statepoint.10.*', True)
harness.execute_test()

View file

@ -65,19 +65,22 @@ class SourceFileTestHarness(TestHarness):
'Source file is not a binary or hdf5 file.'
def _run_openmc_restart(self):
# Get the number of MPI processes.
if self._opts.mpi_exec:
mpi_procs = self._opts.mpi_np
else:
mpi_procs = 1
# Get the name of the source file.
source = glob.glob(os.path.join(os.getcwd(), 'source.10.*'))
# Write the new settings.xml file.
with open('settings.xml','w') as fh:
fh.write(settings2.format(source[0].split('.')[-1]))
if self._opts.mpi_exec != '':
proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
self._opts.exe, os.getcwd()],
stderr=STDOUT, stdout=PIPE)
else:
proc = Popen([self._opts.exe, os.getcwd()],
stderr=STDOUT, stdout=PIPE)
print(proc.communicate()[0])
returncode = proc.returncode
# Run OpenMC.
executor = Executor()
returncode = executor.run_simulation(mpi_procs=mpi_procs)
assert returncode == 0, 'OpenMC did not exit successfully.'
def _cleanup(self):

View file

@ -15,13 +15,7 @@ class StatepointRestartTestHarness(TestHarness):
self._write_results(results)
self._compare_results()
self._run_openmc_restart1()
self._test_output_created()
results = self._get_results()
self._write_results(results)
self._compare_results()
self._run_openmc_restart2()
self._run_openmc_restart()
self._test_output_created()
results = self._get_results()
self._write_results(results)
@ -29,32 +23,20 @@ class StatepointRestartTestHarness(TestHarness):
finally:
self._cleanup()
def _run_openmc_restart1(self):
def _run_openmc_restart(self):
# Get the number of MPI processes.
if self._opts.mpi_exec:
mpi_procs = self._opts.mpi_np
else:
mpi_procs = 1
# Get the name of the statepoint file.
statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))
if self._opts.mpi_exec != '':
proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
self._opts.exe, '-r', statepoint[0], os.getcwd()],
stderr=STDOUT, stdout=PIPE)
else:
proc = Popen([self._opts.exe, '-r', statepoint[0], os.getcwd()],
stderr=STDOUT, stdout=PIPE)
print(proc.communicate()[0])
returncode = proc.returncode
assert returncode == 0, 'OpenMC did not exit successfully.'
def _run_openmc_restart2(self):
statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))
if self._opts.mpi_exec != '':
proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
self._opts.exe, '--restart', statepoint[0],
os.getcwd()], stderr=STDOUT, stdout=PIPE)
else:
proc = Popen([self._opts.exe, '--restart', statepoint[0],
os.getcwd()], stderr=STDOUT, stdout=PIPE)
print(proc.communicate()[0])
returncode = proc.returncode
# Run OpenMC
executor = Executor()
returncode = executor.run_simulation(mpi_procs=mpi_procs,
restart_file=statepoint)
assert returncode == 0, 'OpenMC did not exit successfully.'

View file

@ -12,6 +12,7 @@ import numpy as np
sys.path.insert(0, '../..')
from openmc.statepoint import StatePoint
from openmc.executor import Executor
import openmc.particle_restart as pr
@ -37,24 +38,19 @@ class TestHarness(object):
def _parse_args(self):
parser = OptionParser()
parser.add_option('--mpi_exec', dest='mpi_exec', default='')
parser.add_option('--mpi_exec', dest='mpi_exec', action='store_true',
default=False)
parser.add_option('--mpi_np', dest='mpi_np', default='3')
parser.add_option('--exe', dest='exe')
(self._opts, self._args) = parser.parse_args()
if self._opts.exe is None:
raise Exception('Must specify OpenMC executable from command line '
'with --exe.')
def _run_openmc(self):
if self._opts.mpi_exec != '':
proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
self._opts.exe, os.getcwd()],
stderr=STDOUT, stdout=PIPE)
if self._opts.mpi_exec:
mpi_procs = self._opts.mpi_np
else:
proc = Popen([self._opts.exe, os.getcwd()],
stderr=STDOUT, stdout=PIPE)
print(proc.communicate()[0])
returncode = proc.returncode
mpi_procs = 1
executor = Executor()
returncode = executor.run_simulation(mpi_procs=mpi_procs)
assert returncode == 0, 'OpenMC did not exit successfully.'
def _test_output_created(self):
@ -132,31 +128,21 @@ class HashedTestHarness(TestHarness):
class PlotTestHarness(TestHarness):
"""Specialized TestHarness for running OpenMC plotting tests."""
def execute_test(self):
"""Run OpenMC with the appropriate arguments and check the outputs."""
self._parse_args()
try:
self._run_openmc()
self._test_output_created()
finally:
self._cleanup()
def __init__(self, plot_names):
self._plot_names = plot_names
self._opts = None
self._args = None
def _run_openmc(self):
if self._opts.mpi_exec != '':
proc = Popen([self._opts.mpi_exec, '-np', self._opts.mpi_np,
self._opts.exe, '-p', os.getcwd()],
stderr=STDOUT, stdout=PIPE)
else:
proc = Popen([self._opts.exe, '-p', os.getcwd()],
stderr=STDOUT, stdout=PIPE)
print(proc.communicate()[0])
returncode = proc.returncode
executor = Executor()
returncode = executor.plot_geometry()
assert returncode == 0, 'OpenMC did not exit successfully.'
def _test_output_created(self):
"""Make sure *.ppm has been created."""
assert os.path.exists(os.path.join(os.getcwd(), '1_plot.ppm')), \
'Plot output file does not exist.'
for fname in self._plot_names:
assert os.path.exists(os.path.join(os.getcwd(), fname)), \
'Plot output file does not exist.'
def _cleanup(self):
TestHarness._cleanup(self)
@ -165,6 +151,24 @@ class PlotTestHarness(TestHarness):
if os.path.exists(f):
os.remove(f)
def _get_results(self):
"""Return a string hash of the plot files."""
# Find the plot files.
plot_files = glob.glob(os.path.join(os.getcwd(), '*.ppm'))
# Read the plot files.
outstr = bytes()
for fname in plot_files:
with open(fname, 'rb') as fh:
outstr += fh.read()
# Hash the information and return.
sha512 = hashlib.sha512()
sha512.update(outstr)
outstr = sha512.hexdigest()
return outstr
class CMFDTestHarness(TestHarness):
"""Specialized TestHarness for running OpenMC CMFD tests."""