Skip to content

Commit

Permalink
Applied black
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloprf committed Mar 26, 2024
1 parent d001a51 commit f12d9db
Show file tree
Hide file tree
Showing 39 changed files with 674 additions and 508 deletions.
16 changes: 10 additions & 6 deletions src/mitim_modules/freegsu/FREEGSUmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,21 @@ def runFreeGS(self, dictDVs, plot=False, figs=None, onlyPrepare=False, debug=Fal
out = FREEGStools.evaluator(
dictDVs,
CoilCurrents=self.function_parameters["CoilCurrents"],
CoilCurrents_lower=self.function_parameters["CoilCurrents_lower"]
if "CoilCurrents_lower" in self.function_parameters
else None,
CoilCurrents_lower=(
self.function_parameters["CoilCurrents_lower"]
if "CoilCurrents_lower" in self.function_parameters
else None
),
Constraints=self.function_parameters["Constraints"],
optionsFREEGS=self.function_parameters["optionsFREEGS"],
plot=plot,
figs=figs,
debug=debug,
ProblemExtras=self.function_parameters["params"]
if "params" in self.function_parameters
else None,
ProblemExtras=(
self.function_parameters["params"]
if "params" in self.function_parameters
else None
),
onlyPrepare=onlyPrepare,
)

Expand Down
20 changes: 10 additions & 10 deletions src/mitim_modules/portals/PORTALSmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def default_namelist(Optim):
Optim["surrogateOptions"]["ensureTrainingBounds"] = True

# Acquisition
Optim[
"optimizers"
] = "root_5-botorch-ga" # Added root which is not a default bc it needs dimX=dimY
Optim["optimizers"] = (
"root_5-botorch-ga" # Added root which is not a default bc it needs dimX=dimY
)
Optim["acquisitionType"] = "posterior_mean"

return Optim
Expand Down Expand Up @@ -300,7 +300,7 @@ def prep(
hardGradientLimits=hardGradientLimits,
dfT=self.dfT,
seedInitial=seedInitial,
checkForSpecies=askQuestions
checkForSpecies=askQuestions,
)
print(">> PORTALS initalization module (END)", typeMsg="i")

Expand Down Expand Up @@ -487,13 +487,13 @@ def reuseTrainingTabular(
self_copy = copy.deepcopy(self)
if reevaluateTargets == 1:
self_copy.powerstate.TransportOptions["TypeTransport"] = None
self_copy.powerstate.TransportOptions[
"TypeTarget"
] = self_copy.powerstate.TargetCalc = "powerstate"
self_copy.powerstate.TransportOptions["TypeTarget"] = (
self_copy.powerstate.TargetCalc
) = "powerstate"
else:
self_copy.powerstate.TransportOptions[
"TypeTransport"
] = "tglf_neo_tgyro"
self_copy.powerstate.TransportOptions["TypeTransport"] = (
"tglf_neo_tgyro"
)

results, tgyro, powerstate, dictOFs = runModelEvaluator(
self_copy,
Expand Down
17 changes: 11 additions & 6 deletions src/mitim_modules/portals/aux/PORTALSanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,17 @@ def from_folder(cls, folder, folderRemote=None, folderAnalysis=None):
return cls(opt_fun, folderAnalysis=folderAnalysis)

except (FileNotFoundError, AttributeError) as e:
print("\t- Could not read optimization results due to error:", typeMsg="w")
print(
"\t- Could not read optimization results due to error:", typeMsg="w"
)
print(e)
print("\t- Trying to read PORTALS initialization...", typeMsg="w")
return PORTALSinitializer(folder)
else:
print("\t- Folder does not exist, are you sure you are on the right path?", typeMsg="w")
print(
"\t- Folder does not exist, are you sure you are on the right path?",
typeMsg="w",
)

@classmethod
def merge_instances(cls, instances, folderAnalysis=None, base_index=0):
Expand Down Expand Up @@ -408,7 +413,7 @@ def plotPORTALS(self):
self.plotExpected(fig=fig)

fig = self.fn.add_figure(label="PORTALS Simulation", tab_color=4)
_,_ = self.plotModelComparison(fig=fig)
_, _ = self.plotModelComparison(fig=fig)

def plotMetrics(self, **kwargs):
PORTALSplot.PORTALSanalyzer_plotMetrics(self, **kwargs)
Expand Down Expand Up @@ -666,9 +671,9 @@ def runTGLFfull(
if not os.path.exists(folder):
os.system(f"mkdir {folder}")

if onlyBest:
if onlyBest:
ranges = [self.ibest]
else:
else:
ranges = range(self.ilast + 1)

for ev in ranges:
Expand Down Expand Up @@ -997,7 +1002,7 @@ def plotMetrics(self, extra_lab="", **kwargs):
lastRho=self.powerstates[0].plasma["rho"][-1, -1].item(),
lw=0.5,
ms=0,
label=f'profile #{i}',
label=f"profile #{i}",
)

axs[0].legend(prop={"size": 8})
Expand Down
19 changes: 11 additions & 8 deletions src/mitim_modules/portals/aux/PORTALSinit.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ def initializeProblem(
if checkForSpecies:
speciesNotFound = []
for i in range(len(profiles.Species)):
c = TARGETStools.get_chebyshev_coeffs(profiles.Species[i]['N'])
if c[0]<=-1E10:
speciesNotFound.append(profiles.Species[i]['N'])
if len(speciesNotFound)>0:
a = print(f"\t- Species {speciesNotFound} not found, radiation will be zero in PORTALS. Make sure this is ok with your predictions", typeMsg="q")
c = TARGETStools.get_chebyshev_coeffs(profiles.Species[i]["N"])
if c[0] <= -1e10:
speciesNotFound.append(profiles.Species[i]["N"])
if len(speciesNotFound) > 0:
a = print(
f"\t- Species {speciesNotFound} not found, radiation will be zero in PORTALS. Make sure this is ok with your predictions",
typeMsg="q",
)
if not a:
raise ValueError("Species not found")
"""
Expand Down Expand Up @@ -168,9 +171,9 @@ def initializeProblem(
portals_fun.powerstate.calculateTargets()

# Prepare powerstate for evaluations
portals_fun.powerstate.TransportOptions[
"TypeTransport"
] = portals_fun.PORTALSparameters["model_used"]
portals_fun.powerstate.TransportOptions["TypeTransport"] = (
portals_fun.PORTALSparameters["model_used"]
)
if ModelOptions is not None:
portals_fun.powerstate.TransportOptions["ModelOptions"] = ModelOptions
else:
Expand Down
50 changes: 32 additions & 18 deletions src/mitim_modules/portals/aux/PORTALSplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,9 @@ def PORTALSanalyzer_plotMetrics(
ax.plot(
self.evaluations, resChosen, "-o", lw=1.0, c=c, markersize=2, label=label
)
indeces_plot, colors_plot, labels_plot, markers_plot = define_extra_iterators(self)
indeces_plot, colors_plot, labels_plot, markers_plot = define_extra_iterators(
self
)

for cont, (indexUse, col, lab, mars) in enumerate(
zip(
Expand Down Expand Up @@ -770,7 +772,9 @@ def PORTALSanalyzer_plotMetrics(
markersize=2,
label="$\\chi_R$",
)
indeces_plot, colors_plot, labels_plot, markers_plot = define_extra_iterators(self)
indeces_plot, colors_plot, labels_plot, markers_plot = define_extra_iterators(
self
)

for cont, (indexUse, col, lab, mars) in enumerate(
zip(
Expand Down Expand Up @@ -970,7 +974,9 @@ def PORTALSanalyzer_plotMetrics(
markersize=2,
label="$P_{fus}$",
)
indeces_plot, colors_plot, labels_plot, markers_plot = define_extra_iterators(self)
indeces_plot, colors_plot, labels_plot, markers_plot = define_extra_iterators(
self
)

for cont, (indexUse, col, lab, mars) in enumerate(
zip(
Expand Down Expand Up @@ -1034,22 +1040,21 @@ def define_extra_iterators(self):
if self.ibest != self.evaluations[-2]:
self.iextra = self.iextra + [self.evaluations[-2]]


# Add extra points
colors = GRAPHICStools.listColors()
colors = [color for color in colors if color not in ['r', 'b']]
colors = [color for color in colors if color not in ["r", "b"]]
indeces_plot = indeces_plot + self.iextra
colors_plot = colors_plot+colors[:len(self.iextra)]
colors_plot = colors_plot + colors[: len(self.iextra)]

for i in range(len(self.iextra)):

if self.iextra[i] == -1 or self.iextra[i] == self.evaluations[-1]:
ll = 'Last'
ll = "Last"
else:
ll = 'Extra'
ll = "Extra"
labels_plot = labels_plot + [f"{ll} (#{self.evaluations[self.iextra[i]]})"]

markers_plot = GRAPHICStools.listmarkers()[:len(indeces_plot)]
markers_plot = GRAPHICStools.listmarkers()[: len(indeces_plot)]

return indeces_plot, colors_plot, labels_plot, markers_plot

Expand Down Expand Up @@ -1977,7 +1982,7 @@ def PORTALSanalyzer_plotModelComparison(
quantityX_stds = "QeGB_sim_turb_stds" if UseTGLFfull_x is None else None
quantityY = "QeGB_sim_turb"
quantityY_stds = "QeGB_sim_turb_stds"
metrics['Qe'] = plotModelComparison_quantity(
metrics["Qe"] = plotModelComparison_quantity(
self,
axs[0],
quantityX=quantityX,
Expand All @@ -1999,7 +2004,7 @@ def PORTALSanalyzer_plotModelComparison(
quantityX_stds = "QiGBIons_sim_turb_thr_stds" if UseTGLFfull_x is None else None
quantityY = "QiGBIons_sim_turb_thr"
quantityY_stds = "QiGBIons_sim_turb_thr_stds"
metrics['Qi'] = plotModelComparison_quantity(
metrics["Qi"] = plotModelComparison_quantity(
self,
axs[1],
quantityX=quantityX,
Expand All @@ -2021,7 +2026,7 @@ def PORTALSanalyzer_plotModelComparison(
quantityX_stds = "GeGB_sim_turb_stds" if UseTGLFfull_x is None else None
quantityY = "GeGB_sim_turb"
quantityY_stds = "GeGB_sim_turb_stds"
metrics['Ge'] = plotModelComparison_quantity(
metrics["Ge"] = plotModelComparison_quantity(
self,
axs[2],
quantityX=quantityX,
Expand Down Expand Up @@ -2059,7 +2064,7 @@ def PORTALSanalyzer_plotModelComparison(
quantityX_stds = "GiGB_sim_turb_stds" if UseTGLFfull_x is None else None
quantityY = "GiGB_sim_turb"
quantityY_stds = "GiGB_sim_turb_stds"
metrics['Gi'] = plotModelComparison_quantity(
metrics["Gi"] = plotModelComparison_quantity(
self,
axs[2 + cont],
quantityX=quantityX,
Expand Down Expand Up @@ -2105,7 +2110,7 @@ def PORTALSanalyzer_plotModelComparison(
quantityX_stds = "MtGB_sim_turb_stds"
quantityY = "MtGB_sim_turb"
quantityY_stds = "MtGB_sim_turb_stds"
metrics['Mt'] = plotModelComparison_quantity(
metrics["Mt"] = plotModelComparison_quantity(
self,
axs[2 + cont],
quantityX=quantityX,
Expand Down Expand Up @@ -2142,7 +2147,7 @@ def PORTALSanalyzer_plotModelComparison(
quantityX_stds = "EXeGB_sim_turb_stds"
quantityY = "EXeGB_sim_turb"
quantityY_stds = "EXeGB_sim_turb_stds"
metrics['EX'] = plotModelComparison_quantity(
metrics["EX"] = plotModelComparison_quantity(
self,
axs[2 + cont],
quantityX=quantityX,
Expand Down Expand Up @@ -2171,7 +2176,7 @@ def PORTALSanalyzer_plotModelComparison(

cont += 1

return axs,metrics
return axs, metrics


def plotModelComparison_quantity(
Expand Down Expand Up @@ -2315,6 +2320,7 @@ def plotModelComparison_quantity(

return metrics


# ---------------------------------------------------------------------------------------------------------------------


Expand Down Expand Up @@ -3033,7 +3039,11 @@ def plotFluxComparison(
y = tBest.derived[var] * mult
if plotTargets:
ax.plot(
tBest.profiles["rho(-)"] if not useRoa else tBest.derived["roa"],
(
tBest.profiles["rho(-)"]
if not useRoa
else tBest.derived["roa"]
),
y,
"-.",
lw=0.5,
Expand All @@ -3043,7 +3053,11 @@ def plotFluxComparison(
)
else:
ax.plot(
tBest.profiles["rho(-)"] if not useRoa else tBest.derived["roa"],
(
tBest.profiles["rho(-)"]
if not useRoa
else tBest.derived["roa"]
),
y,
"--",
lw=2,
Expand Down
4 changes: 1 addition & 3 deletions src/mitim_modules/portals/exe/runTGLF.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
parser.add_argument(
"--var", type=float, required=False, default=0.05
) # Variation in inputs (5% default)
parser.add_argument(
"--num", type=int, required=False, default=10
)
parser.add_argument("--num", type=int, required=False, default=10)
parser.add_argument(
"--restart", "-r", required=False, default=False, action="store_true"
)
Expand Down
2 changes: 0 additions & 2 deletions src/mitim_modules/powertorch/aux/PARAMtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def deparametrizer(x, y, printMessages=printDeviations):
printMessages=printMessages,
)


"""
Construct curve in a coarse grid
----------------------------------------------------------------------------------------------------
Expand All @@ -86,7 +85,6 @@ def deparametrizer_coarse_middle(x, y, printMessages=printDeviations):
printMessages=printMessages,
)


return (
dict_param["aLy_coarse"],
deparametrizer,
Expand Down
6 changes: 3 additions & 3 deletions src/mitim_modules/vitals/VITALSmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def default_namelist(Optim):
Optim["initialPoints"] = 8
Optim["BOiterations"] = 20
Optim["newPoints"] = 4
Optim[
"parallelCalls"
] = 4 # each TGLF is run with 4 cores, so 16 total cores consumed with this default
Optim["parallelCalls"] = (
4 # each TGLF is run with 4 cores, so 16 total cores consumed with this default
)
Optim["surrogateOptions"]["TypeMean"] = 2
Optim["StrategyOptions"]["AllowedExcursions"] = [0.1, 0.1]
Optim["StrategyOptions"]["HitBoundsIncrease"] = [1.1, 1.1]
Expand Down
Loading

0 comments on commit f12d9db

Please sign in to comment.