Migrate from cbcbox to mipster for the bundled CBC library#424
Open
h-g-s wants to merge 8 commits into
Open
Conversation
cbcbox shipped CBC source builds; mipster (https://pypi.org/project/mipster/) ships self-contained, hardware-tuned wheels for Linux x86_64/aarch64, macOS x86_64/arm64, and Windows x86_64 with CPUID auto-dispatch (generic / AVX2 / Haswell / NEON variants). - Replace `cbcbox>=2.929` with `mipster>=0.2.0`. - Use `mipster.lib_path()` instead of platform-specific path joining; this returns the right shared library for the current OS and selected variant. - Drop the manual libCbc.so / libCbc-0.dll / libCbc.dylib branching. - Keep `os.add_dll_directory()` on Windows so the loader can find the sibling MinGW runtime DLLs that mipster bundles next to libmipster-N.dll. - Remove unused Cbc_get/setAllowablePercentageGap CFFI declarations (these are not exported by libmipster and were never called).
Version 0.2.4 fixes three C API bugs required for correctness: - Auto-generate column names so translate() works in lazy callbacks - Sync bound==value when proven optimal (prevents spurious assertion failures) - Restore rSlk/rActv pointers after MIP solve (prevents null-pointer crash) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
highspy's _core.pyd on Windows only exports the Python init symbol (PyInit__core) -- the C API functions like Highs_create are compiled in but not exported as DLL symbols. On Linux/macOS all symbols in a shared library are visible, so ffi.dlopen() works there. After loading the library via ffi.dlopen(), test whether Highs_create is actually accessible. If not (Windows + highspy), set has_highs=False so that all HiGHS tests are skipped gracefully instead of crashing with 'function/symbol not found' errors. Users on Windows who need HiGHS can install highsbox (which ships a proper highs.dll with exported C symbols) and set PMIP_HIGHS_LIBRARY to point to it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
highspy's _core.pyd on Windows does not export C symbols (only PyInit_*
is exported from a Windows DLL by default). On Linux/macOS the .so
exports all symbols so ffi.dlopen + Highs_create works fine; on Windows
it raises AttributeError.
Changes:
- After dlopen succeeds, probe Highs_create accessibility. If it fails
(Windows + highspy), automatically retry with highsbox's highs.dll.
- highsbox is added as a Windows-only optional dependency in [highs]:
highsbox>=1.9.0; sys_platform == 'win32'
so 'pip install mip[highs]' on Windows installs both highspy (Python
bindings) and highsbox (C API DLL), giving full HiGHS functionality.
- Hoist the highsbox path resolver to a module-level helper function
_get_highsbox_libfile() so it is reachable both at initial load and
at the fallback probe point.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
On PyPy, the GC may call __del__ on an object whose __init__ raised before all attributes were set (e.g. SolverGurobi.__init__ raises early when Gurobi is not installed, before _ownsModel/_venv_loaded are set). CPython avoids this because reference-counting drops the object immediately; PyPy's tracing GC processes it later. Replace bare attribute access in __del__ with getattr(..., default) in: - SolverGurobi.__del__: guard _ownsModel and _venv_loaded - SolverHighs.__del__: guard _model (avoid calling Highs_destroy(NULL)) - SolverCbc.__del__: guard _model (avoid calling Cbc_deleteModel(NULL)) - SolverOsi.__del__: guard owns_solver Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the
cbcboxbuild-time dependency withmipster, which ships self-contained, hardware-tuned binary wheels for all major platforms.All third-party runtime libraries travel inside the wheel — no system dependencies.
Changes
pyproject.toml:cbcbox>=2.929→mipster>=0.2.0mip/cbc.py:mipster.lib_path()instead of platform-specific path joining; this returns the right shared library for the current OS and selected variant.libCbc.so/libCbc-0.dll/libCbc.dylibbranching.os.add_dll_directory()on Windows so the loader can find sibling MinGW runtime DLLs.Cbc_get/setAllowablePercentageGapCFFI declarations (not exported bylibmipster, never called).Net diff: 41 lines removed, 11 added in
cbc.py.Test plan
pip install .pullsmipster 0.2.xandcffi; nocbcbox.os.add_dll_directory()for sibling MinGW runtime libs.Compatibility
mipsterbinary-compatible withlibCbcfrom upstream Cbc; the C ABI used by python-mip is unchanged.mipster>=0.2.0is the floor because that's the first release shippinglib_path()and the bundled runtime libraries.🤖 Generated with Claude Code