Skip to content

Commit

Permalink
Added default values for AdequacyPatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigurd-Borge committed Oct 4, 2024
1 parent 76e0e8c commit 41068b0
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 16 deletions.
33 changes: 22 additions & 11 deletions src/antares/model/settings/adequacy_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
54 changes: 49 additions & 5 deletions tests/antares/services/local_services/test_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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": "",
Expand All @@ -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):
Expand Down

0 comments on commit 41068b0

Please sign in to comment.