Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test field with FORWARD_INIT:False #9202

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added test-data/ert/heat_equation/cond_0.bgrdecl
Binary file not shown.
Binary file added test-data/ert/heat_equation/cond_1.bgrdecl
Binary file not shown.
Binary file added test-data/ert/heat_equation/cond_2.bgrdecl
Binary file not shown.
Binary file added test-data/ert/heat_equation/cond_3.bgrdecl
Binary file not shown.
Binary file added test-data/ert/heat_equation/cond_4.bgrdecl
Binary file not shown.
Binary file added test-data/ert/heat_equation/cond_5.bgrdecl
Binary file not shown.
Binary file added test-data/ert/heat_equation/cond_6.bgrdecl
Binary file not shown.
Binary file added test-data/ert/heat_equation/cond_7.bgrdecl
Binary file not shown.
Binary file added test-data/ert/heat_equation/cond_8.bgrdecl
Binary file not shown.
Binary file added test-data/ert/heat_equation/cond_9.bgrdecl
Binary file not shown.
26 changes: 26 additions & 0 deletions test-data/ert/heat_equation/config_forward_init_false.ert
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- By default, NumPy utilizes multiple threads, which is beneficial for parallelizable computations.
-- However, the heat equation implementation in this case does not benefit from parallel execution within a single realization.
-- When ERT runs multiple realizations, each one by default uses multiple threads for NumPy operations,
-- leading to resource contention and slower overall execution.
-- Setting these thread counts to 1 ensures each realization uses minimal resources,
-- allowing more realizations to run concurrently and significantly speeding up the entire experiment.
SETENV MKL_NUM_THREADS 1
SETENV NUMEXPR_NUM_THREADS 1
SETENV OMP_NUM_THREADS 1

QUEUE_SYSTEM LOCAL
QUEUE_OPTION LOCAL MAX_RUNNING 100

RANDOM_SEED 11223344

NUM_REALIZATIONS 10
GRID CASE.EGRID

OBS_CONFIG observations

FIELD COND PARAMETER cond.bgrdecl INIT_FILES:cond_%d.bgrdecl FORWARD_INIT:False

GEN_DATA MY_RESPONSE RESULT_FILE:gen_data_%d.out REPORT_STEPS:10,71,132,193,255,316,377,438 INPUT_FORMAT:ASCII

INSTALL_JOB heat_equation HEAT_EQUATION
SIMULATION_JOB heat_equation <IENS> <ITER>
16 changes: 16 additions & 0 deletions test-data/ert/heat_equation/generate_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import numpy as np
import numpy.typing as npt
import pandas as pd
import resfo
import xtgeo
from definition import Coordinate, obs_coordinates, obs_times
from heat_equation import heat_equation, sample_prior_conductivity
Expand Down Expand Up @@ -71,6 +72,19 @@ def make_observations(
return d


def generate_priors():
"""For testing FORWARD_INIT:False"""
rng = np.random.default_rng()
for i in range(10):
cond = sample_prior_conductivity(ensemble_size=1, nx=nx, rng=rng).reshape(
nx, nx
)
resfo.write(
f"cond_{i}.bgrdecl",
[("COND ", cond.flatten(order="F").astype(np.float32))],
)


if __name__ == "__main__":
create_egrid_file()

Expand Down Expand Up @@ -122,3 +136,5 @@ def make_observations(
with open(f"obs_{obs_time}.txt", "w", encoding="utf-8") as fobs:
df = d.iloc[d.index.get_level_values("k") == obs_time]
fobs.write(df.sort_index().to_csv(header=False, index=False, sep=" "))

generate_priors()
7 changes: 7 additions & 0 deletions tests/ert/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ def copy_snake_oil_case(copy_case):
fh.write("QUEUE_OPTION LOCAL MAX_RUNNING 12\n")


@pytest.fixture()
def copy_heat_equation(copy_case):
copy_case("heat_equation")
with open("config.ert", "a", encoding="utf-8") as fh:
fh.write("QUEUE_OPTION LOCAL MAX_RUNNING 12\n")


@pytest.fixture(
name="copy_snake_oil_case_storage",
params=[
Expand Down
40 changes: 40 additions & 0 deletions tests/ert/ui_tests/cli/test_field_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
import numpy.testing
import pytest
import resfo
import xtgeo

Expand Down Expand Up @@ -212,3 +213,42 @@ def test_parameter_update_with_inactive_cells_xtgeo_grdecl(tmpdir):
assert "nan" not in Path(
"simulations/realization-0/iter-1/my_param.grdecl"
).read_text(encoding="utf-8")


@pytest.mark.usefixtures("copy_heat_equation")
def test_foward_init_false():
config = ErtConfig.from_file("config_forward_init_false.ert")
run_cli(
ENSEMBLE_SMOOTHER_MODE,
"--disable-monitor",
"config_forward_init_false.ert",
"--experiment-name",
"es-test",
)

with open_storage(config.ens_path) as storage:
experiment = storage.get_experiment_by_name("es-test")
prior = experiment.get_ensemble_by_name("iter-0")
posterior = experiment.get_ensemble_by_name("iter-1")

param_config = config.ensemble_config.parameter_configs["COND"]

prior_result = prior.load_parameters("COND")["values"]
prior_covariance = np.cov(
prior_result.values.reshape(
prior.ensemble_size, param_config.nx * param_config.ny * param_config.nz
),
rowvar=False,
)

posterior_result = posterior.load_parameters("COND")["values"]
posterior_covariance = np.cov(
posterior_result.values.reshape(
posterior.ensemble_size,
param_config.nx * param_config.ny * param_config.nz,
),
rowvar=False,
)

# Check that generalized variance is reduced by update step.
assert np.trace(prior_covariance) > np.trace(posterior_covariance)
Loading