Support PuLP 4.0 while keeping PuLP 3.x fallback (#131) - #134
Open
ishikaghosh2201 wants to merge 1 commit into
Open
ishikaghosh2201 wants to merge 1 commit into
ishikaghosh2201 wants to merge 1 commit into
Conversation
ishikaghosh2201
requested review from
lizliz
and
a balanced review from Copilot
and removed request for
lizliz
October 3, 2026 05:21
| "pandas", | ||
| "scipy", | ||
| "pulp", | ||
| "highspy; python_version >= '3.12'", |
| prob += pulp.lpSum(x.values()) >= 3 | ||
| prob += t >= pulp.lpSum(x.values()) | ||
|
|
||
| code, status = _solve(prob, select_pulp_solver()) |
This branch has not been deployed
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.


Description
PuLP 4.0.0 removed several APIs that
cereeberus/distance/ilp.pyrelied on. This PR moves the ILP code to the PuLP 4 API and keeps working with PuLP 3.x.ilp.py_new_var(prob, name, cat)usesprob.add_variable(PuLP 4), withpulp.LpVariableas the fallback (PuLP 3)._new_var_dict(prob, name, indices, cat)replacespulp.LpVariable.dicts. It keeps the same(a, b)/(a, b, c)tuple keys, sobuild_map_matricesis unchanged._solve(prob, solver)returns(status_code, status_str). On PuLP 4 it reads theLpSolveStatsobject returned byprob.solve(). On PuLP 3 it usesprob.status/pulp.LpStatus. Status strings shared by both versions are normalized to the PuLP 3 spelling (e.g."Not Solved"), so return values don't depend on the installed version.solve_ilpandsolve_ilp_distnow use these helpers. Their inputs, outputs and constraints are unchanged.select_pulp_solver:getattr, so the missingPULP_CBC_CMDis skipped instead of raisingAttributeError.HiGHS/HiGHS_CMDto the fallback order, after the CBC options, so CBC is still preferred when available."HIGHS"is now accepted as a solver name.returnline at the end ofsolve_ilp_dist.Dependencies
highspy; python_version >= '3.12'topyproject.tomlandrequirements.txt. PuLP 4 no longer bundles a CBC binary, so without this a fresh install on Python 3.12+ has no solver. Python 3.9–3.11 still gets PuLP 3.x with its bundled CBC.Motivation and Context
Fixes #131.
The
pulpdependency has no version cap. PuLP 4.0 (released 2026-09-25) requires Python ≥3.12, so CI on Python 3.12 started installing it, andtest_interleaving.pyfailed with:AttributeError: type object 'LpVariable' has no attribute 'dicts'AttributeError: module 'pulp' has no attribute 'PULP_CBC_CMD'Anyone on Python 3.12+ who ran
pip install cereeberusgot a brokenoptimize(). Rather than pinningpulp<4, this PR supports both versions.How has this been tested?
highspy) and with PuLP 3.x: all tests pass on both.cbcboxinstead of HiGHS: all tests pass.tests/test_ilp_pulp_compatibility.py(14 tests). Most use mocks, so both code paths are tested whichever PuLP version is installed:_new_var/_new_var_dicton the PuLP 4 and PuLP 3 paths: tuple, triple and scalar keys, unique names, empty indices._solve: PuLP 4 status codes map to the PuLP 3 strings, new PuLP 4 codes (e.g.TimeLimit) pass through, and the PuLP 3 path usesprob.status.select_pulp_solver: skips the missingPULP_CBC_CMD, still prefersCOIN_CMDover HiGHS, and accepts"highs"by name.Types of changes
Checklist
pyproject.tomlfile if a new version needs to be pushed to pypi. Note that if the number isn't incremented, the package will not be pushed to pypi, which is useful if this PR is only for updating documentation.make formatto clean up the code withblack.make tests).