-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from bessagroup/mpvanderschelling/issue252
Improving usability by implementing helper function to convert arbitrary functions to DataGenerators
- Loading branch information
Showing
5 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Callable | ||
|
||
import pytest | ||
|
||
from f3dasm import ExperimentData | ||
from f3dasm.design import Domain | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def experiment_data() -> ExperimentData: | ||
domain = Domain() | ||
domain.add_float('x', low=0.0, high=1.0) | ||
|
||
experiment_data = ExperimentData(domain=domain) | ||
|
||
experiment_data.sample(sampler='random', n_samples=10, seed=2023) | ||
return experiment_data | ||
|
||
|
||
def example_function(x: int, s: int): | ||
return x + s, x - s | ||
|
||
|
||
def example_function2(x: int): | ||
return x, -x | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def function_1() -> Callable: | ||
return example_function | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def function_2() -> Callable: | ||
return example_function2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Callable | ||
|
||
import pytest | ||
|
||
from f3dasm import ExperimentData | ||
from f3dasm.datageneration import DataGenerator, convert_function | ||
|
||
pytestmark = pytest.mark.smoke | ||
|
||
|
||
def test_convert_function( | ||
experiment_data: ExperimentData, function_1: Callable): | ||
data_generator = convert_function(f=function_1, input=['x'], output=[ | ||
'y0', 'y1'], kwargs={'s': 103}) | ||
|
||
assert isinstance(data_generator, DataGenerator) | ||
|
||
experiment_data.evaluate(data_generator) | ||
|
||
|
||
def test_convert_function2( | ||
experiment_data: ExperimentData, function_2: Callable): | ||
data_generator = convert_function(f=function_2, input=['x'], output=[ | ||
'y0', 'y1']) | ||
|
||
assert isinstance(data_generator, DataGenerator) | ||
|
||
experiment_data.evaluate(data_generator) |