Comparing multiple PROCESS solutions (MFiles)¶
This tool plots the solution vectors (i.e. final values of optimisation parameters) for different runs of PROCESS. This allows visual comparisons of different solution points.
It can use different intra-solution optimisation parameter normalisations (e.g. initial value, parameter range) and inter-solution normalisations (e.g. normalise to a certain solution).
Known Limitations¶
- The solution vectors (optimisation parameter values at the solution) currently plotted are normalised to the initial point (from the
IN.DAT) of each solution: each element of the vector is the $x_{final}/x_{initial}$, thexcmxxxvalues in theMFILE.DAT. This allows all optimisation parameters to be plotted on the same axis, showing the relative changes from their initial values across multiple solutions. - Solutions being plotted together must also have the same optimisation parameters.
- The solutions plotted in this example are fictitious.
# Reload Process each time (keep editable install up-to-date)
%load_ext autoreload
%autoreload 2
from pathlib import Path
from process.io.plot_solutions import (
RunMetadata,
plot_mfile_solutions,
plot_mfile_solutions_constraints,
)
Plot single solution¶
Plot a single solution, showing optimisation parameters normalised to their initial values.
data_dir = Path("data")
runs_metadata = [
RunMetadata(data_dir / "large_tokamak_1_MFILE.DAT", "large tokamak 1"),
]
# Figure and dataframe returned for optional further modification
fig1, df1 = plot_mfile_solutions(
runs_metadata=runs_metadata,
plot_title="Large tokamak solution 1",
)
df1
| tag | minmax | objf_name | norm_objf | itvar001_name | xcm001 | itvar002_name | xcm002 | itvar003_name | xcm003 | ... | itvar039_name | xcm039 | itvar040_name | xcm040 | itvar041_name | xcm041 | itvar042_name | xcm042 | itvar043_name | xcm043 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | large tokamak 1 | 1.0 | major radius | 1.6 | b_plasma_toroidal_on_axis | 0.887772 | rmajor | 1.0 | temp_plasma_electron_vol_avg_kev | 1.04427 | ... | f_a_cs_turn_steel | 0.864261 | foh_stress | 0.999995 | f_nd_impurity_electrons(13) | 1.621696 | dr_tf_wp_with_insulation | 1.20536 | fne0 | 0.59638 |
1 rows × 90 columns
Plot two solutions¶
Plot two MFILEs together, showing normalised values of the optimisation parameters at the solution points, as well as the objective function values.
runs_metadata = [
RunMetadata(data_dir / "large_tokamak_1_MFILE.DAT", "large tokamak 1"),
RunMetadata(data_dir / "large_tokamak_2_MFILE.DAT", "large tokamak 2"),
]
fig2, df2 = plot_mfile_solutions(
runs_metadata=runs_metadata,
plot_title="2 large tokamak solutions",
)
df2
| tag | minmax | objf_name | norm_objf | itvar001_name | xcm001 | itvar002_name | xcm002 | itvar003_name | xcm003 | ... | itvar039_name | xcm039 | itvar040_name | xcm040 | itvar041_name | xcm041 | itvar042_name | xcm042 | itvar043_name | xcm043 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | large tokamak 1 | 1.0 | major radius | 1.60 | b_plasma_toroidal_on_axis | 0.887772 | rmajor | 1.0 | temp_plasma_electron_vol_avg_kev | 1.044270 | ... | f_a_cs_turn_steel | 0.864261 | foh_stress | 0.999995 | f_nd_impurity_electrons(13) | 1.621696 | dr_tf_wp_with_insulation | 1.205360 | fne0 | 0.59638 |
| 1 | large tokamak 2 | 1.0 | major radius | 1.64 | b_plasma_toroidal_on_axis | 0.950449 | rmajor | 1.0 | temp_plasma_electron_vol_avg_kev | 1.054492 | ... | f_a_cs_turn_steel | 0.866183 | foh_stress | 0.999438 | f_nd_impurity_electrons(13) | 1.454803 | dr_tf_wp_with_insulation | 1.355719 | fne0 | 0.59638 |
2 rows × 90 columns
Plot one solution normalised to another¶
Normalised differences, relative to the a given solution, can also be plotted:
fig3, df3 = plot_mfile_solutions(
runs_metadata=runs_metadata,
plot_title="Large tokamak 2 solution, relative to large tokamak 1",
normalising_tag="large tokamak 1",
)
df3
/home/runner/work/PROCESS/PROCESS/process/io/plot_solutions.py:111: UserWarning: Double-normalising: using opt params normalised to each solution and normalising again to another solution. Are you sure? warn(
| tag | minmax | objf_name | norm_objf | itvar001_name | xcm001 | itvar002_name | xcm002 | itvar003_name | xcm003 | ... | itvar039_name | xcm039 | itvar040_name | xcm040 | itvar041_name | xcm041 | itvar042_name | xcm042 | itvar043_name | xcm043 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | large tokamak 1 | 1.0 | major radius | 1.60 | b_plasma_toroidal_on_axis | 0.887772 | rmajor | 1.0 | temp_plasma_electron_vol_avg_kev | 1.044270 | ... | f_a_cs_turn_steel | 0.864261 | foh_stress | 0.999995 | f_nd_impurity_electrons(13) | 1.621696 | dr_tf_wp_with_insulation | 1.205360 | fne0 | 0.59638 |
| 1 | large tokamak 2 | 1.0 | major radius | 1.64 | b_plasma_toroidal_on_axis | 0.950449 | rmajor | 1.0 | temp_plasma_electron_vol_avg_kev | 1.054492 | ... | f_a_cs_turn_steel | 0.866183 | foh_stress | 0.999438 | f_nd_impurity_electrons(13) | 1.454803 | dr_tf_wp_with_insulation | 1.355719 | fne0 | 0.59638 |
2 rows × 90 columns
Plot multiple solutions normalised by one¶
Plot two MFILEs, normalised by a third MFILE.
runs_metadata = [
RunMetadata(data_dir / "large_tokamak_1_MFILE.DAT", "large tokamak 1"),
RunMetadata(data_dir / "large_tokamak_2_MFILE.DAT", "large tokamak 2"),
RunMetadata(data_dir / "large_tokamak_3_MFILE.DAT", "large tokamak 3"),
]
fig4, df4 = plot_mfile_solutions(
runs_metadata,
"2 large tokamak solutions, relative to large tokamak 1",
normalising_tag="large tokamak 1",
)
df4
/home/runner/work/PROCESS/PROCESS/process/io/plot_solutions.py:111: UserWarning: Double-normalising: using opt params normalised to each solution and normalising again to another solution. Are you sure? warn(
| tag | minmax | objf_name | norm_objf | itvar001_name | xcm001 | itvar002_name | xcm002 | itvar003_name | xcm003 | ... | itvar039_name | xcm039 | itvar040_name | xcm040 | itvar041_name | xcm041 | itvar042_name | xcm042 | itvar043_name | xcm043 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | large tokamak 1 | 1.0 | major radius | 1.60 | b_plasma_toroidal_on_axis | 0.887772 | rmajor | 1.0 | temp_plasma_electron_vol_avg_kev | 1.044270 | ... | f_a_cs_turn_steel | 0.864261 | foh_stress | 0.999995 | f_nd_impurity_electrons(13) | 1.621696 | dr_tf_wp_with_insulation | 1.205360 | fne0 | 0.59638 |
| 1 | large tokamak 2 | 1.0 | major radius | 1.64 | b_plasma_toroidal_on_axis | 0.950449 | rmajor | 1.0 | temp_plasma_electron_vol_avg_kev | 1.054492 | ... | f_a_cs_turn_steel | 0.866183 | foh_stress | 0.999438 | f_nd_impurity_electrons(13) | 1.454803 | dr_tf_wp_with_insulation | 1.355719 | fne0 | 0.59638 |
| 2 | large tokamak 3 | 1.0 | major radius | 1.68 | b_plasma_toroidal_on_axis | 1.001950 | rmajor | 1.0 | temp_plasma_electron_vol_avg_kev | 1.065104 | ... | f_a_cs_turn_steel | 0.875111 | foh_stress | 0.991054 | f_nd_impurity_electrons(13) | 1.339160 | dr_tf_wp_with_insulation | 1.464856 | fne0 | 0.59638 |
3 rows × 90 columns
RMS Errors¶
Plot RMS errors of multiple solutions relative to a reference solution.
runs_metadata = [
RunMetadata(data_dir / "large_tokamak_1_MFILE.DAT", "large tokamak 1"),
RunMetadata(data_dir / "large_tokamak_2_MFILE.DAT", "large tokamak 2"),
RunMetadata(data_dir / "large_tokamak_3_MFILE.DAT", "large tokamak 3"),
RunMetadata(data_dir / "large_tokamak_4_MFILE.DAT", "large tokamak 4"),
]
fig5, df5 = plot_mfile_solutions(
runs_metadata,
"3 large tokamak solutions with RMS errors normalised to large tokamak 1",
normalising_tag="large tokamak 1",
rmse=True,
)
df5
/home/runner/work/PROCESS/PROCESS/process/io/plot_solutions.py:111: UserWarning: Double-normalising: using opt params normalised to each solution and normalising again to another solution. Are you sure? warn(
| tag | minmax | objf_name | norm_objf | itvar001_name | xcm001 | itvar002_name | xcm002 | itvar003_name | xcm003 | ... | itvar039_name | xcm039 | itvar040_name | xcm040 | itvar041_name | xcm041 | itvar042_name | xcm042 | itvar043_name | xcm043 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | large tokamak 1 | 1.0 | major radius | 1.60 | b_plasma_toroidal_on_axis | 0.887772 | rmajor | 1.0 | temp_plasma_electron_vol_avg_kev | 1.044270 | ... | f_a_cs_turn_steel | 0.864261 | foh_stress | 0.999995 | f_nd_impurity_electrons(13) | 1.621696 | dr_tf_wp_with_insulation | 1.205360 | fne0 | 0.59638 |
| 1 | large tokamak 2 | 1.0 | major radius | 1.64 | b_plasma_toroidal_on_axis | 0.950449 | rmajor | 1.0 | temp_plasma_electron_vol_avg_kev | 1.054492 | ... | f_a_cs_turn_steel | 0.866183 | foh_stress | 0.999438 | f_nd_impurity_electrons(13) | 1.454803 | dr_tf_wp_with_insulation | 1.355719 | fne0 | 0.59638 |
| 2 | large tokamak 3 | 1.0 | major radius | 1.68 | b_plasma_toroidal_on_axis | 1.001950 | rmajor | 1.0 | temp_plasma_electron_vol_avg_kev | 1.065104 | ... | f_a_cs_turn_steel | 0.875111 | foh_stress | 0.991054 | f_nd_impurity_electrons(13) | 1.339160 | dr_tf_wp_with_insulation | 1.464856 | fne0 | 0.59638 |
| 3 | large tokamak 4 | 1.0 | major radius | 1.72 | b_plasma_toroidal_on_axis | 1.002129 | rmajor | 1.0 | temp_plasma_electron_vol_avg_kev | 1.032701 | ... | f_a_cs_turn_steel | 0.904825 | foh_stress | 0.979912 | f_nd_impurity_electrons(13) | 1.351687 | dr_tf_wp_with_insulation | 1.451062 | fne0 | 0.59638 |
4 rows × 90 columns
Solutions normalised by range¶
Use nitvar values instead; the solution optimisation parameters are normalised to the range of their upper and lower bounds.
runs_metadata = [
RunMetadata(data_dir / "large_tokamak_1_MFILE.DAT", "large tokamak 1"),
RunMetadata(data_dir / "large_tokamak_2_MFILE.DAT", "large tokamak 2"),
RunMetadata(data_dir / "large_tokamak_3_MFILE.DAT", "large tokamak 3"),
RunMetadata(data_dir / "large_tokamak_4_MFILE.DAT", "large tokamak 4"),
]
fig6, df6 = plot_mfile_solutions(
runs_metadata,
"4 large tokamak solutions normalised to the range of the optimisation parameters",
normalisation_type="range",
)
df6
| tag | minmax | objf_name | norm_objf | itvar001_name | nitvar001 | itvar002_name | nitvar002 | itvar003_name | nitvar003 | ... | itvar039_name | nitvar039 | itvar040_name | nitvar040 | itvar041_name | nitvar041 | itvar042_name | nitvar042 | itvar043_name | nitvar043 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | large tokamak 1 | 1.0 | major radius | 1.60 | b_plasma_toroidal_on_axis | 0.168400 | rmajor | 1.781757e-10 | temp_plasma_electron_vol_avg_kev | 0.074351 | ... | f_a_cs_turn_steel | 0.727512 | foh_stress | 0.999995 | f_nd_impurity_electrons(13) | 0.061624 | dr_tf_wp_with_insulation | 0.126675 | fne0 | 0.595976 |
| 1 | large tokamak 2 | 1.0 | major radius | 1.64 | b_plasma_toroidal_on_axis | 0.180312 | rmajor | 5.562212e-11 | temp_plasma_electron_vol_avg_kev | 0.075649 | ... | f_a_cs_turn_steel | 0.729132 | foh_stress | 0.999437 | f_nd_impurity_electrons(13) | 0.055282 | dr_tf_wp_with_insulation | 0.173662 | fne0 | 0.595976 |
| 2 | large tokamak 3 | 1.0 | major radius | 1.68 | b_plasma_toroidal_on_axis | 0.190101 | rmajor | 7.485879e-11 | temp_plasma_electron_vol_avg_kev | 0.076997 | ... | f_a_cs_turn_steel | 0.736658 | foh_stress | 0.991045 | f_nd_impurity_electrons(13) | 0.050887 | dr_tf_wp_with_insulation | 0.207768 | fne0 | 0.595976 |
| 3 | large tokamak 4 | 1.0 | major radius | 1.72 | b_plasma_toroidal_on_axis | 0.190135 | rmajor | 1.155775e-11 | temp_plasma_electron_vol_avg_kev | 0.072882 | ... | f_a_cs_turn_steel | 0.761707 | foh_stress | 0.979892 | f_nd_impurity_electrons(13) | 0.051363 | dr_tf_wp_with_insulation | 0.203457 | fne0 | 0.595976 |
4 rows × 90 columns
Actual values¶
runs_metadata = [
RunMetadata(data_dir / "large_tokamak_1_MFILE.DAT", "large tokamak 1"),
RunMetadata(data_dir / "large_tokamak_2_MFILE.DAT", "large tokamak 2"),
RunMetadata(data_dir / "large_tokamak_3_MFILE.DAT", "large tokamak 3"),
RunMetadata(data_dir / "large_tokamak_4_MFILE.DAT", "large tokamak 4"),
]
fig7, df7 = plot_mfile_solutions(
runs_metadata,
"Actual values of optimisation parameters for 4 large tokamak solutions",
normalisation_type=None,
)
df7
| tag | minmax | objf_name | norm_objf | itvar001_name | itvar001 | itvar002_name | itvar002 | itvar003_name | itvar003 | ... | itvar039_name | itvar039 | itvar040_name | itvar040 | itvar041_name | itvar041 | itvar042_name | itvar042 | itvar043_name | itvar043 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | large tokamak 1 | 1.0 | major radius | 1.60 | b_plasma_toroidal_on_axis | 5.060301 | rmajor | 8.0 | temp_plasma_electron_vol_avg_kev | 12.531239 | ... | f_a_cs_turn_steel | 0.691409 | foh_stress | 0.999995 | f_nd_impurity_electrons(13) | 0.000616 | dr_tf_wp_with_insulation | 0.602680 | fne0 | 0.59638 |
| 1 | large tokamak 2 | 1.0 | major radius | 1.64 | b_plasma_toroidal_on_axis | 5.417557 | rmajor | 8.2 | temp_plasma_electron_vol_avg_kev | 12.653898 | ... | f_a_cs_turn_steel | 0.692946 | foh_stress | 0.999438 | f_nd_impurity_electrons(13) | 0.000553 | dr_tf_wp_with_insulation | 0.677859 | fne0 | 0.59638 |
| 2 | large tokamak 3 | 1.0 | major radius | 1.68 | b_plasma_toroidal_on_axis | 5.711117 | rmajor | 8.4 | temp_plasma_electron_vol_avg_kev | 12.781252 | ... | f_a_cs_turn_steel | 0.700089 | foh_stress | 0.991054 | f_nd_impurity_electrons(13) | 0.000509 | dr_tf_wp_with_insulation | 0.732428 | fne0 | 0.59638 |
| 3 | large tokamak 4 | 1.0 | major radius | 1.72 | b_plasma_toroidal_on_axis | 5.712135 | rmajor | 8.6 | temp_plasma_electron_vol_avg_kev | 12.392409 | ... | f_a_cs_turn_steel | 0.723860 | foh_stress | 0.979912 | f_nd_impurity_electrons(13) | 0.000514 | dr_tf_wp_with_insulation | 0.725531 | fne0 | 0.59638 |
4 rows × 90 columns
Plot constraints¶
Plot constraint values for 2 output mfiles.
runs_metadata = [
RunMetadata(data_dir / "large_tokamak_nof_MFILE.DAT", "large tokamak"),
RunMetadata(data_dir / "large_tokamak_nof_2_MFILE.DAT", "large tokamak 2"),
]
fig, eval_df = plot_mfile_solutions_constraints(
runs_metadata=runs_metadata,
title="Constraint values at large tokamak solution",
)
The constraint values are the actual constraint values, where a positive value corresponds to a satisfied constraint.