Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
7289385
Allow users to choose log level for warning / info messages. Apply to…
josiahjohnston Jul 9, 2019
2318c1a
Make `switch solve` command line options easier to do text searches o…
josiahjohnston Jul 9, 2019
f69352e
Fixed bug of storage export crashing for existing storage plants that…
josiahjohnston Jul 6, 2019
41443b1
Fixed a bug where ArgParse doesn't allow unescaped percent signs in h…
josiahjohnston Jul 9, 2019
e6b486e
Change plotting libraries from `ggplot` to `plotnine` because the pyt…
josiahjohnston Jul 9, 2019
3696e70
Export energy balance of local T&D node.
josiahjohnston Jul 10, 2019
9a376d0
When `--interact` is given, use IPython.embed() if IPython is availab…
josiahjohnston Jul 12, 2019
ee9008e
Include storage decisions in dispatch export if the storage module is…
josiahjohnston Jul 13, 2019
469caad
If the optional plotting library is available, filter out its spuriou…
josiahjohnston Jul 17, 2019
e8be456
Fix long-standing bug that used the wrong parameter name in `load_aug…
josiahjohnston Jul 25, 2019
29a4366
Update simple_hydro to model spillways; a crucial feature of hydro pl…
josiahjohnston Jul 25, 2019
849bc8e
Expand export from the dispatch module to simplify analysis:
josiahjohnston Jul 25, 2019
f06c001
Update planning reserves input documentation & reading to reflect tha…
josiahjohnston Jul 31, 2019
889f47f
Write a simple-to-use expression in fuel markets to get post-optimiza…
josiahjohnston Aug 2, 2019
fd0e046
Fix a bug with fuel unavailability when calculating fuel costs relate…
josiahjohnston Aug 7, 2019
1fa7a56
Implement a check for bidirectional transmission lines being specifie…
josiahjohnston Aug 7, 2019
2de5b80
Clarify extra timepoints warning message since it applies to both pla…
josiahjohnston Aug 7, 2019
7e5b960
Update transmission documentation to match implementation changes Mat…
josiahjohnston Aug 7, 2019
56eaad9
Update typo in a warning message.
josiahjohnston Aug 9, 2019
e328fae
Port the extra contribution that ChargeStorage can make to spinning r…
josiahjohnston Aug 9, 2019
89eb49d
Implement predetermined energy capacity for storage, a parallel to pr…
josiahjohnston Aug 9, 2019
d49f633
Fix bugs in planning reserve margin. One bug was a typo in accessing …
josiahjohnston Aug 9, 2019
e5bbfd3
Added a CLI option (`--logging-level`) to explicitly specify logging …
josiahjohnston Aug 13, 2019
766e377
Bumping version number to avoid confusion with 2.0.5 release.
josiahjohnston Aug 13, 2019
b5b1a28
Updating version parser because the prior one (distutils.version) is …
josiahjohnston Aug 16, 2019
3921704
Make min up & downtime constraints more concise & readable, and use s…
josiahjohnston May 19, 2017
94525dc
Condense discussion of issues in code by referring to an issue posted…
josiahjohnston Aug 16, 2019
401288a
Update documentation and code readability. Also remove a weird line o…
josiahjohnston Aug 21, 2019
13cbca7
Make auto_select in load_aug optional and default to True, unless `se…
josiahjohnston Aug 21, 2019
ba088df
Move load_td I/O into its module instead of the transport.build modul…
josiahjohnston Aug 21, 2019
a78f59b
Trim down timepoints printed in error messages to avoid too long of d…
josiahjohnston Sep 12, 2019
21bbc27
Include levelized cost of energy in dispatch summary files.
josiahjohnston Oct 7, 2019
29d0332
Switch from --verbose/--quiet to --log-level flag
mfripp Nov 4, 2019
4642de0
Report unused values in variable_capacity_factors.csv with new logger
mfripp Nov 5, 2019
e95abe3
Better handling of exceptions and warnings for dispatch summary graphs
mfripp Nov 5, 2019
0986979
Improve INSTALL.md formatting
mfripp Aug 14, 2019
5b35956
Cosmetic improvements to code and comments
mfripp Nov 1, 2019
de0db92
Implement --input-aliases option
mfripp Nov 1, 2019
7e9b763
Bump version number to 2.0.6.
mfripp Nov 1, 2019
81967ed
Improve default demand response reserves and share code
mfripp Nov 1, 2019
81fc53f
Bring balancing.demand_response.iterative up-to-date
mfripp Nov 1, 2019
056aeb4
Allow users to split fleet between different charging modes in hawaii.ev
mfripp Nov 1, 2019
1ebbaaf
Update hawaii.fed_subsidies to work with FlatDistPV and SlopedDistPV
mfripp Nov 1, 2019
fe2bee5
Avoid warnings about unused variables if no min H2 tank size specified
mfripp Nov 1, 2019
1bb408a
hawaii.save_results saves blanks if no duals are available; no error
mfripp Nov 1, 2019
b52846c
Use technology priority list when smoothing dispatch
mfripp Nov 1, 2019
8771c80
Allow same-line comments in modules.txt, options.txt and scenarios.txt
mfripp Nov 1, 2019
8cbea8d
Allow zero-weight timeseries
mfripp Nov 1, 2019
a432fbd
Replace psip_2016_12 with heco_outlook_2019
mfripp Nov 2, 2019
4e10f69
Convert gen_multiple_fuels.dat to gen_multiple_fuels.csv
mfripp Nov 2, 2019
621e8dd
Tell user if heco_outlook_2019 has a target for a missing technology
mfripp Nov 2, 2019
396fc66
Update hawaii.scenario_data to work with --scenario-aliases
mfripp Nov 2, 2019
75a4240
Allow different fuel costs for each timepoint (experimental/untested)
mfripp Nov 2, 2019
e912168
Format help code for PEP-8; streamline message creation for edge cases
mfripp Nov 5, 2019
c0c977f
Suppress all warnings from plotnine, including during run_tests.py
mfripp Nov 5, 2019
972a150
Fix bug in reserve code sharing for demand_response.iterative
mfripp Nov 5, 2019
0ce7831
Update version number for examples
mfripp Nov 5, 2019
40ad196
Set deprecated verbose flag at correct point in model creation sequence
mfripp Nov 6, 2019
6f872f0
Rename zone_rfm to zone_fuel_rfm to make indexing clearer
mfripp Nov 22, 2019
b452614
Fix bug in storage fixed cost calculations
mfripp Nov 22, 2019
d03e79a
Include storage energy costs in GenCapitalCosts in gen_cap.csv
mfripp Nov 22, 2019
708b2ca
Apply inflation to connection costs; allow alternative BAU EV chargin…
mfripp Feb 28, 2020
0e53e99
Add fuel_costs.markets_expansion for capacity expansion of fuel markets
mfripp Jul 10, 2020
c0d7f6b
Define per-timepoint fuel costs using fuel_costs.simple_per_timepoint
mfripp Jul 10, 2020
c564a4d
Don't report zonal electricity costs if zonal demand is not defined
mfripp Jul 10, 2020
bef565b
Read gen_predetermined_storage_energy_mwh from gen_build_predetermine…
mfripp Jul 10, 2020
2c22edc
Warn when variables with unassigned values are found during reporting
mfripp Jul 10, 2020
fce90df
Move Switch banner higher in output stream and use logger instead of …
mfripp Jul 10, 2020
d853c46
Skip constructing the model if the prior solution file is missing
mfripp Jul 10, 2020
8cf1809
Don't use IPython for --interact due to bug in list comprehension
mfripp Jul 10, 2020
3b23000
Return solved instance when solve.main() finishes
mfripp Jul 10, 2020
2bdfd80
Report location of model in callstack when using --debug
mfripp Jul 10, 2020
6592911
Add transmission.copperplate module for free power transfer between z…
mfripp Jul 10, 2020
8941a85
Run each scenario in a separate process
mfripp Jul 10, 2020
31629bc
Fix typo in generators.core.build documentation.
mfripp Jul 10, 2020
e17bea3
Fix compatibility with Pyomo 5.7
mfripp Jul 10, 2020
a1b5517
Report when applying --input-aliases
mfripp Jul 10, 2020
bbd5bb2
Count components as they are created when --log-level is 'info'
mfripp Jul 10, 2020
b6475a5
Hawaii: use 'Motor_Gasoline' cost instead of 'Diesel' for ICE vehicles
mfripp Jul 10, 2020
e781c2a
Hawaii: Apply federal tax credits to individual generators to support…
mfripp Jul 10, 2020
07ac462
Hawaii: correct federal tax credits for distributed PV in 2020 and 2021
mfripp Jul 10, 2020
015e36c
Hawaii: Finalize heco_outlook_2019, used for PBR proceeding in Dec. 2019
mfripp Jul 10, 2020
81325d0
Hawaii: add modules representing Oahu forecasts and HECO plans as of …
mfripp Jul 10, 2020
fc8e9b7
Hawaii: add oahu_plants module with rules for all plants; supersedes …
mfripp Jul 10, 2020
02cd79d
Hawaii: update and improve backwards compatibility of scenario_data
mfripp Jul 10, 2020
a183ce3
Handle reserves better in hawaii.smooth_dispatch
mfripp Jul 10, 2020
66aa956
Hawaii: streamline and improve capacity reporting
mfripp Jul 10, 2020
24a6287
Update copyright notices to 2015-2020
mfripp Jul 10, 2020
0d75522
Hawaii: replace kalaeloa with oahu_plants in modules.txt in upgrade s…
mfripp Jul 10, 2020
52566ac
Fix bug in new GENS_FOR_RFM_PERIOD code when no rfm matches a gen
mfripp Jul 11, 2020
433f14e
Improve message about model location during post-mortem debugging
mfripp Jul 11, 2020
5e3f179
Add option to skip saving each decision variable in a separate file (…
josiahjohnston Oct 3, 2019
b010a5e
Fix bugs in creating capacity_by_technology_vertical.csv
mfripp Jul 15, 2020
83860d6
Save model configuration in outputs/model_config.json
mfripp Jul 15, 2020
0ece6a6
Hawaii: fix bugs when saving capacity_by_technology.csv
mfripp Jul 15, 2020
95c9d0f
Identify compatible versions of Pyomo, pyutilib and pandas in setup.py
mfripp Jul 15, 2020
4cb61b1
Merge recent changes from next_release branch
mfripp Jul 24, 2020
d7ed77a
Deprecate auto_select argument to load_aug since it is never needed
mfripp Jul 24, 2020
606cc38
Make compatible with pandas 1.0+
mfripp Jul 24, 2020
0cddb3e
read gen_predetermined_storage_energy_mwh from correct file
mfripp Aug 20, 2020
cc38499
Hawaii: support setting of gen_predetermined_storage_energy_mwh
mfripp Aug 20, 2020
ea6a7b5
Hawaii: update near-term forecasts and HECO Plan
mfripp Aug 20, 2020
ce2f8ba
hawaii package: more informative message about outdated federal subsi…
mfripp Mar 9, 2021
a7e262b
merge changes from 2.0.6 bugfix release
mfripp Mar 9, 2021
d92e507
fix typo in planning_reserves
DesmondZhong Dec 26, 2020
88abc16
fix postprocessing errors in storage module
DesmondZhong May 11, 2021
42c3e60
fix reporting for carbon_policies.py
Jul 4, 2021
ab0e211
clarify description of storage cost bug fixed in 2.0.6
mfripp Oct 17, 2022
139070f
Apply unserved_load at distribution node when available
mfripp Oct 17, 2022
c1113eb
more precision in examples/**/total_cost.txt
mfripp Oct 17, 2022
333c388
include iteration number in result filenames for demand_response.iter…
mfripp Oct 18, 2022
ea53158
add switch_model.balancing.diagnose_infeasibility to help diagnose in…
mfripp Oct 18, 2022
3555e49
fix crashing bug in switch_model.energy_sources.fuel_costs.markets_ex…
mfripp Oct 18, 2022
1175bed
hawaii.save_result: report all projects in capacity_by_*.csv, whether…
mfripp Oct 18, 2022
734f9b3
Add support for multiple land-use classes in hawaii.scenario_data
mfripp Oct 18, 2022
f6bd388
remove extra 'm' from names of cumulative_capacity_by_tech_periods.cs…
mfripp Oct 18, 2022
ac017f7
Improve messages when trying to solve infeasible models
mfripp Oct 18, 2022
c59a9d4
Allow omission of existing_local_td and local_td_annual_cost_per_mw w…
mfripp Oct 18, 2022
2b6a0ff
Adjust examples/diagnose_infeasibility so total_cost will be consiste…
mfripp Oct 18, 2022
4110a65
Don't allow missing values for Expressions when reporting results.
mfripp Oct 18, 2022
19c9200
Use same logger for model and instance (fixes some post-solve logging…
mfripp Oct 18, 2022
944de5c
Allow omission of any column in an optional input .csv file, even if …
mfripp Oct 18, 2022
e23a0f6
various small, cosmetic changes
mfripp Oct 18, 2022
3908fe3
Create and use SwitchAbstractModel and SwitchConcreteModel classes
mfripp Oct 20, 2022
156a349
Remove outdated code from patch_pyomo and reduce nesting
mfripp Oct 20, 2022
7a135f7
Ensure Switch logger output goes to log file and improve logging help
mfripp Oct 20, 2022
2396df7
Improve code for progress messages during model construction
mfripp Oct 20, 2022
4d4601d
Allow running tests from location other than top level directory
mfripp Oct 20, 2022
2ff0ec6
Use lists instead of unordered sets to initialize Sets for Pyomo 5.7+…
mfripp Oct 20, 2022
947fb52
Change Set(...,rule=...) to Set(...,initialize=...)
mfripp Oct 21, 2022
62a0803
update compatibility range
mfripp Oct 21, 2022
4ee5477
don't try to parse command-line arguments during tests
mfripp Oct 21, 2022
27cea89
Apply Black formatting (mostly automated)
mfripp Oct 21, 2022
0c82eaa
change 'is 0' to '== 0' to avoid warning in Python 3.8+
mfripp Oct 22, 2022
7701c4f
move code to create gen_cap.csv from generators.core.build to reporti…
mfripp Oct 24, 2022
71b8615
Make code and examples compatible with Pyomo 5.7 - 6.4
mfripp Oct 24, 2022
2277e08
Add domains for a few more Params
mfripp Oct 24, 2022
70768f6
Remove balancing_areas.csv from examples (have been obsolete for seve…
mfripp Oct 24, 2022
7cf35d4
define --sorted-output for all models and move gen_cap.code back to g…
mfripp Oct 24, 2022
61e9f23
apply --sorted-output more universally
mfripp Oct 24, 2022
59808a9
Bump version number to 2.0.7 in example directories
mfripp Oct 24, 2022
c1026e0
Update copyright date to 2022.
mfripp Oct 24, 2022
24e06ae
rename dispatch-wide.csv to dispatch_wide.csv and fix sorting bug
mfripp Oct 24, 2022
b0a81ee
Rename gen_predetermined_cap to build_gen_predetermined in gen_build_…
mfripp Oct 25, 2022
112c65e
rename generation_projects_info.csv to gen_info.csv
mfripp Oct 25, 2022
333653a
remove obsolete output files from example directories
mfripp Oct 25, 2022
00940c1
Move trans_params.csv/distribution_loss_rate to load_zones.csv/local_…
mfripp Oct 25, 2022
976cf7e
add test for --retrieve-cplex-mip-duals flag
mfripp Oct 25, 2022
526ce3d
Ensure every Param has domain and avoid using obj.keys() to initializ…
mfripp Oct 25, 2022
ffc013f
Use isinstance() to check whether a sum() of Pyomo components has any…
mfripp Oct 25, 2022
2d8cb8a
Prevent deprecation warning for model.preprocess() from Pyomo 6.0+
mfripp Oct 26, 2022
99e0f41
Move model configuration banner above define_components messages
mfripp Oct 26, 2022
84c8e9f
get stdin working for breakpoints, post-mortems and model upgrades un…
mfripp Oct 27, 2022
b629069
miscellaneous cosmetic tweaks and simplifications
mfripp Oct 27, 2022
075df36
merge energy-democracy:fix_scc and report carbon cap duals even for i…
mfripp Oct 27, 2022
cbd02d1
Merge branch 'energy-democracy-fix_scc' into next_release
mfripp Oct 27, 2022
cbabc82
Merge branch 'next_release' into master
mfripp Oct 27, 2022
f8bfae0
Merge pull request #135 from DesmondZhong/master
mfripp Oct 27, 2022
70ad996
Split reporting of generator additions and capacity, and include stor…
mfripp Oct 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*pyc
!.gitignore
.*
*.pyc
**parse_table_datacmds.py
.idea
.DS_Store
gurobi.log
switch_model.egg-info/
venv
Expand Down
29 changes: 22 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
-------------------------------------------------------------------------------
Switch 2.0.7
-------------------------------------------------------------------------------
Note that as of version 5.7, Pyomo no longer supports "inf", "infinity" or "nan"
values in the input files, so Switch will likely report errors if you have
those.

Changed Pyomo dependencies to versions 5.5.1-6.4.2. Note that Pyomo versions
before 5.7.3 don't work with CPLEX version 12.10 or later (see
https://github.com/Pyomo/pyomo/pull/1792). If using a recent version of CPLEX,
you should ensure that you also use version 5.7.3 or later of Pyomo.

Renamed outputs/dispatch-wide.csv to outputs/dispatch_wide.csv

-------------------------------------------------------------------------------
Switch 2.0.6
-------------------------------------------------------------------------------
This release fixes a bug where the fixed costs from all possible build years
were applied each period, instead of only using the build years that are still
in service in the current period. This increased the apparent cost of storage by
approximately (study length) / (storage life). This bug was introduced in
version 2.0.0b3 and persisted through version 2.0.5, so results from earlier
models will need to be updated.
This release fixes a bug where the fixed costs of storage energy capacity (the
MWh part of storage) from all possible build years were mistakenly applied each
period, instead of only using the build years that are still in service in the
current period. This increased the apparent cost of storage by approximately
(study length) / (storage life). This bug was introduced in version 2.0.0b3 and
persisted through version 2.0.5, so results from earlier models will need to be
updated.

This will be the last version of Switch to work in Python 2. It requires at
This will be the last version of Switch to work in Python 2. It requires at
least Python 2.7.12 and also works with Python 3.

-------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ that they also use to solve models. This supports a number of activities:

To work this way, first install Switch as described above (this will install all
the Switch dependencies, even though you will later reinstall Switch itself).
Then, in a terminal window or Anaconda command prompt Anaconda command prompt,
Then, in a terminal window or Anaconda command prompt,
use the `cd` and `mkdir` commands to create and/or enter the directory where you
would like to store the Switch model code and examples. Once you are in that
directory, run the following commands (don't type the comments that start with
Expand Down
6 changes: 4 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
The Pyomo implementation of the SWITCH model for planning least-cost low-emission electricity grids is licensed under Apache License v2.0 which can be obtained at http://www.apache.org/licenses/LICENSE-2.0
The Switch model for planning least-cost low-emission electricity grids is
licensed under Apache License v2.0 which can be obtained at
http://www.apache.org/licenses/LICENSE-2.0.


Apache License
Expand Down Expand Up @@ -201,4 +203,4 @@ The Pyomo implementation of the SWITCH model for planning least-cost low-emissio
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
3 changes: 0 additions & 3 deletions examples/3zone_toy/inputs/balancing_areas.csv

This file was deleted.

6 changes: 3 additions & 3 deletions examples/3zone_toy/inputs/fuel_supply_curves.csv
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
regional_fuel_market,period,tier,unit_cost,max_avail_at_cost
All_DistOil,2020,0,21.9802,inf
All_DistOil,2020,0,21.9802,.
All_DistOil,2030,0,24.5216,100000.0
All_NG,2020,0,4.4647,1950514555.0
All_NG,2020,1,5.0709,inf
All_NG,2020,1,5.0709,.
All_NG,2030,0,5.925,2368354558.0
All_NG,2030,1,5.925,inf
All_NG,2030,1,5.925,.
North_Bio,2020,0,1.7102,6864985.0
North_Bio,2020,1,3.3941,6782413.0
North_Bio,2030,0,2.0438,6064415.0
Expand Down
2 changes: 1 addition & 1 deletion examples/3zone_toy/inputs/gen_build_predetermined.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GENERATION_PROJECT,build_year,gen_predetermined_cap
GENERATION_PROJECT,build_year,build_gen_predetermined
N-Coal_ST,1995,2
N-Geothermal,2000,1
N-NG_CC,2008,2
Expand Down
8 changes: 4 additions & 4 deletions examples/3zone_toy/inputs/load_zones.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LOAD_ZONE,dbid,existing_local_td,local_td_annual_cost_per_mw
North,1,5.5,66406.5
Central,2,3.5,61663.4
South,3,9.5,128040.0
LOAD_ZONE,dbid,existing_local_td,local_td_annual_cost_per_mw,local_td_loss_rate
North,1,5.5,66406.5,0.053
Central,2,3.5,61663.4,0.053
South,3,9.5,128040.0,0.053
2 changes: 1 addition & 1 deletion examples/3zone_toy/inputs/switch_inputs_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.6
2.0.7
4 changes: 2 additions & 2 deletions examples/3zone_toy/inputs/trans_params.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
trans_capital_cost_per_mw_km,trans_lifetime_yrs,trans_fixed_om_fraction,distribution_loss_rate
1000.0,20,0.03,0.053
trans_capital_cost_per_mw_km,trans_lifetime_yrs,trans_fixed_om_fraction
1000.0,20,0.03
2 changes: 1 addition & 1 deletion examples/3zone_toy/outputs/total_cost.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134733088.429
134733088.42929107
29 changes: 17 additions & 12 deletions examples/3zone_toy_stochastic_PySP/PySPInputGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

"""
from __future__ import print_function

# Inputs directory relative to the location of this script.
inputs_dir = "inputs"
# ScenarioStructure.dat and RootNode.dat will be saved to a
Expand All @@ -58,11 +59,10 @@
stage_list = ["Investment", "Operation"]
stage_vars = {
"Investment": ["BuildGen", "BuildLocalTD", "BuildTx"],
"Operation": ["DispatchGen", "GenFuelUseRate"]
"Operation": ["DispatchGen", "GenFuelUseRate"],
}
# List of scenario names
scenario_list = [
"LowFuelCosts", "MediumFuelCosts", "HighFuelCosts"]
scenario_list = ["LowFuelCosts", "MediumFuelCosts", "HighFuelCosts"]

###########################################################

Expand All @@ -82,6 +82,7 @@
instance = model.load_inputs(inputs_dir=inputs_dir)
print("inputs successfully loaded...")


def save_dat_files():

if not os.path.exists(os.path.join(inputs_dir, pysp_subdir)):
Expand All @@ -92,8 +93,9 @@ def save_dat_files():

dat_file = os.path.join(inputs_dir, pysp_subdir, "RootNode.dat")
print("creating and saving {}...".format(dat_file))
utilities.save_inputs_as_dat(model, instance, save_path=dat_file,
sorted_output=model.options.sorted_output)
utilities.save_inputs_as_dat(
model, instance, save_path=dat_file, sorted_output=model.options.sorted_output
)

#######################
# ScenarioStructure.dat
Expand All @@ -117,7 +119,7 @@ def save_dat_files():

f.write("param NodeStage := RootNode {}\n".format(stage_list[0]))
for s in scenario_list:
f.write(" {scen} {st}\n".format(scen=s,st=stage_list[1]))
f.write(" {scen} {st}\n".format(scen=s, st=stage_list[1]))
f.write(";\n\n")

f.write("set Children[RootNode] := ")
Expand All @@ -127,7 +129,7 @@ def save_dat_files():

f.write("param ConditionalProbability := RootNode 1.0")
# All scenarios have the same probability in this example
probs = [1.0/len(scenario_list)] * (len(scenario_list) - 1)
probs = [1.0 / len(scenario_list)] * (len(scenario_list) - 1)
# The remaining probability is lumped in the last scenario to avoid rounding issues
probs.append(1.0 - sum(probs))
for (s, p) in zip(scenario_list, probs):
Expand All @@ -150,14 +152,16 @@ def write_var_name(f, cname):
if hasattr(instance, cname):
dimen = getattr(instance, cname).index_set().dimen
if dimen == 0:
f.write(" {cn}\n".format(cn=cname))
f.write(" {cn}\n".format(cn=cname))
else:
indexing = (",".join(["*"]*dimen))
indexing = ",".join(["*"] * dimen)
f.write(" {cn}[{dim}]\n".format(cn=cname, dim=indexing))
else:
raise ValueError(
"Variable '{}' is not a component of the model. Did you make a typo?".
format(cname))
"Variable '{}' is not a component of the model. Did you make a typo?".format(
cname
)
)

for st in stage_list:
f.write("set StageVariables[{}] := \n".format(st))
Expand All @@ -171,8 +175,9 @@ def write_var_name(f, cname):
f.write(" Operation OperationCost\n")
f.write(";")


####################

if __name__ == '__main__':
if __name__ == "__main__":
# If the script is executed on the command line, then the .dat files are created.
save_dat_files()
42 changes: 26 additions & 16 deletions examples/3zone_toy_stochastic_PySP/ReferenceModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

# Ideally, we would use the main codebase to generate the model, but the
# mandatory switch argument parser is interferring with pysp's command line tools
#model = switch_model.solve.main(return_model=True)
# model = switch_model.solve.main(return_model=True)

module_list = switch_model.solve.get_module_list(args=None)
model = utilities.create_model(module_list, args=[])
Expand All @@ -53,14 +53,19 @@
# are nested inside another function in the financials module, they can't
# be called from this script.


def calc_tp_costs_in_period(m, t):
return sum(
getattr(m, tp_cost)[t] * m.tp_weight_in_year[t]
for tp_cost in m.Cost_Components_Per_TP)
return sum(
getattr(m, tp_cost)[t] * m.tp_weight_in_year[t]
for tp_cost in m.Cost_Components_Per_TP
)


def calc_annual_costs_in_period(m, p):
return sum(
getattr(m, annual_cost)[p]
for annual_cost in m.Cost_Components_Per_Period)
return sum(
getattr(m, annual_cost)[p] for annual_cost in m.Cost_Components_Per_Period
)


# In the current version of Switch, all annual costs are defined
# by First Stage decision variables, such as fixed O&M and capital
Expand All @@ -73,14 +78,19 @@ def calc_annual_costs_in_period(m, p):
# decisions in this example.
# Further comments on this are written in the Readme file.

model.InvestmentCost = Expression(rule=lambda m: sum(
calc_annual_costs_in_period(m, p) * m.bring_annual_costs_to_base_year[p]
for p in m.PERIODS))

model.OperationCost = Expression(rule=lambda m:
sum(
sum(calc_tp_costs_in_period(m, t) for t in m.TPS_IN_PERIOD[p]
) * m.bring_annual_costs_to_base_year[p]
for p in m.PERIODS))
model.InvestmentCost = Expression(
rule=lambda m: sum(
calc_annual_costs_in_period(m, p) * m.bring_annual_costs_to_base_year[p]
for p in m.PERIODS
)
)

model.OperationCost = Expression(
rule=lambda m: sum(
sum(calc_tp_costs_in_period(m, t) for t in m.TPS_IN_PERIOD[p])
* m.bring_annual_costs_to_base_year[p]
for p in m.PERIODS
)
)

print("model successfully loaded...")
3 changes: 0 additions & 3 deletions examples/3zone_toy_stochastic_PySP/inputs/balancing_areas.csv

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GENERATION_PROJECT,build_year,gen_predetermined_cap
GENERATION_PROJECT,build_year,build_gen_predetermined
N-Coal_ST,1995,2
N-Geothermal,2000,1
N-NG_CC,2008,2
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.6
2.0.7
11 changes: 8 additions & 3 deletions examples/3zone_toy_stochastic_PySP/pha_bounds_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
# Use this by adding terms like the following to the runph command:
# --linearize-nonbinary-penalty-terms=5 --bounds-cfgfile=pha_bounds_cfg.py


def pysp_boundsetter_callback(self, scenario_tree, scenario):
m = scenario._instance # see pyomo/pysp/scenariotree/tree_structure.py
m = scenario._instance # see pyomo/pysp/scenariotree/tree_structure.py

# BuildLocalTD
for p in m.PERIODS:
for lz in m.LOAD_ZONES:
m.BuildLocalTD[lz, p].setub(2 * m.zone_expected_coincident_peak_demand[lz, p])
m.BuildLocalTD[lz, p].setub(
2 * m.zone_expected_coincident_peak_demand[lz, p]
)

# Estimate an upper bound of system peak demand for limiting generation unit
# & transmission line builds
system_wide_peak = {}
for p in m.PERIODS:
system_wide_peak[p] = sum(
m.zone_expected_coincident_peak_demand[lz, p] for lz in m.LOAD_ZONES)
m.zone_expected_coincident_peak_demand[lz, p] for lz in m.LOAD_ZONES
)

# BuildGen
for g, bld_yr in m.NEW_GEN_BLD_YRS:
Expand All @@ -27,6 +31,7 @@ def pysp_boundsetter_callback(self, scenario_tree, scenario):
for tx, bld_yr in m.TRANS_BLD_YRS:
m.BuildTx[tx, bld_yr].setub(5 * system_wide_peak[bld_yr])


# For some reason runph looks for pysp_boundsetter_callback when run in
# single-thread mode and ph_boundsetter_callback when called from mpirun with
# remote execution via pyro. so we map both names to the same function.
Expand Down
28 changes: 17 additions & 11 deletions examples/3zone_toy_stochastic_PySP/rhosetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@
from switch_model.utilities import iteritems

try:
from pyomo.repn import generate_standard_repn # Pyomo >=5.6
from pyomo.repn import generate_standard_repn # Pyomo >=5.6

newPyomo = True
except ImportError:
from pyomo.repn import generate_canonical_repn # Pyomo <=5.6
from pyomo.repn import generate_canonical_repn # Pyomo <=5.6

newPyomo = False


def ph_rhosetter_callback(ph, scenario_tree, scenario):
# Derive coefficients from active objective
cost_expr = next(scenario._instance.component_data_objects(
Objective, active=True, descend_into=True
))
# Derive coefficients from active objective
cost_expr = next(
scenario._instance.component_data_objects(
Objective, active=True, descend_into=True
)
)
set_rho_values(ph, scenario_tree, scenario, cost_expr)


Expand Down Expand Up @@ -57,8 +62,7 @@ def set_rho_values(ph, scenario_tree, scenario, cost_expr):

cost_coefficients = {}
var_names = {}
for (variable, coef) in \
zip(standard_repn.linear_vars, standard_repn.linear_coefs):
for (variable, coef) in zip(standard_repn.linear_vars, standard_repn.linear_coefs):
variable_id = symbol_map.getSymbol(variable)
cost_coefficients[variable_id] = coef
var_names[variable_id] = variable.name
Expand All @@ -72,11 +76,13 @@ def set_rho_values(ph, scenario_tree, scenario, cost_expr):
tree_node,
scenario,
variable_id,
cost_coefficients[variable_id] * rho_coefficient)
cost_coefficients[variable_id] * rho_coefficient,
)
set_rho = True
break
if not set_rho:
print(
"Warning! Could not find tree node for variable {}; rho not set."
.format(var_names[variable_id])
"Warning! Could not find tree node for variable {}; rho not set.".format(
var_names[variable_id]
)
)
1 change: 1 addition & 0 deletions examples/3zone_toy_stochastic_PySP/rhosetter_FS_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# The rhosetter module should be in the same directory as this file.
from rhosetter import set_rho_values


def ph_rhosetter_callback(ph, scenario_tree, scenario):
# This component name must match the expression used for first stage
# costs defined in the ReferenceModel.
Expand Down
3 changes: 0 additions & 3 deletions examples/carbon_cap/inputs/balancing_areas.csv

This file was deleted.

Loading