Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(version): support Simulator v9.2 #2188

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
8 changes: 5 additions & 3 deletions antarest/study/business/adequacy_patch_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from antarest.study.business.all_optional_meta import all_optional_model
from antarest.study.business.enum_ignore_case import EnumIgnoreCase
from antarest.study.business.utils import GENERAL_DATA_PATH, FieldInfo, FormFieldsBaseModel, execute_or_add_commands
from antarest.study.model import STUDY_VERSION_8_3, STUDY_VERSION_8_5, Study
from antarest.study.model import STUDY_VERSION_8_3, STUDY_VERSION_8_5, STUDY_VERSION_9_2, Study
from antarest.study.storage.storage_service import StudyStorageService
from antarest.study.storage.variantstudy.model.command.update_config import UpdateConfig

Expand Down Expand Up @@ -63,6 +63,7 @@ class AdequacyPatchFormFields(FormFieldsBaseModel):
"path": f"{ADEQUACY_PATCH_PATH}/set-to-null-ntc-between-physical-out-for-first-step",
"default_value": True,
"start_version": STUDY_VERSION_8_3,
"end_version": STUDY_VERSION_9_2,
},
"price_taking_order": {
"path": f"{ADEQUACY_PATCH_PATH}/price-taking-order",
Expand Down Expand Up @@ -111,9 +112,10 @@ def get_field_values(self, study: Study) -> AdequacyPatchFormFields:

def get_value(field_info: FieldInfo) -> Any:
path = field_info["path"]
start_version = field_info.get("start_version", -1)
start_version = field_info.get("start_version", 0)
end_version = field_info.get("end_version", 100000)
target_name = path.split("/")[-1]
is_in_version = file_study.config.version >= start_version
is_in_version = file_study.config.version >= start_version and file_study.config.version < end_version

return parent.get(target_name, field_info["default_value"]) if is_in_version else None

Expand Down
16 changes: 14 additions & 2 deletions antarest/study/business/advanced_parameters_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from antarest.study.business.all_optional_meta import all_optional_model
from antarest.study.business.enum_ignore_case import EnumIgnoreCase
from antarest.study.business.utils import GENERAL_DATA_PATH, FieldInfo, FormFieldsBaseModel, execute_or_add_commands
from antarest.study.model import STUDY_VERSION_8_8, Study
from antarest.study.model import STUDY_VERSION_8_8, STUDY_VERSION_9_2, Study
from antarest.study.storage.storage_service import StudyStorageService
from antarest.study.storage.variantstudy.model.command.update_config import UpdateConfig

Expand Down Expand Up @@ -100,6 +100,7 @@ class AdvancedParamsFormFields(FormFieldsBaseModel):
seed_thermal_costs: StrictInt
seed_hydro_costs: StrictInt
seed_initial_reservoir_levels: StrictInt
hydro_pmax_format: str

@field_validator("accuracy_on_correlation")
def check_accuracy_on_correlation(cls, v: str) -> str:
Expand Down Expand Up @@ -134,6 +135,7 @@ def check_accuracy_on_correlation(cls, v: str) -> str:
"initial_reservoir_levels": {
"path": f"{OTHER_PREFERENCES_PATH}/initial-reservoir-levels",
"default_value": InitialReservoirLevel.COLD_START.value,
"end_version": STUDY_VERSION_9_2,
},
"power_fluctuations": {
"path": f"{OTHER_PREFERENCES_PATH}/power-fluctuations",
Expand Down Expand Up @@ -212,6 +214,11 @@ def check_accuracy_on_correlation(cls, v: str) -> str:
"path": f"{SEEDS_PATH}/seed-initial-reservoir-levels",
"default_value": 10005489,
},
"hydro_pmax_format": {
"path": f"{OTHER_PREFERENCES_PATH}/hydro-pmax-format",
"default_value": "daily",
"start_version": STUDY_VERSION_9_2,
},
}


Expand All @@ -230,14 +237,19 @@ def get_field_values(self, study: Study) -> AdvancedParamsFormFields:
seeds = general_data.get("seeds - Mersenne Twister", {})

def get_value(field_info: FieldInfo) -> Any:
start_version = field_info.get("start_version", 0)
end_version = field_info.get("end_version", 100000)
is_in_version = file_study.config.version >= start_version and file_study.config.version < end_version
if not is_in_version:
return None
path = field_info["path"]
target_name = path.split("/")[-1]
if ADVANCED_PARAMS_PATH in path:
parent = advanced_params
elif OTHER_PREFERENCES_PATH in path:
parent = other_preferences
else:
parent = seeds
target_name = path.split("/")[-1]
return parent.get(target_name, field_info["default_value"])

return AdvancedParamsFormFields.construct(**{name: get_value(info) for name, info in FIELDS_INFO.items()})
Expand Down
10 changes: 5 additions & 5 deletions antarest/study/business/areas/st_storage_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
from antarest.study.model import STUDY_VERSION_8_8, Study
from antarest.study.storage.rawstudy.model.filesystem.config.model import transform_name_to_id
from antarest.study.storage.rawstudy.model.filesystem.config.st_storage import (
STStorage880Config,
STStorage880Properties,
STStorage920Config,
STStorage920Properties,
STStorageConfigType,
STStorageGroup,
create_st_storage_config,
Expand All @@ -51,7 +51,7 @@

@all_optional_model
@camel_case_model
class STStorageInput(STStorage880Properties):
class STStorageInput(STStorage920Properties):
"""
Model representing the form used to EDIT an existing short-term storage.
"""
Expand Down Expand Up @@ -94,7 +94,7 @@ def to_config(self, study_version: StudyVersion) -> STStorageConfigType:

@all_optional_model
@camel_case_model
class STStorageOutput(STStorage880Config):
class STStorageOutput(STStorage920Config):
"""
Model representing the form used to display the details of a short-term storage entry.
"""
Expand Down Expand Up @@ -303,7 +303,7 @@ def create_storage(
def _make_create_cluster_cmd(self, area_id: str, cluster: STStorageConfigType) -> CreateSTStorage:
command = CreateSTStorage(
area_id=area_id,
parameters=cluster,
parameters=cluster.model_dump(mode="json", by_alias=True, exclude_none=True),
command_context=self.storage_service.variant_study_service.command_factory.command_context,
)
return command
Expand Down
108 changes: 78 additions & 30 deletions antarest/study/business/thematic_trimming_field_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@

from antarest.study.business.all_optional_meta import all_optional_model
from antarest.study.business.utils import FormFieldsBaseModel
from antarest.study.model import STUDY_VERSION_8_1, STUDY_VERSION_8_3, STUDY_VERSION_8_6, STUDY_VERSION_8_8
from antarest.study.model import (
STUDY_VERSION_8_1,
STUDY_VERSION_8_3,
STUDY_VERSION_8_6,
STUDY_VERSION_8_8,
STUDY_VERSION_9_1,
)


@all_optional_model
class ThematicTrimmingFormFields(FormFieldsBaseModel):
class ThematicTrimmingFormFieldsBase(FormFieldsBaseModel):
"""
This class manages the configuration of result filtering in a simulation.

Expand Down Expand Up @@ -96,6 +102,10 @@ class ThematicTrimmingFormFields(FormFieldsBaseModel):
# since v8.3
dens: bool
profit_by_plant: bool


@all_optional_model
class ThematicTrimmingFormFields860(ThematicTrimmingFormFieldsBase):
# topic: Short-Term Storages
# since v8.6
sts_inj_by_plant: bool
Expand Down Expand Up @@ -132,6 +142,34 @@ class ThematicTrimmingFormFields(FormFieldsBaseModel):
other5_level: bool


@all_optional_model
class ThematicTrimmingFormFields910(ThematicTrimmingFormFieldsBase):
sts_inj_by_plant: bool
sts_withdrawal_by_plant: bool
sts_lvl_by_plant: bool
sts_cashflow_by_cluster: bool
sts_by_group: bool


ThematicTrimmingFormFieldsType = t.Union[
ThematicTrimmingFormFields910, ThematicTrimmingFormFields860, ThematicTrimmingFormFieldsBase
]


def get_thematic_trimming_cls(study_version: StudyVersion) -> t.Type[ThematicTrimmingFormFieldsType]:
if study_version >= STUDY_VERSION_9_1:
return ThematicTrimmingFormFields910
elif study_version >= STUDY_VERSION_8_6:
return ThematicTrimmingFormFields860
else:
return ThematicTrimmingFormFieldsBase


def create_thematic_trimming_config(study_version: StudyVersion, **kwargs: t.Any) -> ThematicTrimmingFormFieldsType:
cls = get_thematic_trimming_cls(study_version)
return cls.model_validate(kwargs)


_GENERAL = "General"
_SHORT_TERM_STORAGES = "Short-Term Storages"
_SHORT_TERM_STORAGES_GROUP = "Short-Term Storages - Group"
Expand Down Expand Up @@ -210,40 +248,50 @@ class ThematicTrimmingFormFields(FormFieldsBaseModel):
"sts_lvl_by_plant": {"topic": _SHORT_TERM_STORAGES, "path": "STS lvl by plant", "default_value": True, "start_version": STUDY_VERSION_8_6},
"sts_cashflow_by_cluster": {"topic": _SHORT_TERM_STORAGES, "path": "STS Cashflow By Cluster", "default_value": True, "start_version": STUDY_VERSION_8_8},
# topic: "Short-Term Storages - Group"
"psp_open_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "PSP_open_injection", "default_value": True, "start_version": STUDY_VERSION_8_6},
"psp_open_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "PSP_open_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6},
"psp_open_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "PSP_open_level", "default_value": True, "start_version": STUDY_VERSION_8_6},
"psp_closed_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "PSP_closed_injection", "default_value": True, "start_version": STUDY_VERSION_8_6},
"psp_closed_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "PSP_closed_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6},
"psp_closed_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "PSP_closed_level", "default_value": True, "start_version": STUDY_VERSION_8_6},
"pondage_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Pondage_injection", "default_value": True, "start_version": STUDY_VERSION_8_6},
"pondage_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Pondage_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6},
"pondage_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Pondage_level", "default_value": True, "start_version": STUDY_VERSION_8_6},
"battery_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Battery_injection", "default_value": True, "start_version": STUDY_VERSION_8_6},
"battery_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Battery_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6},
"battery_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Battery_level", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other1_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other1_injection", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other1_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other1_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other1_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other1_level", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other2_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other2_injection", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other2_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other2_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other2_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other2_level", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other3_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other3_injection", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other3_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other3_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other3_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other3_level", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other4_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other4_injection", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other4_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other4_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other4_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other4_level", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other5_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other5_injection", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other5_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other5_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6},
"other5_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other5_level", "default_value": True, "start_version": STUDY_VERSION_8_6},
"psp_open_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "PSP_open_injection", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"psp_open_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "PSP_open_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"psp_open_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "PSP_open_level", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"psp_closed_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "PSP_closed_injection", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"psp_closed_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "PSP_closed_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"psp_closed_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "PSP_closed_level", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"pondage_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Pondage_injection", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"pondage_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Pondage_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"pondage_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Pondage_level", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"battery_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Battery_injection", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"battery_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Battery_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"battery_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Battery_level", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other1_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other1_injection", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other1_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other1_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other1_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other1_level", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other2_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other2_injection", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other2_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other2_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other2_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other2_level", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other3_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other3_injection", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other3_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other3_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other3_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other3_level", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other4_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other4_injection", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other4_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other4_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other4_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other4_level", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other5_injection": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other5_injection", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other5_withdrawal": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other5_withdrawal", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
"other5_level": {"topic": _SHORT_TERM_STORAGES_GROUP, "path": "Other5_level", "default_value": True, "start_version": STUDY_VERSION_8_6, "end_version": STUDY_VERSION_9_1},
# fmt: on
# since v9.1
"sts_by_group": {
"topic": _SHORT_TERM_STORAGES_GROUP,
"path": "STS by group",
"default_value": True,
"start_version": STUDY_VERSION_9_1,
},
}


def get_fields_info(study_version: StudyVersion) -> t.Mapping[str, t.Mapping[str, t.Any]]:
highest_version = StudyVersion.parse(10000000)
lowest_version = StudyVersion.parse(0)
return {
key: info
for key, info in FIELDS_INFO.items()
if (info.get("start_version") or StudyVersion.parse(0)) <= study_version
if info.get("start_version", lowest_version) <= study_version
and info.get("end_version", highest_version) > study_version
}
16 changes: 11 additions & 5 deletions antarest/study/business/thematic_trimming_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

from antares.study.version import StudyVersion

from antarest.study.business.thematic_trimming_field_infos import ThematicTrimmingFormFields, get_fields_info
from antarest.study.business.thematic_trimming_field_infos import (
ThematicTrimmingFormFieldsType,
create_thematic_trimming_config,
get_fields_info,
get_thematic_trimming_cls,
)
from antarest.study.business.utils import GENERAL_DATA_PATH, execute_or_add_commands
from antarest.study.model import Study
from antarest.study.storage.storage_service import StudyStorageService
Expand All @@ -25,7 +30,7 @@ class ThematicTrimmingManager:
def __init__(self, storage_service: StudyStorageService) -> None:
self.storage_service = storage_service

def get_field_values(self, study: Study) -> ThematicTrimmingFormFields:
def get_field_values(self, study: Study) -> ThematicTrimmingFormFieldsType:
"""
Get Thematic Trimming field values for the webapp form
"""
Expand All @@ -44,14 +49,15 @@ def get_value(field_info: t.Mapping[str, t.Any]) -> bool:

fields_info = get_fields_info(StudyVersion.parse(study.version))
fields_values = {name: get_value(info) for name, info in fields_info.items()}
return ThematicTrimmingFormFields(**fields_values)
return create_thematic_trimming_config(StudyVersion.parse(study.version), **fields_values)

def set_field_values(self, study: Study, field_values: ThematicTrimmingFormFields) -> None:
def set_field_values(self, study: Study, field_values: ThematicTrimmingFormFieldsType) -> None:
"""
Set Thematic Trimming config from the webapp form
"""
file_study = self.storage_service.get_storage(study).get_raw(study)
field_values_dict = field_values.model_dump()
cls = get_thematic_trimming_cls(StudyVersion.parse(study.version))
field_values_dict = cls.model_validate(field_values).model_dump()

keys_by_bool: t.Dict[bool, t.List[t.Any]] = {True: [], False: []}
fields_info = get_fields_info(StudyVersion.parse(study.version))
Expand Down
Loading
Loading