Skip to content

Migrate from cbcbox to mipster for the bundled CBC library#424

Open
h-g-s wants to merge 8 commits into
coin-or:masterfrom
h-g-s:migrate-to-mipster
Open

Migrate from cbcbox to mipster for the bundled CBC library#424
h-g-s wants to merge 8 commits into
coin-or:masterfrom
h-g-s:migrate-to-mipster

Conversation

@h-g-s

@h-g-s h-g-s commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces the cbcbox build-time dependency with mipster, which ships self-contained, hardware-tuned binary wheels for all major platforms.

  • Linux x86_64 / aarch64 — manylinux_2_34 wheels with bundled libgfortran/libquadmath/libstdc++/libbz2; AVX2 and NEON variants auto-selected via CPUID.
  • macOS x86_64 / arm64 — generic + Haswell variants on x86_64; single arm64 build.
  • Windows x86_64 — generic + AVX2 variants with bundled MinGW runtime DLLs.

All third-party runtime libraries travel inside the wheel — no system dependencies.

Changes

  • pyproject.toml: cbcbox>=2.929mipster>=0.2.0
  • mip/cbc.py:
    • 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 sibling MinGW runtime DLLs.
    • Remove unused Cbc_get/setAllowablePercentageGap CFFI declarations (not exported by libmipster, never called).

Net diff: 41 lines removed, 11 added in cbc.py.

Test plan

  • Fresh venv: pip install . pulls mipster 0.2.x and cffi; no cbcbox.
  • Smoke solve: 4-variable binary knapsack returns OPTIMAL with obj=34 (expected).
  • Windows DLL search path verified via os.add_dll_directory() for sibling MinGW runtime libs.
  • CI on PR runs the full python-mip test suite.

Compatibility

  • mipster binary-compatible with libCbc from upstream Cbc; the C ABI used by python-mip is unchanged.
  • mipster>=0.2.0 is the floor because that's the first release shipping lib_path() and the bundled runtime libraries.

🤖 Generated with Claude Code

@CLAassistant

CLAassistant commented Jun 8, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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).
@h-g-s h-g-s force-pushed the migrate-to-mipster branch from 20876f0 to 60fa6bb Compare June 8, 2026 13:37
h-g-s and others added 7 commits June 8, 2026 19:56
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants