Skip to content

Commit

Permalink
Merge pull request #204 from bessagroup/mpvanderschelling/issue194
Browse files Browse the repository at this point in the history
Fixes #194
  • Loading branch information
mpvanderschelling committed Oct 30, 2023
2 parents 452c53b + e11a003 commit ae54591
Showing 1 changed file with 75 additions and 6 deletions.
81 changes: 75 additions & 6 deletions src/f3dasm/_src/datageneration/datagenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Standard
import sys
from abc import abstractmethod
from functools import partial
from typing import Any, Callable

Expand Down Expand Up @@ -43,30 +44,80 @@ class DataGenerator:
"""Base class for a data generator"""

def pre_process(self, experiment_sample: ExperimentSample, **kwargs) -> None:
"""Function that handles the pre-processing"""
"""Interface function that handles the pre-processing of the data generator
Notes
-----
If not implemented the function will be skipped
The experiment_sample is cached inside the data generator. This
allows the user to access the experiment_sample in the pre_process, execute
and post_process functions as a class variable called self.experiment_sample.
"""
...

@abstractmethod
def execute(self, **kwargs) -> None:
"""Function that calls the FEM simulator the pre-processing"""
raise NotImplementedError("No execute function implemented!")
"""Interface function that handles the execution of the data generator
Raises
------
NotImplementedError
If the function is not implemented by the user
Notes
-----
The experiment_sample is cached inside the data generator. This
allows the user to access the experiment_sample in the pre_process, execute
and post_process functions as a class variable called self.experiment_sample.
"""

...

def post_process(self, experiment_sample: ExperimentSample, **kwargs) -> None:
"""Function that handles the post-processing"""
"""Interface function that handles the post-processing of the data generator
Notes
-----
If not implemented the function will be skipped
The experiment_sample is cached inside the data generator. This
allows the user to access the experiment_sample in the pre_process, execute
and post_process functions as a class variable called self.experiment_sample.
"""
...

@time_and_log
def _run(self, experiment_sample: ExperimentSample, **kwargs) -> ExperimentSample:
"""Run the data generator
"""
Run the data generator
This function chains the following methods together
* pre_process(); to combine the experiment_sample and the parameters
of the data generator to an input file that can be used to run the data generator
* execute(); to run the data generator and generate the response of the experiment
* post_process(); to process the response of the experiment and store it back
in the experiment_sample
The function also caches the experiment_sample in the data generator. This
allows the user to access the experiment_sample in the pre_process, execute
and post_process functions as a class variable called self.experiment_sample.
Parameters
----------
ExperimentSample : ExperimentSample
The design to run the data generator on
kwargs : dict
The keyword arguments to pass to the pre_process, execute and post_process
Returns
-------
ExperimentSample
Processed design
Processed design with the response of the data generator saved in the
experiment_sample
"""
# Cache the design
self.experiment_sample: ExperimentSample = experiment_sample
Expand All @@ -88,7 +139,25 @@ def _post_simulation(self) -> None:
...

def add_pre_process(self, func: Callable, **kwargs):
"""Add a pre-processing function to the data generator
Parameters
----------
func : Callable
The function to add to the pre-processing
kwargs : dict
The keyword arguments to pass to the pre-processing function
"""
self.pre_process = partial(func, **kwargs)

def add_post_process(self, func: Callable, **kwargs):
"""Add a post-processing function to the data generator
Parameters
----------
func : Callable
The function to add to the post-processing
kwargs : dict
The keyword arguments to pass to the post-processing function
"""
self.post_process = partial(func, **kwargs)

0 comments on commit ae54591

Please sign in to comment.