Skip to content

Commit

Permalink
Update ropt to 0.10.0 (#9405)
Browse files Browse the repository at this point in the history
* Update ropt to 0.10.0

* Run ruff format
  • Loading branch information
verveerpj authored Dec 2, 2024
1 parent 2ef40b4 commit 3a84a98
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ everest = [
"decorator",
"resdata",
"colorama",
"ropt[pandas]>=0.9,<0.10",
"ropt-dakota>=0.9,<0.10",
"ropt[pandas]>=0.1,<0.11",
"ropt-dakota>=0.1,<0.11",
"seba-sqlite",
]

Expand Down
2 changes: 1 addition & 1 deletion src/ert/run_models/everest_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def _slug(entity: str) -> str:

objectives = self._get_active_results(
results,
metadata.config.objective_functions.names, # type: ignore
metadata.config.objectives.names, # type: ignore
control_values,
active,
)
Expand Down
10 changes: 4 additions & 6 deletions src/everest/optimizer/everest2ropt.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ def _parse_objectives(objective_functions: List[ObjectiveFunctionConfig], ropt_c
transforms.append({"method": objective_type})
transform_indices.append(transform_idx)

ropt_config["objective_functions"] = {
ropt_config["objectives"] = {
"names": names,
"weights": weights,
"scales": scales,
"auto_scale": auto_scale,
}
if transforms:
# Only needed if we specified at least one objective type:
ropt_config["objective_functions"]["function_transforms"] = transform_indices
ropt_config["objectives"]["function_transforms"] = transform_indices
ropt_config["function_transforms"] = transforms


Expand Down Expand Up @@ -468,13 +468,11 @@ def _parse_optimization(
# indices to any realization filters that should be applied. In this
# case, we want all objectives and constraints to refer to the same
# filter implementing cvar:
objective_count = len(ropt_config["objective_functions"]["names"])
objective_count = len(ropt_config["objectives"]["names"])
constraint_count = len(
ropt_config.get("nonlinear_constraints", {}).get("names", [])
)
ropt_config["objective_functions"]["realization_filters"] = (
objective_count * [0]
)
ropt_config["objectives"]["realization_filters"] = objective_count * [0]
if constraint_count > 0:
ropt_config["nonlinear_constraints"]["realization_filters"] = (
constraint_count * [0]
Expand Down
12 changes: 6 additions & 6 deletions tests/everest/test_multiobjective.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ def test_multi_objectives2ropt(copy_mocked_test_data_to_tmp):
enopt_config = EnOptConfig.model_validate(
everest2ropt(EverestConfig.model_validate(config_dict))
)
assert len(enopt_config.objective_functions.names) == 2
assert enopt_config.objective_functions.names[1] == ever_objs[1]["name"]
assert enopt_config.objective_functions.weights[1] == ever_objs[1]["weight"] / norm
assert enopt_config.objective_functions.names[0] == ever_objs[0]["name"]
assert enopt_config.objective_functions.weights[0] == ever_objs[0]["weight"] / norm
assert enopt_config.objective_functions.scales[0] == ever_objs[0]["normalization"]
assert len(enopt_config.objectives.names) == 2
assert enopt_config.objectives.names[1] == ever_objs[1]["name"]
assert enopt_config.objectives.weights[1] == ever_objs[1]["weight"] / norm
assert enopt_config.objectives.names[0] == ever_objs[0]["name"]
assert enopt_config.objectives.weights[0] == ever_objs[0]["weight"] / norm
assert enopt_config.objectives.scales[0] == ever_objs[0]["normalization"]


@pytest.mark.integration_test
Expand Down
4 changes: 2 additions & 2 deletions tests/everest/test_ropt_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_everest2ropt_cvar():

ropt_config = everest2ropt(EverestConfig.model_validate(config_dict))

assert ropt_config.objective_functions.realization_filters == [0]
assert ropt_config.objectives.realization_filters == [0]
assert len(ropt_config.realization_filters) == 1
assert ropt_config.realization_filters[0].method == "sort-objective"
assert ropt_config.realization_filters[0].options["sort"] == [0]
Expand All @@ -218,7 +218,7 @@ def test_everest2ropt_cvar():
}

ropt_config = everest2ropt(EverestConfig.model_validate(config_dict))
assert ropt_config.objective_functions.realization_filters == [0]
assert ropt_config.objectives.realization_filters == [0]
assert len(ropt_config.realization_filters) == 1
assert ropt_config.realization_filters[0].method == "cvar-objective"
assert ropt_config.realization_filters[0].options["sort"] == [0]
Expand Down

0 comments on commit 3a84a98

Please sign in to comment.