From 33cc2c2c6ccfce36bda3e3fc9f35acebe771b7b0 Mon Sep 17 00:00:00 2001 From: Feda Curic Date: Thu, 21 Nov 2024 10:30:12 +0100 Subject: [PATCH] Test field with FORWARD_INIT:False --- test-data/ert/heat_equation/cond_0.bgrdecl | Bin 0 -> 432 bytes test-data/ert/heat_equation/cond_1.bgrdecl | Bin 0 -> 432 bytes test-data/ert/heat_equation/cond_2.bgrdecl | Bin 0 -> 432 bytes test-data/ert/heat_equation/cond_3.bgrdecl | Bin 0 -> 432 bytes test-data/ert/heat_equation/cond_4.bgrdecl | Bin 0 -> 432 bytes test-data/ert/heat_equation/cond_5.bgrdecl | Bin 0 -> 432 bytes test-data/ert/heat_equation/cond_6.bgrdecl | Bin 0 -> 432 bytes test-data/ert/heat_equation/cond_7.bgrdecl | Bin 0 -> 432 bytes test-data/ert/heat_equation/cond_8.bgrdecl | Bin 0 -> 432 bytes test-data/ert/heat_equation/cond_9.bgrdecl | Bin 0 -> 432 bytes .../config_forward_init_false.ert | 26 ++++++++++++ test-data/ert/heat_equation/generate_files.py | 21 +++++++++ tests/ert/conftest.py | 7 +++ .../ert/ui_tests/cli/test_field_parameter.py | 40 ++++++++++++++++++ 14 files changed, 94 insertions(+) create mode 100644 test-data/ert/heat_equation/cond_0.bgrdecl create mode 100644 test-data/ert/heat_equation/cond_1.bgrdecl create mode 100644 test-data/ert/heat_equation/cond_2.bgrdecl create mode 100644 test-data/ert/heat_equation/cond_3.bgrdecl create mode 100644 test-data/ert/heat_equation/cond_4.bgrdecl create mode 100644 test-data/ert/heat_equation/cond_5.bgrdecl create mode 100644 test-data/ert/heat_equation/cond_6.bgrdecl create mode 100644 test-data/ert/heat_equation/cond_7.bgrdecl create mode 100644 test-data/ert/heat_equation/cond_8.bgrdecl create mode 100644 test-data/ert/heat_equation/cond_9.bgrdecl create mode 100644 test-data/ert/heat_equation/config_forward_init_false.ert diff --git a/test-data/ert/heat_equation/cond_0.bgrdecl b/test-data/ert/heat_equation/cond_0.bgrdecl new file mode 100644 index 0000000000000000000000000000000000000000..9235e9b352fff92c0ab7779e9ac5a85cefab8146 GIT binary patch literal 432 zcmV;h0Z;w_000m}PfkQ2ARr(B003lCML|pe000mG00EFc0e=NP%AKq}t53T=v#>8d z^HwK6KNMd-jk+Q~r0p3$jw&%fN@8L^2o@ebxhqpXk7!Lkk_HPt#adH87?H3)ShG4m zamCC(P`Nfg8~7YQ2BqXas5WLkcP8ULY~2Yyl75#y%mgAo1LFuk3TL@K>VW({vLfF; z{kbMSop4+}Yqmu`Ty;r4dTn<;odUN$yb2&bz2{#(oqj()YZzEQ_xqbZqj;1)hC?zw zgsRs*l=FQ)vZ$&)&~P?B({b!Ru-QO9gJoeq2egDf#RWb-xJb1=%Xj2H@Y1e75q`!$ zD|WU&HNHbXBCUQu0f*l|BG5TM0=@D-2^B&=CYBFBPF5B_dBb5plxvMYs1MIStC>na zp!Z%sLj{IEDTn4iJDl@BXUPITi-03PpXy6LxivgL-tZJa1^7xp9Nu?7S_*AHMae8b zRt;Z2bd{z*gIDZ7g_F5Ik3lOxugYUT@yVz_FA-ZmVb*OwPhzn@P$bqrP#knWKQi?{ aCVx9W9VanAHSsGyg8H04+GBJ800EG|FsS+pKxqC7`=%VC5P|yWG#9&uH{-lCGxW%nMFfU;~pQC0zI4iS07EPW$ zr1a=M-to>qU_rP)?FHmOCa7sY@)UzVPKL}rn7rsd4X`FX#{5`5r?sL!@SVOtc$08I z1gzsgJU4kj2N+a8Rx>9)i3eLf)lhalfU%iA&&cOL9I&H5o8+rN9NOkUTFiYwAzHpa zf(Ge6pF}7<-n1J%XbGi18@b6pdtk;t@1~bPU+k1XnQOQ}aiU8<*d|Rs4vJPjM&r6Y zy)KJCf1w0F;f-@ZQ}8K3xkRZz^>jZ#%{y~IRQFClrs-!t0{1*Vd$qVfz6*0eFsU~{ zqpZR~1(a<;Cg_7f5S{)&u_0?fF|heRuL$}-KPMDF*} a|D`uTz4|affb-!%EwETW@Xq@H00EG#@3@Wt literal 0 HcmV?d00001 diff --git a/test-data/ert/heat_equation/cond_2.bgrdecl b/test-data/ert/heat_equation/cond_2.bgrdecl new file mode 100644 index 0000000000000000000000000000000000000000..6e0f8e71f301de663c0c3962abbed8d60cfa8b20 GIT binary patch literal 432 zcmV;h0Z;w_000m}PfkQ2ARr(B003lCML|pe000mG00EFb)!8sUzkhZ<)e7c60zZpC zAHu~yL(|$nf8Dn~x^$XA4A8PbIExrRIW%8C5|Xw*7J{EYIsk1yd~+5*vXZ<&0l_&y zJUaV8c#m>Ggv(+-u>it9dA{;LV-W^Fh0r@cz1{La5gw^PRq}B_iVjLZko@gHbpVY& z@O;fbpf4OhggJ^ollZ_t)gEL(Cyrh~ZL;S;gpy)FVQf@DAZ(XEv;aLnbJ8C_LEGa$ zQ?_wGn>C6*`_xH5G7#rLJ9wHv5_By;#T^?zFc0)T{0|O3#~s!_)frzu9)TG@h=l(? z(!b$9^SxO=&q0(wluC>~xGOh4i3i0#QHRw&Q2s7HmJ}pE2zV1ebkrh0uC2sBw!XkW zm4b9WoS@4-X)gUfBn@vq4SzL0GwY^4p}oLAB(Y*YlAd%wz=}3MwE1*C-yiWlq!pt+ zP+7)46_)Hi9dN@wfAOt928zf(h{vZt(KgIK*1|DAM1b8t62zH4t>;KSRsH=wIh7(l afb2>>{H(1%ftocx&a}Tj*|sMD00EFMoU~*B literal 0 HcmV?d00001 diff --git a/test-data/ert/heat_equation/cond_3.bgrdecl b/test-data/ert/heat_equation/cond_3.bgrdecl new file mode 100644 index 0000000000000000000000000000000000000000..dcde3a34d89e9cd24beae10146277f39c5ee5f3e GIT binary patch literal 432 zcmV;h0Z;w_000m}PfkQ2ARr(B003lCML|pe000mG00EFbkWGI+T=VTdKIjlWN#~$G zg@}bd)HBCFJW$*}sNM%a2RN2ME|exdIfqF;1D{|$`UU|$EaWjhq2h->Em|l)wY4}v zCq3&xcoURBi?UcgC?W4X@>}IT0>RooU&OdS0;K6bpOv+yQ*VA-!|_+%@f-`y?nbqsy9MD;xXhu zNPgTu!385gDXTR=ft=$&uCALv%2ljDyx(y@Ohc(ZMOOtsg3!!A#=IIp4_NjM6274_sJ4GF1vdL_;4yNhRPwVqTFzlH~V5x|X6q zz7-lkdHo1LebI05IysCRZoPj?;lRzdwv%1hh0U;bgAy4{24t6m>{68~663EO!22}At)CzP!tNh?V at)OK<=iu5wD#P_bN%7=CB%~4m00EF8X z1^FUAr1LI5R&t6yI$v`>g|}%x9??QS@Ca%^o%n1)3T*{J8krD318VF(k_1XVC(PeI z0HPp1COnWnxi#%Si#^&vLIspSy2J`VgAy6-MMf98#J-dW|$c2vW2^p2o019PJT6 zXM;yR;u6q4#$I_otRT-mnJfH0pShAg)Q#*vFP5P{pk>`a3yUN`O$EL_>XXAi3Zwl$ zC!G90Jl`2VPGi7-yk a^5URC13w8s9*yuoQl1t-j6;k700EF-!l&i{ literal 0 HcmV?d00001 diff --git a/test-data/ert/heat_equation/cond_5.bgrdecl b/test-data/ert/heat_equation/cond_5.bgrdecl new file mode 100644 index 0000000000000000000000000000000000000000..d3f40bdffc4e6587d8a579b3f46a4a4d2dde18ae GIT binary patch literal 432 zcmV;h0Z;w_000m}PfkQ2ARr(B003lCML|pe000mG00EFc+_1ktRZvLKZ9mJ)^uV(GpA-iOHW=uoQ^C%UMyWd0N{B( zn3^v>cM_96qk(llA6`*EqcY_`{ggC71PoL^u`ZK8k{IhhIhKq**tXI>n!2t&r}bn% z23}e}Z)U_ltI5+psgScj+a=mR$?JMQii8e7A=#=v(PKnDy|yeq`CeK-K%!tjfR%nf zbP`BE{VNPV^osmHu~~{gR;D;V2dyAJ-@Tka0duuKG$$!PVZoF?Od%aV=U;R`*+2?E zqS+`vRYr+F5fRQl^*HoD3c6H3IbjSxUX5=*KYPDFow*%9hyM^iPM+&O7H9K5>}$S0 a;x^Gg3Jj`0K3#M_WgfskLxwp300EGBJ+aOJ literal 0 HcmV?d00001 diff --git a/test-data/ert/heat_equation/cond_6.bgrdecl b/test-data/ert/heat_equation/cond_6.bgrdecl new file mode 100644 index 0000000000000000000000000000000000000000..0f7d78025ae3ba980eda638266342a4da782f9c8 GIT binary patch literal 432 zcmV;h0Z;w_000m}PfkQ2ARr(B003lCML|pe000mG00EFclaLNSoLMqIq7rF8#1`j3 z2(v{%FHSi?C=_!)_jxNnufIh$xpaH@9}Fu1~)!G=83RB znqTQZN);|YArpl_0OT@1_v{Tn*eOmw#`)7f#{*M8yt+O=k$|W_IpX9#@O1h9Qz3z>XU}ydXzF2~sXV0Ap`I-e~tfuYoT=e_G)`H%SLS z3{l%Y@Q#{3?IQF)2wVw338!*E08=zSHI$Z>8y$w0L~0-$C;OG02kE(NGS9MEV# z|FzjarmZSJG>}t1%Fii2m2FKvoh+X|-9iIDI`RHMEr7s46fdkl+;Pc2gBhbg2Z(V# ann=MuZ%f`jgzFSO!XIouCKLex00EFf45^U- literal 0 HcmV?d00001 diff --git a/test-data/ert/heat_equation/cond_7.bgrdecl b/test-data/ert/heat_equation/cond_7.bgrdecl new file mode 100644 index 0000000000000000000000000000000000000000..cdbc36de82eda8a5667d6cef86d72a4da9d50bf2 GIT binary patch literal 432 zcmV;h0Z;w_000m}PfkQ2ARr(B003lCML|pe000mG00EFcF|0j5E+=X~Dh1O&C|Zv{ zA08+_1ax0M#K|H)l`SAXgGfUtO)gfFz0J~#93-Yi(5Xy=_7K_e59m6y~D1GohMFbx|i3%@2;Ysm7Mt{veTg^N_ zM&JuSCG$2v5rG6h4*#b=BbmlOVx|l~z36X1Fmz@=tW&N(u^Ik9jAP(GNNA5g8NG}@ a4S>WyCBlk7dQJ2{Xhsa1RkbedC%xYvkxZLk{CVAC4+N5hDRV6sdSW9glxMBk2J@ znmgM+uJ_$PxY5x+t~yUYlO`ZPbAu#5U0i`bV*+eq2U$#FA3was!rwDFBUy-8RHmZj&aFAuy>9?jHlN? zSA1hYAlzI(_^Bd4%hjkqsZ+~8hXZ0iP|C1BC$08CvfdIvf1DIRA^#CS!Z|NLfN`Ne aP4%2VJVqryDvG*44yW=y=0V#400EHLIIpV! literal 0 HcmV?d00001 diff --git a/test-data/ert/heat_equation/cond_9.bgrdecl b/test-data/ert/heat_equation/cond_9.bgrdecl new file mode 100644 index 0000000000000000000000000000000000000000..9eea003c553632b672d56f10c12d0da0834cc337 GIT binary patch literal 432 zcmV;h0Z;w_000m}PfkQ2ARr(B003lCML|pe000mG00EFcf2n9c!fB>I`w)Ua69ZvD zC?do_H`Po)GAnC98fd3L3dqMm7Ni3|Ox5>4zi%l(6RcxEIts!-Ou@`RONBK+Gr(Iw z5YY=i@%?>2@PgVu5vIpKqNrv-5%-KhMbkb&T8CpmR{d;1LTjKvB|E%84*CQ@3av*z z&T$t%d5wBM@<4k)EvXMcNWySHRGsBOTI<6=TI$?DR^uo@R-58Jy?Mt!Q?i{u#-M3H z570J1FGT1-PD%hkdDh%OmLFt5r{SzXs=EX~3)P7~c2Z71#E8~F1a%ESB6;~hOu2GE zijyfox{i53+mZl4)S?nUpjz2K%Dh@X_t2|A4J?R2Aq3b!N>4ICjUQ$}!4`=?*%I?W zy3>9@QYg$oJ{1T+DW-Nn7#wau7aK)DG&O5LcP*MgqLQ3IrS9WEcg~tX)sXZ+lL9S3 zLWep)2E_C~ diff --git a/test-data/ert/heat_equation/generate_files.py b/test-data/ert/heat_equation/generate_files.py index 0f0ebab271b..769ceefe82e 100644 --- a/test-data/ert/heat_equation/generate_files.py +++ b/test-data/ert/heat_equation/generate_files.py @@ -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 @@ -71,6 +72,24 @@ def make_observations( return d +def generate_priors(): + """Generates and saves 10 random conductivity field realizations. + + Uses a prior sampling function to create conductivity fields, + then saves each field to a separate .bgrdecl file in ECLIPSE format + using Fortran-style ordering. Used for testing when FORWARD_INIT + is disabled. + """ + + rng = np.random.default_rng() + for i in range(10): + cond = sample_prior_conductivity(ensemble_size=1, nx=nx, rng=rng) + resfo.write( + f"cond_{i}.bgrdecl", + [("COND ", cond.flatten(order="F").astype(np.float32))], + ) + + if __name__ == "__main__": create_egrid_file() @@ -122,3 +141,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() diff --git a/tests/ert/conftest.py b/tests/ert/conftest.py index 59f4b62b868..7e021f083cf 100644 --- a/tests/ert/conftest.py +++ b/tests/ert/conftest.py @@ -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=[ diff --git a/tests/ert/ui_tests/cli/test_field_parameter.py b/tests/ert/ui_tests/cli/test_field_parameter.py index f849b66f009..4f55ec739a8 100644 --- a/tests/ert/ui_tests/cli/test_field_parameter.py +++ b/tests/ert/ui_tests/cli/test_field_parameter.py @@ -7,6 +7,7 @@ import numpy as np import numpy.testing import polars as pl +import pytest import resfo import xtgeo @@ -332,3 +333,42 @@ def test_field_param_update_using_heat_equation_zero_var_params_and_adaptive_loc ) # Check that generalized variance is reduced by update step. assert np.trace(prior_covariance) > np.trace(posterior_covariance) + + +@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)