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.

Download files

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

Source Distribution

localmip-2.0.10.tar.gz (73.0 kB view details)

Uploaded Source

Built Distributions

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

localmip-2.0.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (423.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

localmip-2.0.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (426.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

localmip-2.0.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (425.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

localmip-2.0.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (425.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

localmip-2.0.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (425.1 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file localmip-2.0.10.tar.gz.

File metadata

  • Download URL: localmip-2.0.10.tar.gz
  • Upload date:
  • Size: 73.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for localmip-2.0.10.tar.gz
Algorithm Hash digest
SHA256 7d02bd62ea87d3c5a790eae3be05546192cee1d3965c1a79a52b52c28b54a30a
MD5 d5011f085e0f982ef58f79598a83e8a7
BLAKE2b-256 28c7afc0abb852d3f333a1c3f6fed798f47eb02b3e341b02ddf571ec7cb60ba2

See more details on using hashes here.

Provenance

The following attestation bundles were made for localmip-2.0.10.tar.gz:

Publisher: publish-python.yml on shaowei-cai-group/Local-MIP

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

File details

Details for the file localmip-2.0.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for localmip-2.0.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 92800c9386cdaafbaba39706ff4c9441277494e1af00ce1abae42e67aa086823
MD5 f48a69dd13c89ecb0ebed6c236bbf2a6
BLAKE2b-256 0d08e73c426ce8646766894ed4f99d8e9bffcad06fab6ce61717f38aee2d4dee

See more details on using hashes here.

Provenance

The following attestation bundles were made for localmip-2.0.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-python.yml on shaowei-cai-group/Local-MIP

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

File details

Details for the file localmip-2.0.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for localmip-2.0.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8bfdd57c142345c44f956b86449b106ce2a3bba29f6d28a29664bb2040172991
MD5 a36cc31793d4e667c791d904ccd8ed08
BLAKE2b-256 a185686dbe9c912e32620a9993e3e5860e4ef0c8f9371765cc065691c3dc1cfc

See more details on using hashes here.

Provenance

The following attestation bundles were made for localmip-2.0.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-python.yml on shaowei-cai-group/Local-MIP

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

File details

Details for the file localmip-2.0.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for localmip-2.0.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7564c7bd6aeee1b2b56ea9ef9433ac808589657fc3740fe9c629caa7759c6ccc
MD5 8fbc5789bc6454acfdd468b2a6461aca
BLAKE2b-256 df930229a48d2edfc547b580d40056f199f1bf7158f1aa588a18a2f3c5ca3d0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for localmip-2.0.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-python.yml on shaowei-cai-group/Local-MIP

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

File details

Details for the file localmip-2.0.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for localmip-2.0.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 616059ea723eacce32eea9cdee347bd924e1619ac611ebbbe88fef0b50fbcfee
MD5 7a747bc6b17dab5f1abf2fc603ea3eb8
BLAKE2b-256 5bf62dd70e27979cef2dea495dd1aae0fa0e609e7573f0f1e4244c9b5c4a8cc2

See more details on using hashes here.

Provenance

The following attestation bundles were made for localmip-2.0.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-python.yml on shaowei-cai-group/Local-MIP

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

File details

Details for the file localmip-2.0.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for localmip-2.0.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 245c1ec98ad22cb8d566e746044e0babf1ab522eded947be44e243e8b5bcba08
MD5 80cc63b76325b403d3ceda67ef91436a
BLAKE2b-256 c312f2672ab6e3833553bb16e4b7c8ec5f8524735dba66300faea20744e2d899

See more details on using hashes here.

Provenance

The following attestation bundles were made for localmip-2.0.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-python.yml on shaowei-cai-group/Local-MIP

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

2.0.10 This release

6 files

2.0.9

6 files

2.0.8

6 files

2.0.7

6 files

2.0.6

6 files

2.0.5

6 files

2.0.4

6 files

2.0.3

6 files

2.0.2

6 files

2.0.1

6 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