-
Install Python (at least version 3.8). You need Python since the entire model is written in Python and is run through Python.
-
Install Gurobi or another solver (e.g. GPLK). Gurobi requires applying for a free academic license on their website.
-
Install Anaconda (or miniconda for a lightweight version that works just the same). Anaconda allows you to work in multiple virtual environments which is often helpful. You can also use Python's built-in
venv
package.
-
Clone this repository to your computer:
git clone /~https://github.com/REAM-lab/switch
-
Navigate to the repository:
cd switch
. -
Create a Python virtual environment from where you'll run Switch:
conda create --name switch
. -
Activate the newly created environment:
conda activate switch
. -
Install the
switch_model
library using:pip install --editable .[dev]
. The--editable
flag indicates that theswitch
command will always use your latest local copy. That is, you won't need to reinstall the package after making a change to the switch code. Adding[dev]
in the command results in extra packages required for development being installed. These packages are listed inextra_require
insetup.py
. There are other options for example,pip install --editable .[plotting,dev]
would install packages for plotting and development. -
Run
switch --help
to make sure your package installed properly.
-
Run
switch new
in an empty folder. This will create aconfig.yaml
file. -
In the
config.yaml
file, specify which scenario you wish to run by specifying thescenario_id
. Note that if your scenario doesn't already exist in the database, you'll need to create it. -
Run
switch get_inputs
to download the scenario input data.
- Run
switch solve --recommended
to solve the scenario. For more options, runswitch solve --help
-
Run
switch graph
to generate graphs for the scenario. -
Optionally, to compare your results to another scenario's results (e.g. a baseline), run
switch compare
.
There are a few techniques to debug a model depending on the issue encountered.
-
All your usual Python debugging techniques are valid. For example, inspecting the error message and stacktrace then looking at the source code to try to figure out what went wrong.
-
You can add
breakpoint()
anywhere in the Python code to pause execution and inspect what is happening. You can also runswitch solve --enable-breakpoints
to automatically pause at key points. -
When in a breakpoint, you can inspect a specific model expression or variable with
pprint()
. For example you can run,model.BuildGen.pprint()
to see the values for theBuildGen
variable. -
Although this is rarely necessary, if you wish to see what is being passed to Gurobi, you can run
switch solve --recommended-debug
. This will create atemp
folder that will contain many files including a.pyomo.lp
file with all the linear programming equations and a.gurobi.txt
with the raw results from solving the linear program. This is sometimes useful if you wish to debug directly in Gurobi since gurobi's console can directly read and load the.pyomo.lp
file. -
If a model is infeasible you can use
--gurobi-find-iis
with--recommended-debug
to automatically generate a.iis
file which will describe the minimal set of equations that make the model infeasible.