Skip to main content

Write Math, Run Python. A Domain-Specific Language for Mathematical Optimization.

Project description

LosPy — Mathematical Optimization Specification

License: MIT Python 3.9+ Security: Hardened

LOS is a Domain-Specific Language (DSL) for mathematical optimization. It compiles human-readable model definitions into executable Python/PuLP code, 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

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
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

los_lang-3.3.2.tar.gz (277.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

los_lang-3.3.2-py3-none-any.whl (78.0 kB view details)

Uploaded Python 3

File details

Details for the file los_lang-3.3.2.tar.gz.

File metadata

  • Download URL: los_lang-3.3.2.tar.gz
  • Upload date:
  • Size: 277.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for los_lang-3.3.2.tar.gz
Algorithm Hash digest
SHA256 eb42390802275ac06c6b21f7f5849a0c8efb15b70e714373b46e75340626bf4e
MD5 cc4db57631099aba3adedb13534c72f1
BLAKE2b-256 503e9bfe010439ea95124196c91d94beab35c221d24291aeab0925ab9e919920

See more details on using hashes here.

File details

Details for the file los_lang-3.3.2-py3-none-any.whl.

File metadata

  • Download URL: los_lang-3.3.2-py3-none-any.whl
  • Upload date:
  • Size: 78.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for los_lang-3.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 90ccce1e39f9d080e38227aaa21d1835b70ec2ac9c4c025e4b1739c326155768
MD5 27627d94650a1607a8bf89a9cdb47827
BLAKE2b-256 fda7e7e85ea88b6facf0ca108751ecbc8e56578b68b902fe299817b14d06eeb4

See more details on using hashes here.

Supported by

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