diff --git a/examples/data/large_tokamak_varyrun_IN.DAT b/examples/data/large_tokamak_varyrun_IN.DAT index 75e2a2759f..08b0f17df8 100644 --- a/examples/data/large_tokamak_varyrun_IN.DAT +++ b/examples/data/large_tokamak_varyrun_IN.DAT @@ -141,7 +141,7 @@ sig_tf_wp_max = 7.5E8 * Allowable maximum shear stress in TF coil conduit (Tr *---------------------* icc = 5 ixc = 6 * nd_plasma_electrons_vol_avg [m-3] -nd_plasma_electrons_vol_avg = 8E20 +nd_plasma_electrons_vol_avg = 6E19 * Neutron wall load upper limit * *-------------------------------* diff --git a/examples/vary_run_example.ex.py b/examples/vary_run_example.ex.py index 6e4d1b3018..b56b935279 100644 --- a/examples/vary_run_example.ex.py +++ b/examples/vary_run_example.ex.py @@ -100,6 +100,7 @@ # %autoreload 2 import os +import re import shutil import tempfile from pathlib import Path @@ -108,6 +109,7 @@ from process.core.repository import get_process_root from process.main import VaryRun +# %% # Path to files data_dir = get_process_root() / "../examples/data/" conf_file = data_dir / "run_process.conf" @@ -132,6 +134,21 @@ vary_run.run() os.chdir(cwd) +# %% +# Find the final file created, as this file converges +# VaryRun will raise an error if it does not find a converging input file +# within the maximum number of iterations +path_to_varyrun_files = Path(temp_dir.name) + +in_dats_created = [ + file.name + for file in path_to_varyrun_files.iterdir() + if re.match(r"([0-9]+)_IN.DAT", file.name) is not None +] + +final_file_prefix = max(int(name.strip("_IN.DAT")) for name in in_dats_created) +converging_in_dat = str(final_file_prefix) + "_IN.DAT" + # %% # Get the initial values from the original input file iteration_variable_names, original_iteration_variable_values = ( @@ -142,13 +159,14 @@ # VaryRun always produces a file called IN.DAT in the same directory # as the conf file _, updated_iteration_variable_values = get_mfile_initial_ixc_values( - Path(temp_dir.name) / "2_IN.DAT", vary_run.data + path_to_varyrun_files / converging_in_dat, vary_run.data ) # %% [markdown] # ## Compare iteration variable values # -# `VaryRun` has changed the values of some iteration variables. +# `VaryRun` has found a converging input file and has changed the initial values of the +# iteration variables: # %% import pandas as pd diff --git a/process/core/io/vary_run/config.py b/process/core/io/vary_run/config.py index 2b6f3f5f10..8d16de4a6e 100644 --- a/process/core/io/vary_run/config.py +++ b/process/core/io/vary_run/config.py @@ -14,6 +14,7 @@ from numpy.random import default_rng from process.core.data_structure.base import DataStructure +from process.core.exceptions import ProcessError from process.core.io.in_dat import InDat from process.core.io.mfile import MFile from process.core.io.vary_run.tools import ( @@ -262,7 +263,14 @@ def create_readme(self): Path(self.wdir, "README.txt").write_text(self.comment) def error_status2readme(self, mfile): - """Appends PROCESS outcome to README.txt if reached maximum iterations""" + """Appends PROCESS outcome to README.txt if reached maximum iterations + + Raises + ------ + ProcessError + If VaryRun does not find a converging IN.DAT within the maximum + number of iterations + """ m_file = MFile(filename=self.wdir / mfile) try: @@ -298,6 +306,8 @@ def error_status2readme(self, mfile): with open(Path(self.wdir, "README.txt"), "a") as readme: readme.write(error_status) print(ifail_msg) + if ifail != SolverOutputCondition.CONVERGED: + raise ProcessError(ifail_msg) def modify_in_dat(self): """Modifies the original IN.DAT file""" diff --git a/tests/integration/data/run_process.conf b/tests/integration/data/run_process.conf index 6abe2f7034..6f922eb729 100644 --- a/tests/integration/data/run_process.conf +++ b/tests/integration/data/run_process.conf @@ -22,18 +22,3 @@ FACTOR = 1.5 * Number of allowed unfeasible points that do not trigger rerunning. NO_ALLOWED_UNFEASIBLE = 0 - -* include a summary file with the iteration variables at each stage. -INCLUDE_ITERVAR_DIFF = True - -* add iteration variables - comma separated -ADD_IXC = - -* remove iteration variables - comma separated -DEL_IXC = - -* add constraint equations - comma separated -ADD_ICC = - -* remove constraint equations - comma separated -DEL_ICC =