-
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
venvpackage.
-
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_modellibrary using:pip install --editable .[dev]. The--editableflag indicates that theswitchcommand 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_requireinsetup.py. There are other options for example,pip install --editable .[plotting,dev]would install packages for plotting and development. -
Run
switch --helpto make sure your package installed properly.
-
Run
switch newin an empty folder. This will create aconfig.yamlfile. -
In the
config.yamlfile, 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_inputsto download the scenario input data.
- Run
switch solve --recommendedto solve the scenario. For more options, runswitch solve --help
-
Run
switch graphto 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-breakpointsto 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 theBuildGenvariable. -
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 atempfolder that will contain many files including a.pyomo.lpfile with all the linear programming equations and a.gurobi.txtwith 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.lpfile. -
If a model is infeasible you can use
--gurobi-find-iiswith--recommended-debugto automatically generate a.iisfile which will describe the minimal set of equations that make the model infeasible.