Write Math, Run Python. A Language for Optimization Specification (LOS).
Project description
LOS — Language for Optimization Specification
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."
Installation
pip install los-lang
Or install from source:
git clone https://github.com/jowpereira/los.git
cd los
pip install -e .
Quick Start
1. Write a Model (production.los)
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
2. Prepare Data
products.csv
Products,Cost
WidgetA,10
WidgetB,15
factories.csv
Factories,Capacity
Factory1,1000
Factory2,2000
3. Solve (solve.py)
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))
Why LOS?
| 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 |
Advanced: Manual Data Binding
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})
Documentation
| 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 |
License
MIT © Jonathan Pereira
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file los_lang-3.3.5.tar.gz.
File metadata
- Download URL: los_lang-3.3.5.tar.gz
- Upload date:
- Size: 279.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bdf9c5959fd8b81cab83dc68b0982171c3cd1a6bd052710793d9d6c7ad39537
|
|
| MD5 |
a6d62e0e5702644bd137f17e6f3f5058
|
|
| BLAKE2b-256 |
f1627a084db1d08787540117201cc668cb4ed7994bf29045aec09231df6ee98b
|
File details
Details for the file los_lang-3.3.5-py3-none-any.whl.
File metadata
- Download URL: los_lang-3.3.5-py3-none-any.whl
- Upload date:
- Size: 78.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a6ad14014083c53cb078ef8e3bb599b2d2830402a7ec95815bfe7772b107452
|
|
| MD5 |
7e1956a39aee26f8f32f72182d3a5cbd
|
|
| BLAKE2b-256 |
7b3013dbec7d0d78aa881c4713ad0b76bd95aa1bf912bc40d6b186f04d3c350b
|