Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CBC in NE double loop notebook #202

Merged
merged 3 commits into from
Jun 26, 2023

Conversation

radhakrishnatg
Copy link
Contributor

Addresses issue:

Fixes notebook error in #200

Summary/Motivation:

Changes proposed in this PR:

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the license terms described in the LICENSE.md and COPYRIGHT.md file at the top level of this directory.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@radhakrishnatg radhakrishnatg self-assigned this May 26, 2023
@radhakrishnatg radhakrishnatg mentioned this pull request May 26, 2023
3 tasks
@radhakrishnatg
Copy link
Contributor Author

Hi @lbianchi-lbl The RE tests that were failing in #199 are also failing in this PR. And, from what I understand, this PR does not include the changes in IDAES 1180. So does that mean that the test failures in #199 are not related to the changes in IDAES 1180?

@lbianchi-lbl
Copy link
Contributor

Hi @lbianchi-lbl The RE tests that were failing in #199 are also failing in this PR. And, from what I understand, this PR does not include the changes in IDAES 1180. So does that mean that the test failures in #199 are not related to the changes in IDAES 1180?

Most likely, that's correct. #199 updates the IDAES requirement, which this PR does not. However, Pyomo 6.6.0 was released 2 days ago, and some of the errors we're seeing now seem to be directly related to that. I've created an issue for the UnboundLocalError (Pyomo/pyomo#2846), but I'm not sure about the solver failures.

In the meantime, while we're still able to do so (i.e. before switching to a version of IDAES that depends on pyomo>6.5.0) we can add a pyomo<6.6 requirement to setup.py. I can push directly to this branch if that's OK.

@radhakrishnatg
Copy link
Contributor Author

Sure, @lbianchi-lbl I'm okay with that. That way, we would know if it is a pyomo issue or DISPATCHES issue. Also, I mentioned a comment in another PR. I'm not seeing the RE test failures locally.

@radhakrishnatg radhakrishnatg mentioned this pull request May 26, 2023
2 tasks
@dguittet
Copy link
Contributor

dguittet commented Jun 5, 2023

On my mac or on the HPC, I'm also not able to reproduce the IPOPT failures in these tests:

FAILED dispatches/case_studies/renewables_case/tests/test_RE_flowsheet.py::test_wind_battery_pem_tank_turb_optimize_simple - ValueError: Cannot load a SolverResults object with bad status: error
FAILED dispatches/case_studies/renewables_case/tests/test_RE_flowsheet.py::test_wind_battery_pem_tank_turb_optimize_detailed - assert 34.74003128616143 == 0 ± 3.0e+00

Edit: this is updating Pyomo to 6.6.0 and using the same version of IPOPT (3.13.2)

@ksbeattie ksbeattie added the Priority:High High Priority Issue or PR label Jun 5, 2023
Copy link
Contributor

@dguittet dguittet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The notebook did not run successfully on my computer due to Prescient simulation errors below. Output also attached as a log file.

nuclear_flowsheet_double_loop_output.log

These are my Prescient and Egret versions:

(dispatches) dguittet@dguittet-34208s dispatches % pip show gridx-egret gridx-prescient
Name: gridx-egret
Version: 0.5.5
Summary: EGRET: Electrical Grid Research and Engineering Tools.
Home-page: https://github.com/grid-parity-exchange/Egret
Author: Michael Bynum, Anya Castillo, Carl Laird, Bernard Knueven and Jean-Paul Watson
Author-email: 
License: Revised BSD
Location: /Users/dguittet/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_egret-0.5.5-py3.8.egg
Requires: coramin, matplotlib, networkx, numpy, pandas, pyomo, pytest, scipy, seaborn
Required-by: gridx-prescient
---
Name: gridx-prescient
Version: 2.2.2
Summary: Power Generation Scenario creation and simulation utilities
Home-page: https://github.com/grid-parity-exchange/Prescient
Author: Jean-Paul Watson, David Woodruff, Andrea Staid, Dominic Yang
Author-email: [email protected]
License: 
Location: /Users/dguittet/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_prescient-2.2.2-py3.8.egg
Requires: gridx-egret, jupyter, matplotlib, networkx, numpy, pandas, pyomo, python-dateutil, scipy
Required-by: dispatches
Stack Trace ``` --------------------------------------------------------------------------- ValueError Traceback (most recent call last) /var/folders/yh/xvlf1svn0xq6r2l4hzsggz2xt3qfdr/T/ipykernel_1181/928836213.py in 33 34 # Run Prescient ---> 35 Prescient().simulate(**options)

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_prescient-2.2.2-py3.8.egg/prescient/simulator/prescient.py in simulate(self, **options)
73 self.config.set_value(options)
74
---> 75 return self._simulate(self.config)
76
77 def _simulate(self, options: PrescientConfig):

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_prescient-2.2.2-py3.8.egg/prescient/simulator/prescient.py in _simulate(self, options)
80 "If you wish to simulate again create a new Prescient object.")
81 self.simulate_called = True
---> 82 return super().simulate(options)
83
84 def main(args=None):

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_prescient-2.2.2-py3.8.egg/prescient/simulator/simulator.py in simulate(self, options)
102
103 if time_step.is_planning_time:
--> 104 oracle_manager.call_planning_oracle(options, time_step)
105
106 if time_step.is_ruc_activation_time:

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_prescient-2.2.2-py3.8.egg/prescient/simulator/oracle_manager.py in call_planning_oracle(self, options, time_step)
129 ''' Create a new RUC and make it the pending RUC
130 '''
--> 131 projected_state = self._get_projected_state(options, time_step)
132 uc_hour, uc_date = self._get_uc_activation_time(options, time_step)
133 self._generate_pending_ruc(options, uc_date, uc_hour, projected_state)

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_prescient-2.2.2-py3.8.egg/prescient/simulator/oracle_manager.py in _get_projected_state(self, options, time_step)
88 )
89
---> 90 projected_sced_instance, solve_time = self.engine.solve_sced_instance(options, projected_sced_instance)
91
92 future_state = StateWithOffset(current_state, projected_sced_instance, ruc_delay)

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_prescient-2.2.2-py3.8.egg/prescient/engine/egret/engine.py in solve_sced_instance(self, options, sced_instance, output_initial_conditions, output_loads, lp_filename)
175 ptdf_options = None
176
--> 177 pyo_model = create_sced_uc_model(sced_instance,
178 ptdf_options = ptdf_options,
179 PTDF_matrix_dict=ptdf_manager.PTDF_matrix_dict,

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_prescient-2.2.2-py3.8.egg/prescient/engine/egret/engine.py in create_sced_uc_model(model_data, network_constraints, relaxed, **kwargs)
66 network_constraints,
67 ]
---> 68 return _get_uc_model(model_data, formulation_list, relaxed, **kwargs)
69
70 class EgretEngine(ModelingEngine):

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_egret-0.5.5-py3.8.egg/egret/models/unit_commitment.py in _get_uc_model(model_data, formulation_list, relax_binaries, **kwargs)
30 def _get_uc_model(model_data, formulation_list, relax_binaries, **kwargs):
31 formulation = UCFormulation(*formulation_list)
---> 32 return generate_model(model_data, formulation, relax_binaries, **kwargs)
33
34 def create_tight_unit_commitment_model(model_data,

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_egret-0.5.5-py3.8.egg/egret/model_library/unit_commitment/uc_model_generator.py in generate_model(model_data, uc_formulation, relax_binaries, ptdf_options, PTDF_matrix_dict, slack_type)
72 md = model_data.clone_in_service()
73 scale_ModelData_to_pu(md, inplace=True)
---> 74 return _generate_model( md, *_get_formulation_from_UCFormulation( uc_formulation ), relax_binaries , ptdf_options, PTDF_matrix_dict, slack_type )
75
76 def _generate_model( model_data,

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_egret-0.5.5-py3.8.egg/egret/model_library/unit_commitment/uc_model_generator.py in _generate_model(model_data, _status_vars, _power_vars, _reserve_vars, _non_dispatchable_vars, _generation_limits, _ramping_limits, _production_costs, _uptime_downtime, _startup_costs, _power_balance, _reserve_requirement, _objective, _relax_binaries, _ptdf_options, _PTDF_matrix_dict, _slack_type)
133 services.storage_services(model)
134 services.load_services(model)
--> 135 services.ancillary_services(model)
136 getattr(power_balance, _power_balance)(model, _slack_type)
137 getattr(reserve_requirement, _reserve_requirement)(model)

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_egret-0.5.5-py3.8.egg/egret/model_library/unit_commitment/uc_utils.py in wrapper(*args, **kwds)
62 warnings.warn(msg)
63 setattr(model, attr, func.name)
---> 64 return func(*args, **kwds)
65 return wrapper
66 return actual_decorator

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_egret-0.5.5-py3.8.egg/egret/model_library/unit_commitment/services.py in ancillary_services(model)
369 ## except flexiramp which is it's own thing
370 if add_regulation_reserve:
--> 371 regulation_services(model, zone_initializer_builder, zone_requirement_getter, gens_in_reserve_zone_getter)
372 else:
373 model.regulation_service = None

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_egret-0.5.5-py3.8.egg/egret/model_library/unit_commitment/uc_utils.py in wrapper(*args, **kwds)
62 warnings.warn(msg)
63 setattr(model, attr, func.name)
---> 64 return func(*args, **kwds)
65 return wrapper
66 return actual_decorator

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/gridx_egret-0.5.5-py3.8.egg/egret/model_library/unit_commitment/services.py in regulation_services(model, zone_initializer_builder, zone_requirement_getter, gens_in_reserve_zone_getter)
537 def regulation_low_limit_validator(m, v, g, t):
538 return (v <= value(m.RegulationHighLimit[g,t]) and v >= value(m.MinimumPowerOutput[g,t]))
--> 539 model.RegulationLowLimit = Param(model.AGC_Generators, model.TimePeriods, within=NonNegativeReals, validate=regulation_low_limit_validator, initialize=TimeMapper(agc_gen_attrs['p_min_agc']))
540
541 # Regulation capacity is calculated as the min of "regulation band" and RegulationMinutes*AutomaticResponseRate

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/pyomo/core/base/block.py in setattr(self, name, val)
578 # Pyomo components are added with the add_component method.
579 #
--> 580 self.add_component(name, val)
581 else:
582 #

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/pyomo/core/base/block.py in add_component(self, name, val)
1183 )
1184 try:
-> 1185 val.construct(data)
1186 except:
1187 err = sys.exc_info()[1]

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/pyomo/core/base/param.py in construct(self, data)
787 # Step #1: initialize data from rule value
788 #
--> 789 self._construct_from_rule_using_setitem()
790 #
791 # Step #2: allow any user-specified (external) data to override

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/pyomo/core/base/indexed_component.py in _construct_from_rule_using_setitem(self)
778 # The index is coming in externally; we need to validate it
779 for index in rule.indices():
--> 780 self[index] = rule(block, index)
781 elif not self.index_set().isfinite():
782 # If the index is not finite, then we cannot iterate

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/pyomo/core/base/indexed_component.py in setitem(self, index, val)
703 obj = self._data.get(index, _NotFound)
704 if obj is _NotFound:
--> 705 return self._setitem_when_not_present(index, val)
706 else:
707 return self._setitem_impl(index, obj, val)

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/pyomo/core/base/param.py in _setitem_when_not_present(self, index, value, _check_domain)
709 # Because we do not have a _ParamData, we cannot rely on the
710 # validation that occurs in _ParamData.set_value()
--> 711 self._validate_value(index, value, _check_domain)
712 return value
713 except:

~/miniconda3/envs/dispatches/lib/python3.8/site-packages/pyomo/core/base/param.py in _validate_value(self, index, value, validate_domain, data)
737 )
738 if not valid:
--> 739 raise ValueError(
740 "Invalid parameter value: %s[%s] = '%s', value type=%s.\n"
741 "\tValue failed parameter validation rule"

ValueError: Invalid parameter value: RegulationLowLimit[('121_NUCLEAR_1', 1)] = '3.96', value type=.
Value failed parameter validation rule

</details>


@dguittet dguittet self-requested a review June 6, 2023 19:09
@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (03b936a) 89.49% compared to head (08d358c) 89.49%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #202   +/-   ##
=======================================
  Coverage   89.49%   89.49%           
=======================================
  Files          67       67           
  Lines        8238     8238           
=======================================
  Hits         7373     7373           
  Misses        865      865           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@lbianchi-lbl
Copy link
Contributor

lbianchi-lbl commented Jun 20, 2023

@radhakrishnatg will try running again after updating to the current dependencies (IDAES 2.0/Pyomo 6.5) (ensure pip show idaes-pse pyomo to confirm the versions installed) and see if the error persists.

@lbianchi-lbl
Copy link
Contributor

lbianchi-lbl commented Jun 26, 2023

  • @radhakrishnatg is experiencing errors on Windows on Python 3.8 but not 3.9
    • Error is likely not related to this PR
    • Possibly related to Numpy's (lack of) support for 3.8 in recent version
    • Check with python -c "from PySAM import Windpower"

@lbianchi-lbl
Copy link
Contributor

We can merge this while investigating the issue reported by @radhakrishnatg since it's likely not related (and the cell is skipped in CI anyway).

@lbianchi-lbl lbianchi-lbl merged commit e1771b4 into gmlc-dispatches:main Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:High High Priority Issue or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants