Run EPM from Python#
Using the Python interface enables advanced features such as scenario creation, sensitivity analysis, and Monte Carlo simulations.
You don’t need to know Python—just follow the steps below.
You must have Python installed. See the prerequisites for setup instructions.
1. Create a Python Environment#
A Python environment ensures that all required libraries for EPM are available and isolated from other projects.
Important:
Before creating the environment, you should have GAMS installed on your computer, with a recent version (ideally >= 48).
On Windows#
If you plan to run Monte Carlo analysis on Windows, first install Microsoft C++ Build Tools (needed to compile the optional chaospy package):
Go to VSCode build tools
Download and install Build Tools for Visual Studio.
During installation, check the option:
C++ build tools
Then you can follow these steps:
Open a terminal or command prompt (Anaconda Prompt).
Navigate to the folder where you cloned EPM:
cd EPM
Create a new environment named
epm_env:conda create -n epm_env python=3.10
Activate the environment:
conda activate epm_env
Install the required libraries:
pip install -r requirements.txt
(Optional – Monte Carlo only) Install
chaospy:pip install chaospy==4.3.18
On Mac#
Follow the same steps as on Windows (minus the Build Tools prerequisite). Install chaospy only if you plan to run Monte Carlo analysis.
On Linux (remote server)#
Open a terminal or command prompt.
Navigate to the folder where you cloned EPM:
cd EPM
Create a new environment named
epm_env, specifying some Linux compilers.
conda create -n epm_env python=3.10 numpy cython gcc_linux-64 gxx_linux-64 -c conda-forge
Activate the environment:
conda activate epm_env
export TMPDIR=~/pip_tmp
Install additional packages from the shared
requirements.txtfile:
pip install -r requirements.txt
(Optional – Monte Carlo only) Install
chaospy:
pip install chaospy==4.3.18
2. Run the Model (Basic Test)#
Once the environment is set up, you can test the model:
Navigate to the
epmcode directory:cd epm
Run the model:
python epm.py
This runs the model using the default input folder and configuration.
3. Input Data#
All input data need to be within the epm/input folder. The path of the input file are defined based on this reference.
Input data are defined in a folder folder_input and controlled via a config.csv file, which specifies what CSV files to use for each parameter in the model.
Example input structure is provided in the GitHub
mainbranch under theinputfolder. See the input documentation for full details.
By default, the model uses the data_test input folder and input/config.csv file, but command line arguments allow you to specify different folders and configurations.
Input data for EPM is specified through two key components:
Input Folder (
FOLDER_INPUT)
This folder contains all the necessary.csvinput files for the model, organized by type (e.g.,data_test_region). It holds the raw data the model reads.
--folder_input#
Type: string
Default:
data_testPurpose: Folder containing the CSV input data for the simulation.
Notes: Should contain the input files referenced in the config.
Configuration File (
config.csv)
This CSV file defines which input files correspond to which parameters in the model for the baseline scenario. It includes the parameternameand the relativefilepath inside the input folder. An example of a configuration file is available here: Exampleconfig.csv
--config#
Type: string
Default:
input/config.csvPurpose: Specifies the configuration file that defines baseline input CSV files and parameters.
Notes: The config file is required for proper data loading and scenario configuration.
--modeltype#
Type: string
Default:
None(falls back to the value defined inconfig.csv)Purpose: Overrides the model type used by GAMS; accepts values such as
MIPorRMIP.Notes: Use this flag to test relaxed problems (
RMIP) or enforce a specific formulation without editingconfig.csv.
Important Configuration Options in config.csv
Option |
Description |
|---|---|
|
How the model is solved: |
|
Logging verbosity: |
|
Report size: |
|
Solver formulation: |
|
Relative path to the CPLEX options file (for example |
4. Specifying Optional Arguments for your Run#
Check Run EPM Advanced Features for additional explanations on advanced features like sensitivity analysis, Monte Carlo simulations, and scenario management.
--simple#
Type: list of strings
Default: [‘DiscreteCap’, ‘y’]
Purpose: Enables simplified model modes by toggling specified parameters.
--cpu#
Type: integer
Default: 1
Purpose: Number of CPU cores to use for running scenarios in parallel.
--engine#
Type: string
Default: None
Purpose: Path to a GAMS Engine file for running simulations remotely.
--postprocess#
Type: string
Default: None
Purpose: Runs only postprocessing on an existing output folder, skipping simulation.
--plot_selected_scenarios#
Type: list of strings
Default:
"all"Purpose: Specifies scenarios to plot in postprocessing.
--no_plot_dispatch#
Type: flag (boolean)
Default: False (dispatch plotting enabled by default)
Purpose: Disables automatic creation of dispatch plots to save time and memory.
--graphs_folder#
Type: string
Default:
imgPurpose: Directory where postprocessing graphs and plots will be saved.
--simulation_label#
Type: string
Default: timestamp generated name
Purpose: Replaces the automatic timestamp with a custom name for the results folder.
--scenarios#
Type: string
Default: None (flag omitted)
Purpose: Path to a scenario definition file specifying multiple scenarios and their overridden inputs.
Notes: Use
--scenarioswith no value to load the defaultscenarios.csv. Provide a custom path (for example--scenarios alternative.csv) to select a different file. If the flag is omitted entirely, only the baseline scenario runs.
--selected_scenarios#
Type: list of strings
Default: None
Purpose: Specifies a subset of scenarios from the scenarios file to run.
Alias:
-SExample:
-S baseline ScenarioA
--sensitivity#
Type: flag (boolean)
Default: False
Purpose: Enables sensitivity analysis which automatically modifies select parameters to evaluate model sensitivity.
Usage: Include
--sensitivityto enable.
--project_assessment#
Type: list of strings
Default: None
Purpose: Specifies projects to exclude from the simulation to assess counterfactual scenarios.
Example:
--project_assessment SolarProject
--montecarlo#
Type: flag (boolean)
Default: False
Purpose: Enables Monte Carlo simulation by sampling uncertain parameters multiple times.
Usage: Include
--montecarloto enable.
--montecarlo_samples#
Type: integer
Default: 10
Purpose: Number of random samples/scenarios to generate during Monte Carlo analysis.
Notes: Larger numbers increase accuracy but require more computation.
--uncertainties#
Type: string
Default: None
Purpose: CSV file that specifies uncertain parameters and their distributions for Monte Carlo sampling.
Notes: Required if
--montecarlois enabled.
--reduced_output#
Type: flag (boolean)
Default: False
Purpose: Generates reduced-size outputs to save memory, useful for large Monte Carlo runs.
Example Usage#
Run EPM with a custom input folder, sensitivity analysis enabled, and multiple CPU cores:
It is important to specify the
config.csvpath when running python. Otherwise, a default value will be used, calibrated on thedata_test_regionfolder.
python epm.py --folder_input data_test_region --config input/data_test_region/config.csv --sensitivity --cpu 4
Run postprocessing only on a previous simulation folder:
python epm.py --postprocess simulations_run_2025-05-01_12-00-00
Run Monte Carlo analysis with 20 samples and a specified uncertainties file:
python epm.py --folder_input data_test_region --config input/data_test_region/config.csv --montecarlo --montecarlo_samples 20 --uncertainties input/data_test_region/uncertainties.csv