Demonstration of VaryRun¶
A Jupyter notebook to demonstrate usage of VaryRun in PROCESS.
VaryRun is a tool which takes an input file that does not converge and varies the initial values of the
iteration variables, within a tolerance, to find an initial point that converges, and creates
a new input file using these values.
VaryRun requires a .conf file which specifies certain parameters needed for VaryRun.
In this file, you specify the original input file, the maximum number of iterations to be performed, and a factor within which the iteration variables are changed.
If VaryRun is able to find a new initial point within the maximum number of iterations, it produces a new input file, called IN.DAT, in the same directory as your initial input file. This new file will now converge when you run PROCESS.
Setup¶
We run the examples in a temporary directory so all the inputs are copied there and the outputs contained there before the directory is removed when the example has finished
running. This keeps the examples directory tidy and does not permanently modify any data files. This use of temporary directories is not needed for regular use of PROCESS.
VaryRun setup¶
VaryRun requires a .conf file in order to run. An example .conf file is displayed below.
WDIRspecifies the path to the working directory wherePROCESSis being run, here is is.to run in the directory of the.conffile, which is inexamples/dataORIGINAL_IN_DATis providing the name of the original input fileNITERis specifying the maximum number of iterations to performSEEDis specifying a random number generator. Here it is set to 5 so the results of runningVaryRunon the original input file will always be the sameFACTORis specifying a factor within which the iteration variables will change. Here it is set to 1.5, so this means the iteration variables can be varied within 50% of their initial values in the original input file
* CONFIG FILE FOR RUNNING PROCESS WITH MODIFIED IN.DAT
*
* Path to working directory in which PROCESS is run.
WDIR = .
* original IN.DAT name (should not be called IN.DAT!)
ORIGINAL_IN_DAT = ORIGINAL_IN.DAT
* Max no. iterations
NITER = 30
* integer seed for random number generator; use None for random seed
SEED = 5
* factor within which the iteration variables are changed
FACTOR = 1.5
Run VaryRun¶
Run PROCESS on an input file using the VaryRun class. The initial input file, large_tokamak_varyrun_IN.DAT does not converge. VaryRun will vary the initial values of the iteration variables to find an initial point that converges, and will create a new input file, IN.DAT, with these new values.
%load_ext autoreload
%autoreload 2
import os
import shutil
import tempfile
from pathlib import Path
from process.core.io.mfile_utils import get_mfile_initial_ixc_values
from process.core.repository import get_process_root
from process.main import VaryRun
# Define project root dir; when running a notebook, the cwd is the dir the notebook is in
PROJ_DIR = Path.cwd().parent
# Path to files
data_dir = get_process_root() / "../examples/data/"
conf_file = data_dir / "run_process.conf"
input_file = data_dir / "large_tokamak_varyrun_IN.DAT"
temp_dir = tempfile.TemporaryDirectory()
input_path = Path(temp_dir.name) / "large_tokamak_IN.DAT"
conf_path = Path(temp_dir.name) / "run_process.conf"
shutil.copy(input_file, input_path)
shutil.copy(conf_file, conf_path)
# VaryRun uses process_config.py, which changes the current working directory
# via os.chdir() to the temporary dir. Apart from being bad practice, once the
# temp dir is removed, this causes Path.cwd() (as used in plot_scans.py) to
# throw an exception when trying to return the (now deleted) CWD. Hence it
# needs to be set back after VaryRun()
# TODO Remove the os.chdir() from VaryRun
cwd = Path.cwd()
vary_run = VaryRun(conf_path.as_posix())
vary_run.run()
os.chdir(cwd)
# Get the initial values from the original input file
iteration_variable_names, original_iteration_variable_values = (
get_mfile_initial_ixc_values(input_file)
)
# Get the initial values from the new input file produced by VaryRun
# 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) / "IN.DAT"
)
No comment in config file /tmp/tmp7qb73y6h/run_process.conf Working directory: /tmp/tmp7qb73y6h Original IN.DAT: /tmp/tmp7qb73y6h/large_tokamak_IN.DAT Number of iterations 30 random seed 5 variable range factor 1.5 Config file /tmp/tmp7qb73y6h/run_process.conf Comment no. allowed UNFEASIBLE points 0
/home/runner/work/PROCESS/PROCESS/process/core/init.py:92: UserWarning: Lower limit of volume averaged electron temperature (temp_plasma_electron_vol_avg_kev) has been raised to ensure temp_plasma_electron_vol_avg_kev > temp_plasma_pedestal_kev check_process(inputs) /home/runner/work/PROCESS/PROCESS/process/core/init.py:92: UserWarning: temp_cs_superconductor_margin_min and tmargmin should not both be specified in IN.DAT temp_cs_superconductor_margin_min has been ignored check_process(inputs)
************************************************************************************************************** ************************************************** PROCESS *************************************************** ************************************** Power Reactor Optimisation Code *************************************** ************************************************************************************************************** Version : 3.3.1.dev34+g6d036d5d5 Git Tag : v3.3.0-34-g6d036d5d Git Branch : main Date : 26/02/2026 UTC Time : 16:34 User : runner Computer : runnervmnay03 Directory : /tmp/tmp7qb73y6h Input : Run title : generic large tokamak Run type : Reactor concept design: Pulsed tokamak model, (c) UK Atomic Energy Authority ************************************************************************************************************** Equality constraints : 3 Inequality constraints : 23 Total constraints : 26 Iteration variables : 19 Max iterations : 200 Figure of merit : +1 -- minimise major radius Convergence parameter : 1e-07 ************************************************************************************************************** 0 PROCESS run started ...
finished.
WARNING: 1 non-feasible point(s) in sweep! Rerunning! 1 PROCESS run started ...
Error: There was a problem with the PROCESS execution! Command '['process', '-i', '/tmp/tmp7qb73y6h/IN.DAT', '--solver', 'vmcon']' returned non-zero exit status 1. Refer to the logfile for more information!
finished. PROCESS has stopped without finishing! 2 PROCESS run started ...
finished.
WARNING: 1 non-feasible point(s) in sweep! Rerunning! 3 PROCESS run started ...
finished.
WARNING: 1 non-feasible point(s) in sweep! Rerunning! 4 PROCESS run started ...
finished.
WARNING: 1 non-feasible point(s) in sweep! Rerunning! 5 PROCESS run started ...
Error: There was a problem with the PROCESS execution! Command '['process', '-i', '/tmp/tmp7qb73y6h/IN.DAT', '--solver', 'vmcon']' returned non-zero exit status 1. Refer to the logfile for more information!
finished. PROCESS has stopped without finishing! 6 PROCESS run started ...
finished.
There were warnings in the final PROCESS run. Please check the log file! The IN.DAT file does not contain any obsolete variables. ************************************************************************************************************** ************************************************** PROCESS *************************************************** ************************************** Power Reactor Optimisation Code *************************************** ************************************************************************************************************** Version : 3.3.1.dev34+g6d036d5d5 Git Tag : v3.3.0-34-g6d036d5d Git Branch : main Date : 26/02/2026 UTC Time : 16:35 User : runner Computer : runnervmnay03 Directory : /home/runner/work/PROCESS/PROCESS Input : /home/runner/work/PROCESS/PROCESS/examples/data/large_tokamak_varyrun_IN.DAT Run title : Generic large tokamak Run type : Reactor concept design: Pulsed tokamak model, (c) UK Atomic Energy Authority ************************************************************************************************************** Equality constraints : 3 Inequality constraints : 23 Total constraints : 26 Iteration variables : 19 Max iterations : 200 Figure of merit : +1 -- minimise major radius Convergence parameter : 1e-07 ************************************************************************************************************** The IN.DAT file does not contain any obsolete variables.
************************************************************************************************************** ************************************************** PROCESS *************************************************** ************************************** Power Reactor Optimisation Code *************************************** ************************************************************************************************************** Version : 3.3.1.dev34+g6d036d5d5 Git Tag : v3.3.0-34-g6d036d5d Git Branch : main Date : 26/02/2026 UTC Time : 16:35 User : runner Computer : runnervmnay03 Directory : /home/runner/work/PROCESS/PROCESS Input : /tmp/tmp7qb73y6h/IN.DAT Run title : generic large tokamak Run type : Reactor concept design: Pulsed tokamak model, (c) UK Atomic Energy Authority ************************************************************************************************************** Equality constraints : 3 Inequality constraints : 23 Total constraints : 26 Iteration variables : 19 Max iterations : 200 Figure of merit : +1 -- minimise major radius Convergence parameter : 1e-07 **************************************************************************************************************
/home/runner/work/PROCESS/PROCESS/process/core/init.py:92: UserWarning: Lower limit of volume averaged electron temperature (temp_plasma_electron_vol_avg_kev) has been raised to ensure temp_plasma_electron_vol_avg_kev > temp_plasma_pedestal_kev check_process(inputs) /home/runner/work/PROCESS/PROCESS/process/core/init.py:92: UserWarning: temp_cs_superconductor_margin_min and tmargmin should not both be specified in IN.DAT temp_cs_superconductor_margin_min has been ignored check_process(inputs)
Compare iteration variable values¶
VaryRun has changed the values of some iteration variables.
import pandas as pd
# Use pandas to display the values of the iteration variables before and after running VaryRun
df = pd.DataFrame({
"Iteration variable names": iteration_variable_names,
"Original values": original_iteration_variable_values,
"Updated values": updated_iteration_variable_values,
})
df
| Iteration variable names | Original values | Updated values | |
|---|---|---|---|
| 0 | b_plasma_toroidal_on_axis | 5.700000e+00 | 4.691456e+00 |
| 1 | rmajor | 8.000000e+00 | 8.823252e+00 |
| 2 | temp_plasma_electron_vol_avg_kev | 1.200000e+01 | 9.572595e+00 |
| 3 | beta_total_vol_avg | 3.000000e-02 | 3.012747e-02 |
| 4 | nd_plasma_electrons_vol_avg | 8.000000e+20 | 5.676209e+20 |
| 5 | hfact | 1.100000e+00 | 1.133752e+00 |
| 6 | dr_cs | 5.000000e-01 | 6.786659e-01 |
| 7 | q95 | 3.500000e+00 | 3.314526e+00 |
| 8 | dr_bore | 2.000000e+00 | 2.211844e+00 |
| 9 | f_c_plasma_non_inductive | 4.000000e-01 | 3.527138e-01 |
| 10 | t_tf_superconductor_quench | 2.500000e+01 | 2.691199e+01 |
| 11 | dr_tf_nose_case | 5.000000e-01 | 5.638358e-01 |
| 12 | dx_tf_turn_steel | 8.000000e-03 | 8.425048e-03 |
| 13 | f_a_tf_turn_cable_copper | 8.000000e-01 | 8.848461e-01 |
| 14 | c_tf_turn | 6.500000e+04 | 7.196741e+04 |
| 15 | f_nd_alpha_electron | 1.000000e-01 | 7.235617e-02 |
| 16 | f_a_cs_turn_steel | 8.000000e-01 | 5.533841e-02 |
| 17 | f_nd_impurity_electrons(13) | 3.800000e-04 | 3.800000e-04 |
| 18 | dr_tf_wp_with_insulation | 5.000000e-01 | 4.683058e-01 |
temp_dir.cleanup()