Skip to content

Commit

Permalink
Add logger messages for when model_func is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusHolly committed Nov 8, 2024
1 parent a1ae6b7 commit bef17fb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
)

0 comments on commit bef17fb

Please sign in to comment.