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(...), andprepare(...)
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-bindingscompiles the Local-MIP core and the extension together inside the wheel build.- The local helper script
python-bindings/build.shstill 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_sizeis derived fromclear_ops(),set_single_op(...), andappend_op(...); update move outputs through those helpers instead of writing the size directly.- Python callbacks can optionally receive a Python
user_dataobject; 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.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| localmip-2.0.10.tar.gz | 73.0 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| localmip-2.0.10-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.10-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.10-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.10-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.10-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.10.tar.gz
| Download URL | localmip-2.0.10.tar.gz |
|---|---|
| Size | 73.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7d02bd62ea87d3c5a790eae3be05546192cee1d3965c1a79a52b52c28b54a30a
|
|
BLAKE2b-256 checksum How to use checksums |
28c7afc0abb852d3f333a1c3f6fed798f47eb02b3e341b02ddf571ec7cb60ba2
|
| 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 12, 2026.
Transparency logRelease files / localmip-2.0.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | localmip-2.0.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 423.6 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
92800c9386cdaafbaba39706ff4c9441277494e1af00ce1abae42e67aa086823
|
|
BLAKE2b-256 checksum How to use checksums |
0d08e73c426ce8646766894ed4f99d8e9bffcad06fab6ce61717f38aee2d4dee
|
| 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 12, 2026.
Transparency logRelease files / localmip-2.0.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | localmip-2.0.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 426.5 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
8bfdd57c142345c44f956b86449b106ce2a3bba29f6d28a29664bb2040172991
|
|
BLAKE2b-256 checksum How to use checksums |
a185686dbe9c912e32620a9993e3e5860e4ef0c8f9371765cc065691c3dc1cfc
|
| 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 12, 2026.
Transparency logRelease files / localmip-2.0.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | localmip-2.0.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 425.2 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
7564c7bd6aeee1b2b56ea9ef9433ac808589657fc3740fe9c629caa7759c6ccc
|
|
BLAKE2b-256 checksum How to use checksums |
df930229a48d2edfc547b580d40056f199f1bf7158f1aa588a18a2f3c5ca3d0a
|
| 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 12, 2026.
Transparency logRelease files / localmip-2.0.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | localmip-2.0.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 425.5 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
616059ea723eacce32eea9cdee347bd924e1619ac611ebbbe88fef0b50fbcfee
|
|
BLAKE2b-256 checksum How to use checksums |
5bf62dd70e27979cef2dea495dd1aae0fa0e609e7573f0f1e4244c9b5c4a8cc2
|
| 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 12, 2026.
Transparency logRelease files / localmip-2.0.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | localmip-2.0.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 425.1 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
245c1ec98ad22cb8d566e746044e0babf1ab522eded947be44e243e8b5bcba08
|
|
BLAKE2b-256 checksum How to use checksums |
c312f2672ab6e3833553bb16e4b7c8ec5f8524735dba66300faea20744e2d899
|
| 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 12, 2026.
Transparency log