← 开源
khalil-research

PyEPO

A PyTorch-based End-to-End Predict-then-Optimize Library for Linear and Integer Programming

Model DevelopmentClassical MLJupyter Notebook
在 GitHub 打开
增长势头
+024 小时新增 Star0.0%
694
Star
90
Fork
+1
本周
6
贡献者
创建于 2021-02-12 · 更新于 2026-10-11 · 今日第 14902 名
主要开发者
LucasBoTangsenneberdenjacobmosseri

khalil-research/PyEPO 排名第 14,902,有 694 个星标。

同类别比较

khalil-research/PyEPO 排名第 14,902,此处有 8 个同类条目;flink-extended/dl-on-flink 排名第 14,901。

同类别比较
名称排名指标
aleju/mario-ai14,883
语言:
Lua
星标数:
695
分叉数:
142
简介:
Playing Mario with Deep Reinforcement Learning
mv-lab/swin2sr14,889
语言:
Python
星标数:
695
分叉数:
83
简介:
[ECCV] Swin2SR: SwinV2 Transformer for Compressed Image Super-Resolution and Restoration. Advances in Image Manipulation (AIM) workshop ECCV 2022. Try it out! over 3.3M runs https://replicate.com/mv-lab/swin2sr
soobinseo/Transformer-TTS14,890
语言:
Python
星标数:
695
分叉数:
139
简介:
A Pytorch Implementation of "Neural Speech Synthesis with Transformer Network"
flink-extended/dl-on-flink14,901
语言:
Java
星标数:
694
分叉数:
196
简介:
Deep Learning on Flink aims to integrate Flink and deep learning frameworks (e.g. TensorFlow, PyTorch, etc) to enable distributed deep learning training and inference on a Flink cluster.
KarhouTam/FL-bench14,908
语言:
Python
星标数:
693
分叉数:
116
简介:
Benchmark of federated learning. Dedicated to the community. 🤗
ankane/eps14,913
语言:
Ruby
星标数:
693
分叉数:
15
简介:
Machine learning for Ruby
elastic/eland14,915
语言:
Python
星标数:
693
分叉数:
112
简介:
Python Client and Toolkit for DataFrames, Big Data, Machine Learning and ETL in Elasticsearch
microsoft/LLM2CLIP14,920
语言:
Python
星标数:
693
分叉数:
34
简介:
LLM2CLIP significantly improves already state-of-the-art CLIP models.
关键参数与规格
关键参数与规格
参数值
语言Jupyter Notebook
类别Model Development
子类别Classical ML
关键词Optimization
星标数694
分叉数90
贡献者6
创建日期2021-02-12
更新日期2026-10-11
1 天星标数0
7 天星标数1
排名14,902
上次排名14,737
排名变化-165
7 天星标排名10,912
上次 7 天星标排名10,969
7 天星标排名变化57
总星标排名14,979
上次总星标排名14,956
总星标排名变化-23
国家Canada
README 摘录

PyEPO: A PyTorch/JAX-based End-to-End Predict-then-Optimize Tool Learning Framework Publication This repository is the official implementation of the paper: PyEPO: A PyTorch-based End-to-End Predict-then-Optimize Library for Linear and Integer Programming (Mathematical Programming Computation, 2024) Citation: If you use the **CaVE** loss, please also cite: Introduction is a Python library for predict-then-optimize. It focuses on problems where a model predicts objective coefficients and the feasible region is fixed, then

trains the predictor against downstream decision quality rather than prediction error alone. models optimization problems with GurobiPy, COPT, Pyomo, Google OR-Tools, or MPAX, and exposes the optimization layer through PyTorch and JAX training frontends. The symbolic frontend can define LPs, MIPs, and supported fixed-quadratic objective terms, then compile the same model to a PyEPO backend. For end-to-end learning on **binary linear programs** (TSP, CVRP, knapsack, . ), includes **CaVE** [[13]]( a cone-alignment loss that uses binding-constraint

normals at the true optimum. CaVE requires and a Gurobi-backed for extracting binding constraints. In the CVRP-20 setup from notebook 04 ( , 10 epochs, single process), CaVE+ trains 8. 2x faster than SPO+; CaVE-Hybrid with trains 10. also integrates MPAX, a JAX-based solver for GPU batch solving of linear and quadratic programs. Documentation The official docs can be found at Slides A PyEPO tutorial was presented at the ACC 2024 conference. Notebooks Experiments To **reproduce the experiments

** in the original paper, use the code and instructions in the MPC branch. That branch reflects an early PyEPO version and is intended for reproduction rather than current development. Features **End-to-end gradient surrogates** for predict-then-optimize, covering the seven families in the docs: *Surrogate losses*: convex upper bound on regret (**SPO+** [[1]]( and finite-difference directional gradient (**PG** [[11]]( *Perturbed methods*: Monte Carlo gradients over random cost perturbations: **DPO** and **PFYL** [[5]]( [[6]]( **I-MLE** [[9]]( **AI

-MLE** [[10]]( *Regularized methods*: L2-regularized Frank-Wolfe over the convex hull of feasible solutions: **RFWO** and **RFYL** [[6]]( *Black-box methods*: surrogate backward rules for discrete solvers: **DBB** [[3]]( (interpolation) and **NID** [[4]]( (signed identity). *Cone-aligned estimation*: project the predicted cost onto binding-constraint normals at the true optimum; binary linear programs only: **CaVE** [[13]]( *Contrastive methods*: margin against a cached pool of non-optimal solutions: **NCE** and **CMAP** [[7]]( *Learning to rank*: rank the true optimum highest

among the pool: pointwise / pairwise / listwise **LTR** [[8]]( **Multi-solver backend** under a unified API: Gurobi, COPT, Pyomo, Google OR-Tools, and the GPU-native MPAX PDHG solver. **Symbolic modeling** with : define an LP, MIP, or supported fixed-quadratic objective once with , , and constraints, then compile it to a PyEPO backend. The compiled model is an and works with PyEPO training methods. **Parallel solving** via a Pathos worker pool to amortize per-instance ILP solves across a mini-batch. **Solution

caching** [[7]]( reuses previously computed optima to skip redundant solver calls in contrastive and ranking training. **kNN-smoothed targets** [[12

常见问题

记录了多少星标和分叉?

khalil-research/PyEPO 有 694 个星标和 90 个分叉。

仓库排名是多少?

khalil-research/PyEPO 排名第 14,902。

记录的语言和类别是什么?

khalil-research/PyEPO 有 694 个星标,语言为 Jupyter Notebook,类别为 Model Development。

哪个仓库排名最接近?

khalil-research/PyEPO 与 flink-extended/dl-on-flink 比较,后者排名第 14,901,有 694 个星标。

README

PyEPO: A PyTorch/JAX-based End-to-End Predict-then-Optimize Tool

Learning Framework

Publication

This repository is the official implementation of the paper: PyEPO: A PyTorch-based End-to-End Predict-then-Optimize Library for Linear and Integer Programming (Mathematical Programming Computation, 2024)

Citation:

@article{tang2024,
  title={PyEPO: a PyTorch-based end-to-end predict-then-optimize library for linear and integer programming},
  author={Tang, Bo and Khalil, Elias B},
  journal={Mathematical Programming Computation},
  issn={1867-2957},
  doi={10.1007/s12532-024-00255-x},
  year={2024},
  month={July},
  publisher={Springer}
}

If you use the CaVE loss, please also cite:

@inproceedings{tang2024cave,
  title={CaVE: A Cone-Aligned Approach for Fast Predict-then-Optimize with Binary Linear Programs},
  author={Tang, Bo and Khalil, Elias B},
  booktitle={Integration of Constraint Programming, Artificial Intelligence, and Operations Research},
  pages={193--210},
  year={2024},
  publisher={Springer}
}

Introduction

PyEPO is a Python library for predict-then-optimize. It focuses on problems where a model predicts objective coefficients and the feasible region is fixed, then trains the predictor against downstream decision quality rather than prediction error alone.

PyEPO models optimization problems with GurobiPy, COPT, Pyomo, Google OR-Tools, or MPAX, and exposes the optimization layer through PyTorch and JAX training frontends. The symbolic pyepo.dsl frontend can define LPs, MIPs, and supported fixed-quadratic objective terms, then compile the same model to a PyEPO backend.

For end-to-end learning on binary linear programs (TSP, CVRP, knapsack, ...), PyEPO includes CaVE [13], a cone-alignment loss that uses binding-constraint normals at the true optimum. CaVE requires optDatasetConstrs and a Gurobi-backed optModel for extracting binding constraints. In the CVRP-20 setup from notebook 04 (num_data=1000, 10 epochs, single process), CaVE+ trains 8.2x faster than SPO+; CaVE-Hybrid with solve_ratio=0.3 trains 10.5x faster with higher final regret.

PyEPO also integrates MPAX, a JAX-based solver for GPU batch solving of linear and quadratic programs.

Documentation

The official PyEPO docs can be found at https://khalil-research.github.io/PyEPO.

Slides

A PyEPO tutorial was presented at the ACC 2024 conference. The talk slides are available here.

Notebooks

  • 01 Optimization Model: Build an optimization solver
  • 02 Optimization Dataset: Generate synthetic data and use optDataset
  • 03 Training and Testing: Train method families on a shortest-path dataset
  • 04 CaVE for Binary Linear Programs: Train with the cone-aligned CaVE loss on TSP
  • 05 2D Knapsack Solution Visualization: Visualize solutions for the knapsack problem
  • 06 Warcraft Shortest Path: Train shortest path models on the Warcraft terrains dataset
  • 07 Real-World Energy Scheduling: Apply PyEPO to an energy scheduling dataset
  • 08 kNN Robust Losses: Use optDatasetKNN for robust losses
  • 09 Solving on MPAX with PDHG: Use MPAX for GPU-accelerated batch solving
  • 10 JAX Frontend: Train PyEPO losses in JAX/Flax with jax.grad

Experiments

To reproduce the experiments in the original paper, use the code and instructions in the MPC branch. That branch reflects an early PyEPO version and is intended for reproduction rather than current development.

Features

  • End-to-end gradient surrogates for predict-then-optimize, covering the seven families in the docs:
    • Surrogate losses: convex upper bound on regret (SPO+ [1]) and finite-difference directional gradient (PG [11]).
    • Perturbed methods: Monte Carlo gradients over random cost perturbations: DPO and PFYL [5] [6], I-MLE [9], AI-MLE [10].
    • Regularized methods: L2-regularized Frank-Wolfe over the convex hull of feasible solutions: RFWO and RFYL [6].
    • Black-box methods: surrogate backward rules for discrete solvers: DBB [3] (interpolation) and NID [4] (signed identity).
    • Cone-aligned estimation: project the predicted cost onto binding-constraint normals at the true optimum; binary linear programs only: CaVE [13].
    • Contrastive methods: margin against a cached pool of non-optimal solutions: NCE and CMAP [7].
    • Learning to rank: rank the true optimum highest among the pool: pointwise / pairwise / listwise LTR [8].
  • Multi-solver backend under a unified optModel API: Gurobi, COPT, Pyomo, Google OR-Tools, and the GPU-native MPAX PDHG solver.
  • Symbolic modeling with pyepo.dsl: define an LP, MIP, or supported fixed-quadratic objective once with Variable, Parameter, and constraints, then compile it to a PyEPO backend. The compiled model is an optModel and works with PyEPO training methods.
  • Parallel solving via a Pathos worker pool to amortize per-instance ILP solves across a mini-batch.
  • Solution caching [7] reuses previously computed optima to skip redundant solver calls in contrastive and ranking training.
  • kNN-smoothed targets [12] replace each label with a neighborhood aggregate for noise-robust regret.

Installation

Pip Install

Install the PyPI release with:

pip install pyepo

Conda Install

Install the Anaconda Cloud package with:

conda install -c pyepo pyepo

Install from Source

Clone PyEPO from GitHub.

git clone -b main --depth 1 https://github.com/khalil-research/PyEPO.git

Install the package from the local checkout.

pip install ./PyEPO/pkg

Solver Backends

PyEPO compiles optimization models onto a solver backend. A bare pip install pyepo does not install one; each backend has a pip extra that installs its package alongside PyEPO, e.g. pip install pyepo[gurobi] (also copt, pyomo, ortools, mpax, cave for the Clarabel-based CaVE loss, or all). The default backend is Gurobi; for a license-free setup, use Pyomo or OR-Tools with an open solver.

Dependencies

Core dependencies include:

Solver and frontend packages depend on the backend you use: GurobiPy, COPT, Pyomo, OR-Tools, MPAX, JAX, Flax, and optax are installed as needed.

Sample Code

An end-to-end predict-then-optimize example. The optimization model is defined with pyepo.dsl and compiled to Gurobi; change backend to use another PyEPO backend such as COPT, Pyomo, OR-Tools, or MPAX.

import pyepo
from pyepo import EPO, dsl
import torch
from torch import nn
from torch.utils.data import DataLoader

# generate knapsack data
num_item = 10
weights, feat, costs = pyepo.data.knapsack.genData(
    1000, 5, num_item, 3, deg=4, noise_width=0.5, seed=135,
)
capacity = (weights.sum(axis=1) * 0.5).astype(int)

# define the optimization problem
x = dsl.Variable(num_item, vtype=EPO.BINARY)
c = dsl.Parameter(num_item)
optmodel = dsl.Problem(dsl.Maximize(c @ x), [weights @ x <= capacity]).compile(backend="gurobi")

# build dataset
dataset = pyepo.data.dataset.optDataset(optmodel, feat, costs)
dataloader = DataLoader(dataset, batch_size=32, shuffle=True)

# train a linear predictor with SPO+
predmodel = nn.Linear(5, num_item)
spo = pyepo.func.SPOPlus(optmodel, processes=1)
optimizer = torch.optim.Adam(predmodel.parameters(), lr=1e-3)

for epoch in range(10):
    for xb, cb, wb, zb in dataloader:
        loss = spo(predmodel(xb), cb, wb, zb)
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()

print("Training regret:", pyepo.metric.regret(predmodel, optmodel, dataloader))

JAX frontend (pyepo.func.jax)

End-to-end training of a shortest-path predictor on a 5x5 grid with the SPO+ loss (Flax + optax):

import jax
import jax.numpy as jnp
import optax
from flax import linen as nn

import pyepo
from pyepo.data.dataset import optDataset
from pyepo.func.jax import SPOPlus

# optimization model: 5x5 grid shortest path
grid = (5, 5)
optmodel = pyepo.model.shortestPathModel(grid)

# synthetic data
x, c = pyepo.data.shortestpath.genData(
    num_data=1000, num_features=5, grid=grid, deg=4, noise_width=0.5, seed=135,
)
ds = optDataset(optmodel, x, c)
xj = jnp.asarray(x, jnp.float32)
cj, wj, zj = (jnp.asarray(a, jnp.float32) for a in (ds.costs, ds.sols, ds.objs))

# linear predictor and SPO+ loss
predmodel = nn.Dense(optmodel.num_cost)
params = predmodel.init(jax.random.PRNGKey(0), xj[:1])
spo = SPOPlus(optmodel, reduction="mean")
optimizer = optax.adam(1e-2)
opt_state = optimizer.init(params)

# end-to-end training
for epoch in range(10):
    grads = jax.grad(lambda p: spo(predmodel.apply(p, xj), cj, wj, zj))(params)
    updates, opt_state = optimizer.update(grads, opt_state)
    params = optax.apply_updates(params, updates)

Reference

排名相邻
同类项目