PyOPF
is Optimal Power Flow (OPF) modeling framework in Python.
This modeling is basically based on Pyomo
, which is a solver-agnostic optimization modeling package in Python.
PyOPF
generally can take PGLib based input and formulate various OPF problems including AC-OPF, DC-OPF.
pip install opf
- Dependencies
- python>=3.8
- pyomo>=6.5.0
- numpy>=1.22.3
- ipopt>=1.0.3
-
⭕ AC-OPF (AC Optimal Power Flow):
model = opf.build_model('acopf')
- AC-OPF with a polar bus voltage variable representations.
- The detailed formulation can be found in PGLib.
PyOPF
takes the the input files from PGLib, which is basically based on MATPOWER format.- Uses various solvers supported in Pyomo including IPOPT and Gurobi to solve problem instances.
-
⭕ DC-OPF (DC Optimal Power Flow)
model = opf.build_model('dcopf') # base DC-OPF model model = opf.build_model('dcopf-ptdf') # DC-OPF model using PTDF
- Linear approximation to AC-OPF.
- Also support PTDF (power transfer distribution factor) based formulation.
- Only use active power generations and bus voltage angles (for base DC-OPF) as variables.
- Like AC-OPF, PGLib m-files can be taken as input.
PyOPF
fully supports primal and dual warmstarting for IPOPT. Documentation is to be added.model.setup_warmstart(warmstart_solution_dict)
Running AC-OPF from PGLib.
-
Before solving the AC-OPF, you should install IPOPT, which is a canonical solver for AC-OPF, as follows:
conda install -c conda-forge ipopt
-
Running the following AC-OPF problem
import opf # build abstract model for AC-OPF model = opf.build_model('acopf') # load pglib input model file network = opf.parse_file("./data/pglib_opf_case5_pjm.m") # create the model instance (concrete model) model.instantiate(network) # solve the problem result = model.solve(solver_option={'print_level' : 5, 'linear_solver': 'ma27'}, tee=True) # check the optimal objective value print('obj value', result['obj_cost']) # check the (primal) optimal solution print('primal solution', result['sol']['primal'])
- If you exploit this repository in your research, please cite using the following BibTeX:
@software{
PyOPF_2023,
author = {Park, Seonho},
doi = {10.5281/zenodo.7772531},
license = {MIT},
month = {10},
title = {{PyOPF: Optimal Power Flow Modeling in Python}},
version = {0.3.1},
year = {2023}
}