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

Fix bug where duplicate dates in summary caused update to crash #6014

Merged
merged 1 commit into from
Sep 21, 2023
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
7 changes: 5 additions & 2 deletions src/clib/lib/enkf/read_summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ ERT_CLIB_SUBMODULE("_read_summary", m) {
const ecl_smspec_type *smspec = ecl_sum_get_smspec(summary);
std::vector<std::pair<std::string, std::vector<double>>>
summary_vectors{};

std::vector<std::string> seen_keys{};
oyvindeide marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < ecl_smspec_num_nodes(smspec); i++) {
const ecl::smspec_node &smspec_node =
ecl_smspec_iget_node_w_node_index(smspec, i);
const char *key = smspec_node.get_gen_key1();
if (matches(keys, key)) {
if ((matches(keys, key)) &&
!(std::find(seen_keys.begin(), seen_keys.end(), key) !=
seen_keys.end())) {
seen_keys.push_back(key);
int start = ecl_sum_get_first_report_step(summary);
int end = ecl_sum_get_last_report_step(summary);
std::vector<double> data{};
Expand Down
6 changes: 3 additions & 3 deletions src/ert/config/summary_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def read_from_file(self, run_path: str, iens: int) -> xr.Dataset:
f"{last} from: {run_path}/{filename}.UNSMRY"
)

summary_data = read_summary(summary, self.keys)
summary_data = read_summary(summary, list(set(self.keys)))
summary_data.sort(key=lambda x: x[0])
data = [d for _, d in summary_data]
keys = [k for k, _ in summary_data]

return xr.Dataset(
ds = xr.Dataset(
{"values": (["name", "time"], data)},
coords={"time": time_map, "name": keys},
)
return ds.drop_duplicates("time")
21 changes: 21 additions & 0 deletions tests/unit_tests/scenarios/test_summary_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,24 @@ def run_sim(dates, value, fname="ECLIPSE_CASE"):
)
t_step["FOPR"] = value
ecl_sum.fwrite()


def test_that_duplicate_summary_time_steps_does_not_fail(
setup_configuration,
prior_ensemble,
target_ensemble,
):
ert = setup_configuration
ert.sample_prior(prior_ensemble, list(range(ert.getEnsembleSize())))
response_times = [
[datetime(2014, 9, 9)],
[datetime(2014, 9, 9)],
[datetime(2014, 9, 9), datetime(2014, 9, 9)],
[datetime(2014, 9, 9)],
[datetime(2014, 9, 9), datetime(1988, 9, 9)],
]
create_responses(ert, prior_ensemble, response_times)

es_update = ESUpdate(ert)

es_update.smootherUpdate(prior_ensemble, target_ensemble, "an id")
Loading