Skip to content

Commit a6c8359

Browse files
committed
Resolve differences with testing to get consistent results in conda tests
1 parent fcf258e commit a6c8359

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

modules/stochastic_tools/test/tests/web_server_control/test_stochastic_controls_vpp.py

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,24 @@
77
# *
88
# * Licensed under LGPL 2.1, please see LICENSE for details
99
# * https://www.gnu.org/licenses/lgpl-2.1.html
10-
import numpy as np
11-
import sys
10+
"""
11+
This should be called by the test harness with sub.i input file.
12+
13+
The purpose is to test StochasticControl for perturbing input parameters and
14+
gathering results on-the-fly using the MOOSE WebServerControl for VPP style outputs.
15+
16+
It works by checking predefined matrices and running the STM with some
17+
benchmark problems. There is no
18+
"gold" file in this sense, it instead checks for syntax correctness.
19+
"""
20+
1221
import os
13-
import importlib
14-
import importlib.util
15-
import argparse
22+
import sys
1623
import shutil
24+
import numpy as np
25+
import argparse
26+
import importlib.util
27+
import importlib
1728

1829
StochasticControl = None
1930
StochasticRunOptions = None
@@ -62,46 +73,48 @@ def test_options():
6273
if __name__ == "__main__":
6374
options = {
6475
'input_name':'stochastic_run.i',
65-
'ignore_solve_not_converge':False
6676
}
6777
cmd = os.environ.get("RUNAPP_COMMAND")
6878
if cmd is None:
6979
sys.exit("Missing expected command variable RUNAPP_COMMAND")
7080
cmd = cmd.split()
71-
81+
# Gather MPI options if running with MPI
7282
if "-n" in cmd:
73-
mpi_index = cmd.index("-n")-1
83+
mpi_index = cmd.index("-n") - 1
7484
options["mpi_command"] = cmd[mpi_index]
75-
options["num_procs"] = int(cmd[mpi_index+2])
76-
exec_index = cmd.index("-i")-1
85+
options["num_procs"] = int(cmd[mpi_index + 2])
86+
# Get executable and input file based on position of '-i' argument
87+
exec_index = cmd.index("-i") - 1
7788
executable = cmd[exec_index]
78-
input_file = cmd[exec_index+2]
79-
options["cli_args"] = cmd[(exec_index + 3):]
89+
input_file = cmd[exec_index + 2]
90+
# Everything after the input is cli_args
91+
options["cli_args"] = cmd[(exec_index + 3) :]
8092

8193
if StochasticControl is None:
82-
_exec_dir = os.path.dirname(os.path.abspatch(shutil.which(executable)))
94+
_exec_dir = os.path.dirname(os.path.abspath(shutil.which(executable)))
8395
_share_dir = os.path.abspath(os.path.join(_exec_dir, "..", "share"))
84-
_moose_stm_python = os.path.join(_share_dir, "stochastic_tools","python")
96+
_moose_stm_python = os.path.join(_share_dir, "stochastic_tools", "python")
8597
_moose_python = os.path.join(_moose_stm_python,'..','..','..','python')
8698
if not (tryImportStochasticControl(_moose_python) and tryImportStochasticControl(_moose_stm_python)):
8799
raise ModuleNotFoundError("Could not find MOOSE stochastic tools module python utilities.")
88100

89101
if StochasticRunOptions.MultiAppMode.BATCH_RESET is not None:
90-
options['multiapp_mode'] = StochasticRunOptions.MultiAppMode.BATCH_RESET,
102+
options['multiapp_mode'] = StochasticRunOptions.MultiAppMode.BATCH_RESET
91103
cli_args = test_options()
92-
input_file_name = 'main_runner.i'
104+
parameters = ['capsule1:Postprocessors/frequency_factor/value',
105+
'capsule1:Postprocessors/activation_energy/value',
106+
'capsule1:BCs/heat_DRV_outer/value',
107+
'capsule1:mesh_specified'
108+
]
109+
qois = ['capsule_01/x', 'capsule_01/temp']
93110
input_file = 'vpp_test_runner.i'
94-
command_possibilities = []
95-
with StochasticControl(executable=executable,
96-
physics_input=input_file,
97-
options=StochasticRunOptions(**options),
98-
parameters=['capsule1:Postprocessors/frequency_factor/value',
99-
'capsule1:Postprocessors/activation_energy/value',
100-
'capsule1:BCs/heat_DRV_outer/value',
101-
'capsule1:mesh_specified'],
102-
quantities_of_interest=['capsule_01/x',
103-
'capsule_01/temp',
104-
]) as runner:
111+
with StochasticControl(
112+
executable=executable,
113+
physics_input=input_file,
114+
parameters=parameters,
115+
quantities_of_interest=qois,
116+
options=StochasticRunOptions(**options),
117+
) as runner:
105118
if cmd[exec_index+3]==0:
106119
runner.configCache(tol=[1,1e-10,1e-14,1e-14])
107120
elif cmd[exec_index+3]==1:

0 commit comments

Comments
 (0)