Skip to content

Commit

Permalink
Apply review changes from #364
Browse files Browse the repository at this point in the history
  • Loading branch information
ro-oliveira95 committed Mar 12, 2024
1 parent 32c28a5 commit 7954b9a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 48 deletions.
10 changes: 5 additions & 5 deletions src/alfasim_sdk/result_reader/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1777,13 +1777,13 @@ def open_result_file(
The result HDF file, or None if it doesn't exist or is still being created.
"""
filepath = result_directory / result_filename
ignored_file = result_directory / f"{result_filename}.creating"
creating_file = result_directory / f"{result_filename}.creating"

if not filepath.is_file():
yield None
# Avoid to read result files with incomplete metadata.
elif not ignored_file.is_file():
# Do not open incomplete file.
if creating_file.is_file():
yield None
else:
with _open_result_file(filepath) as file:
yield file
else:
yield None
83 changes: 40 additions & 43 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,53 +280,51 @@ def _create_and_populate_hm_result_file(
result_dir.mkdir(parents=True, exist_ok=True)
result_filepath = result_dir / "result"

file = h5py.File(result_filepath, "x", libver="latest", locking=False)
meta_group = file.create_group(META_GROUP_NAME, track_order=True)
data_group = file.create_group(HISTORY_MATCHING_GROUP_NAME, track_order=True)

dataset = data_group.create_dataset(
dataset_key,
shape=result.shape,
dtype=np.float64,
maxshape=tuple(None for _ in result.shape),
)

objective_functions = {
"observed_curve_1": {"trend_id": "trend_1", "property_id": "holdup"},
"observed_curve_2": {"trend_id": "trend_2", "property_id": "pressure"},
}

fake_meta = {
"parametric_var_1": {
"parametric_var_id": "parametric_var_1",
"parametric_var_name": "mg",
"min_value": limits[0][0],
"max_value": limits[0][1],
"objective_functions": objective_functions,
"data_index": 0,
},
"parametric_var_2": {
"parametric_var_id": "parametric_var_2",
"parametric_var_name": "mo",
"min_value": limits[1][0],
"max_value": limits[1][1],
"objective_functions": objective_functions,
"data_index": 1,
},
}

meta_group.attrs[HISTORY_MATCHING_GROUP_NAME] = json.dumps(fake_meta)
dataset[:] = result
with h5py.File(result_filepath, "x", libver="latest", locking=False) as file:
meta_group = file.create_group(META_GROUP_NAME, track_order=True)
data_group = file.create_group(HISTORY_MATCHING_GROUP_NAME, track_order=True)

dataset = data_group.create_dataset(
dataset_key,
shape=result.shape,
dtype=np.float64,
maxshape=tuple(None for _ in result.shape),
)

file.swmr_mode = True
file.close()
objective_functions = {
"observed_curve_1": {"trend_id": "trend_1", "property_id": "holdup"},
"observed_curve_2": {"trend_id": "trend_2", "property_id": "pressure"},
}

fake_meta = {
"parametric_var_1": {
"parametric_var_id": "parametric_var_1",
"parametric_var_name": "mg",
"min_value": limits[0][0],
"max_value": limits[0][1],
"objective_functions": objective_functions,
"data_index": 0,
},
"parametric_var_2": {
"parametric_var_id": "parametric_var_2",
"parametric_var_name": "mo",
"min_value": limits[1][0],
"max_value": limits[1][1],
"objective_functions": objective_functions,
"data_index": 1,
},
}

meta_group.attrs[HISTORY_MATCHING_GROUP_NAME] = json.dumps(fake_meta)
dataset[:] = result

file.swmr_mode = True


@pytest.fixture()
def hm_probabilistic_results_dir(datadir: Path) -> Path:
"""
Crete a History Matching result folder with a populated result file for each type of analysis
(probabilistic and deterministic).
Create a History Matching Probabilistic result folder with a populated HDF5 file.
"""
import numpy as np

Expand All @@ -349,8 +347,7 @@ def hm_probabilistic_results_dir(datadir: Path) -> Path:
@pytest.fixture()
def hm_deterministic_results_dir(datadir: Path) -> Path:
"""
Crete a History Matching result folder with a populated result file for each type of analysis
(probabilistic and deterministic).
Create a History Matching Deterministic result folder with a populated HDF5 file.
"""
import numpy as np

Expand Down

0 comments on commit 7954b9a

Please sign in to comment.