Skip to content

Commit 158d7f2

Browse files
h-g-sCopilot
andcommitted
Fix black formatting in cbc.py; exclude pypy3.11 on macos-14
cbcbox ARM dylib is built on macos-15 (M2+) and may use CPU instructions not available on macos-14 (M1), causing SIGILL with PyPy. CPython on macos-14 is unaffected. pypy3.11 is still tested on macos-15. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 97733ee commit 158d7f2

2 files changed

Lines changed: 18 additions & 24 deletions

File tree

.github/workflows/github-ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ jobs:
4141
matrix:
4242
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+
# cbcbox ARM dylib built on macos-15 (M2+); may use instructions unavailable on macos-14 (M1)
46+
- os: macos-14
47+
python-version: "pypy3.11"
4448

4549
steps:
4650

mip/cbc.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,15 @@
8888
):
8989
libfile = os.path.join(_lib_dir, "libCbc.dylib")
9090
else:
91-
raise NotImplementedError(
92-
"Your operating system/platform is not supported"
93-
)
91+
raise NotImplementedError("Your operating system/platform is not supported")
9492
cbclib = ffi.dlopen(libfile)
9593
has_cbc = True
9694
except Exception as e:
9795
logger.error("An error occurred while loading the CBC library:\t " "{}\n".format(e))
9896
has_cbc = False
9997

10098
if has_cbc:
101-
ffi.cdef(
102-
"""
99+
ffi.cdef("""
103100
typedef int(*cbc_progress_callback)(void *model,
104101
int phase,
105102
int step,
@@ -546,8 +543,7 @@
546543
const char *Cbc_featureName(int i);
547544
548545
void Cbc_reset(Cbc_Model *model);
549-
"""
550-
)
546+
""")
551547

552548
CHAR_ONE = "{}".format(chr(1)).encode("utf-8")
553549
CHAR_ZERO = "\0".encode("utf-8")
@@ -1008,12 +1004,10 @@ def cbc_get_osi_name_indexes(osi_solver) -> Dict[str, int]:
10081004
return nameIdx
10091005

10101006
# progress callback
1011-
@ffi.callback(
1012-
"""
1007+
@ffi.callback("""
10131008
int (void *, int, int, const char *, double, double, double,
10141009
int, int *, void *)
1015-
"""
1016-
)
1010+
""")
10171011
def cbc_progress_callback(
10181012
model,
10191013
phase: int,
@@ -1036,11 +1030,9 @@ def cbc_inc_callback(
10361030
return
10371031

10381032
# cut callback
1039-
@ffi.callback(
1040-
"""
1033+
@ffi.callback("""
10411034
void (void *osi_solver, void *osi_cuts, void *app_data, int level, int npass)
1042-
"""
1043-
)
1035+
""")
10441036
def cbc_cut_callback(osi_solver, osi_cuts, app_data, depth, npass):
10451037
if (
10461038
osi_solver == ffi.NULL
@@ -1452,10 +1444,8 @@ def write(self, file_path: str):
14521444
elif ".bas" in file_path.lower():
14531445
cbclib.Cbc_writeBasis(self._model, fpstr, CHAR_ONE, 2)
14541446
else:
1455-
raise ValueError(
1456-
"Enter a valid extension (.lp, .mps or .bas) \
1457-
to indicate the file format"
1458-
)
1447+
raise ValueError("Enter a valid extension (.lp, .mps or .bas) \
1448+
to indicate the file format")
14591449

14601450
def read(self, file_path: str) -> None:
14611451
if not isfile(file_path):
@@ -1484,10 +1474,8 @@ def read(self, file_path: str) -> None:
14841474
logger.info("Optimal LP basis successfully loaded.")
14851475

14861476
else:
1487-
raise ValueError(
1488-
"Enter a valid extension (.lp, .mps or .bas) \
1489-
to indicate the file format"
1490-
)
1477+
raise ValueError("Enter a valid extension (.lp, .mps or .bas) \
1478+
to indicate the file format")
14911479

14921480
def set_start(self, start: List[Tuple[Var, numbers.Real]]) -> None:
14931481
# Augment start list with default zero values for absent non-continuous variables
@@ -1778,7 +1766,9 @@ def add_var(
17781766
numnz = len(column.constrs)
17791767

17801768
isInt = (
1781-
CHAR_ONE if var_type.upper() == "B" or var_type.upper() == "I" else CHAR_ZERO
1769+
CHAR_ONE
1770+
if var_type.upper() == "B" or var_type.upper() == "I"
1771+
else CHAR_ZERO
17821772
)
17831773
cbclib.Osi_addCol(
17841774
self.osi,

0 commit comments

Comments
 (0)