From e9ff14451c2a6e0ba8f9d79c1b726b6bb044750f Mon Sep 17 00:00:00 2001 From: Adam Atia Date: Wed, 30 Oct 2024 11:36:19 -0400 Subject: [PATCH] repair failing check by updating config option name; also update exception message --- .../multiperiod/price_taker_model.py | 17 +++++++++-------- .../multiperiod/tests/test_price_taker.py | 19 +++++++------------ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/idaes/apps/grid_integration/multiperiod/price_taker_model.py b/idaes/apps/grid_integration/multiperiod/price_taker_model.py index 22cda2d36d..f3cdf485da 100644 --- a/idaes/apps/grid_integration/multiperiod/price_taker_model.py +++ b/idaes/apps/grid_integration/multiperiod/price_taker_model.py @@ -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?) @@ -51,6 +51,7 @@ import idaes.logger as idaeslog +from idaes.core.util.exceptions import ConfigurationError _logger = idaeslog.getLogger(__name__) @@ -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") @@ -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] diff --git a/idaes/apps/grid_integration/multiperiod/tests/test_price_taker.py b/idaes/apps/grid_integration/multiperiod/tests/test_price_taker.py index b2eae865dd..77be902d59 100644 --- a/idaes/apps/grid_integration/multiperiod/tests/test_price_taker.py +++ b/idaes/apps/grid_integration/multiperiod/tests/test_price_taker.py @@ -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(): @@ -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." ), ):