From 865c0920ca9a1f78597404c680eb9c2668cd37b1 Mon Sep 17 00:00:00 2001 From: "Oddvar Lia (ST MSU GEO)" Date: Fri, 24 Nov 2023 14:34:44 +0100 Subject: [PATCH] Updated test code --- .../example_case/scripts/FM_SIM_FIELD | 2 +- .../example_case/scripts/common_functions.py | 50 +++++++++++++------ .../example_case/scripts/sim_fields.py | 22 +++++--- .../example_case/sim_field_case_A.ert | 16 +++--- .../example_case/sim_field_local_case_A.ert | 17 +++---- 5 files changed, 64 insertions(+), 43 deletions(-) diff --git a/tests/jobs/localisation/example_case/scripts/FM_SIM_FIELD b/tests/jobs/localisation/example_case/scripts/FM_SIM_FIELD index b78850cb7..53ae455ca 100644 --- a/tests/jobs/localisation/example_case/scripts/FM_SIM_FIELD +++ b/tests/jobs/localisation/example_case/scripts/FM_SIM_FIELD @@ -1,6 +1,6 @@ EXECUTABLE ./sim_fields.py -ARGLIST +ARGLIST STDERR sim_fields.stderr STDOUT sim_fields.stdout diff --git a/tests/jobs/localisation/example_case/scripts/common_functions.py b/tests/jobs/localisation/example_case/scripts/common_functions.py index 69e5cbf5d..3e58e8b13 100644 --- a/tests/jobs/localisation/example_case/scripts/common_functions.py +++ b/tests/jobs/localisation/example_case/scripts/common_functions.py @@ -2,10 +2,11 @@ Common functions used by the scripts: init_test_case.py and sim_field.py """ import copy +import dataclasses import math -import os from dataclasses import dataclass -from typing import Tuple +from pathlib import Path +from typing import Any, Dict, Tuple import gstools as gs import numpy as np @@ -50,7 +51,7 @@ class Field: initial_file_name: str = "init_files/FieldParam" updated_file_name: str = "FieldParam" seed_file: str = "randomseeds.txt" - variogram: str = "exponential" + variogram: str = "gaussian" correlation_range: Tuple[float] = (250.0, 500.0, 2.0) correlation_azimuth: float = 0.0 correlation_dip: float = 0.0 @@ -134,18 +135,35 @@ class Settings: localisation: Localisation = Localisation() optional: Optional = Optional() - -def read_config_file(config_file_name): - # Modify default settings if config_file exists - settings = Settings() - if os.path.exists(config_file_name): - with open(config_file_name, "r", encoding="utf-8") as yml_file: - settings_yml = yaml.safe_load(yml_file) - - updated_settings = update_settings(settings, settings_yml) - return updated_settings - - raise IOError("Missing config file ") + def update(self, updates): + for key, value in updates.items(): + if hasattr(self, key): + attr = getattr(self, key) + if dataclasses.is_dataclass(attr): + for attr_key, attr_value in value.items(): + if hasattr(attr, attr_key): + setattr(attr, attr_key, attr_value) + else: + setattr(self, key, value) + + +def read_config_file(config_file_name: Path) -> Dict[str, Any]: + with open(config_file_name, "r", encoding="utf-8") as f: + settings = yaml.safe_load(f) + model_size = ModelSize(**settings["settings"]["model_size"]) + field = Field(**settings["settings"]["field"]) + response = Response(**settings["settings"]["response"]) + observation = Observation(**settings["settings"]["observation"]) + localisation = Localisation(**settings["settings"]["localisation"]) + optional = Optional(**settings["settings"]["optional"]) + return Settings( + model_size=model_size, + field=field, + response=response, + observation=observation, + localisation=localisation, + optional=optional, + ) def update_key(key, default_value, settings_dict, parent_key=None): @@ -493,7 +511,6 @@ def generate_field_and_upscale( def get_seed(seed_file_name, r_number): - # Realization number counted from 0 with open(seed_file_name, "r", encoding="utf8") as file: lines = file.readlines() try: @@ -504,6 +521,7 @@ def get_seed(seed_file_name, r_number): raise IOError( "Invalid seed value in file for realization{r_number}" ) from exc + print(f"Seed value from get_seed: {seed_value} Realisation number: {r_number} ") return seed_value diff --git a/tests/jobs/localisation/example_case/scripts/sim_fields.py b/tests/jobs/localisation/example_case/scripts/sim_fields.py index ee8ba162b..2f651dcea 100755 --- a/tests/jobs/localisation/example_case/scripts/sim_fields.py +++ b/tests/jobs/localisation/example_case/scripts/sim_fields.py @@ -2,6 +2,7 @@ """ Script used as forward model in ERT to test localisation. """ +import os import sys # pylint: disable=import-error, redefined-outer-name @@ -56,7 +57,9 @@ def get_iteration_real_number_config_file(argv): print(f"ERT realization: {real_number}") config_file_name = argv[3] - return iteration, real_number, config_file_name + + config_path = argv[4] + return iteration, real_number, config_file_name, config_path def main(args): @@ -75,18 +78,21 @@ def main(args): # and the coarse grid with upscaled values must have Eclipse grid index origin # Read config_file if it exists. Use default settings for everything not specified. - iteration, real_number, config_file_name = get_iteration_real_number_config_file( - args - ) + ( + iteration, + real_number, + config_file_name, + config_path, + ) = get_iteration_real_number_config_file(args) settings = read_config_file(config_file_name) - + print(f"Config path: {config_path}") if iteration == 0: print(f"Generate new field parameter realization:{real_number} ") # Simulate field (with trend) upscaled_values = generate_field_and_upscale( real_number, iteration, - settings.field.seed_file, + os.path.join(config_path, settings.field.seed_file), settings.field.algorithm, settings.field.name, settings.field.initial_file_name, @@ -142,9 +148,9 @@ def main(args): if settings.optional.write_obs_pred_diff_field_file: obs_field_object = read_obs_field_from_file( settings.response.file_format, - settings.observation.reference_param_file, + os.path.join(config_path, settings.observation.reference_param_file), settings.response.grid_file_name, - settings.observation.reference_field_name, + os.path.join(config_path, settings.observation.reference_field_name), ) upscaled_field_object = read_upscaled_field_from_file( iteration, diff --git a/tests/jobs/localisation/example_case/sim_field_case_A.ert b/tests/jobs/localisation/example_case/sim_field_case_A.ert index 609991707..5a66783a5 100644 --- a/tests/jobs/localisation/example_case/sim_field_case_A.ert +++ b/tests/jobs/localisation/example_case/sim_field_case_A.ert @@ -1,5 +1,4 @@ DEFINE $USER -DEFINE /scratch/fmu DEFINE sim_field_A DEFINE randomseeds.txt DEFINE /example_test_config_A.yml @@ -10,7 +9,6 @@ INSTALL_JOB SIM_FIELD scripts/FM_SIM_FIELD DEFINE /observations/observations.obs OBS_CONFIG -TIME_MAP time_map.txt JOBNAME sim_fields_ @@ -19,12 +17,13 @@ NUM_REALIZATIONS 10 -- Set number of realizations to run MAX_RUNTIME 18000 -- Set the maximum allowed run time (in seconds) MIN_REALIZATIONS 1 -- Success criteria MAX_SUBMIT 1 -- How many times should the queue system retry a simulation. -QUEUE_OPTION LSF MAX_RUNNING 100 -- Choke the number of simultaneous run -QUEUE_OPTION LSF LSF_QUEUE mr -- Assign LSF cluster queue to use - -RUNPATH ///realization-/iter- +-- QUEUE_OPTION LSF MAX_RUNNING 100 -- Choke the number of simultaneous run +-- QUEUE_OPTION LSF LSF_QUEUE mr -- Assign LSF cluster queue to use +QUEUE_SYSTEM LOCAL +QUEUE_OPTION LOCAL MAX_RUNNING 10 RANDOM_SEED 123456 -- ERT seed value +RUNPATH simulations//realization-/iter- ENSPATH output//storage -- Storage of internal ert data UPDATE_LOG_PATH output//update_log -- Info of active and inactive data points RUNPATH_FILE output//runpath_file -- List of runpaths @@ -47,11 +46,10 @@ FORWARD_MODEL COPY_FILE(=/, ==/init_files/ObsField.roff, =/init_files/ObsField.roff) FORWARD_MODEL MAKE_SYMLINK(=/GRID_STANDARD.EGRID, =/GRID_STANDARD.EGRID) -FORWARD_MODEL MAKE_SYMLINK(=/UpscaleGrid.EGRID, =/UpscaleGrid.EGRID) +FORWARD_MODEL MAKE_SYMLINK(=/GRID_STANDARD_UPSCALED.EGRID, =/GRID_STANDARD_UPSCALED.EGRID) -- The main forward model simulating gaussian field with trend, and upscale -FORWARD_MODEL SIM_FIELD(=, =, =) - +FORWARD_MODEL SIM_FIELD(=, =, =, =) GRID /GRID_STANDARD.EGRID -- Necessary for AHM using field parameters diff --git a/tests/jobs/localisation/example_case/sim_field_local_case_A.ert b/tests/jobs/localisation/example_case/sim_field_local_case_A.ert index 483dae1c5..6acb507a0 100644 --- a/tests/jobs/localisation/example_case/sim_field_local_case_A.ert +++ b/tests/jobs/localisation/example_case/sim_field_local_case_A.ert @@ -1,5 +1,4 @@ DEFINE $USER -DEFINE /scratch/fmu DEFINE sim_field_local_A DEFINE randomseeds.txt DEFINE /example_test_config_A.yml @@ -10,21 +9,21 @@ INSTALL_JOB SIM_FIELD scripts/FM_SIM_FIELD DEFINE /observations/observations.obs OBS_CONFIG -TIME_MAP time_map.txt JOBNAME sim_fields_ -NUM_REALIZATIONS 10 -- Set number of realizations to run +NUM_REALIZATIONS 10 -- Set number of realizations to run MAX_RUNTIME 18000 -- Set the maximum allowed run time (in seconds) MIN_REALIZATIONS 1 -- Success criteria MAX_SUBMIT 1 -- How many times should the queue system retry a simulation. -QUEUE_OPTION LSF MAX_RUNNING 100 -- Choke the number of simultaneous run -QUEUE_OPTION LSF LSF_QUEUE mr -- Assign LSF cluster queue to use - -RUNPATH ///realization-/iter- +-- QUEUE_OPTION LSF MAX_RUNNING 100 -- Choke the number of simultaneous run +-- QUEUE_OPTION LSF LSF_QUEUE mr -- Assign LSF cluster queue to use +QUEUE_SYSTEM LOCAL +QUEUE_OPTION LOCAL MAX_RUNNING 10 RANDOM_SEED 123456 -- ERT seed value +RUNPATH simulations//realization-/iter- ENSPATH output//storage -- Storage of internal ert data UPDATE_LOG_PATH output//update_log -- Info of active and inactive data points RUNPATH_FILE output//runpath_file -- List of runpaths @@ -47,10 +46,10 @@ FORWARD_MODEL COPY_FILE(=/, ==/init_files/ObsField.roff, =/init_files/ObsField.roff) FORWARD_MODEL MAKE_SYMLINK(=/GRID_STANDARD.EGRID, =/GRID_STANDARD.EGRID) -FORWARD_MODEL MAKE_SYMLINK(=/UpscaleGrid.EGRID, =/UpscaleGrid.EGRID) +FORWARD_MODEL MAKE_SYMLINK(=/GRID_STANDARD_UPSCALED.EGRID, =/GRID_STANDARD_UPSCALED.EGRID) -- The main forward model simulating gaussian field with trend, and upscale -FORWARD_MODEL SIM_FIELD(=, =, =) +FORWARD_MODEL SIM_FIELD(=, =, =, =) GRID /GRID_STANDARD.EGRID -- Necessary for AHM using field parameters