Repository navigation
fix(pulp): avoid PuLP 4.0-deprecated APIs - #103
Conversation
- create variables via prob.add_variable_dicts when available - pick backend: solver_name -> COIN_CMD -> HiGHS -> bundled PULP_CBC_CMD - honour solver_name (was ignored), read binaries with > 0.5 threshold - dedupe solve/solve_with_weights into _solve_ilp Co-Authored-By: dominicusin <dominicusin@yahoo.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| name = _SOLVER_ALIASES.get(self.solver_name.upper(), self.solver_name) | ||
| return pulp.getSolver(name, msg=False, timeLimit=time_limit) |
There was a problem hiding this comment.
🟡 Explicit CBC selection skips bundled solver
On PuLP 2.x or 3.x without system CBC, solver_name="CBC" selects unavailable COIN_CMD. Solving falls back to greedy despite an available bundled CBC, losing optimal results for some inputs.
Learn more
PuLP 2.x and 3.x can ship a bundled CBC binary through PULP_CBC_CMD. COIN_CMD instead requires a separate cbc executable on PATH, so the CBC alias is not interchangeable with the bundled solver on those versions. The explicit branch returns COIN_CMD without checking availability. The solve wrapper catches the resulting failure and uses greedy, while the automatic branch still reaches the bundled solver.
Example: With PuLP 3.3, no cbc on PATH, and packages A conflicting with B and C, PulPSolver(solver_name="CBC").solve(...) takes greedy; bundled CBC can select B and C instead of A.
Recommended fix: For the CBC alias, check COIN_CMD.available() and use the bundled PULP_CBC_CMD when present on pre-4.0 PuLP. Keep explicit backend selection separate from the default HiGHS preference, and add an end-to-end test with COIN_CMD.available() false.
Was this helpful? React with 👍 or 👎 to provide feedback.
… explicit CBC - PuLP 4.0 removed LpStatus and returns LpSolveStats from solve(); the import failure silently disabled PulPSolver on Python 3.12. - solver_name='CBC' now uses bundled PULP_CBC_CMD when no system CBC. - Tests no longer assume PULP_CBC_CMD / LpVariable.dicts exist. Co-Authored-By: dominicusin <dominicusin@yahoo.com>
Summary
Running the suite on PuLP 3.3 printed 30+
DeprecationWarnings fromPulPSolver. Both APIs it calls will be removed in PuLP 4.0:LpVariable.dictsandPULP_CBC_CMD.Changes in
package_maximizer/solvers/pulp_solver.py:_binary_vars()usesprob.add_variable_dicts(...)when PuLP provides it, and otherwise falls back toLpVariable.dicts, sopulp>=2.5still works._make_backend()tries these in order:solver_name, viapulp.getSolver. The aliasesCBC→COIN_CMDandHIGHS→HiGHSare accepted. Before this changesolver_namewas stored but never used.COIN_CMDif acbcbinary is available (system install orpip install pulp[cbc]).HiGHS/HiGHS_CMD.PULP_CBC_CMD, with its deprecation warning suppressed (PuLP < 4.0 only). If none of these exist it raisesRuntimeError,solve()catches it, and the greedy fallback runs.value > 0.5instead of== 1. The old check could drop selected packages when the solver returns a value like 0.9999999.solveandsolve_with_weightsnow share one_solve_ilpinstead of two copies of the same model code.No dependency changes.
pulp[cbc]stays optional.Checks
cbcbinary on PATH, and with-W error::DeprecationWarning:pulp.New tests in
tests/test_pulp_solver.py::TestPulPBackendSelectioncover the alias handling, the order of backend selection, the bundled fallback with no warning, the no-backend error path, and the legacy variable API.Link to Devin session: https://app.devin.ai/sessions/7a195999dfd146d48fbc98f4bab6707a
Open in Devin Desktop: https://app.devin.ai/desktop/session/7a195999dfd146d48fbc98f4bab6707a?variant=devin
Requested by: @dominicusin