Skip to main content

A unified framework for Operation Research modeling with polars

Project description

xplor: A Modern DataFrame-Centric Optimization Framework

PyPI version License

xplor provides a unified framework for building Operation Research models using polars DataFrames. By leveraging polars' performance and ergonomic API, xplor makes mathematical optimization more intuitive and maintainable.

Features

  • 🚀 Polars Integration: Built on top of polars for high-performance data operations
  • 🧩 Solver Agnostic: Designed to support multiple solvers (currently Gurobi, more coming soon)
  • 📝 Intuitive API: Natural expression syntax for constraints and objectives
  • Vectorized Operations: Efficient model building with DataFrame operations
  • 🔍 Type Hints: Full typing support for better IDE integration

Installation

pip install xplor

For Gurobi support, make sure you have Gurobi installed and licensed:

pip install gurobipy

Quick Start

Here's a simple example showing how to build and solve an optimization model using xplor:

import xplor.gurobi as pg
import polars as pl
import gurobipy as gp

# Create a model
model = gp.Model()

# Create sample data
df = pl.DataFrame({
    "i": [0, 0, 1, 2, 2],
    "j": [1, 2, 0, 0, 1],
    "u": [0.3, 1.2, 0.7, 0.9, 1.2],
    "c": [1.3, 1.7, 1.4, 1.1, 0.9],
    "obj": [2.5, 2.7, 1.2, 1.7, 3.9],
})

# Add variables and constraints
df = (
    df
    .pipe(pg.add_vars, model, name="x", ub="u", obj="obj", indices=["i", "j"])
    .pipe(pg.apply_eval, "y = 2 * x - c")
)

# Add constraints using grouped operations
(
    df
    .group_by("i")
    .agg(pg.quicksum("y"), pl.col("c").min())
    .pipe(pg.add_constrs, model, "y <= c", name="constr")
)

# Solve the model
model.optimize()

# Extract solution
solution = df.with_columns(pg.read_value("x"))

Current Status

xplor is in active development. Currently supported:

  • ✅ Gurobi backend
  • ✅ Basic model building operations
  • ✅ Variable and constraint creation
  • ✅ Expression evaluation
  • ✅ Solution reading

Planned features:

  • 🚧 Support for additional solvers (CPLEX, CBC, SCIP)
  • 🚧 Extended modeling capabilities
  • 🚧 Performance optimizations
  • 🚧 More utility functions

Why xplor?

xplor aims to modernize the Operation Research workflow by:

  1. Using polars instead of pandas for better performance and memory usage
  2. Providing a consistent API across different solvers
  3. Making model building more intuitive with DataFrame operations
  4. Enabling better code organization and maintenance

Comparison with Other Tools

xplor is heavily inspired by gurobipy-pandas but differs in these key aspects:

  • Uses polars instead of pandas for better performance
  • Designed to be solver-agnostic from the ground up

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

# Clone the repository
git clone https://github.com/gab23r/xplor.git
cd xplor

# Install development dependencies
uv sync --all-extras

# Run tests
pytest

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xplor-0.1.3.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

xplor-0.1.3-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file xplor-0.1.3.tar.gz.

File metadata

  • Download URL: xplor-0.1.3.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.2

File hashes

Hashes for xplor-0.1.3.tar.gz
Algorithm Hash digest
SHA256 779add67715b54e5a6da0fc2d950e6134a1944c1de7f88f446e9802895acc049
MD5 65733bee4744bb7bb9447d9416fd0029
BLAKE2b-256 7bc602dbc0fcc947d0cd404b0df3ce5b7cb21938f0f389d5caee2704a37e361f

See more details on using hashes here.

File details

Details for the file xplor-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: xplor-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.2

File hashes

Hashes for xplor-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2750e6a6c15c561b792afc11954a0f220dd5a46a299bfc6e3b3c8767eccd98af
MD5 9a7c90bf1fcbab96b9c2688513360608
BLAKE2b-256 56da495ae386c4885a6fff937173f636f5cef29a929c645a5ddf1fde3b072320

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page