LOS is a Language for Optimization Specification. It compiles human-readable model definitions into executable Python code (currently using PuLP as the primary engine), keeping your business logic clean and your data pipeline separate.
"Write Math, Run Python."
pip install los-lang
Or install from source:
git clone https://github.com/jowpereira/los.git
cd los
pip install -e .
import "products.csv"
import "factories.csv"
set Products
set Factories
param Cost[Products]
param Capacity[Factories]
var qty[Products, Factories] >= 0
minimize:
sum(qty[p,f] * Cost[p] for p in Products, f in Factories)
subject to:
capacity_limit:
sum(qty[p,f] for p in Products) <= Capacity[f]
for f in Factories
products.csv
Products,Cost
WidgetA,10
WidgetB,15
factories.csv
Factories,Capacity
Factory1,1000
Factory2,2000
import los
result = los.solve("production.los")
if result.is_optimal:
print(f"Optimal Cost: {result.objective}")
print(result.get_variable("qty", as_df=True))
| Feature | LOS | Raw PuLP/Pyomo |
|---|---|---|
| Readability | Whiteboard-like syntax | Python boilerplate |
| Data Binding | Native CSV imports | Manual DataFrame wrangling |
| Security | Sandboxed execution | Full Python access |
| Debug | Inspect generated code (model.code()) |
Black box |
| Solver | CBC, GLPK, Gurobi, CPLEX (via PuLP) | Same |
| Backends | PuLP (Pyomo planned) | N/A |
For dynamic data (APIs, databases), inject DataFrames directly:
import los
import pandas as pd
df = pd.DataFrame({"Products": ["A", "B"], "Cost": [10, 20]})
result = los.solve("model.los", data={"Products": df})
| Document | Description |
|---|---|
| User Manual | Full syntax reference and API guide |
| Security Policy | Sandbox details and threat model |
| Changelog | Version history |
| Backlog | Roadmap and future features |
| Contributing | How to contribute |
MIT © Jonathan Pereira