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()
  • ModelVar.requires_integrality()

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.

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.6.tar.gz (67.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.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (406.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

localmip-2.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (408.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

localmip-2.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (406.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

localmip-2.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (406.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

localmip-2.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (406.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for localmip-2.0.6.tar.gz
Algorithm Hash digest
SHA256 a7452715755c558ab893d9c073df2843734fc1272cba3dfc7d7c204fcd79fd49
MD5 3acde72e78bbd15f7c1b54447b3b6cf9
BLAKE2b-256 65791a62f579368c5b1c04c6b6f2fd1ea60daf0f041605966247047a1fe44600

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 60a94ba6f7ae33173d484695625acb4df328a368ba4cbe9325dc2f197b062934
MD5 14bd501afc60ccb87177e14a779e1a66
BLAKE2b-256 0dd01ff628a5e3e1b4f179c04ca62204db58e970d039fdfee67aa94f35c4cf7e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f76cda04315f737e64f310f95638a30887e7851f37d4ddf9d6284f215d8dee40
MD5 b69182d524764466ff3dedd49671b5a0
BLAKE2b-256 6b1141ba808d9a153f663b7ea741f321273772ba9e56b1bd3818cccdb1d32324

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bd832fbe9ce93b158a4aecb9eafb3b24e3056e61fa0742b49a5e3e6c596e2211
MD5 0ae93909f8080306cd55e6cb4e704d6a
BLAKE2b-256 bb15faff287f894c0ce017e523588d9f2c35c1ede069d78f5a242650481715e1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8631d41c6619922e8414934f53d6804aeab871111b543c5957daefc8b0b020b7
MD5 7407f8e8f218a2bd1675dab8e968a787
BLAKE2b-256 659c998e0bb2eea6ec24aaaf1de0497f5e4fba7dea220435dd5a2b04b5fd4c1f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f63510750394b9737ee62d95df2ab4bde94ae4092192ad941c06b4cee90696bd
MD5 25f94306866ee58212c13627b7b27e3f
BLAKE2b-256 d6ae864503c9f5e4207a09095c8e112b34c17793462a547799c75c5dcea0bb7d

See more details on using hashes here.

Provenance

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