From 41068b0d4b7598c665e07fce61d4aa1bc3dd15f4 Mon Sep 17 00:00:00 2001 From: Sigurd Borge Date: Fri, 4 Oct 2024 15:47:56 +0200 Subject: [PATCH] Added default values for AdequacyPatch --- src/antares/model/settings/adequacy_patch.py | 33 ++++++++---- .../services/local_services/test_study.py | 54 +++++++++++++++++-- 2 files changed, 71 insertions(+), 16 deletions(-) diff --git a/src/antares/model/settings/adequacy_patch.py b/src/antares/model/settings/adequacy_patch.py index b0c843a9..684d6dfa 100644 --- a/src/antares/model/settings/adequacy_patch.py +++ b/src/antares/model/settings/adequacy_patch.py @@ -11,26 +11,37 @@ # This file is part of the Antares project. from enum import Enum -from typing import Optional from pydantic import BaseModel from pydantic.alias_generators import to_camel +from antares.tools.all_optional_meta import all_optional_model + class PriceTakingOrder(Enum): DENS = "DENS" LOAD = "Load" -class AdequacyPatchProperties(BaseModel, alias_generator=to_camel): +class DefaultAdequacyPatchProperties(BaseModel, populate_by_name=True, alias_generator=to_camel): # version 830 - enable_adequacy_patch: Optional[bool] = None - ntc_from_physical_areas_out_to_physical_areas_in_adequacy_patch: Optional[bool] = None - ntc_between_physical_areas_out_adequacy_patch: Optional[bool] = None + enable_adequacy_patch: bool = False + ntc_from_physical_areas_out_to_physical_areas_in_adequacy_patch: bool = True + ntc_between_physical_areas_out_adequacy_patch: bool = True # version 850 - price_taking_order: Optional[PriceTakingOrder] = None - include_hurdle_cost_csr: Optional[bool] = None - check_csr_cost_function: Optional[bool] = None - threshold_initiate_curtailment_sharing_rule: Optional[int] = None - threshold_display_local_matching_rule_violations: Optional[int] = None - threshold_csr_variable_bounds_relaxation: Optional[int] = None + price_taking_order: PriceTakingOrder = PriceTakingOrder.DENS + include_hurdle_cost_csr: bool = False + check_csr_cost_function: bool = False + enable_first_step: bool = False + threshold_initiate_curtailment_sharing_rule: int = 0 + threshold_display_local_matching_rule_violations: int = 0 + threshold_csr_variable_bounds_relaxation: int = 3 + + +@all_optional_model +class AdequacyPatchProperties(DefaultAdequacyPatchProperties): + pass + + +class AdequacyPatchPropertiesLocal(DefaultAdequacyPatchProperties): + pass diff --git a/tests/antares/services/local_services/test_study.py b/tests/antares/services/local_services/test_study.py index c57c9ad6..1e5c7a84 100644 --- a/tests/antares/services/local_services/test_study.py +++ b/tests/antares/services/local_services/test_study.py @@ -45,8 +45,18 @@ LinkUiLocal, TransmissionCapacities, ) -from antares.model.settings.general import BuildingMode, GeneralProperties, Mode, Month, WeekDay -from antares.model.settings.study_settings import StudySettings +from antares.model.settings.adequacy_patch import ( + DefaultAdequacyPatchProperties, + PriceTakingOrder, +) +from antares.model.settings.general import ( + BuildingMode, + DefaultGeneralProperties, + Mode, + Month, + WeekDay, +) +from antares.model.settings.study_settings import DefaultStudySettings, StudySettingsLocal from antares.model.study import create_study_local from antares.service.local_services.area_local import AreaLocalService from antares.service.local_services.link_local import LinkLocalService @@ -310,12 +320,12 @@ def test_local_study_has_settings(self, local_study): local_study_settings = local_study.get_settings() # Then assert local_study.get_settings() - assert isinstance(local_study_settings, StudySettings) + assert isinstance(local_study_settings, DefaultStudySettings) def test_local_study_has_correct_default_general_properties(self, local_study): # Given # https://antares-simulator.readthedocs.io/en/latest/user-guide/solver/04-parameters/ - expected_general_properties = GeneralProperties.model_validate( + expected_general_properties = DefaultGeneralProperties.model_validate( { "mode": Mode.ECONOMY, "horizon": "", @@ -339,12 +349,46 @@ def test_local_study_has_correct_default_general_properties(self, local_study): } ) # When - expected_study_settings = StudySettings(general_properties=expected_general_properties) + expected_study_settings = StudySettingsLocal(general_properties=expected_general_properties) # Then assert local_study.get_settings().general_properties == expected_general_properties assert local_study.get_settings() == expected_study_settings + def test_local_study_has_correct_default_adequacy_patch_properties(self, local_study): + # Given + expected_adequacy_patch_properties = DefaultAdequacyPatchProperties.model_validate( + { + "enable_adequacy_patch": False, + "ntc_from_physical_areas_out_to_physical_areas_in_adequacy_patch": True, + "ntc_between_physical_areas_out_adequacy_patch": True, + "price_taking_order": PriceTakingOrder.DENS, + "include_hurdle_cost_csr": False, + "check_csr_cost_function": False, + "enable_first_step": False, + "threshold_initiate_curtailment_sharing_rule": 0, + "threshold_display_local_matching_rule_violations": 0, + "threshold_csr_variable_bounds_relaxation": 3, + } + ) + expected_study_settings = StudySettingsLocal( + adequacy_patch_properties=DefaultAdequacyPatchProperties.model_validate( + expected_adequacy_patch_properties.model_dump(exclude_none=True) + ) + ) + + # When + actual_adequacy_patch_properties = DefaultAdequacyPatchProperties.model_validate( + local_study.get_settings().adequacy_patch_properties.model_dump(exclude_none=True) + ) + actual_study_settings = StudySettingsLocal.model_validate( + local_study.get_settings().model_dump(exclude_none=True) + ) + + # Then + assert actual_adequacy_patch_properties == expected_adequacy_patch_properties + assert actual_study_settings == expected_study_settings + class TestCreateArea: def test_areas_sets_ini_content(self, tmp_path, local_study):