Skip to main content

Python bindings for the Local-MIP solver

Project description

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.enable_model_api()
  • LocalMIP.add_var(...), LocalMIP.add_con(...)
  • LocalMIP.get_solution()

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.

Project details


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.4.tar.gz (63.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.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (392.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

localmip-2.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (396.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

localmip-2.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (394.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

localmip-2.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (394.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

localmip-2.0.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (394.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for localmip-2.0.4.tar.gz
Algorithm Hash digest
SHA256 b60df65725a9ccd720dbac23fc079476f2a48f54c13210a04097e163a675c5ff
MD5 c81f78bef5c125c74068810b10d5c769
BLAKE2b-256 805cfdcc14c164151b8ce5c359976dd268f8192dd6b0ed812eb6327c9f0b124d

See more details on using hashes here.

Provenance

The following attestation bundles were made for localmip-2.0.4.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.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for localmip-2.0.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 85dc2d73a36a58e241c234281d2a46c42aad086a06b2a5a9623c0e05712e09d0
MD5 df2ea795488ab069258625f60a2db0da
BLAKE2b-256 295b6eacc667cf74ab573455450b63c791038c711f514af43887fbefb8b95dc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for localmip-2.0.4-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.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for localmip-2.0.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 45ef394d8b85f78f549ec8e3f89e07c643cbe381da6f31707d97f293602a54cc
MD5 65a0a7d27f8feb7c5bfd700989208696
BLAKE2b-256 c2765a14a7135dcb3171f43d261e48aa39c8f1e057981ac3854373ecdfc77ff5

See more details on using hashes here.

Provenance

The following attestation bundles were made for localmip-2.0.4-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.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for localmip-2.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d700332ba09300ef2e9c4938e2927f9395da60ab5bf91a18f977e67159fbc173
MD5 7e807489452a0ce26ddaf0bfd38df5a7
BLAKE2b-256 ac966a87f45865da1f0cf014c32ab5dd2d09eec6e4555d086766e624fd5884a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for localmip-2.0.4-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.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for localmip-2.0.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a9850bc0f955599905c1829227084ecef94aaf513bf39a9537627da1efe8688f
MD5 0b0a08bc93b00336ce25ee35b24eb9f3
BLAKE2b-256 ee3ce98688bc415ffe8fd104fa9db3a6b7a67065f3bab13c77dfcef4b8075393

See more details on using hashes here.

Provenance

The following attestation bundles were made for localmip-2.0.4-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.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for localmip-2.0.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 74885ceffd77a74cf86dab4c38bdf8054ff3cd76d2f37aec3609a2e8f9239c3a
MD5 90bc30f2b7bf1195de274331ee433d75
BLAKE2b-256 f142ee8371bdd64b86f29b78135676e311dbb83d84e4adef80886f58374ae2d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for localmip-2.0.4-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.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page