Skip to main content

lp2graph

ci docs PyPI License

Typed-graph representation of LP, MIP, and MILP formulations.

lp2graph is a focused library for representing optimization problems as typed graphs and deriving multiple views of them — schema, hybrid, and ground — from a single canonical data model. It ships:

  • A version-stable JSON schema for formulations.
  • Three view derivations that turn a formulation into a typed graph.
  • Structural metrics computed deterministically over the model and views.
  • SVG renderers and a static interactive viewer.
  • Export adapters to PyG, DGL, NetworkX, LaTeX, and Pyomo.

The core has no solver dependency. Pyomo, JuMP, and friends are optional extras.

Install

pip install lp2graph                       # core only
pip install "lp2graph[networkx]"           # NetworkX export
pip install "lp2graph[pyg]"                # PyG export
pip install "lp2graph[all]"                # everything

60-second tour

from lp2graph import load
from lp2graph.views import schema, hybrid, ground
from lp2graph.metrics.structural import structural_summary
from lp2graph.metrics.flags import presence_flags
from lp2graph.render.svg import render_svg

f = load("formulations/constraints/mip_2_1_big_m.json")

# Three views from one canonical model.
g_schema  = schema(f)                       # templates and indices
g_hybrid  = hybrid(f)                       # + offset-labeled edges
g_ground  = ground(f, {"I": 4})             # + degeneracy filters

# Metrics, deterministic.
print(structural_summary(g_schema)["graph_diameter"].value)
print(presence_flags(f)["has_big_m"].value)

# Render with the deliberate visual identity.
open("graph.svg", "w").write(render_svg(g_hybrid, title=f.name))

Or from the command line:

lp2graph validate formulations/constraints/lp_1_1_fixed_sequence.json
lp2graph render   formulations/constraints/mip_2_1_big_m.json --view hybrid --output mip_2_1.svg
lp2graph metrics  formulations/constraints/mip_2_4_time_indexed.json
lp2graph export   formulations/constraints/mip_2_8_pesp.json --format latex

Text ⇄ graph, and solving (deterministic, no LLM)

Beyond the views, lp2graph offers a bidirectional, deterministic interface between a formulation's text and its graph, plus a real solver back-end:

# graph -> paper-style LaTeX (\mathcal sets, \sum, \forall, big-M) and back
lp2graph latex   formulations/constraints/pesp_solvable.json --output pesp.tex
lp2graph parse   pesp.tex                         # LaTeX -> canonical JSON

# ground with instance data and solve the MILP (CBC / HiGHS / Gurobi)
lp2graph solve   formulations/constraints/assignment.json \
                 --instance corpus/validation/codec_pipeline/instances/assignment_4x4.json

# graph -> natural-language problem description (+ data tables)
lp2graph describe formulations/constraints/pesp_solvable.json --instance ...
from lp2graph import load, to_canonical_latex, from_canonical_latex, describe
from lp2graph.solve import Instance, solve

f = load("formulations/constraints/assignment.json")
g = from_canonical_latex(to_canonical_latex(f))   # text round-trips the graph
print(solve(g, Instance(cardinalities={"W": 4, "J": 4},
                        parameters={"c": [[9, 2, 7, 8], ...]})).objective)

The codec is a tested fixed point and the solvable content round-trips exactly; an end-to-end suite confirms the JSON→LaTeX→parse→ground→solve loop reproduces independently-known optima across CBC/HiGHS/Gurobi. See docs/text-graph-interface.md.

What goes in, what comes out

A formulation is a JSON document validated against schema/canonical.schema.json. It declares index families (e.g. I, T), parameters, variable templates, constraint templates with quantifiers and bindings, and an optional objective with first-class terms.

The schema view exposes templates and indices — the topology of the problem. The hybrid view adds per-term offset, sign, and modulo labels. The ground view materializes every instance at given index cardinalities and applies degeneracy filters.

See docs/data-model.md and docs/views.md for the long form.

Status

v0.1 is an alpha. The schema and the canonical model are stable for a representative cross-section of formulations; the catalog is in active expansion. Tracked open questions live as open-question issues so they are visible.

Documentation

Contributing

See CONTRIBUTING.md. Bugs, new formulations, design decisions, and good-first-issues all have dedicated templates.

License

Apache 2.0. Portions adapted from joernmht/raiLPminerExperimentation under MIT — see docs/extraction-report.md.

Download files

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

Source Distribution

lp2graph-0.3.0.tar.gz (243.1 kB view details)

Uploaded Source

Built Distribution

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

lp2graph-0.3.0-py3-none-any.whl (144.7 kB view details)

Uploaded Python 3

File details

Details for the file lp2graph-0.3.0.tar.gz.

File metadata

  • Download URL: lp2graph-0.3.0.tar.gz
  • Upload date:
  • Size: 243.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lp2graph-0.3.0.tar.gz
Algorithm Hash digest
SHA256 1a65505e769ca77641041b033b2b045e6fbf852275c963d6799e8bcf8846b847
MD5 26ec8867250e488e65dda6567c553ef3
BLAKE2b-256 534fb7f6f073ccb5fdde40276b74184f16dab0d9b5c1adc08eda3a844d9e6b73

See more details on using hashes here.

Provenance

The following attestation bundles were made for lp2graph-0.3.0.tar.gz:

Publisher: release.yml on joernmht/lp2graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lp2graph-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lp2graph-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 144.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lp2graph-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 655c5bc90ecb24125d80b0c85e0336a4a2bd02f7e4d4ea035bef092753a8adce
MD5 e613fb486817c52c03ebf1e6b6873784
BLAKE2b-256 232a119a0682bc68f2c670ffcee97b91b22a48073ae3d63b0b1b33822a2febdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for lp2graph-0.3.0-py3-none-any.whl:

Publisher: release.yml on joernmht/lp2graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page