-
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.
Fix data indexing issue and add column renaming functionality
- Loading branch information
1 parent
9be5928
commit 6d99381
Showing
8 changed files
with
956 additions
and
19 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
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,130 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import pytest | ||
import xarray as xr | ||
|
||
from f3dasm._src.design.parameter import (_CategoricalParameter, | ||
_ContinuousParameter, | ||
_DiscreteParameter) | ||
from f3dasm._src.experimentdata._experimental._newexperimentdata2 import \ | ||
ExperimentData | ||
from f3dasm.design import Domain, make_nd_continuous_domain | ||
|
||
SEED = 42 | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def seed() -> int: | ||
return SEED | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def domain() -> Domain: | ||
|
||
space = { | ||
'x1': _ContinuousParameter(-5.12, 5.12), | ||
'x2': _DiscreteParameter(-3, 3), | ||
'x3': _CategoricalParameter(["red", "green", "blue"]) | ||
} | ||
|
||
return Domain(space=space) | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def domain_continuous() -> Domain: | ||
return make_nd_continuous_domain(bounds=np.array([[0., 1.], [0., 1.], [0., 1.]]), dimensionality=3) | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def experimentdata(domain: Domain) -> ExperimentData: | ||
e_data = ExperimentData(domain) | ||
e_data.sample(sampler='random', n_samples=10, seed=SEED) | ||
return e_data | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def experimentdata2(domain: Domain) -> ExperimentData: | ||
return ExperimentData.from_sampling(sampler='random', domain=domain, n_samples=10, seed=SEED) | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def experimentdata_continuous(domain_continuous: Domain) -> ExperimentData: | ||
return ExperimentData.from_sampling(sampler='random', domain=domain_continuous, n_samples=10, seed=SEED) | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def experimentdata_expected() -> ExperimentData: | ||
domain_continuous = make_nd_continuous_domain( | ||
bounds=np.array([[0., 1.], [0., 1.], [0., 1.]]), dimensionality=3) | ||
data = ExperimentData.from_sampling( | ||
sampler='random', domain=domain_continuous, n_samples=10, seed=SEED) | ||
for es, output in zip(data, np.zeros((10, 1))): | ||
es.store(name='y', object=float(output)) | ||
data._set_experiment_sample(es) | ||
data.add(input_data=np.array([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]]), | ||
output_data=np.array([[0.0], [0.0]]), domain=data.domain) | ||
|
||
# data._input_data.data = data._input_data.data.round(6) | ||
return data | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def experimentdata_expected_no_output() -> ExperimentData: | ||
domain_continuous = make_nd_continuous_domain( | ||
bounds=np.array([[0., 1.], [0., 1.], [0., 1.]]), dimensionality=3) | ||
data = ExperimentData.from_sampling( | ||
sampler='random', domain=domain_continuous, n_samples=10, seed=SEED) | ||
data.add(input_data=np.array( | ||
[[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]]), domain=domain_continuous) | ||
|
||
# data._input_data.data = data._input_data.data.round(6) | ||
|
||
return data | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def experimentdata_expected_only_domain() -> ExperimentData: | ||
domain_continuous = make_nd_continuous_domain( | ||
bounds=np.array([[0., 1.], [0., 1.], [0., 1.]]), dimensionality=3) | ||
return ExperimentData(domain=domain_continuous) | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def numpy_array(domain_continuous: Domain) -> np.ndarray: | ||
rng = np.random.default_rng(SEED) | ||
return rng.random((10, len(domain_continuous))) | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def numpy_output_array(domain_continuous: Domain) -> np.ndarray: | ||
return np.zeros((10, 1)) | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def xarray_dataset(domain_continuous: Domain) -> xr.Dataset: | ||
rng = np.random.default_rng(SEED) | ||
# np.random.seed(SEED) | ||
input_data = rng.random((10, len(domain_continuous))) | ||
input_names = domain_continuous.names | ||
|
||
output_data = pd.DataFrame() | ||
output_names = output_data.columns.to_list() | ||
|
||
return xr.Dataset({'input': xr.DataArray(input_data, dims=['iterations', 'input_dim'], coords={ | ||
'iterations': range(len(input_data)), 'input_dim': input_names}), | ||
'output': xr.DataArray(output_data, dims=['iterations', 'output_dim'], coords={ | ||
'iterations': range(len(output_data)), 'output_dim': output_names})}) | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def pandas_dataframe(domain_continuous: Domain) -> pd.DataFrame: | ||
# np.random.seed(SEED) | ||
rng = np.random.default_rng(SEED) | ||
return pd.DataFrame(rng.random((10, len(domain_continuous))), columns=domain_continuous.names) | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def continuous_parameter() -> _ContinuousParameter: | ||
return _ContinuousParameter(lower_bound=0., upper_bound=1.) |
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,43 @@ | ||
import pandas as pd | ||
|
||
from f3dasm._src.experimentdata._experimental._jobqueue2 import \ | ||
Index as _JobQueue | ||
|
||
# from f3dasm._src.experimentdata._jobqueue import _JobQueue | ||
|
||
|
||
def test_select_all_with_matching_status(): | ||
# Create a job queue with some jobs | ||
job_queue = _JobQueue() | ||
job_queue.jobs = pd.Series( | ||
['in progress', 'running', 'completed', 'in progress', 'failed']) | ||
|
||
# Select all jobs with status 'in progress' | ||
selected_jobs = job_queue.select_all('in progress') | ||
|
||
# Check if the selected jobs match the expected result | ||
assert (selected_jobs.jobs == ['in progress', 'in progress']).all() | ||
|
||
|
||
def test_select_all_with_no_matching_status(): | ||
# Create a job queue with some jobs | ||
job_queue = _JobQueue() | ||
job_queue.jobs = pd.Series( | ||
['in progress', 'running', 'completed', 'in progress', 'failed']) | ||
|
||
# Select all jobs with status 'cancelled' | ||
selected_jobs = job_queue.select_all('cancelled') | ||
|
||
# Check if the selected jobs match the expected result | ||
assert selected_jobs.jobs.empty | ||
|
||
|
||
def test_select_all_with_empty_job_queue(): | ||
# Create an empty job queue | ||
job_queue = _JobQueue() | ||
|
||
# Select all jobs with status 'in progress' | ||
selected_jobs = job_queue.select_all('in progress') | ||
|
||
# Check if the selected jobs match the expected result | ||
assert selected_jobs.jobs.empty |
Oops, something went wrong.