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 append the build directory to PYTHONPATH or copy the .so next to your script:

import sys
sys.path.append("python-bindings/build")  # if not installed
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.1.tar.gz (61.3 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.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (385.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

localmip-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (386.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

localmip-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (386.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

localmip-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (386.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

localmip-2.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (385.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for localmip-2.0.1.tar.gz
Algorithm Hash digest
SHA256 e475ba133848f3cbd16db63584b22610394429ee1b1988cb8a284ff5c4ef1f02
MD5 b536eaf0447de555863c35742c176fbf
BLAKE2b-256 c4316b5171bac91776eb06a10bebf61114ee45116020ecc94ed59fd8c3ae10ec

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c19ae334637a3d8323d775c06e681f2f47450ab5b61ed653ea8e090078835944
MD5 9ac3445db3ece91dca8a2518c1c97df5
BLAKE2b-256 2d975f9c4824e567f085f5f602305bc4fdee392056b0f7b7e73dc693679babdf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 41ad3d55968e6a7edb8b26f9d4face30880dfeea21609c712c551f3f894fca48
MD5 46c891a70b74fd65a7da451bed1f122c
BLAKE2b-256 0deeb5bad5dc819b2f63848d431d981576a08c5eaec83e53e34008af75bbfcb9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e053bdc3627237cb085b935fb08193c232f66b80ed5d5ea1172b359fea82e371
MD5 accce29db40ee06faa63e88d863a50f1
BLAKE2b-256 b188defd8fe737c57f04538bdf7d3757e1dac8aef4719f70d70983893cb3644c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d9b23a3c97e75861bffa2736a32a8431fc7068c9aaf8b4bbc7d1715a589f2fae
MD5 84def87cdf1ca74dba663c966d9ec9a6
BLAKE2b-256 61323315ed6cbebd2fa9cc30d07178194b3d9b5f499885df44035f1266db6217

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 949b7f6fc43d60c33da78b0aaab2c90cca4f50d2521ecd4eb67fcae3d09424d7
MD5 8377851b2e55c9270644ed9cbd187087
BLAKE2b-256 1b47d87855f761211101be51c4e815602c19d86ae979f596f7e0b753fd589953

See more details on using hashes here.

Provenance

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