From 3a84a98e4447dbf7101d8661fbfcc6ee525181f6 Mon Sep 17 00:00:00 2001 From: Peter Verveer Date: Mon, 2 Dec 2024 13:25:53 +0100 Subject: [PATCH] Update ropt to 0.10.0 (#9405) * Update ropt to 0.10.0 * Run ruff format --- pyproject.toml | 4 ++-- src/ert/run_models/everest_run_model.py | 2 +- src/everest/optimizer/everest2ropt.py | 10 ++++------ tests/everest/test_multiobjective.py | 12 ++++++------ tests/everest/test_ropt_initialization.py | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9beff0083db..c643ad0d4f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", ] diff --git a/src/ert/run_models/everest_run_model.py b/src/ert/run_models/everest_run_model.py index 56aa3255e8e..0dc5128082c 100644 --- a/src/ert/run_models/everest_run_model.py +++ b/src/ert/run_models/everest_run_model.py @@ -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, ) diff --git a/src/everest/optimizer/everest2ropt.py b/src/everest/optimizer/everest2ropt.py index f01b9b68ac6..8df0a90ac21 100644 --- a/src/everest/optimizer/everest2ropt.py +++ b/src/everest/optimizer/everest2ropt.py @@ -278,7 +278,7 @@ 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, @@ -286,7 +286,7 @@ def _parse_objectives(objective_functions: List[ObjectiveFunctionConfig], ropt_c } 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 @@ -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] diff --git a/tests/everest/test_multiobjective.py b/tests/everest/test_multiobjective.py index 62acb6c73f4..7ea40f32d02 100644 --- a/tests/everest/test_multiobjective.py +++ b/tests/everest/test_multiobjective.py @@ -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 diff --git a/tests/everest/test_ropt_initialization.py b/tests/everest/test_ropt_initialization.py index cea3dfcb2a0..380ce6f262a 100644 --- a/tests/everest/test_ropt_initialization.py +++ b/tests/everest/test_ropt_initialization.py @@ -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] @@ -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]