Skip to content

Commit

Permalink
repair failing check by updating config option name; also update exce…
Browse files Browse the repository at this point in the history
…ption message
  • Loading branch information
adam-a-a committed Oct 30, 2024
1 parent 2cd22e4 commit e9ff144
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
17 changes: 9 additions & 8 deletions idaes/apps/grid_integration/multiperiod/price_taker_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# for full copyright and license information.
#################################################################################
"""
Immediate ToDo list:
Immediate #TODO list:
- Write methods to handle the representative day case
- automate cash flow expressions (likely use a
weighted sum for representative days?)
Expand Down Expand Up @@ -51,6 +51,7 @@


import idaes.logger as idaeslog
from idaes.core.util.exceptions import ConfigurationError

_logger = idaeslog.getLogger(__name__)

Expand Down Expand Up @@ -427,8 +428,8 @@ def build_multiperiod_model(self, **kwargs):
**kwargs,
)

# If append_lmp_data is automatic, need to append the LMP data.
# Check if LMP has already been defined with the append_lmp_data
# If declare_lmp_param config option on OperationModel is True, need to append the LMP data to the OperationModel.
# Check if LMP has already been defined on the PriceTakerModel with the append_lmp_data
# function above
LMP_exists = hasattr(self, "LMP")

Expand All @@ -438,13 +439,13 @@ def build_multiperiod_model(self, **kwargs):
for p in period:
for blk in period[p].component_data_objects(Block):
if isinstance(blk, OperationModelData):
if blk.config.append_lmp_data:
if blk.config.declare_lmp_param:
if not LMP_exists:
raise ValueError(
raise ConfigurationError(
f"OperationModelData has been defined to automatically "
+ f"populate LMP data. However, m.LMP does not exist. "
+ f"Please run the append_lmp_data function first or set the "
+ f"append_lmp_data attribute to False when configuring "
+ f"populate LMP data. However, self.LMP does not exist, where self is an instance of PriceTakerModel. "
+ f"Please run the append_lmp_data method from the PriceTakerModel class first or set the "
+ f"declare_lmp_param configuration option to False when configuring "
+ f"your OperationModelData object."
)
blk.LMP = self.LMP[p]
Expand Down
19 changes: 7 additions & 12 deletions idaes/apps/grid_integration/multiperiod/tests/test_price_taker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import idaes.logger as idaeslog

from idaes.apps.grid_integration.multiperiod.price_taker_model import PriceTakerModel

from idaes.core.util.exceptions import ConfigurationError

@pytest.fixture
def excel_data():
Expand Down Expand Up @@ -959,27 +959,22 @@ def test_build_hourly_cashflow_logger_message_no_op_blks(excel_data, caplog):


@pytest.mark.unit
def test_build_multiperiod_model_no_LMP_logger_message(excel_data):
def test_build_multiperiod_model_no_LMP_logger_message():
# Tests building the model with startup/shutdown then ramping rate with LMP as a single year with all time points
# Create an instance of the Pricetrackermodel class
# Create an instance of the PriceTakerModel class
m = PriceTakerModel()

m._n_time_points = 240
m.set_days = None
m.set_years = None

# m.sofc_design = DesignModel(model_func=SOFC_design_model, model_args={"min_power": 200, "max_power": 650})
m.sofc_design = aml.Block()
m.sofc_design.PMAX = 650
m.sofc_design.PMIN = 200
m.sofc_design.build_unit = 1
with pytest.raises(
ValueError,
ConfigurationError,
match=(
"OperationModelData has been defined to automatically "
+ "populate LMP data. However, m.LMP does not exist. "
+ "Please run the append_lmp_data function first or set the "
+ "append_lmp_data attribute to False when configuring "
+ "populate LMP data. However, self.LMP does not exist, where self is an instance of PriceTakerModel. "
+ "Please run the append_lmp_data method from the PriceTakerModel class first or set the "
+ "declare_lmp_param configuration option to False when configuring "
+ "your OperationModelData object."
),
):
Expand Down

0 comments on commit e9ff144

Please sign in to comment.