-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add run experiment with design matrix to ensemble experiment panel
- Prefil active realization box with realizations from design matrix - Use design_matrix parameters in ensemble experiment - add test run cli with design matrix and poly example - add test that save parameters internalize DataFrame parameters in the storage - add merge function to merge design parameters with existing parameters
- Loading branch information
Showing
18 changed files
with
407 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
|
||
from ert.storage import Ensemble | ||
|
||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
000 /data/workspace/ert/test-data/ert/poly_design/poly_out/realization-0/iter-0 poly.ert-0 000 | ||
001 /data/workspace/ert/test-data/ert/poly_design/poly_out/realization-1/iter-0 poly.ert-1 000 | ||
002 /data/workspace/ert/test-data/ert/poly_design/poly_out/realization-2/iter-0 poly.ert-2 000 | ||
003 /data/workspace/ert/test-data/ert/poly_design/poly_out/realization-3/iter-0 poly.ert-3 000 | ||
004 /data/workspace/ert/test-data/ert/poly_design/poly_out/realization-4/iter-0 poly.ert-4 000 | ||
005 /data/workspace/ert/test-data/ert/poly_design/poly_out/realization-5/iter-0 poly.ert-5 000 | ||
006 /data/workspace/ert/test-data/ert/poly_design/poly_out/realization-6/iter-0 poly.ert-6 000 | ||
007 /data/workspace/ert/test-data/ert/poly_design/poly_out/realization-7/iter-0 poly.ert-7 000 | ||
008 /data/workspace/ert/test-data/ert/poly_design/poly_out/realization-8/iter-0 poly.ert-8 000 | ||
009 /data/workspace/ert/test-data/ert/poly_design/poly_out/realization-9/iter-0 poly.ert-9 000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
EXECUTABLE poly_eval.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
a UNIFORM 0 1 | ||
b UNIFORM 0 2 | ||
c UNIFORM 0 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
GENERAL_OBSERVATION POLY_OBS { | ||
DATA = POLY_RES; | ||
INDEX_LIST = 0,2,4,6,8; | ||
OBS_FILE = poly_obs_data.txt; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
QUEUE_OPTION LOCAL MAX_RUNNING 10 | ||
RUNPATH poly_out/realization-<IENS>/iter-<ITER> | ||
OBS_CONFIG observations | ||
NUM_REALIZATIONS 10 | ||
MIN_REALIZATIONS 1 | ||
GEN_DATA POLY_RES RESULT_FILE:poly.out | ||
DESIGN_MATRIX poly_design.xlsx DESIGN_SHEET:DesignSheet01 DEFAULT_SHEET:DefaultSheet | ||
GEN_KW COEFFS coeff_priors | ||
INSTALL_JOB poly_eval POLY_EVAL | ||
FORWARD_MODEL poly_eval |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python | ||
import json | ||
|
||
|
||
def _load_coeffs(filename): | ||
with open(filename, encoding="utf-8") as f: | ||
return json.load(f)["COEFFS"] | ||
|
||
|
||
def _evaluate(coeffs, x): | ||
return coeffs["a"] * x**2 + coeffs["b"] * x + coeffs["c"] | ||
|
||
|
||
if __name__ == "__main__": | ||
coeffs = _load_coeffs("parameters.json") | ||
output = [_evaluate(coeffs, x) for x in range(10)] | ||
with open("poly.out", "w", encoding="utf-8") as f: | ||
f.write("\n".join(map(str, output))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
2.1457049781272213 0.6 | ||
8.769219841380755 1.4 | ||
12.388014786122742 3.0 | ||
25.600464531354252 5.4 | ||
42.35204755970952 8.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import os | ||
import stat | ||
from textwrap import dedent | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import pytest | ||
|
||
from ert.config import ErtConfig | ||
from ert.mode_definitions import ENSEMBLE_EXPERIMENT_MODE | ||
from ert.storage import open_storage | ||
from tests.ert.ui_tests.cli.run_cli import run_cli | ||
|
||
|
||
@pytest.mark.usefixtures("copy_poly_case") | ||
def test_run_poly_example_with_design_matrix(): | ||
design_matrix = "poly_design.xlsx" | ||
num_realizations = 10 | ||
a_values = list(range(num_realizations)) | ||
design_matrix_df = pd.DataFrame( | ||
{ | ||
"REAL": list(range(num_realizations)), | ||
"a": a_values, | ||
} | ||
) | ||
default_sheet_df = pd.DataFrame([["b", 1], ["c", 2]]) | ||
with pd.ExcelWriter(design_matrix) as xl_write: | ||
design_matrix_df.to_excel(xl_write, index=False, sheet_name="DesignSheet01") | ||
default_sheet_df.to_excel( | ||
xl_write, index=False, sheet_name="DefaultSheet", header=False | ||
) | ||
|
||
with open("poly.ert", "w", encoding="utf-8") as fout: | ||
fout.write( | ||
dedent( | ||
"""\ | ||
QUEUE_OPTION LOCAL MAX_RUNNING 10 | ||
RUNPATH poly_out/realization-<IENS>/iter-<ITER> | ||
NUM_REALIZATIONS 10 | ||
MIN_REALIZATIONS 1 | ||
GEN_DATA POLY_RES RESULT_FILE:poly.out | ||
DESIGN_MATRIX poly_design.xlsx DESIGN_SHEET:DesignSheet01 DEFAULT_SHEET:DefaultSheet | ||
INSTALL_JOB poly_eval POLY_EVAL | ||
FORWARD_MODEL poly_eval | ||
""" | ||
) | ||
) | ||
|
||
with open("poly_eval.py", "w", encoding="utf-8") as f: | ||
f.write( | ||
dedent( | ||
"""\ | ||
#!/usr/bin/env python | ||
import numpy as np | ||
import sys | ||
import json | ||
def _load_coeffs(filename): | ||
with open(filename, encoding="utf-8") as f: | ||
return json.load(f)["DESIGN_MATRIX"] | ||
def _evaluate(coeffs, x): | ||
return coeffs["a"] * x**2 + coeffs["b"] * x + coeffs["c"] | ||
if __name__ == "__main__": | ||
coeffs = _load_coeffs("parameters.json") | ||
output = [_evaluate(coeffs, x) for x in range(10)] | ||
with open("poly.out", "w", encoding="utf-8") as f: | ||
f.write("\\n".join(map(str, output))) | ||
""" | ||
) | ||
) | ||
os.chmod( | ||
"poly_eval.py", | ||
os.stat("poly_eval.py").st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH, | ||
) | ||
|
||
run_cli( | ||
ENSEMBLE_EXPERIMENT_MODE, | ||
"--disable-monitor", | ||
"poly.ert", | ||
"--experiment-name", | ||
"test-experiment", | ||
) | ||
storage_path = ErtConfig.from_file("poly.ert").ens_path | ||
with open_storage(storage_path) as storage: | ||
experiment = storage.get_experiment_by_name("test-experiment") | ||
params = experiment.get_ensemble_by_name("default").load_parameters( | ||
"DESIGN_MATRIX" | ||
)["values"] | ||
np.testing.assert_array_equal(params[:, 0], a_values) | ||
np.testing.assert_array_equal(params[:, 1], 10 * [1]) | ||
np.testing.assert_array_equal(params[:, 2], 10 * [2]) |
Oops, something went wrong.