Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Price taker model for DISPATCHES, Rehashed (#1358)
* Added basic price-taker framework * run black * add in get_optimal_n_clusters as separate method. hand off to Marcus * Add methods for computing the optimal # of clusters and making an elbow plot * add fom to typos.toml in github/workflows to pass spellcheck * fix typo * Add tests for new functions (excel import failing) * Update dependencies * Add pytest marks * Fix typo where TimeStep data was being used instead of BaseCaseTax * Update test file * Add warning for when kmax is not set * Address Radha's comments and start adding testing (WIP) * Add more tests * Add cluster_lmp_data function * linearizing su_sd cosntraints and fixing the price traker model * Removing files that were mistakenly saved on this branch * modified startup and shutdown constraint function * add set_period to startup and shutdown func * developed a function to add startup/shutdown constraints * Constructed a function that adds startup and shutdown constraints * Added deepgetattr function and had the ramp-up/down and start-up/down functions to add constraints through pyomo blocks * linearized ramping constraints * Added auxiliary variables * added a third mccor constraint for each aux var and created a capacity argument for ramping func * changed startup_shutdown constraints to have the shutdown binary var * changed rule for min_start_up constraint * fixed startup_shutdown function constraints, changed default values for ramping function * added new method for adding aux variables * removed aux variable delcaration and added a new config option to opt blk * added comments * small addition * added design_blk * added deepgetattr and constraint for the add capacity aux var func * finished the new method and ramping function * Allowed _add_capacity_aux_vars to be cosntructed when the build function gets called * added a for loop that calls on the _add_capacity_aux_vars function t times * Updating PT model for SOFC case study * Updated price_taker_model.py doc Removed some unused variables. Beautified some of the code. Made all documentation for functions consistent and more useful. Added a few ToDo's for new functionality to be added to the class. * Updated init of PriceTakerModel Updated the formatting in the initialization of the PriceTakerModel. Added a check to the seed setter for integer inputs. Also added a check to the horizon_length setter for integer inputs. * Added missing documentation Added function description and Args/Returns statements for the 'generate_daily_data' function. * Corrected constraint expressions Corrected the mathematical expressions for the constraints for ramping rates and startup/shutdown expressions. Namely, the expressions now appropriately constrain power ramp rates under all scenarios. Also, design decisions to build and it's impact on whether an equipment can turn on or not has been fixed. Minimum downtime constraint was also fixed. Also, I added a check to make sure that the up_time and down_time inputs are valid under the assumptions. * Added tests for input checking Added tests to check the seed, horizon_length, and minimum up_time/down_time inputs. All tests pass. As a note, the tests for clustering the LMP data need to change as they are failing. Parsed data is passed instead of raw data. I am looking into this. * Updated checks for get_optimal_clusters Added validity checks to make sure kmin and kmax >= 0 and are integer values. Also, kmin < kmax. Also, added tests to ensure that each edge case is appropriately handled. * Fixed typos in test_price_taker.py Fixed a few typos and made language more clear. * Added input checks on add_ramping_constraints Added checks that the ramping rates as inputs are between 0 and 1 (fractions of the maximum capacity). Also added tests for each of these scenarios. * Fixed broken test Code used 1-based indexing but test used 0-based. Fixed the mistmatch. * Added automated LMP population Added an attribute to the CONFIG of OperationModelData that will be True by default. The attribute, append_lmp_data, will work with building the multiperiod_model so that LMP data will automatically be populated. Old way required a dummy value for m.LMP at the operational level and the user updated LMP manually for each time period. Also removed some hard-coded values in the append_lmp_data() function. * Fixed getitem issues with Sets Updated code to be more modern and follow new Pyomo paradigms. Removed warnings for constructing both the ramping rate and startup/shutdown/min uptime/min downtime constraints. Also edited a few lines to beautify. * Removed redundant set definition The set 'range_time_steps' was defined in both the ramping rate and startup/shutdown function. Also, wrote the try/except statement with the hasattr() function instead since it is one line and much neater. * Added n_clusters check in append_lmp_data Added a check to make sure that n_clusters is feasible. Also added tests to capture edge cases. * Reorganizing unit logging messages tests Disaggregated the unit tests for logger messages. Should make it easier to debug later. * Moved deepgetattr to import from design_and_operation_models.py Removed duplicate deepgetattr function and added it as an import to the __init__.py file in the idaes.apps.grid_integration tree. Also, added a test for deepgetattr's error message. * Added checks and tests Added a check and test for n_clusters being a valid value for cluster_lmp_data. Also added a check to see if the horizon length exceed the raw_data length, meaning an empty data frame would be returned. * Updated data processing workflow Removed reconfigure data as it was poor coding practice (i.e., all functionality was done by generate_daily_data). Updated all tests to accommodate. Updated all functions in price_taker_model to accommodate. Also added warning messages for when sheet and column are not defined along with test for these warning messages. * Small update to append_lmp_data Updated lmp_data to allow for non-integer columns to be used. Ultimately, the user should be responsible for column naming and correlating LMP data. Code is now more general. * Updated get_optimal_n_clusters Found a case where the warning message should play (and added comments that a few test could be deleted as functions work properly but output may depend on external packages of kneed and scikit-learn). Also fixed up get_optimal_n_clusters and cluster_lmp_data as there were some unnecessary loops, lines of code, and if statements to test. * Updated cash flow construction Updated the ability to make hourly cashflows. Now the user can provide all cashflows associated with all operation block models and the total cost and total revenue for each time point is generated to be used in the build cashflow function for the objective function. Still need to add tests for each of the logger messages (but the function appears to be working correctly). * Added tests for cashflows Added tests for some of the logger warning messages from the build_hourly_cashflows and build_cashflows functions. Through these tests, most of the building code has also been tested. Remaining are two cases that will cover the rest of the build cases, options for the operational block, and the nonlinear case studies. Also, I am considering adding a function to add the capacity limitation (both linear and nonlinear w/ and w/o linearization). * Fixed typos and ran black Ran black to adhere to code formatting guidelines. * Run black Finished running black on a missed file from last commit. * Fixed some broken tests Broken file tests fixed for other systems. Also fixed a typo in the startup/shutdown assignment constraint. * Removed a test that is failing This test may produce different results based on what machine it is run from. Removed, but this will cause a couple lines of code to be uncovered. * Reverted pytests.ini and corrected tests Incorporated changes recommended by lbianchi-lbl to avoid conflicts and to correct an uncommitted change to the price_taker_model file. * Updated plotting test Updated the plot test to now plt.show() the figure. Instead, the user will use plt.show() if desired. * Ran Black again Ran black to format recent changes. Trying to make sure current tests succeed on the builds. * Updating tests Made a new test and fixed another. Wanted to cover some stray lines of code that were not run from the tests originally. * Add capacity limits function Added a function to add capacity limits for a given commodity. This was originally meant to be a user activity with linearization called at the operation_and_design_models level, however it appears it would be better in the price-taker-class itself. Discussions with Krishna have led us to use a NotImplementedError for a couple other things as well. All code now tested (except multi-year time horizons). Final testing offline for model format and finishing docstrings. * Added final docstring Finished adding docstrings to all complex functions. * Ran black Ran black to reformat the changed files. * Bugfix capacity constraints Fixed a big where I accidentally called the lower bound twice instead of the lower bound AND the upper bound. Code has been tested and lines up with solutions done in a more "by-hand" fashion. * Removed multiyear LMP support Decided to let multiyear LMP analysis to rest on the user instead of generalizing that example within the price-taker-class. * Delete idaes/apps/grid_integration/multiperiod/ERCOT_WEST_2022_shutdown_formulation_NEW.csv Removed extraneous file added by accident. * Update docstring for n_clusters Should resolve sphinx warnings. Co-authored-by: Ludovico Bianchi <lbianchi@lbl.gov> * Fixed typos. * Removed design_blk as an input for Operation_Model Removed design_blk and assume the user will take care of this as an additional argument in the 'model_args' keyword. * Fixed typo in error message in tests * Replace deepgetattr with find_component() As discussed, replacing the borrowed deepgetattr function with the more "Pyomothonic" find_component method. * Changed dependence of tests on .xlsx to .csv Updated the test dependence to be on .csv files, per request. * Changed deepgetattr functionality to find_component Updated the borrowed deepgetattr() function to be more "Pyomothonic" with the native find_component() function. Also updated .xlsx dependency of the test functions to be dependent on .csv file types as requested. * Updated test to remove .xlsx dependencies Removed .xlsx dependency for testing and removed deprecated .xlsx test files. Added a shortened .csv file to replace the shortened .xlsx file. * Update on build_hourly_cashflows docstring Updating to fix Sphinx build issues. * Update for Sphinx again * Ran black * Updated SkeletonUnitModelData to ProcessBlockData Using lighter weight parent class for design and operation model blocks. * Made sklearn and kneed optional, added log msgs Made sklearn and kneed optional imports to perform clustering. Logger messages and import errors added for when functions are called that use these packages. Updated setup.py to reflect that these are no longer new dependencies. * Updated tests for price taker class Updated tests for optional imports. Moved plotting test to within a separate function. Ran black on all code. * Fixed optional import tests Split tests so that optional import tests are now all separated from tests that do not use optional imports. * Ran black * Bugfix kmeans for LMP * merged idaes main * Revert "merged idaes main" This reverts commit 46a3331. * Add initial documentation for pricetaker * Add autoclass to documentation * Fix typos in documentation * Reformat how math equations are handled * add subtle additions to price-taker model used in workhop * Test for seed instance and seed ValueError * Check for expected string outputs rather than using f-strings * Separate tests that check for multiple error messages * Separate a majority of the code outside of the pytest.raises * Update imports * Add version check for sklearn * Add separate function & test for generating elbow plots * Refines version testing and # of optimal clusters testing * Remove unused imports * Correct acronym in pricetaker documentation * Remove commented code in design_and_operation_models * Add dependencies for scikit-learn and kneed * Update imports and seed.setter method * Resolve test failures * Update pricetaker to not create new dependencies * Update pricetaker testing based on previous commit * Refine docstring for compute_sse method * Make compute_sse a prviate method & move outside of class * Update compute_sse docstring * Added tests for design and operation model classes * repair failing check by updating config option name; also update exception message * black * add more exception handling * Update docs/reference_guides/apps/grid_integration/multiperiod/Price_Taker.rst Co-authored-by: Adam Atia <aatia@keylogic.com> * blk * try to fix docstrings to mitigate sphinx error * Remove unnecessary f-strings * Remove/re-add commented code in price taker testing * Add logger messages for when model_func is not defined * Refactor: Added clustering and unit commitment * Empty commit to test permission * Run Black * Update clustering.py and the associated test file * Refine clustering testing * Updated clustering methods * Added UnitCommitmentData class for data processing * Updated tests for the refactored code * Added separate tests for rep days which can be skipped * Created a new folder called pricetaker * Updated import paths * Fixed sphinx error * Fix sphinx doc string failure * Added a method for adding linking constraints * Fixed a typo in the function name --------- Co-authored-by: Radhakrishna <radhakrishnatg@gmail.com> Co-authored-by: adam-a-a <aatia@keylogic.com> Co-authored-by: MarcusHolly <marcus.holly@keylogic.com> Co-authored-by: Ludovico Bianchi <lbianchi@lbl.gov> Co-authored-by: Tyler Jaffe <tyler.jaffe@netl.doe.gov> Co-authored-by: Daniel Laky <daniellaky@Daniels-MacBook-Pro.local> Co-authored-by: Daniel Laky <29078718+dlakes94@users.noreply.github.com> Co-authored-by: Daniel Laky <daniellaky@Daniels-MBP.salemcourthouse.com> Co-authored-by: MarcusHolly <96305519+MarcusHolly@users.noreply.github.com> Co-authored-by: Keith Beattie <ksbeattie@lbl.gov> Co-authored-by: Radhakrishna Tumbalam Gooty <42144353+radhakrishnatg@users.noreply.github.com>
- Loading branch information