Skip to content

Commit

Permalink
Merge pull request #71 from upb-lea/core_loss_split
Browse files Browse the repository at this point in the history
try to move lint tests into pytests instead of CI for local tests
  • Loading branch information
gituser789 authored Nov 30, 2023
2 parents 61ff687 + a73aac5 commit ee9e31e
Show file tree
Hide file tree
Showing 12 changed files with 354 additions and 557 deletions.
41 changes: 22 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,32 @@ jobs:
- name: check linting using pycodestyle
run: |
pip install pycodestyle
pip install pytest
cd tests/integration
pytest lint.py
cd ../..
# code
pycodestyle femmt/constants.py
pycodestyle femmt/logparser.py
pycodestyle femmt/enumerations.py
pycodestyle femmt/dtos.py
#pycodestyle femmt/constants.py
#pycodestyle femmt/logparser.py
#pycodestyle femmt/enumerations.py
#pycodestyle femmt/dtos.py
# example files
pycodestyle femmt/examples/advanced_inductor_sweep.py
pycodestyle femmt/examples/advanced_sto.py
pycodestyle femmt/examples/basic_inductor.py
pycodestyle femmt/examples/basic_inductor_foil_vertical.py
pycodestyle femmt/examples/basic_transformer.py
pycodestyle femmt/examples/basic_transformer_5_windings.py
pycodestyle femmt/examples/basic_transformer_center_tapped.py
pycodestyle femmt/examples/basic_transformer_integrated.py
pycodestyle femmt/examples/basic_transformer_interleaved.py
pycodestyle femmt/examples/basic_transformer_n_winding.py
pycodestyle femmt/examples/basic_transformer_stacked.py
pycodestyle femmt/examples/basic_transformer_stacked_center_tapped.py
pycodestyle femmt/examples/basic_transformer_three_winding.py
pycodestyle tests/integration/test_femmt.py
#pycodestyle femmt/examples/advanced_inductor_sweep.py
#pycodestyle femmt/examples/advanced_sto.py
#pycodestyle femmt/examples/basic_inductor.py
#pycodestyle femmt/examples/basic_inductor_foil_vertical.py
#pycodestyle femmt/examples/basic_transformer.py
#pycodestyle femmt/examples/basic_transformer_5_windings.py
#pycodestyle femmt/examples/basic_transformer_center_tapped.py
#pycodestyle femmt/examples/basic_transformer_integrated.py
#pycodestyle femmt/examples/basic_transformer_interleaved.py
#pycodestyle femmt/examples/basic_transformer_n_winding.py
#pycodestyle femmt/examples/basic_transformer_stacked.py
#pycodestyle femmt/examples/basic_transformer_stacked_center_tapped.py
#pycodestyle femmt/examples/basic_transformer_three_winding.py
#pycodestyle tests/integration/test_femmt.py
- name: install femmt package
run: |
Expand All @@ -62,7 +66,6 @@ jobs:
pip install --upgrade pip
pip install opencv-python
pip install -e .
pip install pytest
- name: install material database package
run: |
Expand Down
144 changes: 94 additions & 50 deletions femmt/functions_reluctance.py

Large diffs are not rendered by default.

52 changes: 35 additions & 17 deletions femmt/hpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
# Third parry libraries
from femmt import MagneticComponent


def _copy_electro_magnetic_necessary_files(src_folder: str, dest_folder: str):
"""Inner function. Needed in order to appropriately run parallel simulations since some GetDP files are changed in every simulation instance
"""
Inner function. Needed in order to appropriately run parallel simulations since some GetDP files are
changed in every simulation instance
:param src_folder: Path to the base electro_magnetic folder
:type src_folder: str
:param dest_folder: Path to the folder where the necessary files shall be stored. The "new" electro_magnetic folder for the corresponding simulation.
:param dest_folder: Path to the folder where the necessary files shall be stored. The "new" electro_magnetic
folder for the corresponding simulation.
:type dest_folder: str
"""
files = ["fields.pro", "ind_axi_python_controlled.pro", "solver.pro", "values.pro"]
Expand All @@ -22,12 +26,17 @@ def _copy_electro_magnetic_necessary_files(src_folder: str, dest_folder: str):
to_path = os.path.join(dest_folder, file)
shutil.copy(from_path, to_path)


def hpc_single_simulation(parameters: Dict):
"""The default function which is used for parallel execution. Using this function for every model create_model() and single_simulation will be executed.
If for the parallel simulation a custom function is needed you can take this as an example. The parameters dictionary is always given to the parallel executed function.
"""
The default function which is used for parallel execution. Using this function for every model create_model()
and single_simulation will be executed.
If for the parallel simulation a custom function is needed you can take this as an example. The parameters
dictionary is always given to the parallel executed function.
:param parameters: Dictionary containing the needed parameters. One parameters is always 'model' which is the MagneticComponent. The other one is
always 'simulation_parameters' which is also a dict and then contains the parameters given to the run() function (for this specific model).
:param parameters: Dictionary containing the needed parameters. One parameter is always 'model' which is the
MagneticComponent. The other one is always 'simulation_parameters' which is also a dict and then contains
the parameters given to the run() function (for this specific model).
:type parameters: Dict
"""
model = parameters["model"]
Expand All @@ -45,21 +54,30 @@ def hpc_single_simulation(parameters: Dict):
model.create_model(freq=freq, pre_visualize_geometry=False, save_png=False)
model.single_simulation(freq=freq, current=current, plot_interpolation=False, show_fem_simulation_results=False)

def run_hpc(n_processes: int, models: List[MagneticComponent], simulation_parameters: List[Dict], working_directory: str, custom_hpc: Callable = None):
"""Executes the given models on the given number of parallel processes. Typically this number shouldn't be higher than the number of cores of the processor.

:param n_processes: Number of parallel processes. If this is equal to None the number returned by os.cpu_count() is used.
def run_hpc(n_processes: int, models: List[MagneticComponent], simulation_parameters: List[Dict],
working_directory: str, custom_hpc: Callable = None):
"""
Executes the given models on the given number of parallel processes. Typically, this number
shouldn't be higher than the number of cores of the processor.
:param n_processes: Number of parallel processes. If None, the number returned by os.cpu_count() is used.
:type n_processes: int
:param models: List of MagneticComponents which shall be simulated in parallel.
:type models: List[MagneticComponent]
:param simulation_parameters: List of dictionaries containing the parameters for the parallel simulation. The Nth item corresponds to the Nth MagneticComponent in models.
For the default hpc_function this dictionary needs the frequency and the current (which is needed for the single_simulation function).
Since the dictionary is given to the hpc_function directly, if a custom_hpc function is used the needed parameters can be added through this dict.
:param simulation_parameters: List of dictionaries containing the parameters for the parallel simulation.
The Nth item corresponds to the Nth MagneticComponent in models.
For the default hpc_function this dictionary needs the frequency and the current
(which is needed for the single_simulation function).
Since the dictionary is given to the hpc_function directly, if a custom_hpc function is used the
needed parameters can be added through this dict.
:type simulation_parameters: List[Dict]
:param working_directory: The directory which will store the model data and results data for every parallel simulation.
:param working_directory: The directory stores the model data and results data for every parallel simulation.
:type working_directory: str
:param custom_hpc: If set to None the default hpc will be used (create_model() and single_simulation() are executed). If a custom_hpc is set this function
will be called for the parallel execution and the funtion parameters is the simulation_parameter dict taken from the simulation_parameters list., defaults to None
:param custom_hpc: If set to None the default hpc will be used (create_model() and single_simulation()
are executed). If a custom_hpc is set this function
will be called for the parallel execution and the funtion parameters is the simulation_parameter dict taken
from the simulation_parameters list., defaults to None
:type custom_hpc: Callable, optional
"""
electro_magnetic_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "electro_magnetic")
Expand All @@ -81,7 +99,8 @@ def run_hpc(n_processes: int, models: List[MagneticComponent], simulation_parame
_copy_electro_magnetic_necessary_files(electro_magnetic_folder, model_electro_magnetic_directory)

# Update directories for each model
model.file_data.update_paths(model_working_directory, model_electro_magnetic_directory, strands_coefficients_folder)
model.file_data.update_paths(model_working_directory, model_electro_magnetic_directory,
strands_coefficients_folder)
model.file_data.clear_previous_simulation_results()

# Create pool of workers and apply _hpc to it
Expand All @@ -98,4 +117,3 @@ def run_hpc(n_processes: int, models: List[MagneticComponent], simulation_parame
pool.map(hpc_single_simulation, parameters)
else:
pool.map(custom_hpc, parameters)

1 change: 0 additions & 1 deletion femmt/optimization/ito_dtos.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,3 @@ class ItoSingleResultFile:
secondary_litz_wire_loss: float
core_2daxi_total_volume: float
total_loss: float

Loading

0 comments on commit ee9e31e

Please sign in to comment.