Skip to main content

Python Bindings (pybind11)

This folder provides a pybind11 module that exposes Local_MIP to Python without touching the main solver code.

The bindings expose the core solver configuration and result-query API used in normal runs, including .set parameter-file loading, plus the in-memory modeling interface.

Install from PyPI

For Linux x86_64:

python3 -m pip install localmip

Import it directly:

import localmip_py as lm

Install from the repository

From repo root:

python3 -m pip install ./python-bindings

This builds both the Local-MIP core and the pybind11 extension during installation. After installation, the module can be imported directly:

python3 -c "import localmip_py as lm; print(lm.LocalMIP)"

Run the demos

From repo root:

python3 python-bindings/sample.py
python3 python-bindings/model_api_demo.py
python3 python-bindings/test_python_api.py
python3 python-bindings/smoke_test.py

Development build without pip

The legacy local build flow is still supported. From repo root:

PY_EXE="$(python3 -c 'import sys; print(sys.executable)')"
PYTHON_EXECUTABLE="${PY_EXE}" python-bindings/build.sh

Output: python-bindings/build/localmip_py.cpython-*.so (exact suffix depends on Python version).

Use the same interpreter for build and run so the compiled module suffix matches the interpreter that imports it:

PY_EXE="$(python3 -c 'import sys; print(sys.executable)')"
PYTHON_EXECUTABLE="${PY_EXE}" python-bindings/build.sh
"${PY_EXE}" python-bindings/sample.py
"${PY_EXE}" python-bindings/model_api_demo.py
"${PY_EXE}" python-bindings/test_python_api.py
"${PY_EXE}" python-bindings/smoke_test.py

Use in Python

If installed with pip:

import localmip_py as lm

If using the local development build, either put the build directory at the front of PYTHONPATH or copy the .so next to your script:

import sys
sys.path.insert(0, "python-bindings/build")  # prefer the local build
import localmip_py as lm

solver = lm.LocalMIP()
solver.set_model_file("test-set/sct1.mps")
solver.set_sol_path("py_example.sol")
solver.set_time_limit(10.0)
solver.set_log_obj(True)

# Optional: register a start callback
stats = {"calls": 0}

def start_cbk(ctx, user_data):
    user_data["calls"] += 1
    if ctx.shared.binary_idx_list:
        idx = ctx.shared.binary_idx_list[0]
        ctx.current_values[idx] = 1.0

solver.set_start_cbk(start_cbk, stats)
solver.run()

print("Feasible:", solver.is_feasible(), "Obj:", solver.get_obj_value())
print("Start callback calls:", stats["calls"])

Model API (Programmatic Modeling)

The bindings also expose Local-MIP's Model API, which lets you build a model directly in Python (mirrors example/model-api/model_api_demo.cpp).

Run the demo:

PY_EXE="$(python3 -c 'import sys; print(sys.executable)')"
"${PY_EXE}" python-bindings/model_api_demo.py

Smoke test:

PY_EXE="$(python3 -c 'import sys; print(sys.executable)')"
"${PY_EXE}" python-bindings/test_python_api.py

Key symbols:

  • lm.Sense.{minimize,maximize}
  • lm.VarType.{binary,general_integer,real,fixed}
  • LocalMIP.set_param_set_file(...)
  • LocalMIP.set_bms_unsat_con(...), set_bms_mtm_unsat_op(...), set_bms_sat_con(...), set_bms_mtm_sat_op(...), set_bms_flip_op(...), set_bms_easy_op(...), set_bms_random_op(...)
  • LocalMIP.get_solution()
  • ModelVar.requires_integrality()
  • lm.ModelPrepareOptions, lm.PreparedModel.from_file(...)
  • lm.ModelBuilder.add_var(...), add_con(...), and prepare(...)

Shared model, multiple Python workers

LocalMIP(prepared_model) keeps the frozen model alive and shares it without copying. Each solver has independent RNG and search state:

import threading
import localmip_py as lm

options = lm.ModelPrepareOptions()
model = lm.PreparedModel.from_file("instance.mps", options)
solvers = [lm.LocalMIP(model) for _ in range(4)]

for seed, solver in enumerate(solvers, start=1):
    solver.set_random_seed(seed)
    solver.set_time_limit(10.0)
    solver.set_log_obj(False)

workers = [threading.Thread(target=solver.run) for solver in solvers]
for worker in workers:
    worker.start()
for worker in workers:
    worker.join()

run() releases the GIL, so independent searches can execute concurrently. Python callbacks reacquire the GIL, so callback-heavy searches may serialize while callbacks run. Local-MIP does not create Python threads or merge results; the application schedules the workers and selects the final incumbent.

Each LocalMIP object accepts exactly one run() call, including a call that ends by throwing an exception. Create another solver for a new seed or model; multiple solvers can reuse the same PreparedModel.

Notes

  • pip install ./python-bindings compiles the Local-MIP core and the extension together inside the wheel build.
  • The local helper script python-bindings/build.sh still works for iterative development builds.
  • Long-running run() releases the GIL; Python callbacks reacquire the GIL before execution.
  • Callback contexts (Start::Start_Ctx, etc.) are exposed as structured Python objects with read-only shared sequence views and writable fields where the solver expects mutation.
  • NeighborCtx.op_size is derived from clear_ops(), set_single_op(...), and append_op(...); update move outputs through those helpers instead of writing the size directly.
  • Python callbacks can optionally receive a Python user_data object; if omitted, the old shorter callback signatures still work.
  • Writable start/restart callback values and custom moves are checked for finite values, bounds, and integrality before the solver accepts them.

Release files for localmip 2.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for localmip 2.0.9
File Size Uploaded
localmip-2.0.9.tar.gz 72.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for localmip 2.0.9
File
localmip-2.0.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
localmip-2.0.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
localmip-2.0.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
localmip-2.0.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
localmip-2.0.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details

Total release size:2.2 MB

Release files / localmip-2.0.9.tar.gz

Download URL localmip-2.0.9.tar.gz
Size 72.5 kB
Tags Source
SHA-256 checksum
How to use checksums
df2da563f24cc751bad6de86541f6ddb1d83c360f2b22916351840d22ce01ad9
BLAKE2b-256 checksum
How to use checksums
127973df8a8898a14da8b599e0a28d6a58c0c4036fac57c94fb235e569dfd543
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 8, 2026.

Transparency log

Release files / localmip-2.0.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL localmip-2.0.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 430.7 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a9d40b2fa24253e0133712f2b1a2c5dd800cbd79409e6421ca5184bcaf840abb
BLAKE2b-256 checksum
How to use checksums
cdb9280f34d2574cd86816e404d9f7fbf9cf41dc3ac5adf2bf94d1274b703cec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 8, 2026.

Transparency log

Release files / localmip-2.0.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL localmip-2.0.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 433.2 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
2f7945c953cdb6e7e0c063c468defc9b615a947cbc0b7a8c58ccbd5f1c46339d
BLAKE2b-256 checksum
How to use checksums
c35f409518cad29c8aa4369e3f2caf00febb3b3ecc06e340cdaeede6cc314b39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 8, 2026.

Transparency log

Release files / localmip-2.0.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL localmip-2.0.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 432.5 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7495cf5c51e2dded5233607bd5a55156d84fccf968afead835ccfc0544304b4b
BLAKE2b-256 checksum
How to use checksums
7d1b96c0a991f6864a24e4239f64c1fb5447254c901474463c5ae7a59ac3d70c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 8, 2026.

Transparency log

Release files / localmip-2.0.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL localmip-2.0.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 432.5 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
8ed15ac609e18bc24adff093e2344861935176a8ab3416ad340e141631424dea
BLAKE2b-256 checksum
How to use checksums
211fff4cfc1b9bd6603f83dfa46381dc8aae2bdc28773a6b69daa29df19c0698
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 8, 2026.

Transparency log

Release files / localmip-2.0.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL localmip-2.0.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 432.3 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
4dd5b07ea08a810bd550a693660a28ad01fbb1622f10d24f1b7c695ffc82ef7e
BLAKE2b-256 checksum
How to use checksums
0ed11764fe8d190b35560ec3c14eb241e102afefc22953d93c28d428a7a93faa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 8, 2026.

Transparency log

Release history Release notifications | RSS feed

2.0.10

6 release files

This release

2.0.9 This release

6 release files

2.0.8

6 release files

2.0.7

6 release files

2.0.6

6 release files

2.0.5

6 release files

2.0.4

6 release files

2.0.3

6 release files

2.0.2

6 release files

2.0.1

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