Skip to content

Commit 79db76b

Browse files
General-purpose improvements from the WECC branch; more exports, utility function upgrades like automatically pickling the an entire solution object and reloading it, optionally plotting results, updates to a few examples to make them consistent with the current code.
1 parent 67c54b1 commit 79db76b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+525
-861
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
.DS_Store
55
gurobi.log
66
switch_model.egg-info/
7+
venv

AUTHORS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
# contributions of individuals can be tracked via git history.
55

66
Matthias Fripp <mfripp@hawaii.edu>
7+
Rodrigo Henriquez <rhenriqueza@uc.cl>
8+
Patricia Hidalgo-Gonzalez <patricia.hidalgo.g@berkeley.edu>
79
Josiah Johnston <siah@berkeley.edu>
810
Benjamin Maluenda <bmaluend@uc.cl>
911
Ana Mileva
1012
Mark Seaborn
11-
Rodrigo Henriquez <rhenriqueza@uc.cl>
13+
1214

1315
# Organizations
1416

DEV_INSTALL.txt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
ADVANCED INSTALLATION NOTES FOR DEVELOPERS AND ADVANCED USERS
2+
3+
If you are prone to work with more than one version of switch, you will
4+
greatly benefit from python virtual environments which isolate your project's
5+
python software from other versions that may be installed on the computer.
6+
Software requirements and compatibilities change over time, sometimes in
7+
incompatible ways. Virtual environments also help developers ensure they have
8+
included all necessary dependencies in setup.py and aren't relying on
9+
mannually installed system libraries. Using virtual environments to
10+
encapsulate each project's customized software allows active and archived
11+
projects to coexist on a single computer. These instructions assume you have
12+
read INSTALL, have installed Anaconda (or equivalent), pip and solver
13+
prerequisites.
14+
15+
INSTALLATION WITH PYTHON VIRTUAL ENVIRONMENTS FOR DEVELOPMENT
16+
17+
1. Open either a terminal or Anaconda command prompt (Start -> Anaconda ->
18+
Anaconda Prompt)
19+
20+
2a. DEVELOPERS
21+
Developers often work with switch example directories and don't necessarily
22+
have a separate folder with inputs for analysis. In this case, the source
23+
directory doubles as your project directory. Execute these commands, but
24+
set PROJECT_DIR to the actual path you want to use.
25+
PROJECT_DIR=/path/to/new/switch/checkout
26+
SRC_DIR="$PROJECT_DIR"
27+
28+
2b. ANALYSTS
29+
Analysts typically have a directory per project that stores data for their
30+
input scenarios as well as a copy of the code they are using. Execute these
31+
commands, but set PROJECT_DIR to the actual path you want to use.
32+
PROJECT_DIR=/path/to/project/directory
33+
SRC_DIR="$PROJECT_DIR"/switch_source
34+
35+
Note: If you are using one of Matthias's packaged scenarios with a
36+
submodule or subtree, set SRC_DIR to that subfolder instead of doing a
37+
fresh git checkout. In this case, skip step 3.
38+
39+
3. Download a copy of switch
40+
git clone https://github.com/switch-model/switch.git "$SRC_DIR"
41+
42+
4. Create a virtual environment in your project directory, and install switch
43+
and its prerequisites.
44+
cd "$PROJECT_DIR"
45+
pip install virtualenv
46+
virtualenv venv
47+
source venv/bin/activate
48+
pip install --editable "$SRC_DIR"
49+
50+
Note: The --editable flag ensures that any changes to your downloaded copy
51+
of switch will be immediately reflected to your installed copy in the
52+
virtual environment.
53+
54+
5. Record the exact version of every library you are using so you can
55+
precisely replicate this setup in the future.
56+
pip freeze > requirements.txt
57+
Without this step, you are at higher risk of not being able to readily
58+
repeat or extend this analysis, especially if future releases of libraries
59+
are not completely backwards compatible (this has happened a few times in
60+
the past few years).
61+
62+
63+
EXECUTION
64+
65+
1. Open either a terminal or Anaconda command prompt (Start -> Anaconda ->
66+
Anaconda Prompt) and navigate to your project directory.
67+
2. Activate your virtual environment with the following command:
68+
source venv/bin/activate
69+
3. Execute switch like normal
70+
switch solve ...

examples/3zone_toy_stochastic_PySP/PySPInputGenerator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
# Stage names. Can be any string and must be specified in order.
5757
stage_list = ["Investment", "Operation"]
5858
stage_vars = {
59-
"Investment": ["BuildProj", "BuildLocalTD", "BuildTrans"],
60-
"Operation": ["DispatchProj", "ProjFuelUseRate"]
59+
"Investment": ["BuildGen", "BuildLocalTD", "BuildTx"],
60+
"Operation": ["DispatchGen", "GenFuelUseRate"]
6161
}
6262
# List of scenario names
6363
scenario_list = [

examples/3zone_toy_stochastic_PySP/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Available at: http://mpc.zib.de/index.php/MPC/article/viewFile/85/39
1313
Pyomo Online Documentation:
1414
https://software.sandia.gov/downloads/pub/pyomo/PyomoOnlineDocs.html
1515

16-
If any concepts on stochastic programming need to be adquired or refreshed, a
16+
If any concepts on stochastic programming need to be acquired or refreshed, a
1717
good reference is: Birge, J. R. & Louveaux, F. (2011). Introduction to
1818
Stochastic Programming. 2nd Edition. Springer Science+Business Media.
1919

examples/3zone_toy_stochastic_PySP/ReferenceModel.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,13 @@
5353
# be called from this script.
5454

5555
def calc_tp_costs_in_period(m, t):
56-
return sum(
57-
getattr(m, tp_cost)[t] * m.tp_weight_in_year[t]
58-
for tp_cost in m.cost_components_tp)
59-
56+
return sum(
57+
getattr(m, tp_cost)[t] * m.tp_weight_in_year[t]
58+
for tp_cost in m.Cost_Components_Per_TP)
6059
def calc_annual_costs_in_period(m, p):
61-
return sum(
62-
getattr(m, annual_cost)[p]
63-
for annual_cost in m.cost_components_annual)
60+
return sum(
61+
getattr(m, annual_cost)[p]
62+
for annual_cost in m.Cost_Components_Per_Period)
6463

6564
# In the current version of Switch-Pyomo, all annual costs are defined
6665
# by First Stage decision variables, such as fixed O&M and capital
@@ -74,12 +73,13 @@ def calc_annual_costs_in_period(m, p):
7473
# Further comments on this are written in the Readme file.
7574

7675
model.InvestmentCost = Expression(rule=lambda m: sum(
77-
calc_annual_costs_in_period(m, p) * financials.uniform_series_to_present_value(
78-
m.discount_rate, m.period_length_years[p]) * financials.future_to_present_value(
79-
m.discount_rate, (m.period_start[p] - m.base_financial_year)) for p in m.PERIODS))
80-
model.OperationCost = Expression(rule=lambda m: sum(
81-
sum(calc_tp_costs_in_period(m, t) for t in m.PERIOD_TPS[p]) * financials.uniform_series_to_present_value(
82-
m.discount_rate, m.period_length_years[p]) * financials.future_to_present_value(
83-
m.discount_rate, (m.period_start[p] - m.base_financial_year)) for p in m.PERIODS))
76+
calc_annual_costs_in_period(m, p) * m.bring_annual_costs_to_base_year[p]
77+
for p in m.PERIODS))
78+
79+
model.OperationCost = Expression(rule=lambda m:
80+
sum(
81+
sum(calc_tp_costs_in_period(m, t) for t in m.TPS_IN_PERIOD[p]
82+
) * m.bring_annual_costs_to_base_year[p]
83+
for p in m.PERIODS))
8484

8585
print "model successfully loaded..."

0 commit comments

Comments
 (0)