ukaea / PROCESS

PROCESS is a systems code at UKAEA that calculates in a self-consistent manner the parameters of a fusion power plant with a specified performance, ensuring that its operating limits are not violated, and with the option to optimise to a given function of these parameters.
https://ukaea.github.io/PROCESS/
MIT License
36 stars 11 forks source link

Easier accessibility to key values #3302

Open JaeBeom1019 opened 2 months ago

JaeBeom1019 commented 2 months ago

I am interested in determining whether there is a simpler method to directly access and print specific variable values from the results, without the need to manually open the OUT.DAT file. While I am aware of methods to display key output variables, such as:

print(f"Heat transport system: {single_run.models.costs.c226:.3e} M$")
print(f"Electrical plant equipment: {single_run.models.costs.c24:.3e} M$")

these require detailed knowledge of the entire data structure to accurately reference and print the desired variables. For instance, if I want to view only a few specific variables like rmajor, rminor, q0, beta_n, and Q-value, I would need to search through the data structure to identify the correct paths to print these values.

Currently, using the following approach:

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

results are typically presented as figures or tables, which does not provide direct access to individual variable values.

It would be highly beneficial to have a more straightforward method to access and print specific key result variables, such as runs_metadata.rmajor, runs_metadata.thwcndut, and others. This would significantly enhance the usability and efficiency of working with the data. I hope there would be a function that can convert OUT.DAT data into dictionary or class type structure.

timothy-nunn commented 2 months ago

Hi @JaeBeom1019,

We are currently converting the PROCESS physics and engineering models from Fortran to Python (https://github.com/ukaea/PROCESS/issues/2879). Following this, we can convert the data structure from Fortran to Python (https://github.com/ukaea/PROCESS/issues/2893). Once we have a fully pythonised codebase, we look to further improve the data architecture behind PROCESS as this will have benefits to our internal modelling and development team, other software looking to interface with PROCESS, and external collaborators.

We currently have functionality in review that will write the MFile into a JSON format, could this be of use to you (https://github.com/ukaea/PROCESS/pull/3287)? If you are looking to access the intermediate values (as in, before PROCESS has converged) then this might be slightly trickier but I can look into it.

Thanks for your continued interest in PROCESS, Tim

JaeBeom1019 commented 2 months ago

Thank you for your prompt response!

To clarify, what I’m hoping to achieve is printing specific key values, rather than intermediate values. I would appreciate it if you could provide a code example on how to print the rmajor value, perhaps in a format like the following: print(f"Electrical plant equipment: {single_run.models.costs.c24:.3e} M$") It’s perfectly fine if the path is Fortran-based, as shown above.