Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
6314214
By default, CGYRO file always includes Mt and GZ
pabloprf Apr 20, 2025
b1b8309
Better naming for surrogate selector
pabloprf Apr 23, 2025
c03fa8a
Changed naming of transforms. Allows backcompatibility for now
pabloprf Apr 23, 2025
86fa40d
Towards a generalization of input object in powerstate
pabloprf Apr 23, 2025
f791aeb
Towards deparametrizer renaming
pabloprf Apr 23, 2025
ddb4f0b
Towards a deparametrizer renaming (2)
pabloprf Apr 23, 2025
0d0513d
misc
pabloprf Apr 23, 2025
62c146e
Full code refactoring (NO BACK-COMPATIBILITY) to separate transport, …
pabloprf Apr 23, 2025
f1953c5
tutorial fixes
pabloprf Apr 24, 2025
083293d
Separation of CGYRO model from TGYRO
pabloprf Apr 24, 2025
12d0d14
removed references to "turbulence"
pabloprf Apr 24, 2025
459255f
CGYRO model better organization
pabloprf Apr 24, 2025
3c9a675
misc appearance
pabloprf Apr 24, 2025
11cd3fe
Moved CGYRO handlers from PORTALS to POWERTORCH
pabloprf Apr 24, 2025
182225a
Cleaned up CGYRO trick (1)
pabloprf Apr 24, 2025
de3c67b
Towards renaming of powertorch fluxes from, e.g., Pe to QeMWm2 for m…
pabloprf Apr 24, 2025
bc5c442
Do not ask the user if the folder Outputs is empty
pabloprf Apr 24, 2025
aca599e
Further Pe->QeMWm2 transition
pabloprf Apr 24, 2025
5a21f92
Towards Pe -> Qe transition (2)
pabloprf Apr 24, 2025
d8936f0
Turb and Neo naming to _tr_turb and _tr_neo
pabloprf Apr 24, 2025
fc23b7e
Tar to _tar
pabloprf Apr 24, 2025
6054f94
removed deprecated TargetType warning
pabloprf Apr 24, 2025
cc8774b
Cleaned up way to define fixed targets
pabloprf Apr 24, 2025
ef30864
misc
pabloprf Apr 24, 2025
ecc579b
Transitioned momentum to new naming convention
pabloprf Apr 24, 2025
73b3f30
Corrected ions position
pabloprf Apr 24, 2025
da3cd84
renaming to tgyro_to_powerstate
pabloprf Apr 25, 2025
d1311c9
misc
pabloprf Apr 25, 2025
3569fe1
Removed unnecessary PORTALSinteraction scripts
pabloprf Apr 25, 2025
62d32e3
Moved geometry tools to gacode
pabloprf Apr 25, 2025
9ea3fd3
Towards a tglf scan trick common to standalone TGLF (1)
pabloprf Apr 25, 2025
29710c0
TGLF module now retrieves Momentum and Exchange
pabloprf Apr 25, 2025
8d40071
Scan trick now correctly treats Momentum and Exchange
pabloprf Apr 25, 2025
b4f8a96
misc
pabloprf Apr 28, 2025
8153d57
Fix print statement so single and double quotes are separate
Apr 29, 2025
d6c9a4c
Fixed case when no radiation compontents available
pabloprf Apr 29, 2025
2320712
Minor bug of r/a legend in powertorch convergence
pabloprf Apr 29, 2025
f161c93
Printing more info on gacode radiation components
pabloprf Apr 30, 2025
5915a8e
Added capabiility to only print info from gacode, not plot
pabloprf Apr 30, 2025
bd4ed62
Store profiles_transport in powerstate, not the transport subclass, f…
pabloprf Apr 30, 2025
b71dba4
Added minimum absolute change in gradients during tglf scan trick
pabloprf Apr 30, 2025
9370ea7
UFILEStools changed: now the temporal variables is written first
mmuraca Jul 1, 2024
3c00dd6
normalized poloidal flux added in ASTRA_CDFtools and get_MXH_from_RZ …
mmuraca Jul 3, 2024
6108a59
ASTRA_CDFtools includes new definitions of variables, improved labels…
mmuraca Oct 16, 2024
c827925
new ASTRA_REPO added to MITIM for newer version of ASTRA including a …
mmuraca Oct 16, 2024
b0aa630
modified UFILEStools to not transpose the Z variable when trying to o…
mmuraca Oct 16, 2024
816f46a
GUItools modified to have bigger font when writing tabs labels in a g…
mmuraca Oct 16, 2024
f166351
few updates on ASTRAtools.py to improve the class which sends automat…
mmuraca Oct 16, 2024
e84443b
few other definition added to astraCDFtools (angioni peaking scaling,…
mmuraca Oct 30, 2024
03fc2ea
ASTRA_CDFtools.py modified to include more variables and a function t…
mmuraca Nov 22, 2024
689b60d
added few lines with line average density in ASTRA_CDFtools
mmuraca Dec 11, 2024
99c0eca
Added minimum PLH (wrt to density) formula, metal wall scaling and ne…
mmuraca Jan 16, 2025
d9c699f
Added few variables and updated notebook in ASTRA_CDFtools module
mmuraca Jan 31, 2025
ab2d012
Few changes to ASTRA_CDFtools, now it looks better and has few more v…
mmuraca Mar 20, 2025
fe83dd1
few variables for radiative power. PRWOL_PUET may have a bug in the d…
mmuraca May 9, 2025
7059cbc
Few variables added in ASTRA post processing tools. PEDT, POH substit…
mmuraca May 21, 2025
77f06af
More structured module, with details an names about the variables
mmuraca May 21, 2025
8828fda
More details about the variables, more comments and cleaning. No majo…
mmuraca May 21, 2025
19ff031
Very minimal change before to push
mmuraca May 21, 2025
736a270
Integrated toroidal current density profile
jo-hall Jun 11, 2025
12a3245
added shear from internal calculation for comparison
jo-hall Jun 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/mitim_modules/freegsu/utils/FREEGSUparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def createProblemParameters(
dvs_min.extend(dvs_min2)
dvs_max.extend(dvs_max2)

transformation = produceNewInputs
transformation = input_transform_freegs
else:
transformation = None

Expand Down Expand Up @@ -376,7 +376,7 @@ def extractCont(x, cont):
return v


def produceNewInputs(X, output, bounds, ParamProfile):
def input_transform_freegs(X, output, bounds, ParamProfile):
"""
X will be a tensor (with or without gradients) batch*dim, unnormalized
"""
Expand Down
2 changes: 1 addition & 1 deletion src/mitim_modules/maestro/tmp_tests/maestro_test1.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"MODELparameters": { "RoaLocations": [0.35,0.55,0.75,0.875,0.9],
"ProfilesPredicted": ["te", "ti", "ne"],
"Physics_options": {"TypeTarget": 3},
"transport_model": {"turbulence":'TGLF',"TGLFsettings": 6, "extraOptionsTGLF": {'USE_BPER':True}}},
"transport_model": {"TGLFsettings": 6, "extraOptionsTGLF": {'USE_BPER':True}}},
"INITparameters": {"FastIsThermal": True, "removeIons": [5,6], "quasineutrality": True},
"optimization_options": {
"convergence_options": {
Expand Down
2 changes: 1 addition & 1 deletion src/mitim_modules/maestro/utils/EPEDbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from mitim_tools.popcon_tools import FunctionalForms
from mitim_tools.misc_tools.LOGtools import printMsg as print
from mitim_modules.maestro.utils.MAESTRObeat import beat
from mitim_modules.powertorch.physics import CALCtools
from mitim_modules.powertorch.utils import CALCtools
from IPython import embed

# <> Function to interpolate a curve <>
Expand Down
6 changes: 3 additions & 3 deletions src/mitim_modules/maestro/utils/PORTALSbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def prepare(self,

profiles = self.profiles_current
for i in range(len(profiles.Species)):
data_df = pd.read_csv(__mitimroot__ / "src" / "mitim_modules" / "powertorch" / "physics" / "radiation_chebyshev.csv")
data_df = pd.read_csv(__mitimroot__ / "src" / "mitim_modules" / "powertorch" / "physics_models" / "radiation_chebyshev.csv")
if not (data_df['Ion'].str.lower()==profiles.Species[i]["N"].lower()).any():
print(f"\t\t- {profiles.Species[i]['N']} not found in radiation table, looking for closest Z (+- 5) USING THE Z SPECIFIED IN THE INPUT.GACODE (fully stripped assumption)",typeMsg='w')
# Find closest Z
Expand All @@ -56,7 +56,7 @@ def prepare(self,

new_name = data_df['Ion'][iZ]

print(f"\t\t\t- Changing name of ion from {profiles.Species[i]["N"]} ({profiles.Species[i]["Z"]}) to {new_name} ({Z[iZ]})")
print(f'\t\t\t- Changing name of ion from {profiles.Species[i]["N"]} ({profiles.Species[i]["Z"]}) to {new_name} ({Z[iZ]})')

profiles.profiles['name'][i] = profiles.Species[i]["N"] = new_name

Expand Down Expand Up @@ -344,7 +344,7 @@ def _inform(self, use_previous_residual = True, use_previous_surrogate_data = Tr
# In the situation where the last radial location moves, I cannot reuse that surrogate data
if last_radial_location_moved and reusing_surrogate_data:
print('\t\t- Last radial location was moved, so surrogate data will not be reused for that specific location')
self.optimization_options['surrogate_options']["extrapointsModelsAvoidContent"] = ['Tar',f'_{len(self.MODELparameters[strKeys])}']
self.optimization_options['surrogate_options']["extrapointsModelsAvoidContent"] = ['_tar',f'_{len(self.MODELparameters[strKeys])}']
self.try_flux_match_only_for_first_point = False

def _inform_save(self):
Expand Down
79 changes: 30 additions & 49 deletions src/mitim_modules/portals/PORTALSmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
from collections import OrderedDict
from mitim_tools.misc_tools import IOtools
from mitim_tools.gacode_tools import PROFILEStools
from mitim_tools.gacode_tools.utils import PORTALSinteraction
from mitim_modules.portals import PORTALStools
from mitim_modules.portals.utils import (
PORTALSinit,
PORTALSoptimization,
PORTALSanalysis,
)
from mitim_modules.powertorch.physics import TRANSPORTtools, TARGETStools
from mitim_modules.powertorch.physics_models import targets_analytic, transport_tgyro, transport_cgyro
from mitim_tools.opt_tools import STRATEGYtools
from mitim_tools.opt_tools.utils import BOgraphics
from mitim_tools.misc_tools.LOGtools import printMsg as print
Expand Down Expand Up @@ -64,7 +63,7 @@ def default_namelist(optimization_options, CGYROrun=False):
optimization_options['acquisition_options']['relative_improvement_for_stopping'] = 1e-2

# Surrogate
optimization_options["surrogate_options"]["selectSurrogate"] = partial(PORTALStools.selectSurrogate, CGYROrun=CGYROrun)
optimization_options["surrogate_options"]["surrogate_selection"] = partial(PORTALStools.surrogate_selection_portals, CGYROrun=CGYROrun)

if CGYROrun:
# CGYRO runs should prioritize accuracy
Expand Down Expand Up @@ -171,7 +170,7 @@ def __init__(
"Tfast_ratio": False, # Keep the ratio of Tfast/Te constant throughout the Te evolution
"ensureMachNumber": None, # Change w0 to match this Mach number when Ti varies
},
"transport_model": {"turbulence":'TGLF',"TGLFsettings": 6, "extraOptionsTGLF": {}}
"transport_model": {"TGLFsettings": 6, "extraOptionsTGLF": {}}
}

for key in self.MODELparameters.keys():
Expand All @@ -193,8 +192,12 @@ def __init__(
"""

# Selection of model
transport_evaluator = TRANSPORTtools.tgyro_model
targets_evaluator = TARGETStools.analytical_model
if CGYROrun:
transport_evaluator = transport_cgyro.cgyro_model
else:
transport_evaluator = transport_tgyro.tgyro_model

targets_evaluator = targets_analytic.analytical_model

self.PORTALSparameters = {
"percentError": [5,10,1], # (%) Error (std, in percent) of model evaluation [TGLF (treated as minimum if scan trick), NEO, TARGET]
Expand Down Expand Up @@ -341,15 +344,15 @@ def _define_reuse_models(self):
'''
The user can define a list of strings to avoid reusing surrogates.
e.g.
'Tar' to avoid reusing targets
'_tar' to avoid reusing targets
'_5' to avoid reusing position 5
'''

self.optimization_options['surrogate_options']['extrapointsModels'] = []

# Define avoiders
if self.optimization_options['surrogate_options']['extrapointsModelsAvoidContent'] is None:
self.optimization_options['surrogate_options']['extrapointsModelsAvoidContent'] = ['Tar']
self.optimization_options['surrogate_options']['extrapointsModelsAvoidContent'] = ['_tar']

# Define extrapointsModels
for key in self.surrogate_parameters['surrogate_transformation_variables_lasttime'].keys():
Expand Down Expand Up @@ -416,17 +419,16 @@ def scalarized_objective(self, Y):
-------------------------------------------------------------------------
Prepare transport dictionary
-------------------------------------------------------------------------
Note: var_dict['QeTurb'] must have shape (dim1...N, num_radii)
Note: var_dict['Qe_tr_turb'] must have shape (dim1...N, num_radii)
"""

var_dict = {}
for of in ofs_ordered_names:
var, _ = of.split("_")

var = '_'.join(of.split("_")[:-1])
if var not in var_dict:
var_dict[var] = torch.Tensor().to(Y)
var_dict[var] = torch.cat(
(var_dict[var], Y[..., ofs_ordered_names == of]), dim=-1
)
var_dict[var] = torch.cat((var_dict[var], Y[..., ofs_ordered_names == of]), dim=-1)

"""
-------------------------------------------------------------------------
Expand All @@ -436,7 +438,7 @@ def scalarized_objective(self, Y):
res must have shape (dim1...N)
"""

of, cal, _, res = PORTALSinteraction.calculate_residuals(self.powerstate, self.PORTALSparameters,specific_vars=var_dict)
of, cal, _, res = PORTALStools.calculate_residuals(self.powerstate, self.PORTALSparameters,specific_vars=var_dict)

return of, cal, res

Expand Down Expand Up @@ -468,7 +470,7 @@ def check_flags(self):
print("\t- Requested fineTargetsResolution, so running powerstate target calculations",typeMsg="w")
self.PORTALSparameters["TargetCalc"] = "powerstate"

if not issubclass(self.PORTALSparameters["transport_evaluator"], TRANSPORTtools.tgyro_model) and (self.PORTALSparameters["TargetCalc"] == "tgyro"):
if not issubclass(self.PORTALSparameters["transport_evaluator"], transport_tgyro.tgyro_model) and (self.PORTALSparameters["TargetCalc"] == "tgyro"):
print("\t- Requested TGYRO targets, but transport evaluator is not tgyro, so changing to powerstate",typeMsg="w")
self.PORTALSparameters["TargetCalc"] = "powerstate"

Expand All @@ -480,9 +482,6 @@ def check_flags(self):
print("\t- In PORTALS TGYRO evaluations, we need to not recompute gradients (GradientsType=0)",typeMsg="i")
self.MODELparameters["Physics_options"]["GradientsType"] = 0

if 'TargetType' in self.MODELparameters["Physics_options"]:
raise Exception("\t- TargetType is not used in PORTALS anymore")

if self.PORTALSparameters["TargetCalc"] == "tgyro" and self.PORTALSparameters['profiles_postprocessing_fun'] is not None:
print("\t- Requested custom modification of postprocessing function but targets from tgyro... are you sure?",typeMsg="q")

Expand Down Expand Up @@ -555,7 +554,7 @@ def reuseTrainingTabular(
self_copy.powerstate.TransportOptions["transport_evaluator"] = None
self_copy.powerstate.TargetOptions["ModelOptions"]["TypeTarget"] = "powerstate"
else:
self_copy.powerstate.TransportOptions["transport_evaluator"] = TRANSPORTtools.tgyro_model
self_copy.powerstate.TransportOptions["transport_evaluator"] = transport_tgyro.tgyro_model

_, dictOFs = runModelEvaluator(
self_copy,
Expand All @@ -571,7 +570,7 @@ def reuseTrainingTabular(
# ------------------------------------------------------------------------------------

for i in dictOFs:
if "Tar" in i:
if "_tar" in i:
print(f"Changing {i} in file")

optimization_data.data[i].iloc[numPORTALS] = dictOFs[i]["value"].cpu().numpy().item()
Expand Down Expand Up @@ -646,67 +645,49 @@ def runModelEvaluator(
return powerstate, dictOFs

def map_powerstate_to_portals(powerstate, dictOFs):
"""
"""

for var in powerstate.ProfilesPredicted:
# Write in OFs
for i in range(powerstate.plasma["rho"].shape[1] - 1): # Ignore position 0, which is rho=0
if var == "te":
var0, var1 = "Qe", "Pe"
var0, var1 = "Qe", "QeMWm2"
elif var == "ti":
var0, var1 = "Qi", "Pi"
var0, var1 = "Qi", "QiMWm2"
elif var == "ne":
var0, var1 = "Ge", "Ce"
elif var == "nZ":
var0, var1 = "GZ", "CZ"
elif var == "w0":
var0, var1 = "Mt", "Mt"
var0, var1 = "Mt", "MtJm2"

"""
TRANSPORT calculation
---------------------
"""

dictOFs[f"{var0}Turb_{i+1}"]["value"] = powerstate.plasma[
f"{var1}_tr_turb"
][0, i+1]
dictOFs[f"{var0}Turb_{i+1}"]["error"] = powerstate.plasma[
f"{var1}_tr_turb_stds"
][0, i+1]
dictOFs[f"{var0}_tr_turb_{i+1}"]["value"] = powerstate.plasma[f"{var1}_tr_turb"][0, i+1]
dictOFs[f"{var0}_tr_turb_{i+1}"]["error"] = powerstate.plasma[f"{var1}_tr_turb_stds"][0, i+1]

dictOFs[f"{var0}Neo_{i+1}"]["value"] = powerstate.plasma[
f"{var1}_tr_neo"
][0, i+1]
dictOFs[f"{var0}Neo_{i+1}"]["error"] = powerstate.plasma[
f"{var1}_tr_neo_stds"
][0, i+1]
dictOFs[f"{var0}_tr_neo_{i+1}"]["value"] = powerstate.plasma[f"{var1}_tr_neo"][0, i+1]
dictOFs[f"{var0}_tr_neo_{i+1}"]["error"] = powerstate.plasma[f"{var1}_tr_neo_stds"][0, i+1]

"""
TARGET calculation
---------------------
If that radius & profile position has target, evaluate
"""

dictOFs[f"{var0}Tar_{i+1}"]["value"] = powerstate.plasma[f"{var1}"][
0, i+1
]
dictOFs[f"{var0}Tar_{i+1}"]["error"] = powerstate.plasma[
f"{var1}_stds"
][0, i+1]
dictOFs[f"{var0}_tar_{i+1}"]["value"] = powerstate.plasma[f"{var1}"][0, i+1]
dictOFs[f"{var0}_tar_{i+1}"]["error"] = powerstate.plasma[f"{var1}_stds"][0, i+1]

"""
Turbulent Exchange
------------------
"""
if 'PexchTurb_1' in dictOFs:
for i in range(powerstate.plasma["rho"].shape[1] - 1):
dictOFs[f"PexchTurb_{i+1}"]["value"] = powerstate.plasma["PexchTurb"][
0, i+1
]
dictOFs[f"PexchTurb_{i+1}"]["error"] = powerstate.plasma[
"PexchTurb_stds"
][0, i+1]
dictOFs[f"PexchTurb_{i+1}"]["value"] = powerstate.plasma["PexchTurb"][0, i+1]
dictOFs[f"PexchTurb_{i+1}"]["error"] = powerstate.plasma["PexchTurb_stds"][0, i+1]

return dictOFs

Expand Down
Loading