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

refactor(settings): introduce new class specifically for update #77

Merged
merged 49 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d3d8903
create classes
MartinBelthle Feb 7, 2025
cab5fec
change methods
MartinBelthle Feb 7, 2025
9fcb161
continue work
MartinBelthle Feb 7, 2025
f300251
shush some mypy errors
MartinBelthle Feb 7, 2025
d107df8
use the right union
MartinBelthle Feb 7, 2025
b6f6a81
fix little mypy error
MartinBelthle Feb 7, 2025
8d5ef96
fix mypy issue
MartinBelthle Feb 10, 2025
5520e0c
fix mypy
MartinBelthle Feb 10, 2025
382d0ed
fix
MartinBelthle Feb 10, 2025
82a190e
put default value in user models
MartinBelthle Feb 10, 2025
a7dd08b
fix
MartinBelthle Feb 10, 2025
4e9c293
little refactoring
MartinBelthle Feb 10, 2025
0199fb6
add default value inside model
MartinBelthle Feb 10, 2025
e83a93d
change export mps
MartinBelthle Feb 10, 2025
6602eb6
fix set
MartinBelthle Feb 10, 2025
7e69950
change syntax for Python3.9
MartinBelthle Feb 10, 2025
19818eb
change syntax for Python3.9
MartinBelthle Feb 10, 2025
dc3e6b0
create conversion method
MartinBelthle Feb 10, 2025
b21cb91
rename method
MartinBelthle Feb 10, 2025
86e60ae
fix an important issue
MartinBelthle Feb 10, 2025
caa4f5b
fix unit test
MartinBelthle Feb 10, 2025
738b5d9
fix unit test
MartinBelthle Feb 10, 2025
ebfd6b9
fix test
MartinBelthle Feb 10, 2025
1cdf4f5
fix
MartinBelthle Feb 10, 2025
0cfef1b
rename parameter
MartinBelthle Feb 10, 2025
da9f255
thinking
MartinBelthle Feb 10, 2025
ffd57eb
change method
MartinBelthle Feb 10, 2025
b1eed5e
continue work
MartinBelthle Feb 10, 2025
2c569e3
fix lots of tests
MartinBelthle Feb 10, 2025
f800510
make all test work
MartinBelthle Feb 10, 2025
dd07b88
fix integration test and remove todo
MartinBelthle Feb 10, 2025
e6f8b9d
try to merge with main
MartinBelthle Feb 10, 2025
aad68e0
fix mypy issues
MartinBelthle Feb 10, 2025
c18f81c
Merge branch 'main' into feat/introduce-update-settings-parameters
MartinBelthle Feb 10, 2025
373d4d3
continue work
MartinBelthle Feb 10, 2025
b6f6259
continue work
MartinBelthle Feb 10, 2025
20f27cc
continue work
MartinBelthle Feb 10, 2025
09ca5bd
continue work
MartinBelthle Feb 10, 2025
bd33aa7
fix CI
MartinBelthle Feb 10, 2025
90c81b8
fix integration test
MartinBelthle Feb 11, 2025
07ffc8a
add another test
MartinBelthle Feb 11, 2025
a337186
add test on export mps
MartinBelthle Feb 11, 2025
3ad346f
add clear exception on specific parameter
MartinBelthle Feb 11, 2025
110356d
little optim in local
MartinBelthle Feb 11, 2025
9947502
fix test
MartinBelthle Feb 11, 2025
d31a9eb
fix test
MartinBelthle Feb 11, 2025
79526e4
instanciate dataclass correctly
MartinBelthle Feb 11, 2025
e7075a5
rebase with main
MartinBelthle Feb 11, 2025
0fef0ca
cleaning a bit
MartinBelthle Feb 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/antares/craft/model/settings/adequacy_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ class PriceTakingOrder(Enum):

@dataclass
class AdequacyPatchParameters:
include_adq_patch: bool = False
set_to_null_ntc_from_physical_out_to_physical_in_for_first_step: bool = True
set_to_null_ntc_between_physical_out_for_first_step: bool = True
price_taking_order: PriceTakingOrder = PriceTakingOrder.DENS
include_hurdle_cost_csr: bool = False
check_csr_cost_function: bool = False
threshold_initiate_curtailment_sharing_rule: int = 0
threshold_display_local_matching_rule_violations: int = 0
threshold_csr_variable_bounds_relaxation: int = 3


@dataclass
class AdequacyPatchParametersUpdate:
include_adq_patch: Optional[bool] = None
set_to_null_ntc_from_physical_out_to_physical_in_for_first_step: Optional[bool] = None
set_to_null_ntc_between_physical_out_for_first_step: Optional[bool] = None
Expand Down
28 changes: 26 additions & 2 deletions src/antares/craft/model/settings/advanced_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
from dataclasses import dataclass
from dataclasses import dataclass, field
from enum import Enum
from typing import Optional

Expand Down Expand Up @@ -63,6 +63,30 @@ class RenewableGenerationModeling(Enum):

@dataclass
class AdvancedParameters:
initial_reservoir_levels: InitialReservoirLevel = InitialReservoirLevel.COLD_START
hydro_heuristic_policy: HydroHeuristicPolicy = HydroHeuristicPolicy.ACCOMMODATE_RULES_CURVES
hydro_pricing_mode: HydroPricingMode = HydroPricingMode.FAST
power_fluctuations: PowerFluctuation = PowerFluctuation.FREE_MODULATIONS
shedding_policy: SheddingPolicy = SheddingPolicy.SHAVE_PEAKS
unit_commitment_mode: UnitCommitmentMode = UnitCommitmentMode.FAST
number_of_cores_mode: SimulationCore = SimulationCore.MEDIUM
renewable_generation_modelling: RenewableGenerationModeling = RenewableGenerationModeling.CLUSTERS
accuracy_on_correlation: set[OutputChoices] = field(default_factory=set)


@dataclass
class SeedParameters:
seed_tsgen_thermal: int = 3005489
seed_tsnumbers: int = 5005489
seed_unsupplied_energy_costs: int = 6005489
seed_spilled_energy_costs: int = 7005489
seed_thermal_costs: int = 8005489
seed_hydro_costs: int = 9005489
seed_initial_reservoir_levels: int = 10005489


@dataclass
class AdvancedParametersUpdate:
initial_reservoir_levels: Optional[InitialReservoirLevel] = None
hydro_heuristic_policy: Optional[HydroHeuristicPolicy] = None
hydro_pricing_mode: Optional[HydroPricingMode] = None
Expand All @@ -75,7 +99,7 @@ class AdvancedParameters:


@dataclass
class SeedParameters:
class SeedParametersUpdate:
seed_tsgen_thermal: Optional[int] = None
seed_tsnumbers: Optional[int] = None
seed_unsupplied_energy_costs: Optional[int] = None
Expand Down
21 changes: 21 additions & 0 deletions src/antares/craft/model/settings/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ class OutputFormat(EnumIgnoreCase):

@dataclass
class GeneralParameters:
mode: Mode = Mode.ECONOMY
horizon: str = ""
nb_years: int = 1
simulation_start: int = 1
simulation_end: int = 365
january_first: WeekDay = WeekDay.MONDAY
first_month_in_year: Month = Month.JANUARY
first_week_day: WeekDay = WeekDay.MONDAY
leap_year: bool = False
year_by_year: bool = False
simulation_synthesis: bool = True
building_mode: BuildingMode = BuildingMode.AUTOMATIC
user_playlist: bool = False
thematic_trimming: bool = False
geographic_trimming: bool = False
store_new_set: bool = False
nb_timeseries_thermal: int = 1


@dataclass
class GeneralParametersUpdate:
mode: Optional[Mode] = None
horizon: Optional[str] = None
nb_years: Optional[int] = None
Expand Down
21 changes: 19 additions & 2 deletions src/antares/craft/model/settings/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,31 @@ class SimplexOptimizationRange(Enum):


class ExportMPS(Enum):
NONE = "none"
TRUE = "True"
FALSE = "False"
OPTIM1 = "optim1"
OPTIM2 = "optim2"
BOTH_OPTIMS = "both-optims"


@dataclass
class OptimizationParameters:
simplex_range: SimplexOptimizationRange = SimplexOptimizationRange.WEEK
transmission_capacities: OptimizationTransmissionCapacities = OptimizationTransmissionCapacities.LOCAL_VALUES
include_constraints: bool = True
include_hurdlecosts: bool = True
include_tc_minstablepower: bool = True
include_tc_min_ud_time: bool = True
include_dayahead: bool = True
include_strategicreserve: bool = True
include_spinningreserve: bool = True
include_primaryreserve: bool = True
include_exportmps: ExportMPS = ExportMPS.FALSE
include_exportstructure: bool = False
include_unfeasible_problem_behavior: UnfeasibleProblemBehavior = UnfeasibleProblemBehavior.ERROR_VERBOSE


@dataclass
class OptimizationParametersUpdate:
simplex_range: Optional[SimplexOptimizationRange] = None
transmission_capacities: Optional[OptimizationTransmissionCapacities] = None
include_constraints: Optional[bool] = None
Expand Down
4 changes: 2 additions & 2 deletions src/antares/craft/model/settings/playlist_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

@dataclass
class PlaylistParameters:
status: bool = True
weight: float = 1.0
status: bool
weight: float
94 changes: 81 additions & 13 deletions src/antares/craft/model/settings/study_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,91 @@
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.
from dataclasses import dataclass
from dataclasses import asdict, dataclass, field
from typing import Optional

from antares.craft.model.settings.adequacy_patch import AdequacyPatchParameters
from antares.craft.model.settings.advanced_parameters import AdvancedParameters, SeedParameters
from antares.craft.model.settings.general import GeneralParameters
from antares.craft.model.settings.optimization import OptimizationParameters
from antares.craft.model.settings.adequacy_patch import AdequacyPatchParameters, AdequacyPatchParametersUpdate
from antares.craft.model.settings.advanced_parameters import (
AdvancedParameters,
AdvancedParametersUpdate,
SeedParameters,
SeedParametersUpdate,
)
from antares.craft.model.settings.general import GeneralParameters, GeneralParametersUpdate
from antares.craft.model.settings.optimization import OptimizationParameters, OptimizationParametersUpdate
from antares.craft.model.settings.playlist_parameters import PlaylistParameters
from antares.craft.model.settings.thematic_trimming import ThematicTrimmingParameters
from antares.craft.model.settings.thematic_trimming import ThematicTrimmingParameters, ThematicTrimmingParametersUpdate


@dataclass
class StudySettings:
general_parameters: Optional[GeneralParameters] = None
optimization_parameters: Optional[OptimizationParameters] = None
advanced_parameters: Optional[AdvancedParameters] = None
seed_parameters: Optional[SeedParameters] = None
adequacy_patch_parameters: Optional[AdequacyPatchParameters] = None
class StudySettingsUpdate:
general_parameters: Optional[GeneralParametersUpdate] = None
optimization_parameters: Optional[OptimizationParametersUpdate] = None
advanced_parameters: Optional[AdvancedParametersUpdate] = None
seed_parameters: Optional[SeedParametersUpdate] = None
adequacy_patch_parameters: Optional[AdequacyPatchParametersUpdate] = None
thematic_trimming_parameters: Optional[ThematicTrimmingParametersUpdate] = None
playlist_parameters: Optional[dict[int, PlaylistParameters]] = None
thematic_trimming_parameters: Optional[ThematicTrimmingParameters] = None


@dataclass
class StudySettings:
general_parameters: GeneralParameters = field(default_factory=GeneralParameters)
optimization_parameters: OptimizationParameters = field(default_factory=OptimizationParameters)
advanced_parameters: AdvancedParameters = field(default_factory=AdvancedParameters)
seed_parameters: SeedParameters = field(default_factory=SeedParameters)
adequacy_patch_parameters: AdequacyPatchParameters = field(default_factory=AdequacyPatchParameters)
thematic_trimming_parameters: ThematicTrimmingParameters = field(default_factory=ThematicTrimmingParameters)
playlist_parameters: dict[int, PlaylistParameters] = field(default_factory=dict)

def from_update_settings(self, update_settings: StudySettingsUpdate) -> "StudySettings":
current_settings = asdict(self)
for key, values in asdict(update_settings).items():
if values is not None:
for inner_key, inner_value in values.items():
if inner_value is not None:
current_settings[key][inner_key] = inner_value

general_parameters = GeneralParameters(**current_settings["general_parameters"])
optimization_parameters = OptimizationParameters(**current_settings["optimization_parameters"])
advanced_parameters = AdvancedParameters(**current_settings["advanced_parameters"])
seed_parameters = SeedParameters(**current_settings["seed_parameters"])
adequacy_patch_parameters = AdequacyPatchParameters(**current_settings["adequacy_patch_parameters"])
thematic_trimming_parameters = ThematicTrimmingParameters(**current_settings["thematic_trimming_parameters"])
playlist_parameters: dict[int, PlaylistParameters] = {}
for year in current_settings["playlist_parameters"]:
playlist_parameters[year] = PlaylistParameters(**current_settings["playlist_parameters"][year])

return StudySettings(
general_parameters,
optimization_parameters,
advanced_parameters,
seed_parameters,
adequacy_patch_parameters,
thematic_trimming_parameters,
playlist_parameters,
)

def to_update_settings(self) -> StudySettingsUpdate:
current_settings = asdict(self)
general_parameters = GeneralParametersUpdate(**current_settings["general_parameters"])
optimization_parameters = OptimizationParametersUpdate(**current_settings["optimization_parameters"])
advanced_parameters = AdvancedParametersUpdate(**current_settings["advanced_parameters"])
seed_parameters = SeedParametersUpdate(**current_settings["seed_parameters"])
adequacy_patch_parameters = AdequacyPatchParametersUpdate(**current_settings["adequacy_patch_parameters"])
thematic_trimming_parameters = ThematicTrimmingParametersUpdate(
**current_settings["thematic_trimming_parameters"]
)
playlist_parameters: dict[int, PlaylistParameters] = {}
for year in current_settings["playlist_parameters"]:
playlist_parameters[year] = PlaylistParameters(**current_settings["playlist_parameters"][year])

return StudySettingsUpdate(
general_parameters,
optimization_parameters,
advanced_parameters,
seed_parameters,
adequacy_patch_parameters,
thematic_trimming_parameters,
playlist_parameters,
)
98 changes: 98 additions & 0 deletions src/antares/craft/model/settings/thematic_trimming.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,104 @@

@dataclass
class ThematicTrimmingParameters:
ov_cost: bool = False
op_cost: bool = False
mrg_price: bool = False
co2_emis: bool = False
dtg_by_plant: bool = False
balance: bool = False
row_bal: bool = False
psp: bool = False
misc_ndg: bool = False
load: bool = False
h_ror: bool = False
wind: bool = False
solar: bool = False
nuclear: bool = False
lignite: bool = False
coal: bool = False
gas: bool = False
oil: bool = False
mix_fuel: bool = False
misc_dtg: bool = False
h_stor: bool = False
h_pump: bool = False
h_lev: bool = False
h_infl: bool = False
h_ovfl: bool = False
h_val: bool = False
h_cost: bool = False
unsp_enrg: bool = False
spil_enrg: bool = False
lold: bool = False
lolp: bool = False
avl_dtg: bool = False
dtg_mrg: bool = False
max_mrg: bool = False
np_cost: bool = False
np_cost_by_plant: bool = False
nodu: bool = False
nodu_by_plant: bool = False
flow_lin: bool = False
ucap_lin: bool = False
loop_flow: bool = False
flow_quad: bool = False
cong_fee_alg: bool = False
cong_fee_abs: bool = False
marg_cost: bool = False
cong_prob_plus: bool = False
cong_prob_minus: bool = False
hurdle_cost: bool = False
res_generation_by_plant: bool = False
misc_dtg_2: bool = False
misc_dtg_3: bool = False
misc_dtg_4: bool = False
wind_offshore: bool = False
wind_onshore: bool = False
solar_concrt: bool = False
solar_pv: bool = False
solar_rooft: bool = False
renw_1: bool = False
renw_2: bool = False
renw_3: bool = False
renw_4: bool = False
dens: bool = False
profit_by_plant: bool = False
sts_inj_by_plant: bool = False
sts_withdrawal_by_plant: bool = False
sts_lvl_by_plant: bool = False
psp_open_injection: bool = False
psp_open_withdrawal: bool = False
psp_open_level: bool = False
psp_closed_injection: bool = False
psp_closed_withdrawal: bool = False
psp_closed_level: bool = False
pondage_injection: bool = False
pondage_withdrawal: bool = False
pondage_level: bool = False
battery_injection: bool = False
battery_withdrawal: bool = False
battery_level: bool = False
other1_injection: bool = False
other1_withdrawal: bool = False
other1_level: bool = False
other2_injection: bool = False
other2_withdrawal: bool = False
other2_level: bool = False
other3_injection: bool = False
other3_withdrawal: bool = False
other3_level: bool = False
other4_injection: bool = False
other4_withdrawal: bool = False
other4_level: bool = False
other5_injection: bool = False
other5_withdrawal: bool = False
other5_level: bool = False
sts_cashflow_by_cluster: bool = False


@dataclass
class ThematicTrimmingParametersUpdate:
ov_cost: Optional[bool] = None
op_cost: Optional[bool] = None
mrg_price: Optional[bool] = None
Expand Down
Loading