From b2bbba93427d2c1469e0f7cadf9a44d079bfc068 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Mon, 20 Nov 2023 17:31:05 +0100 Subject: [PATCH] fix(commands): remove draft --- .../business/matrix_constants_generator.py | 46 +++++++------------ .../command/create_binding_constraint.py | 32 ++++--------- .../command/update_binding_constraint.py | 4 +- 3 files changed, 26 insertions(+), 56 deletions(-) diff --git a/antarest/study/storage/variantstudy/business/matrix_constants_generator.py b/antarest/study/storage/variantstudy/business/matrix_constants_generator.py index eca1425579..d5c929e5bd 100644 --- a/antarest/study/storage/variantstudy/business/matrix_constants_generator.py +++ b/antarest/study/storage/variantstudy/business/matrix_constants_generator.py @@ -35,13 +35,9 @@ ONES_SCENARIO_MATRIX = "ones_scenario_matrix" # Binding constraint aliases -BINDING_CONSTRAINT_HOURLY_V86 = "empty_2nd_member_hourly_v86" -BINDING_CONSTRAINT_DAILY_V86 = "empty_2nd_member_daily_v86" -BINDING_CONSTRAINT_WEEKLY_V86 = "empty_2nd_member_daily_v86" - -BINDING_CONSTRAINT_HOURLY_V87 = "empty_2nd_member_hourly_v87" -BINDING_CONSTRAINT_DAILY_V87 = "empty_2nd_member_daily_v87" -BINDING_CONSTRAINT_WEEKLY_V87 = "empty_2nd_member_daily_v87" +BINDING_CONSTRAINT_HOURLY = "empty_2nd_member_hourly" +BINDING_CONSTRAINT_DAILY = "empty_2nd_member_daily" +BINDING_CONSTRAINT_WEEKLY = "empty_2nd_member_daily" # Short-term storage aliases ST_STORAGE_PMAX_INJECTION = ONES_SCENARIO_MATRIX @@ -93,17 +89,10 @@ def _init(self) -> None: self.hashes[MISCGEN_TS] = self.matrix_service.create(FIXED_8_COLUMNS) # Binding constraint matrices - # fmt:off - series_before_v87 = matrix_constants.binding_constraint.series_before_v87 - self.hashes[BINDING_CONSTRAINT_HOURLY_V86] = self.matrix_service.create(series_before_v87.default_binding_constraint_hourly) - self.hashes[BINDING_CONSTRAINT_DAILY_V86] = self.matrix_service.create(series_before_v87.default_binding_constraint_daily) - self.hashes[BINDING_CONSTRAINT_WEEKLY_V86] = self.matrix_service.create(series_before_v87.default_binding_constraint_weekly) - - series_after_v87 = matrix_constants.binding_constraint.series_after_v87 - self.hashes[BINDING_CONSTRAINT_HOURLY_V87] = self.matrix_service.create(series_after_v87.default_binding_constraint_hourly) - self.hashes[BINDING_CONSTRAINT_DAILY_V87] = self.matrix_service.create(series_after_v87.default_binding_constraint_daily) - self.hashes[BINDING_CONSTRAINT_WEEKLY_V87] = self.matrix_service.create(series_after_v87.default_binding_constraint_weekly) - # fmt:on + series = matrix_constants.binding_constraint.series_before_v87 + self.hashes[BINDING_CONSTRAINT_HOURLY] = self.matrix_service.create(series.default_binding_constraint_hourly) + self.hashes[BINDING_CONSTRAINT_DAILY] = self.matrix_service.create(series.default_binding_constraint_daily) + self.hashes[BINDING_CONSTRAINT_WEEKLY] = self.matrix_service.create(series.default_binding_constraint_weekly) # Some short-term storage matrices use np.ones((8760, 1)) self.hashes[ONES_SCENARIO_MATRIX] = self.matrix_service.create( @@ -162,20 +151,17 @@ def get_default_reserves(self) -> str: def get_default_miscgen(self) -> str: return MATRIX_PROTOCOL_PREFIX + self.hashes[MISCGEN_TS] - def get_binding_constraint_hourly(self, version: int) -> str: - if version < 870: - return MATRIX_PROTOCOL_PREFIX + self.hashes[BINDING_CONSTRAINT_HOURLY_V86] - return MATRIX_PROTOCOL_PREFIX + self.hashes[BINDING_CONSTRAINT_HOURLY_V87] + def get_binding_constraint_hourly(self) -> str: + """2D-matrix of shape (8760, 3), filled-in with zeros.""" + return MATRIX_PROTOCOL_PREFIX + self.hashes[BINDING_CONSTRAINT_HOURLY] - def get_binding_constraint_daily(self, version: int) -> str: - if version < 870: - return MATRIX_PROTOCOL_PREFIX + self.hashes[BINDING_CONSTRAINT_DAILY_V86] - return MATRIX_PROTOCOL_PREFIX + self.hashes[BINDING_CONSTRAINT_DAILY_V87] + def get_binding_constraint_daily(self) -> str: + """2D-matrix of shape (365, 3), filled-in with zeros.""" + return MATRIX_PROTOCOL_PREFIX + self.hashes[BINDING_CONSTRAINT_DAILY] - def get_binding_constraint_weekly(self, version: int) -> str: - if version < 870: - return MATRIX_PROTOCOL_PREFIX + self.hashes[BINDING_CONSTRAINT_WEEKLY_V86] - return MATRIX_PROTOCOL_PREFIX + self.hashes[BINDING_CONSTRAINT_WEEKLY_V87] + def get_binding_constraint_weekly(self) -> str: + """2D-matrix of shape (52, 3), filled-in with zeros.""" + return MATRIX_PROTOCOL_PREFIX + self.hashes[BINDING_CONSTRAINT_WEEKLY] def get_st_storage_pmax_injection(self) -> str: """2D-matrix of shape (8760, 1), filled-in with ones.""" diff --git a/antarest/study/storage/variantstudy/model/command/create_binding_constraint.py b/antarest/study/storage/variantstudy/model/command/create_binding_constraint.py index 2f5eb6c364..178c918a0c 100644 --- a/antarest/study/storage/variantstudy/model/command/create_binding_constraint.py +++ b/antarest/study/storage/variantstudy/model/command/create_binding_constraint.py @@ -27,14 +27,13 @@ MatrixType = List[List[MatrixData]] -def check_matrix_values(time_step: BindingConstraintFrequency, values: MatrixType, version: int) -> None: +def check_matrix_values(time_step: BindingConstraintFrequency, values: MatrixType) -> None: """ Check the binding constraint's matrix values for the specified time step. Args: time_step: The frequency of the binding constraint: "hourly", "daily" or "weekly". values: The binding constraint's 2nd member matrix. - version: Corresponds to the study version Raises: ValueError: @@ -48,13 +47,8 @@ def check_matrix_values(time_step: BindingConstraintFrequency, values: MatrixTyp } # Check the matrix values and create the corresponding matrix link array = np.array(values, dtype=np.float64) - actual_shape = array.shape - expected_shape = shapes[time_step] - if version < 870: - if actual_shape != expected_shape: - raise ValueError(f"Invalid matrix shape {actual_shape}, expected {expected_shape}") - elif actual_shape[0] != expected_shape[0]: - raise ValueError(f"Invalid matrix length {actual_shape[0]}, expected {expected_shape[0]}") + if array.shape != shapes[time_step]: + raise ValueError(f"Invalid matrix shape {array.shape}, expected {shapes[time_step]}") if np.isnan(array).any(): raise ValueError("Matrix values cannot contain NaN") @@ -73,8 +67,6 @@ class AbstractBindingConstraintCommand(ICommand, metaclass=ABCMeta): filter_year_by_year: Optional[str] = None filter_synthesis: Optional[str] = None comments: Optional[str] = None - group: Optional[str] = None - version: int = 1 def to_dto(self) -> CommandDTO: args = { @@ -85,7 +77,6 @@ def to_dto(self) -> CommandDTO: "comments": self.comments, "filter_year_by_year": self.filter_year_by_year, "filter_synthesis": self.filter_synthesis, - "group": self.group, } if self.values is not None: args["values"] = strip_matrix_protocol(self.values) @@ -122,25 +113,20 @@ def validate_series( constants: GeneratorMatrixConstants constants = values["command_context"].generator_matrix_constants time_step = values["time_step"] - # todo: change this fake version to the actual study version. I do not see a nice way to do it :/ - # Solutions i thought of : - # 1) Add the study version to the class attributes -> Solve the issue but weird and hard to do sometimes - # 2) Add the value pre=True in the validator and each time creating a class, specify the study version. - # It's also weird and hard to do ... - fake_version = 860 if v is None: # Use an already-registered default matrix methods = { - BindingConstraintFrequency.HOURLY: constants.get_binding_constraint_hourly(fake_version), - BindingConstraintFrequency.DAILY: constants.get_binding_constraint_daily(fake_version), - BindingConstraintFrequency.WEEKLY: constants.get_binding_constraint_weekly(fake_version), + BindingConstraintFrequency.HOURLY: constants.get_binding_constraint_hourly, + BindingConstraintFrequency.DAILY: constants.get_binding_constraint_daily, + BindingConstraintFrequency.WEEKLY: constants.get_binding_constraint_weekly, } - return methods[time_step] + method = methods[time_step] + return method() if isinstance(v, str): # Check the matrix link return validate_matrix(v, values) if isinstance(v, list): - check_matrix_values(time_step, v, fake_version) + check_matrix_values(time_step, v) return validate_matrix(v, values) # Invalid datatype # pragma: no cover diff --git a/antarest/study/storage/variantstudy/model/command/update_binding_constraint.py b/antarest/study/storage/variantstudy/model/command/update_binding_constraint.py index f01fe7969d..ea52dca4c4 100644 --- a/antarest/study/storage/variantstudy/model/command/update_binding_constraint.py +++ b/antarest/study/storage/variantstudy/model/command/update_binding_constraint.py @@ -52,9 +52,7 @@ def validate_series( # Check the matrix link return validate_matrix(v, values) if isinstance(v, list): - # todo: change this fake version by the actual study version - fake_version = 860 - check_matrix_values(time_step, v, fake_version) + check_matrix_values(time_step, v) return validate_matrix(v, values) # Invalid datatype # pragma: no cover