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-bindingscompiles the Local-MIP core and the extension together inside the wheel build.- The local helper script
python-bindings/build.shstill 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_sizeis derived fromclear_ops(),set_single_op(...), andappend_op(...); update move outputs through those helpers instead of writing the size directly.- Python callbacks can optionally receive a Python
user_dataobject; if omitted, the old shorter callback signatures still work.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file localmip-2.0.2.tar.gz.
File metadata
- Download URL: localmip-2.0.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e00b7e042d5876eda9263bc30f15b21dcef0b3c33b82acd5e06cbc043aaca44b
|
|
| MD5 |
12dc4716e02d0509023442f976cbc996
|
|
| BLAKE2b-256 |
eaab24c6f1402e5edb807e53f995f33ab73f4a31245568133a2bac00184a214a
|
Provenance
The following attestation bundles were made for localmip-2.0.2.tar.gz:
Publisher:
publish-python.yml on shaowei-cai-group/Local-MIP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
localmip-2.0.2.tar.gz -
Subject digest:
e00b7e042d5876eda9263bc30f15b21dcef0b3c33b82acd5e06cbc043aaca44b - Sigstore transparency entry: 1179807013
- Sigstore integration time:
-
Permalink:
shaowei-cai-group/Local-MIP@55b322fa1bc1a2028818d00688bef588363854cf -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/shaowei-cai-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@55b322fa1bc1a2028818d00688bef588363854cf -
Trigger Event:
push
-
Statement type:
File details
Details for the file localmip-2.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: localmip-2.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 385.8 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
955ab5468b21c447dc09b2b8c29c3ec64db98a3a5550b2c3800eb5a06a76841c
|
|
| MD5 |
4f2cc66cee75bed648fe971b52e55e41
|
|
| BLAKE2b-256 |
fe9dc9fd1169666d03a7cd157682d66eed2a3f818fc027ce973011e02b4aaabc
|
Provenance
The following attestation bundles were made for localmip-2.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish-python.yml on shaowei-cai-group/Local-MIP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
localmip-2.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
955ab5468b21c447dc09b2b8c29c3ec64db98a3a5550b2c3800eb5a06a76841c - Sigstore transparency entry: 1179807066
- Sigstore integration time:
-
Permalink:
shaowei-cai-group/Local-MIP@55b322fa1bc1a2028818d00688bef588363854cf -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/shaowei-cai-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@55b322fa1bc1a2028818d00688bef588363854cf -
Trigger Event:
push
-
Statement type:
File details
Details for the file localmip-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: localmip-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 386.9 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c14fad5eec7918c65a5b513b71b089d8a45cb48363ed1fb46000f3c29e55126
|
|
| MD5 |
370677c82b6f371d9817fc1777bc19a3
|
|
| BLAKE2b-256 |
458f85f6b9cc09d57f5598036e776a742e0f50237364e6f35c3a393dd6ad64e8
|
Provenance
The following attestation bundles were made for localmip-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish-python.yml on shaowei-cai-group/Local-MIP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
localmip-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
5c14fad5eec7918c65a5b513b71b089d8a45cb48363ed1fb46000f3c29e55126 - Sigstore transparency entry: 1179807024
- Sigstore integration time:
-
Permalink:
shaowei-cai-group/Local-MIP@55b322fa1bc1a2028818d00688bef588363854cf -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/shaowei-cai-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@55b322fa1bc1a2028818d00688bef588363854cf -
Trigger Event:
push
-
Statement type:
File details
Details for the file localmip-2.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: localmip-2.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 386.1 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e4348c5b2a2644c0048f641bf6cc04ecf7548424854c09fa020a070346f7ef3
|
|
| MD5 |
c23064bf1778f2d78d74bc157afbf591
|
|
| BLAKE2b-256 |
f86ab2a78ebdf1aa312c2b3b24594d652645a089b726e871f24a9336bf8709b7
|
Provenance
The following attestation bundles were made for localmip-2.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish-python.yml on shaowei-cai-group/Local-MIP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
localmip-2.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
8e4348c5b2a2644c0048f641bf6cc04ecf7548424854c09fa020a070346f7ef3 - Sigstore transparency entry: 1179807055
- Sigstore integration time:
-
Permalink:
shaowei-cai-group/Local-MIP@55b322fa1bc1a2028818d00688bef588363854cf -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/shaowei-cai-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@55b322fa1bc1a2028818d00688bef588363854cf -
Trigger Event:
push
-
Statement type:
File details
Details for the file localmip-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: localmip-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 386.4 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
422d57b6665991438bfd334c201d6daf55bb81ede452ed1ca43346b2ec260b21
|
|
| MD5 |
06dd8deb92bfd118fd9d0d91af5ff8de
|
|
| BLAKE2b-256 |
0469859420c43cf4941d5f7d5c9789c26e90c1bcb5d73f2af99382357821ff55
|
Provenance
The following attestation bundles were made for localmip-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish-python.yml on shaowei-cai-group/Local-MIP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
localmip-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
422d57b6665991438bfd334c201d6daf55bb81ede452ed1ca43346b2ec260b21 - Sigstore transparency entry: 1179807033
- Sigstore integration time:
-
Permalink:
shaowei-cai-group/Local-MIP@55b322fa1bc1a2028818d00688bef588363854cf -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/shaowei-cai-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@55b322fa1bc1a2028818d00688bef588363854cf -
Trigger Event:
push
-
Statement type:
File details
Details for the file localmip-2.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: localmip-2.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 385.9 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1117a5a15ac0a936721610c86760ab04cfe7261295d715f62536ea5c4f74feeb
|
|
| MD5 |
471714e054714d7dfe87f49533f893e5
|
|
| BLAKE2b-256 |
807c692cc903b7e2cf3d4d39a0f32c05b27607b2b3e1077d821aeba08f61c3ad
|
Provenance
The following attestation bundles were made for localmip-2.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish-python.yml on shaowei-cai-group/Local-MIP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
localmip-2.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
1117a5a15ac0a936721610c86760ab04cfe7261295d715f62536ea5c4f74feeb - Sigstore transparency entry: 1179807045
- Sigstore integration time:
-
Permalink:
shaowei-cai-group/Local-MIP@55b322fa1bc1a2028818d00688bef588363854cf -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/shaowei-cai-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@55b322fa1bc1a2028818d00688bef588363854cf -
Trigger Event:
push
-
Statement type: