mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Fix command-line arguments for regression tests
This commit is contained in:
parent
740f03fce1
commit
0d3845c327
9 changed files with 75 additions and 63 deletions
17
tests/conftest.py
Normal file
17
tests/conftest.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from tests.regression_tests import config as regression_config
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption('--exe')
|
||||
parser.addoption('--mpi', action='store_true')
|
||||
parser.addoption('--mpiexec')
|
||||
parser.addoption('--mpi-np')
|
||||
parser.addoption('--update', action='store_true')
|
||||
parser.addoption('--build-inputs', action='store_true')
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
opts = ['exe', 'mpi', 'mpiexec', 'mpi_np', 'update', 'build_inputs']
|
||||
for opt in opts:
|
||||
if config.getoption(opt) is not None:
|
||||
regression_config[opt] = config.getoption(opt)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# Test configuration options for regression tests
|
||||
config = {
|
||||
'exe': 'openmc',
|
||||
'mpi': False,
|
||||
'mpiexec': 'mpiexec',
|
||||
'mpi_np': '2',
|
||||
'update': False,
|
||||
'build_inputs': False
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import numpy as np
|
|||
import openmc
|
||||
|
||||
from tests.testing_harness import PyAPITestHarness
|
||||
from tests.regression_tests import config
|
||||
|
||||
# OpenMC simulation parameters
|
||||
batches = 10
|
||||
|
|
@ -133,24 +134,18 @@ class MGXSTestHarness(PyAPITestHarness):
|
|||
for case in cases:
|
||||
build_mgxs_library(case)
|
||||
|
||||
if self._opts.mpi_exec is not None:
|
||||
mpi_args = [self._opts.mpi_exec, '-n', self._opts.mpi_np]
|
||||
openmc.run(openmc_exec=self._opts.exe, mpi_args=mpi_args)
|
||||
if config['mpi']:
|
||||
mpi_args = [config['mpiexec'], '-n', config['mpi_np']]
|
||||
openmc.run(openmc_exec=config['exe'], mpi_args=mpi_args)
|
||||
|
||||
else:
|
||||
openmc.run(openmc_exec=self._opts.exe)
|
||||
openmc.run(openmc_exec=config['exe'])
|
||||
|
||||
sp = openmc.StatePoint('statepoint.' + str(batches) + '.h5')
|
||||
|
||||
# Write out k-combined.
|
||||
outstr += 'k-combined:\n'
|
||||
form = '{0:12.6E} {1:12.6E}\n'
|
||||
outstr += form.format(sp.k_combined[0], sp.k_combined[1])
|
||||
|
||||
# Enforce closing statepoint and summary files so HDF5
|
||||
# does not throw an error during the next OpenMC execution
|
||||
sp._f.close()
|
||||
sp._summary._f.close()
|
||||
with openmc.StatePoint('statepoint.{}.h5'.format(batches)) as sp:
|
||||
# Write out k-combined.
|
||||
outstr += 'k-combined:\n'
|
||||
form = '{0:12.6E} {1:12.6E}\n'
|
||||
outstr += form.format(sp.k_combined[0], sp.k_combined[1])
|
||||
|
||||
return outstr
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import openmc.mgxs
|
|||
from openmc.examples import pwr_pin_cell
|
||||
|
||||
from tests.testing_harness import PyAPITestHarness
|
||||
from tests.regression_tests import config
|
||||
|
||||
|
||||
class MGXSTestHarness(PyAPITestHarness):
|
||||
|
|
@ -31,11 +32,11 @@ class MGXSTestHarness(PyAPITestHarness):
|
|||
|
||||
def _run_openmc(self):
|
||||
# Initial run
|
||||
if self._opts.mpi_exec is not None:
|
||||
mpi_args = [self._opts.mpi_exec, '-n', self._opts.mpi_np]
|
||||
openmc.run(openmc_exec=self._opts.exe, mpi_args=mpi_args)
|
||||
if config['mpi']:
|
||||
mpi_args = [config['mpiexec'], '-n', config['mpi_np']]
|
||||
openmc.run(openmc_exec=config['exe'], mpi_args=mpi_args)
|
||||
else:
|
||||
openmc.run(openmc_exec=self._opts.exe)
|
||||
openmc.run(openmc_exec=config['exe'])
|
||||
|
||||
# Build MG Inputs
|
||||
# Get data needed to execute Library calculations.
|
||||
|
|
@ -63,11 +64,11 @@ class MGXSTestHarness(PyAPITestHarness):
|
|||
sp._summary._f.close()
|
||||
|
||||
# Re-run MG mode.
|
||||
if self._opts.mpi_exec is not None:
|
||||
mpi_args = [self._opts.mpi_exec, '-n', self._opts.mpi_np]
|
||||
openmc.run(openmc_exec=self._opts.exe, mpi_args=mpi_args)
|
||||
if config['mpi']:
|
||||
mpi_args = [config['mpiexec'], '-n', config['mpi_np']]
|
||||
openmc.run(openmc_exec=config['exe'], mpi_args=mpi_args)
|
||||
else:
|
||||
openmc.run(openmc_exec=self._opts.exe)
|
||||
openmc.run(openmc_exec=config['exe'])
|
||||
|
||||
def _cleanup(self):
|
||||
super(MGXSTestHarness, self)._cleanup()
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import h5py
|
|||
import openmc
|
||||
|
||||
from tests.testing_harness import TestHarness
|
||||
from tests.regression_tests import config
|
||||
|
||||
|
||||
class PlotTestHarness(TestHarness):
|
||||
|
|
@ -15,20 +16,18 @@ class PlotTestHarness(TestHarness):
|
|||
self._plot_names = plot_names
|
||||
|
||||
def _run_openmc(self):
|
||||
openmc.plot_geometry(openmc_exec=self._opts.exe)
|
||||
openmc.plot_geometry(openmc_exec=config['exe'])
|
||||
|
||||
def _test_output_created(self):
|
||||
"""Make sure *.ppm has been created."""
|
||||
for fname in self._plot_names:
|
||||
assert os.path.exists(os.path.join(os.getcwd(), fname)), \
|
||||
'Plot output file does not exist.'
|
||||
assert os.path.exists(fname), 'Plot output file does not exist.'
|
||||
|
||||
def _cleanup(self):
|
||||
super(PlotTestHarness, self)._cleanup()
|
||||
for fname in self._plot_names:
|
||||
path = os.path.join(os.getcwd(), fname)
|
||||
if os.path.exists(path):
|
||||
os.remove(path)
|
||||
if os.path.exists(fname):
|
||||
os.remove(fname)
|
||||
|
||||
def _get_results(self):
|
||||
"""Return a string hash of the plot files."""
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import os
|
|||
import openmc
|
||||
|
||||
from tests.testing_harness import TestHarness
|
||||
from tests.regression_tests import config
|
||||
|
||||
|
||||
class StatepointRestartTestHarness(TestHarness):
|
||||
|
|
@ -46,12 +47,12 @@ class StatepointRestartTestHarness(TestHarness):
|
|||
statepoint = statepoint[0]
|
||||
|
||||
# Run OpenMC
|
||||
if self._opts.mpi_exec is not None:
|
||||
mpi_args = [self._opts.mpi_exec, '-n', self._opts.mpi_np]
|
||||
openmc.run(restart_file=statepoint, openmc_exec=self._opts.exe,
|
||||
if config['mpi']:
|
||||
mpi_args = [config['mpiexec'], '-n', config['mpi_np']]
|
||||
openmc.run(restart_file=statepoint, openmc_exec=config['exe'],
|
||||
mpi_args=mpi_args)
|
||||
else:
|
||||
openmc.run(openmc_exec=self._opts.exe, restart_file=statepoint)
|
||||
openmc.run(openmc_exec=config['exe'], restart_file=statepoint)
|
||||
|
||||
|
||||
def test_statepoint_restart():
|
||||
|
|
|
|||
|
|
@ -10,29 +10,21 @@ import shutil
|
|||
import sys
|
||||
|
||||
import numpy as np
|
||||
|
||||
import openmc
|
||||
from openmc.examples import pwr_core
|
||||
|
||||
from tests.regression_tests import config
|
||||
|
||||
|
||||
class TestHarness(object):
|
||||
"""General class for running OpenMC regression tests."""
|
||||
|
||||
def __init__(self, statepoint_name):
|
||||
self._sp_name = statepoint_name
|
||||
self.parser = OptionParser()
|
||||
self.parser.add_option('--exe', dest='exe', default='openmc')
|
||||
self.parser.add_option('--mpi_exec', dest='mpi_exec', default=None)
|
||||
self.parser.add_option('--mpi_np', dest='mpi_np', default='2')
|
||||
self.parser.add_option('--update', dest='update', action='store_true',
|
||||
default=False)
|
||||
self._opts = None
|
||||
self._args = None
|
||||
|
||||
def main(self):
|
||||
"""Accept commandline arguments and either run or update tests."""
|
||||
(self._opts, self._args) = self.parser.parse_args()
|
||||
if self._opts.update:
|
||||
if config['update']:
|
||||
self.update_results()
|
||||
else:
|
||||
self.execute_test()
|
||||
|
|
@ -60,11 +52,11 @@ class TestHarness(object):
|
|||
self._cleanup()
|
||||
|
||||
def _run_openmc(self):
|
||||
if self._opts.mpi_exec is not None:
|
||||
openmc.run(openmc_exec=self._opts.exe,
|
||||
mpi_args=[self._opts.mpi_exec, '-n', self._opts.mpi_np])
|
||||
if config['mpi']:
|
||||
mpi_args = [config['mpiexec'], '-n', config['mpi_np']]
|
||||
openmc.run(openmc_exec=config['exe'], mpi_args=mpi_args)
|
||||
else:
|
||||
openmc.run(openmc_exec=self._opts.exe)
|
||||
openmc.run(openmc_exec=config['exe'])
|
||||
|
||||
def _test_output_created(self):
|
||||
"""Make sure statepoint.* and tallies.out have been created."""
|
||||
|
|
@ -179,9 +171,9 @@ class ParticleRestartTestHarness(TestHarness):
|
|||
|
||||
def _run_openmc(self):
|
||||
# Set arguments
|
||||
args = {'openmc_exec': self._opts.exe}
|
||||
if self._opts.mpi_exec is not None:
|
||||
args['mpi_args'] = [self._opts.mpi_exec, '-n', self._opts.mpi_np]
|
||||
args = {'openmc_exec': config['exe']}
|
||||
if config['mpi']:
|
||||
args['mpi_args'] = [config['mpiexec'], '-n', config['mpi_np']]
|
||||
|
||||
# Initial run
|
||||
openmc.run(**args)
|
||||
|
|
@ -231,8 +223,6 @@ class ParticleRestartTestHarness(TestHarness):
|
|||
class PyAPITestHarness(TestHarness):
|
||||
def __init__(self, statepoint_name, model=None):
|
||||
super(PyAPITestHarness, self).__init__(statepoint_name)
|
||||
self.parser.add_option('-b', '--build-inputs', dest='build_only',
|
||||
action='store_true', default=False)
|
||||
if model is None:
|
||||
self._model = pwr_core()
|
||||
else:
|
||||
|
|
@ -242,10 +232,9 @@ class PyAPITestHarness(TestHarness):
|
|||
|
||||
def main(self):
|
||||
"""Accept commandline arguments and either run or update tests."""
|
||||
(self._opts, self._args) = self.parser.parse_args()
|
||||
if self._opts.build_only:
|
||||
if config['build_inputs']:
|
||||
self._build_inputs()
|
||||
elif self._opts.update:
|
||||
elif config['update']:
|
||||
self.update_results()
|
||||
else:
|
||||
self.execute_test()
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import openmc.capi
|
|||
@pytest.fixture(scope='module')
|
||||
def pincell_model():
|
||||
"""Set up a model to test with and delete files when done"""
|
||||
openmc.reset_auto_ids()
|
||||
pincell = openmc.examples.pwr_pin_cell()
|
||||
|
||||
# Add a tally
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
# Run regression test suite
|
||||
cd build
|
||||
ctest
|
||||
|
||||
# Run source check
|
||||
cd ../tests
|
||||
cd tests
|
||||
if [[ $TRAVIS_PYTHON_VERSION == "3.4" && $OMP == 'n' && $MPI == 'n' ]]; then
|
||||
./check_source.py
|
||||
fi
|
||||
|
||||
# Run unit tests
|
||||
pytest --cov=../openmc -v unit_tests/
|
||||
# Run regression and unit tests
|
||||
if [[ $MPI == 'y' ]]; then
|
||||
pytest --cov=../openmc -v --mpi
|
||||
else
|
||||
pytest --cov=../openmc -v
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue