From df3f5f1f2569e98dfea8a634b28fe63e308465e5 Mon Sep 17 00:00:00 2001 From: Martin van der Schelling <61459087+mpvanderschelling@users.noreply.github.com> Date: Thu, 26 Oct 2023 17:04:26 -0400 Subject: [PATCH 1/3] Fixes #194 --- .../_src/datageneration/datagenerator.py | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/f3dasm/_src/datageneration/datagenerator.py b/src/f3dasm/_src/datageneration/datagenerator.py index 81a4742e..ff663164 100644 --- a/src/f3dasm/_src/datageneration/datagenerator.py +++ b/src/f3dasm/_src/datageneration/datagenerator.py @@ -7,6 +7,7 @@ # Standard import sys +from abc import abstractmethod from functools import partial from typing import Any, Callable @@ -43,15 +44,32 @@ 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 + """ ... + @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 + """ + ... 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 + """ ... @time_and_log @@ -88,7 +106,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) From f47bc0f29ad9abc4b18cb9122d1c2a5940d3fdf1 Mon Sep 17 00:00:00 2001 From: Martin van der Schelling <61459087+mpvanderschelling@users.noreply.github.com> Date: Mon, 30 Oct 2023 10:27:19 -0400 Subject: [PATCH 2/3] added more descriptive docstrings --- .../_src/datageneration/datagenerator.py | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/f3dasm/_src/datageneration/datagenerator.py b/src/f3dasm/_src/datageneration/datagenerator.py index ff663164..c0f501e0 100644 --- a/src/f3dasm/_src/datageneration/datagenerator.py +++ b/src/f3dasm/_src/datageneration/datagenerator.py @@ -49,6 +49,10 @@ def pre_process(self, experiment_sample: ExperimentSample, **kwargs) -> None: 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. """ ... @@ -60,7 +64,14 @@ def execute(self, **kwargs) -> None: ------ 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: @@ -69,22 +80,42 @@ def post_process(self, experiment_sample: ExperimentSample, **kwargs) -> None: 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 + """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 From e11a00352fc4e0a0db7b5188df05ec4e02c41ab8 Mon Sep 17 00:00:00 2001 From: Martin van der Schelling <61459087+mpvanderschelling@users.noreply.github.com> Date: Mon, 30 Oct 2023 10:35:17 -0400 Subject: [PATCH 3/3] flake8 error resolved at docstring --- src/f3dasm/_src/datageneration/datagenerator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/f3dasm/_src/datageneration/datagenerator.py b/src/f3dasm/_src/datageneration/datagenerator.py index 71a8a30d..93d421f5 100644 --- a/src/f3dasm/_src/datageneration/datagenerator.py +++ b/src/f3dasm/_src/datageneration/datagenerator.py @@ -116,7 +116,7 @@ def _run(self, experiment_sample: ExperimentSample, **kwargs) -> ExperimentSampl Returns ------- ExperimentSample - Processed design with the response of the data generator saved in the + Processed design with the response of the data generator saved in the experiment_sample """ # Cache the design