Skip to content

Allow zero-valued LP Python model updates#1421

Open
fallintoplace wants to merge 1 commit into
NVIDIA:mainfrom
fallintoplace:fix/lp-python-zero-updates
Open

Allow zero-valued LP Python model updates#1421
fallintoplace wants to merge 1 commit into
NVIDIA:mainfrom
fallintoplace:fix/lp-python-zero-updates

Conversation

@fallintoplace

Copy link
Copy Markdown

Summary

Problem.updateConstraint and Problem.updateObjective used truthiness checks for optional numeric updates. That meant valid zero values such as rhs=0 or constant=0 were silently ignored.

This updates those checks to distinguish omitted arguments from explicit zero-valued updates. It also removes the mutable default list from both methods while keeping the existing call behavior.

Validation

  • python3 -m py_compile python/cuopt/cuopt/linear_programming/problem.py python/cuopt/cuopt/tests/linear_programming/test_python_API.py
  • git diff --check

Not run locally: PYTHONPATH=python/cuopt uvx --with 'pytest<9.0' pytest python/cuopt/cuopt/tests/linear_programming/test_python_API.py -k 'problem_update_accepts_zero_values' -q could not collect because this checkout does not include the generated/native cuopt.linear_programming.internals.internals module.

@fallintoplace fallintoplace requested a review from a team as a code owner June 10, 2026 21:35
@fallintoplace fallintoplace requested a review from Iroy30 June 10, 2026 21:35
@copy-pr-bot

copy-pr-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ce65f180-0c8a-4ef8-bc9f-1b47016244f9

📥 Commits

Reviewing files that changed from the base of the PR and between c99a5ce and c552401.

📒 Files selected for processing (2)
  • python/cuopt/cuopt/linear_programming/problem.py
  • python/cuopt/cuopt/tests/linear_programming/test_python_API.py

📝 Walkthrough

Walkthrough

The PR fixes mutable default arguments and improves parameter handling in two Problem class methods. updateConstraint and updateObjective now use None defaults instead of empty lists, and both methods respect falsy numeric values like 0 instead of skipping them during updates.

Changes

Mutable defaults and falsy value handling

Layer / File(s) Summary
updateConstraint method fix
python/cuopt/cuopt/linear_programming/problem.py
Method signature changes coeffs parameter default from mutable [] to None. Implementation initializes coeffs to an empty list when omitted and updates constr.RHS only when rhs is not None, allowing zero to be a valid RHS value.
updateObjective method fix
python/cuopt/cuopt/linear_programming/problem.py
Method signature changes coeffs parameter default from mutable [] to None. Implementation normalizes coeffs to an empty list when omitted, updates ObjConstant only when constant is not None, and updates ObjSense only when sense is not None, ensuring zero and falsy enum values are correctly applied.
Test coverage for zero values
python/cuopt/cuopt/tests/linear_programming/test_python_API.py
New test test_problem_update_accepts_zero_values validates that constraint RHS and objective constant can be set to zero without being ignored.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes


Suggested labels

non-breaking, improvement


Suggested reviewers

  • rgsl888prabhu
  • tmckayus
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Allow zero-valued LP Python model updates' directly and clearly summarizes the main change: enabling explicit zero values in LP model update methods.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem (truthiness checks ignoring zero values), the solution (distinguishing omitted arguments from explicit zeros, removing mutable defaults), and validation steps performed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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