From a6f8457c435516353f2ac2d3cf4f7b76c304b49d Mon Sep 17 00:00:00 2001 From: DanSava Date: Wed, 29 Jan 2025 11:33:14 +0200 Subject: [PATCH] Remove control type filed --- docs/everest/minimal_example.rst | 3 --- src/everest/config/control_config.py | 13 +++------- src/everest/config/everest_config.py | 15 +++++++----- .../everest/egg/everest/model/config.yml | 1 - .../everest/egg/everest/model/config_flow.yml | 1 - .../everest/math_func/config_advanced.yml | 1 - .../everest/math_func/config_minimal.yml | 1 - .../everest/math_func/config_multiobj.yml | 1 - tests/everest/conftest.py | 2 -- tests/everest/test_config_validation.py | 24 ++++--------------- tests/everest/test_controls.py | 4 +--- .../config_full_gradient_info.yml | 1 - .../config_input_constraints.yml | 1 - .../config_multi_objectives.yml | 1 - .../config_output_constraints.yml | 1 - .../mocked_test_case/config_samplers.yml | 3 --- .../mocked_test_case/config_workflow.yml | 1 - .../mocked_test_case/mocked_multi_batch.yml | 1 - .../mocked_test_case/mocked_test_case.yml | 1 - .../everest/model/array.yml | 2 -- .../everest/model/index.yml | 2 -- tests/everest/test_data/templating/config.yml | 1 - ...valid_config_maintained_forward_models.yml | 2 -- .../valid_config_file/invalid_yaml_config.yml | 1 - .../valid_config_file/valid_yaml_config.yml | 1 - .../valid_yaml_config_no_algorithm.yml | 1 - tests/everest/test_discrete.py | 1 - tests/everest/test_everest_config.py | 5 ---- tests/everest/test_output_constraints.py | 6 ----- tests/everest/test_res_initialization.py | 1 - tests/everest/test_yaml_parser.py | 1 - 31 files changed, 17 insertions(+), 83 deletions(-) diff --git a/docs/everest/minimal_example.rst b/docs/everest/minimal_example.rst index cefb787824f..962b8118357 100644 --- a/docs/everest/minimal_example.rst +++ b/docs/everest/minimal_example.rst @@ -32,7 +32,6 @@ everest_config.yml:: controls: - name: point - type: generic_control min: -1.0 max: 1.0 initial_guess: 0 @@ -57,7 +56,6 @@ everest_config.yml:: controls: - name: point - type: generic_control initial_guess: 0 perturbation_magnitude : 0.001 variables: @@ -216,7 +214,6 @@ everest_config.yml:: controls: - name: point - type: generic_control min: -1.0 max: 1.0 initial_guess: 0 diff --git a/src/everest/config/control_config.py b/src/everest/config/control_config.py index fc924cfac5b..4d4f9b74aaf 100644 --- a/src/everest/config/control_config.py +++ b/src/everest/config/control_config.py @@ -42,16 +42,9 @@ class ControlConfig(BaseModel): name: Annotated[str, AfterValidator(no_dots_in_string)] = Field( description="Control name" ) - type: Literal["well_control", "generic_control"] = Field( - description=""" -Only two allowed control types are accepted - -* **well_control**: Standard built-in Everest control type designed for field\ - optimization - -* **generic_control**: Enables the user to define controls types to be employed for\ - customized optimization jobs. -""" + type: str | None = Field( + default=None, + description="""Type has been deprecated and can be removed from the config""", ) variables: Annotated[ ControlVariable, diff --git a/src/everest/config/everest_config.py b/src/everest/config/everest_config.py index e9855930d22..1cca87aa14d 100644 --- a/src/everest/config/everest_config.py +++ b/src/everest/config/everest_config.py @@ -452,15 +452,18 @@ def validate_variable_name_match_well_name(self) -> Self: # pylint: disable=E02 wells = self.wells if controls is None or wells is None: return self - well_names = [w.name for w in wells] + well_names = {w.name for w in wells} if not well_names: return self for c in controls: - if c.type == "generic_control": - continue - for v in c.variables: - if v.name not in well_names: - raise ValueError("Variable name does not match any well name") + variable_names = {v.name for v in c.variables} + if len(variable_names.intersection(well_names)) not in { + 0, + len(variable_names), + }: + raise ValueError( + "Variable names should either all or none match well names" + ) return self diff --git a/test-data/everest/egg/everest/model/config.yml b/test-data/everest/egg/everest/model/config.yml index ac4049ff15a..70339808a85 100644 --- a/test-data/everest/egg/everest/model/config.yml +++ b/test-data/everest/egg/everest/model/config.yml @@ -20,7 +20,6 @@ wells: controls: - name: well_rate - type: generic_control min: 0 max: 1 perturbation_magnitude: 0.15 diff --git a/test-data/everest/egg/everest/model/config_flow.yml b/test-data/everest/egg/everest/model/config_flow.yml index 90223138436..cdd531591e6 100644 --- a/test-data/everest/egg/everest/model/config_flow.yml +++ b/test-data/everest/egg/everest/model/config_flow.yml @@ -18,7 +18,6 @@ wells: controls: - name: well_rate - type: generic_control min: 0 max: 1 perturbation_magnitude: 0.15 diff --git a/test-data/everest/math_func/config_advanced.yml b/test-data/everest/math_func/config_advanced.yml index b9952f51557..0db0865ae38 100644 --- a/test-data/everest/math_func/config_advanced.yml +++ b/test-data/everest/math_func/config_advanced.yml @@ -6,7 +6,6 @@ controls: min: -1.0 initial_guess: 0.25 perturbation_magnitude: 0.005 - type: generic_control variables: - name: x index: 0 diff --git a/test-data/everest/math_func/config_minimal.yml b/test-data/everest/math_func/config_minimal.yml index 4f8421c940d..1d9170dd6ad 100644 --- a/test-data/everest/math_func/config_minimal.yml +++ b/test-data/everest/math_func/config_minimal.yml @@ -1,6 +1,5 @@ controls: - name: point - type: generic_control min: -1.0 max: 1.0 initial_guess: 0.1 diff --git a/test-data/everest/math_func/config_multiobj.yml b/test-data/everest/math_func/config_multiobj.yml index 721e9948c10..bfb345b3b59 100644 --- a/test-data/everest/math_func/config_multiobj.yml +++ b/test-data/everest/math_func/config_multiobj.yml @@ -1,7 +1,6 @@ controls: - name: point - type: generic_control min: -1.0 max: 1.0 initial_guess: 0 diff --git a/tests/everest/conftest.py b/tests/everest/conftest.py index 41ef76c3e75..dde8e89cdd2 100644 --- a/tests/everest/conftest.py +++ b/tests/everest/conftest.py @@ -53,7 +53,6 @@ def _copy_tree(path: str | None = None): def control_data_no_variables() -> dict[str, str | float]: return { "name": "group_0", - "type": "well_control", "min": 0.0, "max": 0.1, "perturbation_magnitude": 0.005, @@ -213,7 +212,6 @@ def min_config(): controls: - name: my_control - type: well_control min: 0 max: 0.1 variables: diff --git a/tests/everest/test_config_validation.py b/tests/everest/test_config_validation.py index f75ba9ebb57..971bd3a3875 100644 --- a/tests/everest/test_config_validation.py +++ b/tests/everest/test_config_validation.py @@ -185,7 +185,6 @@ def test_that_duplicate_control_names_raise_error(): controls=[ { "name": "group_0", - "type": "well_control", "min": 0, "max": 0.1, "variables": [ @@ -194,7 +193,6 @@ def test_that_duplicate_control_names_raise_error(): }, { "name": "group_0", - "type": "well_control", "min": 0, "max": 0.1, "variables": [ @@ -213,7 +211,6 @@ def test_that_dot_not_in_control_names(): controls=[ { "name": "group_0.2", - "type": "well_control", "min": 0, "max": 0.1, "variables": [ @@ -236,7 +233,6 @@ def test_that_scaled_range_is_valid_range(): controls=[ { "name": "group_0", - "type": "well_control", "min": 0, "max": 0.1, "scaled_range": [2, 1], @@ -294,9 +290,7 @@ def test_that_invalid_control_initial_guess_outside_bounds( ): with pytest.raises(ValueError) as e: EverestConfig.with_defaults( - controls=[ - {"name": "group_0", "type": "well_control", "variables": variables} - ] + controls=[{"name": "group_0", "variables": variables}] ) assert ( @@ -345,7 +339,6 @@ def test_that_invalid_control_unique_entry(variables, unique_key): controls=[ { "name": "group_0", - "type": "well_control", "max": 0, "min": 0.1, "variables": variables, @@ -365,7 +358,6 @@ def test_that_invalid_control_undefined_fields(): controls=[ { "name": "group_0", - "type": "well_control", "variables": [ {"name": "w00"}, ], @@ -386,7 +378,6 @@ def test_that_control_variables_index_is_defined_for_all_variables(): controls=[ { "name": "group_0", - "type": "well_control", "min": 0, "max": 0.1, "variables": [ @@ -998,7 +989,6 @@ def test_load_file_with_errors(copy_math_func_test_data_to_tmp, capsys): content = file.read() with open("config_minimal_error.yml", "w", encoding="utf-8") as file: - content = content.replace("generic_control", "yolo_control") content = content.replace("max: 1.0", "max: not_a number") pos = content.find("name: distance") content = content[: pos + 14] + "\n invalid: invalid" + content[pos + 14 :] @@ -1009,19 +999,13 @@ def test_load_file_with_errors(copy_math_func_test_data_to_tmp, capsys): EverestConfig.load_file_with_argparser("config_minimal_error.yml", parser) captured = capsys.readouterr() + assert "Found 2 validation error" in captured.err - assert "Found 3 validation error" in captured.err - assert "line: 3, column: 11" in captured.err - assert ( - "Input should be 'well_control' or 'generic_control' (type=literal_error)" - in captured.err - ) - - assert "line: 5, column: 10" in captured.err + assert "line: 4, column: 10" in captured.err assert ( "Input should be a valid number, unable to parse string as a number (type=float_parsing)" in captured.err ) - assert "line: 16, column: 5" in captured.err + assert "line: 15, column: 5" in captured.err assert "Extra inputs are not permitted (type=extra_forbidden)" in captured.err diff --git a/tests/everest/test_controls.py b/tests/everest/test_controls.py index 7cbaab07d42..f047d66a885 100644 --- a/tests/everest/test_controls.py +++ b/tests/everest/test_controls.py @@ -37,7 +37,6 @@ def test_controls_initialization(): config.controls.append( ControlConfig( name=exp_grp_name, - type="well_control", variables=[ ControlVariableConfig( name=a_ctrl_name, @@ -84,7 +83,6 @@ def _perturb_control_zero( if revised_control_zero is None: revised_control_zero = ControlConfig( name=control_zero.name, - type=control_zero.type, min=gmin, max=gmax, initial_guess=ginit, @@ -232,7 +230,7 @@ def test_control_none_well_variable_name(): config.controls[0].variables[0].name = illegal_name with pytest.raises( ValidationError, - match="Variable name does not match any well name", + match="Variable names should either all or none match well names", ): EverestConfig.model_validate(config.to_dict()) diff --git a/tests/everest/test_data/mocked_test_case/config_full_gradient_info.yml b/tests/everest/test_data/mocked_test_case/config_full_gradient_info.yml index 21659a17cbe..1104b8e6258 100644 --- a/tests/everest/test_data/mocked_test_case/config_full_gradient_info.yml +++ b/tests/everest/test_data/mocked_test_case/config_full_gradient_info.yml @@ -6,7 +6,6 @@ wells: controls: - name: group - type: well_control min: 0 max: 0.1 variables: diff --git a/tests/everest/test_data/mocked_test_case/config_input_constraints.yml b/tests/everest/test_data/mocked_test_case/config_input_constraints.yml index 914e37e5a61..dbf744f0aa3 100644 --- a/tests/everest/test_data/mocked_test_case/config_input_constraints.yml +++ b/tests/everest/test_data/mocked_test_case/config_input_constraints.yml @@ -20,7 +20,6 @@ wells: controls: - name: group - type: well_control min: 0 max: 0.1 variables: diff --git a/tests/everest/test_data/mocked_test_case/config_multi_objectives.yml b/tests/everest/test_data/mocked_test_case/config_multi_objectives.yml index 3b083d8134f..68b0e473f60 100644 --- a/tests/everest/test_data/mocked_test_case/config_multi_objectives.yml +++ b/tests/everest/test_data/mocked_test_case/config_multi_objectives.yml @@ -19,7 +19,6 @@ wells: controls: - name: group - type: well_control min: 0 max: 0.1 perturbation_magnitude : 0.005 diff --git a/tests/everest/test_data/mocked_test_case/config_output_constraints.yml b/tests/everest/test_data/mocked_test_case/config_output_constraints.yml index 96dd8b87627..82565c21d07 100644 --- a/tests/everest/test_data/mocked_test_case/config_output_constraints.yml +++ b/tests/everest/test_data/mocked_test_case/config_output_constraints.yml @@ -21,7 +21,6 @@ wells: controls: - name: group - type: well_control min: 0 max: 0.1 perturbation_magnitude : 0.005 diff --git a/tests/everest/test_data/mocked_test_case/config_samplers.yml b/tests/everest/test_data/mocked_test_case/config_samplers.yml index d57fe3b97e9..888e2d95d1e 100644 --- a/tests/everest/test_data/mocked_test_case/config_samplers.yml +++ b/tests/everest/test_data/mocked_test_case/config_samplers.yml @@ -6,7 +6,6 @@ wells: controls: - name: group - type: well_control min: 0 max: 0.1 sampler: @@ -21,7 +20,6 @@ controls: initial_guess: 0.0624 - name: group_1 - type: well_control min: 0 max: 0.1 variables: @@ -40,7 +38,6 @@ controls: method: uniform - name: group_2 - type: well_control min: 0 max: 0.1 sampler: diff --git a/tests/everest/test_data/mocked_test_case/config_workflow.yml b/tests/everest/test_data/mocked_test_case/config_workflow.yml index f4f274abddb..4b9e2093ab2 100644 --- a/tests/everest/test_data/mocked_test_case/config_workflow.yml +++ b/tests/everest/test_data/mocked_test_case/config_workflow.yml @@ -5,7 +5,6 @@ wells: controls: - name: group - type: well_control min: 0 max: 0.1 perturbation_magnitude : 0.005 diff --git a/tests/everest/test_data/mocked_test_case/mocked_multi_batch.yml b/tests/everest/test_data/mocked_test_case/mocked_multi_batch.yml index 86b0487c90d..5952d4d9679 100644 --- a/tests/everest/test_data/mocked_test_case/mocked_multi_batch.yml +++ b/tests/everest/test_data/mocked_test_case/mocked_multi_batch.yml @@ -15,7 +15,6 @@ wells: controls: - name: group - type: well_control min: 0 max: 0.1 perturbation_magnitude : 0.005 diff --git a/tests/everest/test_data/mocked_test_case/mocked_test_case.yml b/tests/everest/test_data/mocked_test_case/mocked_test_case.yml index 3ac6efa265f..1eac9fd58b4 100644 --- a/tests/everest/test_data/mocked_test_case/mocked_test_case.yml +++ b/tests/everest/test_data/mocked_test_case/mocked_test_case.yml @@ -28,7 +28,6 @@ wells: controls: - name: group - type: well_control min: 0 max: 0.1 perturbation_magnitude : 0.005 diff --git a/tests/everest/test_data/open_shut_state_modifier/everest/model/array.yml b/tests/everest/test_data/open_shut_state_modifier/everest/model/array.yml index 4d3d3312563..398157dbd10 100644 --- a/tests/everest/test_data/open_shut_state_modifier/everest/model/array.yml +++ b/tests/everest/test_data/open_shut_state_modifier/everest/model/array.yml @@ -22,7 +22,6 @@ wells: controls: - name: well_priorities - type: well_control min: 0.0 max: 1.0 perturbation_magnitude: 0.05 @@ -34,7 +33,6 @@ controls: - { name: WELL-5, initial_guess: [0.52, 0.50, 0.52, 0.56] } - name: swapping_constraints - type: generic_control min: 0.0 max: 1.0 perturbation_magnitude: 0.05 diff --git a/tests/everest/test_data/open_shut_state_modifier/everest/model/index.yml b/tests/everest/test_data/open_shut_state_modifier/everest/model/index.yml index 6db082dba6f..044eae817f5 100644 --- a/tests/everest/test_data/open_shut_state_modifier/everest/model/index.yml +++ b/tests/everest/test_data/open_shut_state_modifier/everest/model/index.yml @@ -22,7 +22,6 @@ wells: controls: - name: well_priorities - type: well_control min: 0.0 max: 1.0 perturbation_magnitude: 0.05 @@ -49,7 +48,6 @@ controls: - { name: WELL-5, index: 4, initial_guess: 0.56 } - name: swapping_constraints - type: generic_control min: 0.0 max: 1.0 perturbation_magnitude: 0.05 diff --git a/tests/everest/test_data/templating/config.yml b/tests/everest/test_data/templating/config.yml index b00ffcd1d19..96f5da92bc7 100644 --- a/tests/everest/test_data/templating/config.yml +++ b/tests/everest/test_data/templating/config.yml @@ -5,7 +5,6 @@ wells: controls: - name: well_drill - type: well_control min: 0 max: 1 variables: diff --git a/tests/everest/test_data/valid_config_file/forward_models/valid_config_maintained_forward_models.yml b/tests/everest/test_data/valid_config_file/forward_models/valid_config_maintained_forward_models.yml index 4854c20b27e..db5d7cc9543 100644 --- a/tests/everest/test_data/valid_config_file/forward_models/valid_config_maintained_forward_models.yml +++ b/tests/everest/test_data/valid_config_file/forward_models/valid_config_maintained_forward_models.yml @@ -13,7 +13,6 @@ wells: controls: - name: well_order - type: well_control min: 0 max: 1 perturbation_magnitude: 0.05 @@ -27,7 +26,6 @@ controls: - name: well_number - type: generic_control min: 0.0 max: 1.0 perturbation_magnitude: 0.1 diff --git a/tests/everest/test_data/valid_config_file/invalid_yaml_config.yml b/tests/everest/test_data/valid_config_file/invalid_yaml_config.yml index 6d93a397b23..095f8a84c95 100644 --- a/tests/everest/test_data/valid_config_file/invalid_yaml_config.yml +++ b/tests/everest/test_data/valid_config_file/invalid_yaml_config.yml @@ -1,7 +1,6 @@ controls: - name: not_really_important_for_this_test - type: generic_control min: -1.0 max: 1.0 initial_guess: 0 diff --git a/tests/everest/test_data/valid_config_file/valid_yaml_config.yml b/tests/everest/test_data/valid_config_file/valid_yaml_config.yml index 45913340bcc..0388ed29ead 100644 --- a/tests/everest/test_data/valid_config_file/valid_yaml_config.yml +++ b/tests/everest/test_data/valid_config_file/valid_yaml_config.yml @@ -1,7 +1,6 @@ controls: - name: not_really_important_for_this_test - type: generic_control min: -1.0 max: 1.0 initial_guess: 0 diff --git a/tests/everest/test_data/valid_config_file/valid_yaml_config_no_algorithm.yml b/tests/everest/test_data/valid_config_file/valid_yaml_config_no_algorithm.yml index 1d372a219a1..e974f3e99bb 100644 --- a/tests/everest/test_data/valid_config_file/valid_yaml_config_no_algorithm.yml +++ b/tests/everest/test_data/valid_config_file/valid_yaml_config_no_algorithm.yml @@ -1,7 +1,6 @@ controls: - name: not_really_important_for_this_test - type: generic_control min: -1.0 max: 1.0 initial_guess: 0 diff --git a/tests/everest/test_discrete.py b/tests/everest/test_discrete.py index a293f523716..2a6f616607c 100644 --- a/tests/everest/test_discrete.py +++ b/tests/everest/test_discrete.py @@ -24,7 +24,6 @@ def test_discrete_optimizer( "controls": [ { "name": "point", - "type": "generic_control", "min": 0, "max": 10, "control_type": "integer", diff --git a/tests/everest/test_everest_config.py b/tests/everest/test_everest_config.py index 0075e763fee..f9d2084770e 100644 --- a/tests/everest/test_everest_config.py +++ b/tests/everest/test_everest_config.py @@ -13,7 +13,6 @@ def test_that_control_config_is_initialized_with_control_variables(): controls_dict = { "name": "hello", - "type": "generic_control", "min": 0, "max": 1, "variables": [ @@ -63,7 +62,6 @@ def test_that_get_output_dir_returns_same_for_old_and_new(): "controls": [ { "name": "group_0", - "type": "well_control", "min": 0, "max": 0.1, "variables": [ @@ -101,7 +99,6 @@ def test_that_invalid_keys_are_linted(): "controls": [ { "name": "group_0", - "type": "well_control", "inital_guss": "well_control", "min": 0, "max": 0.1, @@ -111,7 +108,6 @@ def test_that_invalid_keys_are_linted(): }, { "name": "group_0", - "type": "well_control", "initial_guess": "well_control", "min": 0, "max": 0.1, @@ -243,7 +239,6 @@ def test_that_log_level_property_is_consistent_with_environment_log_level(): "controls": [ { "name": "group_0", - "type": "well_control", "min": 0, "max": 0.1, "variables": [ diff --git a/tests/everest/test_output_constraints.py b/tests/everest/test_output_constraints.py index b7e281a0bc6..bb05ad8ddc9 100644 --- a/tests/everest/test_output_constraints.py +++ b/tests/everest/test_output_constraints.py @@ -54,7 +54,6 @@ def test_wrong_output_constr_def(copy_mocked_test_data_to_tmp): "controls": [ { "name": "well_order", - "type": "well_control", "min": 0, "max": 1, "variables": [{"name": "w07", "initial_guess": 0.0633}], @@ -84,7 +83,6 @@ def test_wrong_output_constr_def(copy_mocked_test_data_to_tmp): "controls": [ { "name": "well_order", - "type": "well_control", "min": 0, "max": 1, "variables": [{"name": "w07", "initial_guess": 0.0633}], @@ -110,7 +108,6 @@ def test_wrong_output_constr_def(copy_mocked_test_data_to_tmp): "controls": [ { "name": "well_order", - "type": "well_control", "min": 0, "max": 1, "variables": [{"name": "w07", "initial_guess": 0.0633}], @@ -139,7 +136,6 @@ def test_wrong_output_constr_def(copy_mocked_test_data_to_tmp): "controls": [ { "name": "well_order", - "type": "well_control", "min": 0, "max": 1, "variables": [{"name": "w07", "initial_guess": 0.0633}], @@ -168,7 +164,6 @@ def test_wrong_output_constr_def(copy_mocked_test_data_to_tmp): "controls": [ { "name": "well_order", - "type": "well_control", "min": 0, "max": 1, "variables": [{"name": "w07", "initial_guess": 0.0633}], @@ -198,7 +193,6 @@ def test_upper_bound_output_constraint_def(copy_mocked_test_data_to_tmp): "controls": [ { "name": "group_0", - "type": "well_control", "min": 0, "max": 1, "variables": [{"name": "w07", "initial_guess": 0.0633}], diff --git a/tests/everest/test_res_initialization.py b/tests/everest/test_res_initialization.py index 3375dafda29..dfdcb6d13df 100644 --- a/tests/everest/test_res_initialization.py +++ b/tests/everest/test_res_initialization.py @@ -112,7 +112,6 @@ def test_everest_to_ert_controls(tmp_path, monkeypatch): controls: - name: my_control - type: well_control min: 0 max: 0.1 variables: diff --git a/tests/everest/test_yaml_parser.py b/tests/everest/test_yaml_parser.py index 233db0b2533..50b7569ad9a 100644 --- a/tests/everest/test_yaml_parser.py +++ b/tests/everest/test_yaml_parser.py @@ -34,7 +34,6 @@ def test_read_file(tmp_path, monkeypatch): controls: - name: my_control - type: well_control min: 0 max: 0.1 variables: