Skip to content
Merged
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
26 changes: 16 additions & 10 deletions src/ert/run_models/_create_run_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ def _value_export_txt(
with path.open("w") as f:
for key, param_map in values.items():
for param, value in param_map.items():
if isinstance(value, (int | float)):
if key == DESIGN_MATRIX_GROUP:
print(f"{param} {value:g}", file=f)
else:
print(f"{key}:{param} {value:g}", file=f)
elif key == DESIGN_MATRIX_GROUP:
print(f"{param} {value}", file=f)
if isinstance(value, int):
value_str = str(value)
elif isinstance(value, float):
value_str = f"{value:g}"
else:
print(f"{key}:{param} {value}", file=f)
value_str = str(value)

if key == DESIGN_MATRIX_GROUP:
print(f"{param} {value_str}", file=f)
else:
print(f"{key}:{param} {value_str}", file=f)


def _value_export_json(
Expand Down Expand Up @@ -214,11 +216,15 @@ def _make_param_substituter(
param_substituter = deepcopy(substituter)
for values in param_data.values():
for param_name, value in values.items():
if isinstance(value, (int, float)):
formatted_value = f"{value:.6g}"
if isinstance(value, int):
formatted_value = str(value)
elif isinstance(value, float):
formatted_value = f"{value:g}"
else:
formatted_value = str(value)

param_substituter[f"<{param_name}>"] = formatted_value

return param_substituter


Expand Down
14 changes: 11 additions & 3 deletions tests/ert/ui_tests/cli/analysis/test_design_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def test_run_poly_example_with_design_matrix_and_genkw_merge(default_values):
"REAL": list(range(num_realizations)),
"a": a_values,
"category": 5 * ["cat1"] + 5 * ["cat2"],
"big_integer": [1e10 + i for i in range(num_realizations)],
}
),
pl.DataFrame(default_values, orient="row"),
Expand All @@ -117,10 +118,11 @@ def test_run_poly_example_with_design_matrix_and_genkw_merge(default_values):
encoding="utf-8",
)

# This adds a dummy category parameter to COEFFS GENKW
# which will be overridden by the design matrix catagorical entries
# This adds a dummy category and big_numbers parameter to COEFFS GENKW
# which will be overridden by the design matrix entries
with open("coeff_priors", "a", encoding="utf-8") as f:
f.write("category UNIFORM 0 1")
f.write("category UNIFORM 0 1\n")
f.write("big_numbers UNIFORM 0 1\n")

Path("poly_eval.py").write_text(
dedent(
Expand Down Expand Up @@ -153,6 +155,7 @@ def _evaluate(coeffs, x):
b: <b>
c: <c>
category: <category>
big_integer: <big_integer>
"""
),
encoding="utf-8",
Expand Down Expand Up @@ -185,6 +188,9 @@ def _evaluate(coeffs, x):
np.testing.assert_array_equal(
params["category"].to_list(), 5 * ["cat1"] + 5 * ["cat2"]
)
np.testing.assert_array_equal(
params["big_integer"].to_list(), [1e10 + i for i in range(10)]
)
np.testing.assert_array_equal(params["b"].to_list(), 10 * [1])
np.testing.assert_array_equal(params["c"].to_list(), 10 * [2])
with open("poly_out/realization-0/iter-0/my_output", encoding="utf-8") as f:
Expand All @@ -193,12 +199,14 @@ def _evaluate(coeffs, x):
assert output[1] == "b: 1"
assert output[2] == "c: 2"
assert output[3] == "category: cat1"
assert output[4] == "big_integer: 10000000000"
with open("poly_out/realization-5/iter-0/my_output", encoding="utf-8") as f:
output = [line.strip() for line in f]
assert output[0] == "a: 5"
assert output[1] == "b: 1"
assert output[2] == "c: 2"
assert output[3] == "category: cat2"
assert output[4] == "big_integer: 10000000005"


@pytest.mark.usefixtures(
Expand Down
1 change: 1 addition & 0 deletions tests/ert/unit_tests/config/test_gen_kw_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def test_gen_kw_config_get_priors(spec, expected):
+ r"LOG10_KW_NAME:MY_KEYWORD "
+ number_regex,
),
("CONST 1.54", False, "KW_NAME:MY_KEYWORD 1.54\n"),
("CONST 1.0", False, "KW_NAME:MY_KEYWORD 1\n"),
("DUNIF 5 1 5", False, r"KW_NAME:MY_KEYWORD " + number_regex),
("ERRF 1 2 0.1 0.1", False, r"KW_NAME:MY_KEYWORD " + number_regex),
Expand Down
Loading