Breakthrough-Energy / SwitchWrapper

Wrapper for Switch
MIT License
1 stars 2 forks source link

fix: replace capacity limit values for existing generators with '.' #82

Closed danielolsen closed 3 years ago

danielolsen commented 3 years ago

Pull Request doc

Purpose

Avoid generating an infeasible model

What the code is doing

We change the code so that entries in the gen_capacity_limit_mw column of the generation_projects_info.csv file for existing generators are filled with ".", rather than the default capacity limits from const.py. This avoids generating an infeasible problem, I think because we do not constrain the existing coal plants to be zero capacity, which conflicts with their non-zero capacities from the gen_build_predetermined.csv file. The original issue for generating this file (#1) was ambiguous as to what should be in these entries, and we made a mistake in porting the logic from the original script in #35.

Testing

Tested manually. Before: the solver returns Infeasible in 1-2 minutes. After: the solver keeps running much longer than that.

Time estimate

5-10 minutes.

danielolsen commented 3 years ago

It runs... sort of:

dolsen@becompute01:~/switchwrapper_test$ ~/.local/bin/switch solve --verbose --s
olver gurobi --suffixes dual

=======================================================================
Switch 2.0.6, http://switch-model.org
=======================================================================
Arguments:
logs_dir='logs', inputs_dir='inputs', suffixes=['dual'], solver='gurobi', solver_manager='serial', outputs_dir='outputs', verbose=True
Modules:
switch_model, switch_model.timescales, switch_model.financials, switch_model.balancing.load_zones, switch_model.energy_sources.properties, switch_model.generators.core.build, switch_model.generators.core.dispatch, switch_model.generators.core.no_commit, switch_model.energy_sources.fuel_costs.simple, switch_model.transmission.local_td, switch_model.transmission.transport.build, switch_model.transmission.transport.dispatch, switch_model.reporting, switch_model.solve
=======================================================================

Model created in 0.24 s.
Loading inputs...
Data read in 3.67 s.

Instance created from data in 161.02 s.

Total time spent constructing model: 164.69 s.

Solving model...
Solved model. Total time spent in solver: 140.247918 s.

Optimization termination condition was optimal.
Solver message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.

Saved results in 22.09 s.
Executing post solve functions...
ERROR: evaluating object as numeric value: BuildTx[88607ac,2030]
        (object: <class 'pyomo.core.base.var._GeneralVarData'>)
    No value for uninitialized NumericValue object BuildTx[88607ac,2030]
ERROR: evaluating object as numeric value: TxCapacityNameplate[88607ac,2030]
        (object: <class 'pyomo.core.base.expression._GeneralExpressionData'>)
    No value for uninitialized NumericValue object BuildTx[88607ac,2030]
Traceback (most recent call last):
  File "/home/dolsen/.local/bin/switch", line 8, in <module>
    sys.exit(main())
  File "/home/dolsen/.local/lib/python3.8/site-packages/switch_model/main.py", line 39, in main
    main()
  File "/home/dolsen/.local/lib/python3.8/site-packages/switch_model/solve.py", line 183, in main
    instance.post_solve()
  File "/home/dolsen/.local/lib/python3.8/site-packages/switch_model/utilities.py", line 252, in post_solve
    module.post_solve(instance, outputs_dir)
  File "/home/dolsen/.local/lib/python3.8/site-packages/switch_model/transmission/transport/build.py", line 336, in post_solve
    normalized_dat = [
  File "/home/dolsen/.local/lib/python3.8/site-packages/switch_model/transmission/transport/build.py", line 346, in <listcomp>
    "TxCapacityNameplate": value(mod.TxCapacityNameplate[tx,p]),
  File "/home/dolsen/.local/lib/python3.8/site-packages/pyomo/core/expr/numvalue.py", line 226, in value
    tmp = obj(exception=True)
  File "/home/dolsen/.local/lib/python3.8/site-packages/pyomo/core/base/expression.py", line 54, in __call__
    return self.expr(exception=exception)
  File "/home/dolsen/.local/lib/python3.8/site-packages/pyomo/core/expr/numeric_expr.py", line 223, in __call__
    return evaluate_expression(self, exception)
  File "/home/dolsen/.local/lib/python3.8/site-packages/pyomo/core/expr/visitor.py", line 974, in evaluate_expression
    return visitor.dfs_postorder_stack(exp)
  File "/home/dolsen/.local/lib/python3.8/site-packages/pyomo/core/expr/visitor.py", line 519, in dfs_postorder_stack
    flag, value = self.visiting_potential_leaf(_sub)
  File "/home/dolsen/.local/lib/python3.8/site-packages/pyomo/core/expr/visitor.py", line 894, in visiting_potential_leaf
    return True, value(node)
  File "/home/dolsen/.local/lib/python3.8/site-packages/pyomo/core/expr/numvalue.py", line 228, in value
    raise ValueError(
ValueError: No value for uninitialized NumericValue object BuildTx[88607ac,2030]

We do have the results.pickle file in the expected location, and it is 132 MB (i.e. not empty), so maybe we have everything we need...