Skip to content

Commit 97733ee

Browse files
h-g-sCopilot
andcommitted
Use cbcbox for CBC binaries, drop bundled libs
- Replace bundled CBC binaries with cbcbox package dependency - Simplify cbc.py library loading: cbcbox is primary source, PMIP_CBC_LIBRARY env var still supported for custom builds - Remove os.chdir() workaround (cbcbox uses proper $ORIGIN rpath) - Remove mip/libraries/ bundled .so/.dylib/.dll files - Remove [tool.setuptools.package-data] for libraries - Bump requires-python to >=3.8 (cbcbox minimum) - Update classifiers: explicit OS/Python version coverage (3.8-3.13, Linux x86_64/aarch64, macOS x86_64/arm64, Windows x64) - CI: update PyPy pypy3.9 -> pypy3.11 (latest stable) - CI: remove macOS PyPy exclusion (was CBC bug, fixed in cbcbox) - CI: remove stale Windows/ubuntu-3.9 exclusion for highsbox - examples/tsp-compact-ulysses22.py: replace max_nodes_same_incumbent (unsupported in new CBC) with max_nodes=500 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 36d0247 commit 97733ee

File tree

12 files changed

+39
-61
lines changed

12 files changed

+39
-61
lines changed

.github/workflows/github-ci.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,8 @@ jobs:
3939
strategy:
4040
fail-fast: false
4141
matrix:
42-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.9-v7.3.15"]
42+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.11"]
4343
os: [macos-14, macos-15, ubuntu-22.04, ubuntu-24.04, windows-2025, windows-2022]
44-
exclude:
45-
# temporarily exclude pypy3 on mac-os as there failing tests caused by bug on cbc side
46-
- os: macos-14
47-
python-version: "pypy3.9-v7.3.15"
48-
- os: macos-15
49-
python-version: "pypy3.9-v7.3.15"
5044

5145
steps:
5246

@@ -57,6 +51,7 @@ jobs:
5751
with:
5852
python-version: ${{ matrix.python-version }}
5953
architecture: x64
54+
allow-prereleases: false
6055

6156
- name: Cache pip dependencies
6257
uses: actions/cache@v4
@@ -77,11 +72,10 @@ jobs:
7772
run: python -m pip install .[test,numpy]
7873

7974
- name: Install gurobi
80-
if: ${{ matrix.python-version != 'pypy3.9-v7.3.15' }}
75+
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
8176
run: python -m pip install .[gurobi]
8277

8378
- name: Install highs
84-
if: ${{ !contains(matrix.os, 'windows') && !(contains(matrix.os, 'ubuntu') && matrix.python-version == '3.9') }}
8579
run: python -m pip install .[highs]
8680

8781
- name: list installed packages

examples/tsp-compact-ulysses22.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def dist(p1: Tuple[float, float], p2: Tuple[float, float]) -> float:
9898
model += y[i] - (n + 1) * x[i][j] >= y[j] - n
9999

100100
# optimizing
101-
model.optimize(max_nodes_same_incumbent=1000)
101+
model.optimize(max_nodes=500)
102102

103103
# checking if a solution was found
104104
if model.num_solutions:

mip/cbc.py

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import logging
44
from typing import Dict, List, Tuple, Optional, Union
55
from sys import platform, maxsize
6-
from os.path import dirname, isfile, exists
7-
from platform import machine as platform_machine
6+
from os.path import dirname
87
import os
98
import multiprocessing as multip
109
import numbers
@@ -56,58 +55,43 @@
5655
DEF_PUMPP = 30
5756

5857
try:
59-
pathmip = dirname(mip.__file__)
60-
pathlib = os.path.join(pathmip, "libraries")
6158
libfile = ""
62-
# if user wants to force the loading of an specific CBC library
63-
# (for debugging purposes, for example)
59+
# if user wants to force the loading of a specific CBC library
6460
if "PMIP_CBC_LIBRARY" in os.environ:
6561
libfile = os.environ["PMIP_CBC_LIBRARY"]
6662
pathlib = dirname(libfile)
67-
6863
if platform.lower().startswith("win"):
6964
if pathlib not in os.environ["PATH"]:
7065
os.environ["PATH"] += ";" + pathlib
66+
old_dir = os.getcwd()
67+
os.chdir(pathlib)
68+
cbclib = ffi.dlopen(libfile)
69+
os.chdir(old_dir)
7170
else:
71+
import cbcbox as _cbcbox
72+
73+
_lib_dir = _cbcbox.cbc_lib_dir()
7274
if "linux" in platform.lower():
73-
if os_is_64_bit:
74-
pathlibe = pathlib
75-
libfile = os.path.join(pathlib, "cbc-c-linux-x86-64.so")
76-
if not exists(libfile):
77-
pathlibe = pathlib
78-
libfile = os.path.join(pathlib, "cbc-c-linux-x86-64.so")
79-
pathlib = pathlibe
80-
else:
75+
if not os_is_64_bit:
8176
raise NotImplementedError("Linux 32 bits platform not supported.")
77+
libfile = os.path.join(_lib_dir, "libCbc.so")
8278
elif platform.lower().startswith("win"):
83-
if os_is_64_bit:
84-
pathlibe = os.path.join(pathlib, "win64")
85-
libfile = os.path.join(pathlibe, "cbc-c-windows-x86-64.dll")
86-
if exists(libfile):
87-
if pathlibe not in os.environ["PATH"]:
88-
os.environ["PATH"] = pathlibe + ";" + os.environ["PATH"]
89-
else:
90-
pathlibe = pathlib
91-
libfile = os.path.join(pathlibe, "cbc-c-windows-x86-64.dll")
92-
if pathlibe not in os.environ["PATH"]:
93-
os.environ["PATH"] = pathlibe + ";" + os.environ["PATH"]
94-
pathlib = pathlibe
95-
96-
else:
79+
if not os_is_64_bit:
9780
raise NotImplementedError("Win32 platform not supported.")
81+
# autotools/MinGW places DLLs under bin/, not lib/
82+
_bin_dir = os.path.join(_cbcbox.cbc_dist_dir(), "bin")
83+
libfile = os.path.join(_bin_dir, "libCbc.dll")
84+
if _bin_dir not in os.environ.get("PATH", ""):
85+
os.environ["PATH"] = _bin_dir + ";" + os.environ["PATH"]
9886
elif platform.lower().startswith("darwin") or platform.lower().startswith(
9987
"macos"
10088
):
101-
if platform_machine().lower().startswith("arm64"):
102-
libfile = os.path.join(pathlib, "cbc-c-darwin-arm64.dylib")
103-
elif os_is_64_bit:
104-
libfile = os.path.join(pathlib, "cbc-c-darwin-x86-64.dylib")
105-
if not libfile:
106-
raise NotImplementedError("You operating system/platform is not supported")
107-
old_dir = os.getcwd()
108-
os.chdir(pathlib)
109-
cbclib = ffi.dlopen(libfile)
110-
os.chdir(old_dir)
89+
libfile = os.path.join(_lib_dir, "libCbc.dylib")
90+
else:
91+
raise NotImplementedError(
92+
"Your operating system/platform is not supported"
93+
)
94+
cbclib = ffi.dlopen(libfile)
11195
has_cbc = True
11296
except Exception as e:
11397
logger.error("An error occurred while loading the CBC library:\t " "{}\n".format(e))
-5.77 MB
Binary file not shown.
-7.05 MB
Binary file not shown.
-19.3 MB
Binary file not shown.
-8.75 MB
Binary file not shown.

mip/libraries/win64/libbz2-1.dll

-96.8 KB
Binary file not shown.
-81.7 KB
Binary file not shown.
-1.87 MB
Binary file not shown.

0 commit comments

Comments
 (0)