From bef17fb36252c48bbda27384e1a124095681db7e Mon Sep 17 00:00:00 2001 From: MarcusHolly Date: Fri, 8 Nov 2024 10:42:33 -0500 Subject: [PATCH] Add logger messages for when model_func is not defined --- .../design_and_operation_models.py | 17 ++++++-- .../tests/test_design_and_operation_models.py | 42 +++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/idaes/apps/grid_integration/multiperiod/design_and_operation_models.py b/idaes/apps/grid_integration/multiperiod/design_and_operation_models.py index db2ff30b44..129a478220 100644 --- a/idaes/apps/grid_integration/multiperiod/design_and_operation_models.py +++ b/idaes/apps/grid_integration/multiperiod/design_and_operation_models.py @@ -91,6 +91,12 @@ def build(self): if self.config.model_func is None: # Function that builds the design model is not specified + _logger.warning( + "The function that builds the design model is not specified." + "model_func must declare all the necessary design variables," + "relations among design variables, capital cost correlations," + "and fixed operating and maintenance cost correlations." + ) return # Call the function that builds the design model @@ -99,14 +105,14 @@ def build(self): # Check if capital and fixed O&M costs are defined if not hasattr(self, "capex"): _logger.warning( - f"'capex' attribute is not set for the design model " + "'capex' attribute is not set for the design model " f"{self.name}. Setting the capital cost of the unit to zero." ) self.capex = 0 if not hasattr(self, "fom"): _logger.warning( - f"'fom' attribute is not set for the design model " + "'fom' attribute is not set for the design model " f"{self.name}. Setting the fixed O&M cost of the unit to zero." ) self.fom = 0 @@ -208,7 +214,12 @@ def build(self): ) if self.config.model_func is None: - # Function that builds the operation model is not specified + _logger.warning( + "The function that builds the operation model is not specified." + "model_func must declare all the necessary operation variables," + "relations among operation variables, and variable" + "operating and maintenance cost correlations." + ) return # Call the function that builds the operation model diff --git a/idaes/apps/grid_integration/multiperiod/tests/test_design_and_operation_models.py b/idaes/apps/grid_integration/multiperiod/tests/test_design_and_operation_models.py index 12165022d7..bb0cc0d999 100644 --- a/idaes/apps/grid_integration/multiperiod/tests/test_design_and_operation_models.py +++ b/idaes/apps/grid_integration/multiperiod/tests/test_design_and_operation_models.py @@ -78,6 +78,27 @@ def dummy_func(_): assert blk.unit_3.fom == 0 +@pytest.mark.unit +def test_design_model_class_logger_message1(caplog): + caplog.clear() + + blk = ConcreteModel() + blk.unit_1 = DesignModel( + model_args={ + "p_min": 150, + "p_max": 600, + "cost": {"capex": 10, "fom": 1}, + }, + ) + + assert ( + "The function that builds the design model is not specified." + "model_func must declare all the necessary design variables," + "relations among design variables, capital cost correlations," + "and fixed operating and maintenance cost correlations." in caplog.text + ) + + @pytest.mark.unit def test_operation_model_class(): """Tests the OperationModel class""" @@ -110,3 +131,24 @@ def op_model(m, des_blk): blk.unit_2_op = OperationModel(declare_op_vars=False, declare_lmp_param=False) for attr in ["op_mode", "startup", "shutdown", "power", "LMP"]: assert not hasattr(blk.unit_2_op, attr) + + +@pytest.mark.unit +def test_operation_model_class_logger_message1(caplog): + caplog.clear() + + def des_model(m): + m.power = Var() + m.capex = 0 + m.fom = 0 + + blk = ConcreteModel() + blk.unit_1_design = DesignModel(model_func=des_model) + blk.unit_1_op = OperationModel(model_args={"des_blk": blk.unit_1_design}) + + assert ( + "The function that builds the operation model is not specified." + "model_func must declare all the necessary operation variables," + "relations among operation variables, and variable" + "operating and maintenance cost correlations." in caplog.text + )