Compile Markdown/LaTeX MIP models into standalone Python solver scripts
Project description
md2mip
Compile natural-language optimization models into standalone solver CLIs.
markdown → (LLM) → IR → codegen → solver CLI (Python + HiGHS)
image → (OCR) → markdown → …
Examples
1. Quick run — data in markdown (knapsack)
models/knapsack.md:
0-1 Knapsack
We have 5 items. Knapsack capacity W=15.
Values: v = (4, 2, 10, 1, 2)
Weights: w = (12, 1, 4, 1, 2)
Pick items to maximize value: max ∑ v_i x_i s.t. ∑ w_i x_i ≤ W, x_i ∈ {0, 1}
One command — the LLM extracts the data automatically:
md2mip run models/knapsack.md
Output:
Status: optimal
Objective: 15.0
Solution:
x[item1] = 0.0
x[item2] = 1.0
x[item3] = 1.0
x[item4] = 1.0
x[item5] = 1.0
2. Compile + run with different data (transportation)
models/transportation.md:
Transportation Problem
Sources I={1,2}, destinations J={1,2,3}. Cost matrix c, supply s=(30, 50), demand d=(20, 25, 35).
min ∑ c_ij x_ij s.t. ∑_j x_ij ≤ s_i, ∑_i x_ij ≥ d_j
# Compile — generates solver script AND data template
md2mip compile models/transportation.md
Output:
Parsed: 2 sets, 3 params, 1 vars, 2 constraints
Confidence: high (no warnings)
Written: out/transportation_solver.py
Written: out/transportation_data.yaml
Run: python out/transportation_solver.py out/transportation_data.yaml
Run the generated solver directly — swap in any data file:
# Run with the generated default data
python out/transportation_solver.py out/transportation_data.yaml
# Run with a larger instance
python out/transportation_solver.py data/transportation_large.yaml
Output:
Status: optimal
Objective: 215.0000
Solution:
x[factory1,warehouse1] = 20.0000
x[factory1,warehouse3] = 10.0000
x[factory2,warehouse2] = 25.0000
x[factory2,warehouse3] = 25.0000
compile always writes two files:
out/<name>_solver.py— standalone solver scriptout/<name>_data.yaml— complete data (if model has inline data) or template to fill in
3. OCR — image to markdown
Got a photo of a model? OCR extracts it:
md2mip ocr docs/knapsack_photo.png -o model.md
Output:
Extracted model from docs/knapsack_photo.png
Written: model.md
Run: md2mip compile model.md
Install
pip install md2mip
Configuration
cp .env.template .env
# Set your ANTHROPIC_API_KEY in .env
CLI
| Command | Description |
|---|---|
compile |
Markdown → standalone solver CLI |
run |
Compile and immediately run with data |
validate |
Compile, run, check expected objective |
ocr |
Extract a math model from an image (LLM vision) |
Run md2mip --help or md2mip <command> --help for details.
Development
make test # offline tests (no LLM)
make test-llm # LLM integration tests
make lint # ruff check
make fmt # ruff format
make typecheck # mypy
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
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 md2mip-0.1.0.tar.gz.
File metadata
- Download URL: md2mip-0.1.0.tar.gz
- Upload date:
- Size: 32.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4a4d22e1bb1470a2ad2d8d1895efb3e756b68eede4a3ebeb981ec5f8d34ad92
|
|
| MD5 |
64086f0b20b82a1786bbc10d034d4f29
|
|
| BLAKE2b-256 |
2d4112628002fc4b7a51b32c1e68ab7d10abf3aa41619a6ce796cf29f9d25c4e
|
Provenance
The following attestation bundles were made for md2mip-0.1.0.tar.gz:
Publisher:
publish.yml on spoorendonk/md2mip
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2mip-0.1.0.tar.gz -
Subject digest:
d4a4d22e1bb1470a2ad2d8d1895efb3e756b68eede4a3ebeb981ec5f8d34ad92 - Sigstore transparency entry: 1115422597
- Sigstore integration time:
-
Permalink:
spoorendonk/md2mip@e5788e6eb279d77897203ffdb2f80798cd77ee11 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/spoorendonk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e5788e6eb279d77897203ffdb2f80798cd77ee11 -
Trigger Event:
release
-
Statement type:
File details
Details for the file md2mip-0.1.0-py3-none-any.whl.
File metadata
- Download URL: md2mip-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94968832b288c5fe530ef7493fdc4ad66a3264c360f57e76c85af5adc25ba199
|
|
| MD5 |
976d7150971c35cd2fe71de8ffdec343
|
|
| BLAKE2b-256 |
9bf65fc808e020b095c067a9de3ff84cbe549f50c622bf748e6a2a5096295822
|
Provenance
The following attestation bundles were made for md2mip-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on spoorendonk/md2mip
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2mip-0.1.0-py3-none-any.whl -
Subject digest:
94968832b288c5fe530ef7493fdc4ad66a3264c360f57e76c85af5adc25ba199 - Sigstore transparency entry: 1115422629
- Sigstore integration time:
-
Permalink:
spoorendonk/md2mip@e5788e6eb279d77897203ffdb2f80798cd77ee11 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/spoorendonk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e5788e6eb279d77897203ffdb2f80798cd77ee11 -
Trigger Event:
release
-
Statement type: