Skip to content

Commit

Permalink
add tqdm reqiuirement, add Pareto plot subtitle
Browse files Browse the repository at this point in the history
  • Loading branch information
gituser789 committed Sep 25, 2024
1 parent 4b100b0 commit 389dbac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
11 changes: 6 additions & 5 deletions femmt/optimization/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pandas as pd
from matplotlib import pyplot as plt
import matplotlib.patches as mpatches
import tqdm

# onw libraries
from femmt.optimization.io_dtos import (InductorOptimizationDTO, InductorOptimizationTargetAndFixedParameters, FemInput,
Expand Down Expand Up @@ -358,7 +359,7 @@ def show_study_results(config: InductorOptimizationDTO) -> None:
storage=f"sqlite:///{config.inductor_optimization_directory}/{config.inductor_study_name}.sqlite3")

fig = optuna.visualization.plot_pareto_front(study, targets=lambda t: (t.values[0], t.values[1]), target_names=["volume in m³", "loss in W"])
fig.update_layout(title=f"{config.inductor_study_name}")
fig.update_layout(title=f"{config.inductor_study_name} <br><sup>{config.inductor_optimization_directory}</sup>")
fig.write_html(f"{config.inductor_optimization_directory}/{config.inductor_study_name}"
f"_{datetime.datetime.now().isoformat(timespec='minutes')}.html")
fig.show()
Expand Down Expand Up @@ -574,7 +575,7 @@ def fem_simulations_from_reluctance_df(reluctance_df: pd.DataFrame, config: Indu
fem_working_directory = os.path.join(
target_and_fix_parameters.working_directories.fem_working_directory, f"process_{process_number}")

for index, _ in reluctance_df.iterrows():
for index, _ in tqdm.tqdm(reluctance_df.iterrows(), total=reluctance_df.shape[0]):

destination_json_file = os.path.join(
target_and_fix_parameters.working_directories.fem_simulation_results_directory,
Expand Down Expand Up @@ -647,8 +648,6 @@ def fem_logs_to_df(reluctance_df: pd.DataFrame, fem_results_folder_path: str) ->
:rtype: pd.DataFrame
"""
files_in_folder = [f for f in os.listdir(fem_results_folder_path) if os.path.isfile(os.path.join(fem_results_folder_path, f))]
print(files_in_folder)
print(len(files_in_folder))

# add new columns to the dataframe, init values with None
reluctance_df['fem_inductance'] = None
Expand Down Expand Up @@ -804,7 +803,7 @@ def single_fem_simulation(fem_input: FemInput, show_visual_outputs: bool = False
return fem_output

@staticmethod
def full_simulation(df_geometry: pd.DataFrame, current_waveform: List, inductor_config_filepath: str, process_number: int = 1):
def full_simulation(df_geometry: pd.DataFrame, current_waveform: List, inductor_config_filepath: str, process_number: int = 1) -> tuple:
"""
Reluctance model (hysteresis losses) and FEM simulation (winding losses and eddy current losses) for geometries from df_geometry.
Expand All @@ -816,6 +815,8 @@ def full_simulation(df_geometry: pd.DataFrame, current_waveform: List, inductor_
:type inductor_config_filepath: str
:param process_number: process number to run the simulation on
:type process_number: int
:return: volume, loss
:rtype: tuple
"""
for index, _ in df_geometry.iterrows():

Expand Down
12 changes: 7 additions & 5 deletions femmt/optimization/sto.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import matplotlib.patches as mpatches
import magnethub as mh
import pandas as pd
import tqdm

class StackedTransformerOptimization:
"""Perform optimizations for the stacked transformer."""
Expand Down Expand Up @@ -483,7 +484,7 @@ def show_study_results(config: StoSingleInputConfig) -> None:
storage=f"sqlite:///{config.stacked_transformer_optimization_directory}/{config.stacked_transformer_study_name}.sqlite3")

fig = optuna.visualization.plot_pareto_front(study, targets=lambda t: (t.values[0], t.values[1]), target_names=["volume in m³", "loss in W"])
fig.update_layout(title=f"{config.stacked_transformer_study_name}")
fig.update_layout(title=f"{config.stacked_transformer_study_name} <br><sup>{config.stacked_transformer_optimization_directory}</sup>")
fig.write_html(f"{config.stacked_transformer_optimization_directory}/{config.stacked_transformer_study_name}"
f"_{datetime.datetime.now().isoformat(timespec='minutes')}.html")
fig.show()
Expand Down Expand Up @@ -700,8 +701,7 @@ def fem_simulations_from_reluctance_df(reluctance_df: pd.DataFrame, config: StoS
target_and_fix_parameters.working_directories.fem_working_directory, f"process_{process_number}")

# pd.read_csv(current_waveforms_csv_file, header=0, index_col=0, delimiter=';')

for index, _ in reluctance_df.iterrows():
for index, _ in tqdm.tqdm(reluctance_df.iterrows(), total=reluctance_df.shape[0]):

destination_json_file = os.path.join(
target_and_fix_parameters.working_directories.fem_simulation_results_directory,
Expand Down Expand Up @@ -1044,8 +1044,10 @@ def full_simulation(df_geometry: pd.DataFrame, current_waveform: List, stacked_t

print(f"P_winding_both reluctance: {reluctance_output.winding_losses}")
print(f"P_winding_both FEM: {fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2}")
print(f"P_winding_both derivation: {(fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2 - reluctance_output.winding_losses) / \
(fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2) * 100}")
winding_derivation = ((fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2 - reluctance_output.winding_losses) / \
(fem_output.p_loss_winding_1 + fem_output.p_loss_winding_2) * 100)
print(f"P_winding_both derivation: "
f"{winding_derivation}")
print(f"P_hyst reluctance: {reluctance_output.p_hyst}")
print(f"P_hyst FEM: {fem_output.core}")
print(f"P_hyst derivation: {(reluctance_output.p_hyst - fem_output.core) / reluctance_output.p_hyst * 100}")
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
'materialdatabase==0.3.0',
'optuna',
'plotly',
'mag-net-hub'],
'mag-net-hub',
'tqdm'],
license="GNU General Public License v3",
long_description=readme + '\n\n' + history,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 389dbac

Please sign in to comment.