Issue getting reports from carbon_policies module

17 views
Skip to first unread message

Brad Venner

unread,
Jun 30, 2021, 12:00:06 PM6/30/21
to Switch Model
Hello Switch model team,

First of all, thanks for producing such a great tool!  We're using it to develop an alternate clean energy plan to our investor-owned utility plan in Colorado.

Second, we're getting an error message when the carbon_policy module tries to report. If you'd rather I open a Github issue rather than using the mailing list, let me know, but it's more likely to be a mistake in my input files.

The "carbon_policies" module itself seems to be working - we get very different mixes when we use it. We're using the social cost of carbon side, not the carbon cap.  The reporting code looks so simple that I can't believe I can't figure out the problem.  I don't expect you to do my debugging, but a hint would help!

I've copied the traceback below, but it seems to be choking on line 82 from carbon_policies.py, which states:

if not model.has_discrete_variables() and model.Enforce_Carbon_Cap[period] in model.dual:

I'm getting a key error, so I'm guessing it's in the dictionary reference in Enforce_Carbon_Cap.

Thanks!

Traceback (most recent call last):
  File "/Users/bradvenner/opt/anaconda3/envs/switch2/bin/switch", line 10, in <module>
    sys.exit(main())
  File "/Users/bradvenner/opt/anaconda3/envs/switch2/lib/python3.6/site-packages/switch_model/main.py", line 39, in main
    main()
  File "/Users/bradvenner/opt/anaconda3/envs/switch2/lib/python3.6/site-packages/switch_model/solve.py", line 183, in main
    instance.post_solve()
  File "/Users/bradvenner/opt/anaconda3/envs/switch2/lib/python3.6/site-packages/switch_model/utilities.py", line 252, in post_solve
    module.post_solve(instance, outputs_dir)
  File "/Users/bradvenner/opt/anaconda3/envs/switch2/lib/python3.6/site-packages/switch_model/policies/carbon_policies.py", line 98, in post_solve
    values=get_row)
  File "/Users/bradvenner/opt/anaconda3/envs/switch2/lib/python3.6/site-packages/switch_model/reporting/__init__.py", line 85, in write_table
    for x in itertools.product(*indexes)
  File "/Users/bradvenner/opt/anaconda3/envs/switch2/lib/python3.6/site-packages/switch_model/reporting/__init__.py", line 85, in <genexpr>
    for x in itertools.product(*indexes)
  File "/Users/bradvenner/opt/anaconda3/envs/switch2/lib/python3.6/site-packages/switch_model/policies/carbon_policies.py", line 82, in get_row
    if not model.has_discrete_variables() and model.Enforce_Carbon_Cap[period] in model.dual:
  File "/Users/bradvenner/opt/anaconda3/envs/switch2/lib/python3.6/site-packages/pyomo/core/base/indexed_component.py", line 555, in __getitem__
    return self._getitem_when_not_present(index)
  File "/Users/bradvenner/opt/anaconda3/envs/switch2/lib/python3.6/site-packages/pyomo/core/base/indexed_component.py", line 839, in _getitem_when_not_present
    raise KeyError(index)
KeyError: 2021

Josiah Johnston

unread,
Jun 30, 2021, 12:13:33 PM6/30/21
to switch...@googlegroups.com
Hi

That error is because the period 2021 doesn’t exist in EnforceCarbonCap. 

After reading the code that defines the constraint and exports is dual , I’m guessing line 82 (that you quoted) needs to be changed to

… and period in model.Enforce_Carbon_Cap and model.Enforce_Carbon_Cap[period] in …


----

Sent from a phone; please excuse brevity and typos

On Jun 30, 2021, at 9:00 AM, Brad Venner <brad....@vennerconsulting.com> wrote:


--
You received this message because you are subscribed to the Google Groups "Switch Model" group.
To unsubscribe from this group and stop receiving emails from it, send an email to switch-model...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/switch-model/b7bcdcbd-5224-4f71-8211-489227548eadn%40googlegroups.com.

Brad Venner

unread,
Jun 30, 2021, 12:18:35 PM6/30/21
to switch...@googlegroups.com
Wow, a response in 15 minutes!  Thanks for the suggestion - I'll try to implement it tonight and get back to the list.

Brad Venner

unread,
Jul 4, 2021, 11:38:27 AM7/4/21
to Switch Model
Josiah's fixed worked - thanks!  I submitted a pull request, hopefully per the "how_to_collaborate.txt" instructions.
Reply all
Reply to author
Forward
0 new messages