8000 fix(pulp): avoid PuLP 4.0-deprecated APIs by devin-ai-integration[bot] · Pull Request #103 · dominicusin/package-maximizer · GitHub
[go: up one dir, main page]

Skip to content

fix(pulp): avoid PuLP 4.0-deprecated APIs - #103

Merged
dominicusin merged 2 commits into
mainfrom
devin/1791932649-pulp-v4-compat
Oct 13, 2026
Merged

dominicusin merged 2 commits into
mainfrom
devin/1791932649-pulp-v4-compat

Conversation

@devin-ai-integration
@devin-ai-integration devin-ai-integration Bot commented Oct 13, 2026 •
Copy link
Copy Markdown
Contributor

Summary

Running the suite on PuLP 3.3 printed 30+ DeprecationWarnings from PulPSolver. Both APIs it calls will be removed in PuLP 4.0: LpVariable.dicts and PULP_CBC_CMD.

Changes in package_maximizer/solvers/pulp_solver.py:

  • Variables: a new _binary_vars() uses prob.add_variable_dicts(...) when PuLP provides it, and otherwise falls back to LpVariable.dicts, so pulp>=2.5 still works.
  • Backend selection: the new _make_backend() tries these in order:
    1. explicit solver_name, via pulp.getSolver. The aliases CBC→COIN_CMD and HIGHS→HiGHS are accepted. Before this change solver_name was stored but never used.
    2. COIN_CMD if a cbc binary is available (system install or pip install pulp[cbc]).
    3. HiGHS / HiGHS_CMD.
    4. the bundled PULP_CBC_CMD, with its deprecation warning suppressed (PuLP < 4.0 only). If none of these exist it raises RuntimeError, solve() catches it, and the greedy fallback runs.
  • Result reading: variable values are read as value > 0.5 instead of == 1. The old check could drop selected packages when the solver returns a value like 0.9999999.
  • Refactor: solve and solve_with_weights now share one _solve_ilp instead of two copies of the same model code.
  • Logging: the non-optimal status message now logs the status name, not the raw integer.

No dependency changes. pulp[cbc] stays optional.

Checks

  • make test passes: 854 passed, 2 skipped. Ran both with and without a cbc binary on PATH, and with -W error::DeprecationWarning:pulp.
  • flake8 critical check passes; black and isort are clean
  • docs updated if behavior changed (n/a)

New tests in tests/test_pulp_solver.py::TestPulPBackendSelection cover 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

- 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>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@coderabbitai
coderabbitai Bot commented Oct 13, 2026 •
Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c9054201-bb2d-438d-a72c-7272559a1f90

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dominicusin
dominicusin enabled auto-merge (squash) October 13, 2026 23:05
@devin-ai-integration devin-ai-integration Bot left a comment
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +132 to +133
name = _SOLVER_ALIASES.get(self.solver_name.upper(), self.solver_name)
return pulp.getSolver(name, msg=False, timeLimit=time_limit)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Devin Review


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>
@dominicusin
dominicusin merged commit 1074692 into main Oct 13, 2026
16 checks passed
@dominicusin
dominicusin deleted the devin/1791932649-pulp-v4-compat branch October 13, 2026 23:13
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.

1 participant

0