ml4opf

Machine Learning for Optimal Power Flow

https://github.com/ai4opt/ml4opf

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.2%) to scientific vocabulary
Last synced: 10 months ago · JSON representation ·

Repository

Machine Learning for Optimal Power Flow

Basic Info
  • Host: GitHub
  • Owner: AI4OPT
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 15.9 MB
Statistics
  • Stars: 14
  • Watchers: 2
  • Forks: 3
  • Open Issues: 5
  • Releases: 0
Created about 2 years ago · Last pushed over 1 year ago
Metadata Files
Readme License Citation

README.md

Copyright Georgia Tech 2024

test status<!-- coverage --> docs status

ML4OPF

ML4OPF is a Python package for developing machine learning proxy models for optimal power flow. It is built on top of PyTorch and PyTorch Lightning, and is designed to be modular and extensible. The main components are:

  • formulations: The main interface to the OPF formulations ACOPF, DCOPF, and Economic Dispatch.

    • Each OPF formulation has three main component classes: OPFProblem, OPFViolation, and OPFModel. The OPFProblem class loads and parses data from disk, the OPFViolation class calculates constraints residuals, incidence matrices, objective value, etc., and the OPFModel class is an abstract base class for proxy models.

Documentation based on docstrings is live here.

Installation

To install ml4opf on macOS (CPU/MPS) and Windows (CPU), run: ```bash pip install git+ssh://git@github.com/AI4OPT/ML4OPF.git

or, to install with optional dependencies (options: "all", "dev", "viz"):

pip install "ml4opf[all] @ git+ssh://git@github.com/AI4OPT/ML4OPF.git" If you don't already have PyTorch on Linux (CPU/CUDA/ROCm) or Windows (CUDA), make sure to provide the correct `--index-url` which you can find [here](https://pytorch.org/get-started/locally/). For example, to install from scratch with CUDA 12.6 and all optional dependencies: bash pip install "ml4opf[all] @ git+ssh://git@github.com/AI4OPT/ML4OPF.git" \ --index-url https://download.pytorch.org/whl/cu126 \ --extra-index-url https://pypi.python.org/simple/ ```

For development, the recommended installation method is using Conda environment files provided at environment.yml and environment_cuda.yml: bash git clone git@github.com:AI4OPT/ML4OPF.git # clone this repo cd ML4OPF # cd into the repo conda env create -f environment.yml # create the environment conda activate ml4opf # activate the environment pip install -e ".[all]" # install ML4OPF

Usage

Training a BasicNeuralNet for ACOPF

```python import torch

load data

from ml4opf import ACProblem

data_path = ...

problem = ACProblem(data_path)

make a basic neural network model

from ml4opf.models.basic_nn import ACBasicNeuralNet # requires pytorch-lightning

config = { "optimizer": "adam", "learningrate": 1e-3, "loss": "mse", "hiddensizes": [500,300,500], "activation": "sigmoid", "boundrepair": "none" # optionally clamp outputs to bounds (choices: "sigmoid", "relu", "clamp") }

model = ACBasicNeuralNet(config, problem)

model.train(trainerkwargs={'maxepochs': 100, 'accelerator': 'auto'}) # pass args to the PyTorch Lightning Trainer

evals = model.evaluate_model()

from ml4opf.viz import makestatsdf print(makestatsdf(evals))

model.savecheckpoint("./basic300bus") # creates a folder called "basic_300bus" with a file "trainer.ckpt" in it. ```

Manually Loading Data

```python import torch

from ml4opf import ACProblem

data_path = ...

parse HDF5/JSON

problem = ACProblem(data_path)

get train/test set:

traindata = problem.traindata testdata = problem.testdata

traindata['input/pd'].shape # torch.Size([52863, 201]) testdata['input/pd'].shape # torch.Size([5000, 201])

if needed, convert the HDF5 data to a tree dictionary instead of a flat dictionary:

from ml4opf.parsers import PGLearnParser h5tree = PGLearnParser.maketree(traindata) # this tree structure should # exactly mimic the # structure of the HDF5 file. h5tree['input']['pd'].shape # torch.Size([52863, 201]) ```

Acknowledgements

This material is based upon work supported by the National Science Foundation AI Institute for Advances in Optimization (AI4OPT) under Grant No. 2112533 and the National Science Foundation Graduate Research Fellowship under Grant No. DGE-2039655. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

Owner

  • Name: AI4OPT
  • Login: AI4OPT
  • Kind: organization

Citation (CITATION.cff)

cff-version: 1.2.0
title: ML4OPF
message: If you use this software, please cite it as below.
type: software
authors:
  - given-names: Michael
    family-names: Klamkin
    email: klam@gatech.edu
    affiliation: >-
      Artificial Intelligence Institute for Advances in
      Optimization
    orcid: 'https://orcid.org/0000-0002-2131-8603'
repository-code: 'https://github.com/AI4OPT/ML4OPF'
license: MIT

GitHub Events

Total
  • Issues event: 21
  • Watch event: 14
  • Delete event: 17
  • Issue comment event: 13
  • Push event: 48
  • Pull request review event: 5
  • Pull request review comment event: 5
  • Pull request event: 32
  • Fork event: 5
  • Create event: 17
Last Year
  • Issues event: 21
  • Watch event: 14
  • Delete event: 17
  • Issue comment event: 13
  • Push event: 48
  • Pull request review event: 5
  • Pull request review comment event: 5
  • Pull request event: 32
  • Fork event: 5
  • Create event: 17

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 4
  • Total pull requests: 9
  • Average time to close issues: about 1 month
  • Average time to close pull requests: about 19 hours
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 0.5
  • Average comments per pull request: 0.11
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 4
  • Pull requests: 9
  • Average time to close issues: about 1 month
  • Average time to close pull requests: about 19 hours
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 0.5
  • Average comments per pull request: 0.11
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • klamike (10)
  • mtanneau (3)
Pull Request Authors
  • klamike (18)
  • mtanneau (4)
Top Labels
Issue Labels
Pull Request Labels
documentation (1)

Dependencies

.github/actions/build/action.yaml actions
  • actions/setup-python v2 composite
.github/workflows/docs.yaml actions
  • ./.github/actions/build * composite
  • actions/checkout v2 composite
.github/workflows/tests.yaml actions
  • ./.github/actions/build * composite
  • actions/checkout v2 composite
environment.yml pypi
pyproject.toml pypi
  • h5py *
  • lightning *
  • torch *