Skip to content

Commit

Permalink
Add support for cases without iteration folder (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnatt authored Apr 17, 2024
1 parent b35ffdf commit df6318c
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ venv.bak/
src/fmu/dataio/version.py
# aggregated examples directory
examples/s/d/nn/xcase/iter-0/
# exported results directory
share/


# mypy
.dmypy.json
Expand Down
8 changes: 4 additions & 4 deletions src/fmu/dataio/providers/_fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def __post_init__(self) -> None:
self._iter_name = self._runpath.name
self._real_name = self._runpath.parent.name
else:
logger.debug("No iteration folder found")
raise NotImplementedError(
"No iteration folder found, this is not supported yet"
)
logger.debug("No iteration folder found, using default name iter-0")
self._iter_name = "iter-0"
self._real_name = self._runpath.name

logger.debug("Found iter name from runpath: %s", self._iter_name)
logger.debug("Found real name from runpath: %s", self._real_name)

Expand Down
17 changes: 17 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
logger = logging.getLogger(__name__)

ERTRUN = "tests/data/drogon/ertrun1"
ERTRUN_NO_ITER = "tests/data/drogon/ertrun1_no_iter"
ERTRUN_REAL0_ITER0 = f"{ERTRUN}/realization-0/iter-0"
ERTRUN_PRED = f"{ERTRUN}/realization-0/pred"

Expand Down Expand Up @@ -129,6 +130,22 @@ def fixture_fmurun_non_equal_real_and_iter(tmp_path_factory, monkeypatch, rootpa
return rootpath


@pytest.fixture(name="fmurun_no_iter_folder", scope="function")
def fixture_fmurun_no_iter_folder(tmp_path_factory, monkeypatch, rootpath):
"""Create a tmp folder structure for testing; with no iter folder!"""
tmppath = tmp_path_factory.mktemp("data3")
newpath = tmppath / ERTRUN_NO_ITER
shutil.copytree(rootpath / ERTRUN_NO_ITER, newpath)
rootpath = newpath / "realization-1"

monkeypatch.setenv(f"_ERT_{FmuEnv.ITERATION_NUMBER.name}", "0")
monkeypatch.setenv(f"_ERT_{FmuEnv.REALIZATION_NUMBER.name}", "1")
monkeypatch.setenv(f"_ERT_{FmuEnv.RUNPATH.name}", str(rootpath))

logger.debug("Ran %s", _current_function_name())
return rootpath


@pytest.fixture(name="fmurun_w_casemetadata_pred", scope="function")
def fixture_fmurun_w_casemetadata_pred(tmp_path_factory, monkeypatch, rootpath):
"""Create a tmp folder structure for testing; here existing fmurun w/ case meta!"""
Expand Down
134 changes: 134 additions & 0 deletions tests/data/drogon/ertrun1_no_iter/realization-1/jobs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"umask" : "0002",
"DATA_ROOT": "/project/fmu/tutorial/drogon/resmod/ff/users/jriv/21.0.0.dev/21.0.0.dev_20210412/ert/model",
"global_environment" : {"ECL300_SITE_CONFIG" : "/prog/res/komodo/2021.03.01-py36-rhel7/root/lib/python3.6/site-packages/ert_configurations/resources/ecl300_config.yml", "ECL100_SITE_CONFIG" : "/prog/res/komodo/2021.03.01-py36-rhel7/root/lib/python3.6/site-packages/ert_configurations/resources/ecl100_config.yml", "RMS_PLUGINS_LIBRARY" : "/project/res/APSGUI/releases/stable", "RMS_SITE_CONFIG" : "/prog/res/komodo/2021.03.01-py36-rhel7/root/lib/python3.6/site-packages/ert_configurations/resources/rms_config.yml", "FLOW_SITE_CONFIG" : "/prog/res/komodo/2021.03.01-py36-rhel7/root/lib/python3.6/site-packages/ert_configurations/resources/flow_config.yml"},
"global_update_path" : {},
"jobList" : [ {"name" : "MAKE_DIRECTORY",
"executable" : "/prog/res/komodo/2021.03.01-py36-rhel7/root/share/ert/shell_scripts/make_directory",
"target_file" : null,
"error_file" : null,
"start_file" : null,
"stdout" : "make_directory.stdout.0",
"stderr" : "make_directory.stderr.0",
"stdin" : null,
"argList" : ["/scratch/fmu/jriv/01_drogon_ahm/realization-0/iter-0//fmuconfig/output"],
"environment" : null,
"exec_env" : null,
"license_path" : null,
"max_running_minutes" : null,
"max_running" : null,
"min_arg" : 1,
"arg_types" : ["STRING"],
"max_arg" : 1
},
{"name" : "COPY_DIRECTORY",
"executable" : "/prog/res/komodo/2021.03.01-py36-rhel7/root/share/ert/shell_scripts/copy_directory",
"target_file" : null,
"error_file" : null,
"start_file" : null,
"stdout" : "copy_directory.stdout.34",
"stderr" : "copy_directory.stderr.34",
"stdin" : null,
"argList" : ["/project/fmu/tutorial/drogon/resmod/ff/users/jriv/21.0.0.dev/21.0.0.dev_20210412/ert/model/../../rms/input/well_modelling","/scratch/fmu/jriv/01_drogon_ahm/realization-0/iter-0//rms/input"],
"environment" : null,
"exec_env" : null,
"license_path" : null,
"max_running_minutes" : null,
"max_running" : null,
"min_arg" : 2,
"arg_types" : ["STRING", "STRING"],
"max_arg" : 2
},
{"name" : "COPY_FILE",
"executable" : "/prog/res/komodo/2021.03.01-py36-rhel7/root/share/ert/shell_scripts/copy_file",
"target_file" : null,
"error_file" : null,
"start_file" : null,
"stdout" : "copy_file.stdout.35",
"stderr" : "copy_file.stderr.35",
"stdin" : null,
"argList" : ["/project/fmu/tutorial/drogon/resmod/ff/users/jriv/21.0.0.dev/21.0.0.dev_20210412/ert/model/../input/distributions/random.seeds","rms/model/random.seeds"],
"environment" : null,
"exec_env" : null,
"license_path" : null,
"max_running_minutes" : null,
"max_running" : null,
"min_arg" : 2,
"arg_types" : ["STRING", "STRING"],
"max_arg" : 2
},
{"name" : "MAKE_SYMLINK",
"executable" : "/prog/res/komodo/2021.03.01-py36-rhel7/root/share/ert/shell_scripts/symlink",
"target_file" : null,
"error_file" : null,
"start_file" : null,
"stdout" : "make_symlink.stdout.42",
"stderr" : "make_symlink.stderr.42",
"stdin" : null,
"argList" : ["/project/fmu/tutorial/drogon/resmod/ff/users/jriv/21.0.0.dev/21.0.0.dev_20210412/ert/model/../../share/observations/seismic","/scratch/fmu/jriv/01_drogon_ahm/realization-0/iter-0//share/observations/seismic"],
"environment" : null,
"exec_env" : null,
"license_path" : null,
"max_running_minutes" : null,
"max_running" : null,
"min_arg" : 2,
"arg_types" : ["STRING", "STRING"],
"max_arg" : 2
},
{"name" : "RMS",
"executable" : "/prog/res/komodo/2021.03.01-py36-rhel7/root/share/ert/forward-models/res/script/rms",
"target_file" : "RMS_TARGET_MAIN",
"error_file" : null,
"start_file" : null,
"stdout" : "RMS.stdout.46",
"stderr" : "RMS.stderr.46",
"stdin" : null,
"argList" : ["0","/project/fmu/tutorial/drogon/resmod/ff/users/jriv/21.0.0.dev/21.0.0.dev_20210412/ert/model/../../rms/model/drogon.rms12.0.2","MAIN","-r","rms/model","-t","RMS_TARGET_MAIN","-i","./","-v","12.0.2","-e","./",""],
"environment" : null,
"exec_env" : null,
"license_path" : null,
"max_running_minutes" : null,
"max_running" : null,
"min_arg" : null,
"arg_types" : [],
"max_arg" : null
},
{"name" : "ECLIPSE100",
"executable" : "/prog/res/komodo/2021.03.01-py36-rhel7/root/share/ert/forward-models/res/script/ecl100",
"target_file" : null,
"error_file" : null,
"start_file" : null,
"stdout" : "ECLIPSE100.stdout.47",
"stderr" : "ECLIPSE100.stderr.47",
"stdin" : null,
"argList" : ["eclipse/model/DROGON-0","-v","2020.2","-n","1",""],
"environment" : null,
"exec_env" : null,
"license_path" : null,
"max_running_minutes" : null,
"max_running" : null,
"min_arg" : null,
"arg_types" : [],
"max_arg" : null
},
{"name" : "DELETE_DIRECTORY",
"executable" : "/prog/res/komodo/2021.03.01-py36-rhel7/root/share/ert/shell_scripts/delete_directory",
"target_file" : null,
"error_file" : null,
"start_file" : null,
"stdout" : "delete_dir.stdout.77",
"stderr" : "delete_dir.stderr.77",
"stdin" : null,
"argList" : ["sim2seis/output/pem/"],
"environment" : null,
"exec_env" : null,
"license_path" : null,
"max_running_minutes" : null,
"max_running" : null,
"min_arg" : 1,
"arg_types" : ["STRING"],
"max_arg" : 1
}],
"run_id" : "26295:22197:2021-4-20-12-50-55:406759315d",
"ert_pid" : "26295"
}
21 changes: 21 additions & 0 deletions tests/data/drogon/ertrun1_no_iter/realization-1/parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"THERYS_PORO_LS" : 0.23,
"THERYS_PORO_US" : 0.31,
"VALYSAR_CHANNEL_AZIMUTH" : 63.2316,
"VALYSAR_CHANNEL_VOLFRAC" : 0.423742,
},
"LOG10_GLOBVAR" : {
"FAULT_SEAL_SCALING" : 0.685516
},
"LOG10_MULTREGT" : {
"MULT_THERYS_VOLON" : -3.21365,
"MULT_VALYSAR_THERYS" : -3.2582,
"MULT_VALYSAR_VOLON" : -2.82607
},
"MULTREGT" : {
"MULT_THERYS_VOLON" : 0.000611439,
"MULT_VALYSAR_THERYS" : 0.000551826,
"MULT_VALYSAR_VOLON" : 0.00149254
},
"GLOBVAR:DCONV_ALTERNATIVE" : 0,
}
11 changes: 11 additions & 0 deletions tests/data/drogon/ertrun1_no_iter/realization-1/parameters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SENSNAME rms_seed
SENSCASE p10_p90
RMS_SEED 1000
KVKH_CHANNEL 0.6
KVKH_CREVASSE 0.3
GLOBVAR:VOLON_FLOODPLAIN_VOLFRAC 0.256355
GLOBVAR:VOLON_PERMH_CHANNEL 1100
GLOBVAR:VOLON_PORO_CHANNEL 0.2
LOG10_GLOBVAR:FAULT_SEAL_SCALING 0.685516
LOG10_MULTREGT:MULT_THERYS_VOLON -3.21365
LOG10_MULTREGT:MULT_VALYSAR_THERYS -3.2582
44 changes: 44 additions & 0 deletions tests/data/drogon/ertrun1_no_iter/share/metadata/fmu_case.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
schema: https://main-fmu-schemas-dev.radix.equinor.com/schemas/0.8.0/fmu_results.json
source: fmu
version: 0.8.0
class: case
tracklog:
- datetime: "2021-05-05T09:20:40.475110"
event: created
user:
id: peesv
fmu:
case:
name: somecasename
uuid: a40b05e8-e47f-47b1-8fee-f52a5116bd37
user:
id: peesv
description:
- My case / ERT run description
restart_from: x40b09e8-d47f-49b1-8fxx-g52a5119bd37_iter-3
model:
description:
- Tutorials & stuff
- Testing new things
name: ff
revision: 21.0.0.dev
masterdata:
smda:
coordinate_system:
identifier: ST_WGS84_UTM37N_P32637
uuid: ad214d85-dac7-19da-e053-c918a4889309
country:
- identifier: Norway
uuid: ad214d85-8a1d-19da-e053-c918a4889309
discovery:
- short_identifier: DROGON
uuid: ad214d85-8a1d-19da-e053-c918a4889309
field:
- identifier: DROGON
uuid: 00000000-0000-0000-0000-000000000000
stratigraphic_column:
identifier: DROGON_2020
uuid: ad214d85-8a1d-19da-e053-c918a4889310
access:
asset:
name: Drogon # adding level to make room for unique ID in the future
17 changes: 17 additions & 0 deletions tests/test_units/test_dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,23 @@ def test_fmurun_attribute_outside_fmu(rmsglobalconfig):
assert edata._fmurun is False


def test_exportdata_no_iter_folder(
fmurun_no_iter_folder, rmsglobalconfig, regsurf, monkeypatch
):
"""Test that the fmuprovider works without a iteration folder"""

monkeypatch.chdir(fmurun_no_iter_folder)
edata = ExportData(config=rmsglobalconfig, content="depth")
assert edata._fmurun is True

edata.export(regsurf)

assert edata._metadata["fmu"]["realization"]["name"] == "realization-1"
assert edata._metadata["fmu"]["realization"]["id"] == 1
assert edata._metadata["fmu"]["iteration"]["name"] == "iter-0"
assert edata._metadata["fmu"]["iteration"]["id"] == 0


def test_fmurun_attribute_inside_fmu(fmurun_w_casemetadata, rmsglobalconfig):
"""Test that _fmurun attribute is True when in fmu"""

Expand Down
25 changes: 24 additions & 1 deletion tests/test_units/test_fmuprovider_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_fmuprovider_arbitrary_iter_name(fmurun_w_casemetadata_pred):
assert str(meta.case.uuid) == "a40b05e8-e47f-47b1-8fee-f52a5116bd37"


def test_fmuprovider_arbitrary_iter_name_(fmurun_non_equal_real_and_iter):
def test_fmuprovider_get_real_and_iter_from_env(fmurun_non_equal_real_and_iter):
"""Test that iter and real number is picked up correctly from env"""

os.chdir(fmurun_non_equal_real_and_iter)
Expand All @@ -129,6 +129,29 @@ def test_fmuprovider_arbitrary_iter_name_(fmurun_non_equal_real_and_iter):
assert myfmu._iter_id == 0


def test_fmuprovider_no_iter_folder(fmurun_no_iter_folder):
"""Test that the fmuprovider works without a iteration folder"""

os.chdir(fmurun_no_iter_folder)
myfmu = FmuProvider(
model=GLOBAL_CONFIG_MODEL, fmu_context=FmuContext.REALIZATION, workflow=WORKFLOW
)
assert myfmu._runpath == fmurun_no_iter_folder
assert myfmu._casepath == fmurun_no_iter_folder.parent
assert myfmu._case_name == "ertrun1_no_iter"
assert myfmu._real_name == "realization-1"
assert myfmu._real_id == 1
assert myfmu._iter_name == "iter-0"
assert myfmu._iter_id == 0

# also check that it is stored correctly in the metadata
meta = myfmu.get_metadata()
assert meta.realization.name == "realization-1"
assert meta.realization.id == 1
assert meta.iteration.name == "iter-0"
assert meta.iteration.id == 0


def test_fmuprovider_prehook_case(tmp_path, globalconfig2, fmurun_prehook):
"""The fmu run case metadata is initialized with Initialize case; then get provider.
Expand Down

0 comments on commit df6318c

Please sign in to comment.