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.5.tar.gz (66.4 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.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (403.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

localmip-2.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (405.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

localmip-2.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (404.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

localmip-2.0.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (404.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

localmip-2.0.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (403.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: localmip-2.0.5.tar.gz
  • Upload date:
  • Size: 66.4 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.5.tar.gz
Algorithm Hash digest
SHA256 65bed378394cb0c7977fd3ddf0e2694087fcf87c49429b8faabdd78cbae11e3e
MD5 ca4463b41899567420c773ca8e539e7b
BLAKE2b-256 ab5de6aba62e4d5d45ad1a82c2d48f70d8742b86775b96b8e8e04c44a712ef6b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 edcd21661a8493dc46ae96816a10780054fb008ed3cc84d067eefac489b9aa6a
MD5 710d148f9117941fb8e5505e43f3b2e9
BLAKE2b-256 be55b70f0f2cf2a2c9d6fc77f5170daddcd2429224c5078fdfa70ebd70afc0b5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf8f01e74e5f6c7f2226f06032fc87fed82830ea450c626905dcb86e5d01b181
MD5 f3371ff710e5187f0229de74ea5c4cba
BLAKE2b-256 1f67c72a187b4532673857909b87bd13a20d821a16b2be406a9719a362056b69

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cea299a9f411111da44163c747754f37009fc482cdb3ff725daa4ee2878954ed
MD5 01b87bb606af64d51d7415cb840eec8f
BLAKE2b-256 5ce83755ede6658fa2abbf91d3d7ced021bf3dfcfac499e3f5ea74d7a790a7d8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f4096511ff643b7d9b2cd35db1d00e2d15b911427984ed460c1439090719200
MD5 53fa1128934633967ca9e7399ad5520a
BLAKE2b-256 c72130701475fcfc4fc2d0d82b1f890eb49948e568dd1b4e5e5909e686024872

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for localmip-2.0.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1eaecb91fd1c6e87cf201372bd26df65c6cf0990f9b1466ffc433757100c150f
MD5 764710c5353058faa0e88b9d8098ead5
BLAKE2b-256 8208aa0111338b867f117bd3867b764163fef15630549682cc0255216bc618eb

See more details on using hashes here.

Provenance

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