Skip to content

Fix incorrect errors with x + x*x, +x, -x in Python API#936

Merged
rapids-bot[bot] merged 5 commits intoNVIDIA:mainfrom
chris-maes:qp_python_fix
Mar 9, 2026
Merged

Fix incorrect errors with x + x*x, +x, -x in Python API#936
rapids-bot[bot] merged 5 commits intoNVIDIA:mainfrom
chris-maes:qp_python_fix

Conversation

@chris-maes
Copy link
Contributor

Description

Issue

Checklist

  • I am familiar with the Contributing Guidelines.
  • Testing
    • New or existing tests cover these changes
    • Added tests
    • Created an issue to follow-up
    • NA
  • Documentation
    • The documentation is up to date with these changes
    • Added new documentation
    • NA

@chris-maes chris-maes requested a review from a team as a code owner March 5, 2026 00:38
@chris-maes chris-maes requested a review from rgsl888prabhu March 5, 2026 00:38
@copy-pr-bot
Copy link

copy-pr-bot bot commented Mar 5, 2026

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.

@chris-maes chris-maes added bug Something isn't working non-breaking Introduces a non-breaking change labels Mar 5, 2026
@chris-maes chris-maes added this to the 26.04 milestone Mar 5, 2026
@chris-maes
Copy link
Contributor Author

/ok to test 72cdcd7

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 84d14aa3-56d3-4c45-baa9-9ebdbf1a2145

📥 Commits

Reviewing files that changed from the base of the PR and between 4253db3 and d21f55f.

📒 Files selected for processing (1)
  • python/cuopt/cuopt/linear_programming/problem.py

📝 Walkthrough

Walkthrough

Adds unary negation (__neg__) and unary plus (__pos__) to Variable, and extends Variable.__add__ and Variable.__sub__ to delegate to QuadraticExpression when that type appears on the other operand, enabling commutative addition and compatible subtraction with quadratic expressions.

Changes

Cohort / File(s) Summary
Variable operator updates
python/cuopt/cuopt/linear_programming/problem.py
Added Variable.__neg__ to return a LinearExpression representing -self; added Variable.__pos__ to return self; extended Variable.__add__ to handle QuadraticExpression by returning other + self; extended Variable.__sub__ to handle QuadraticExpression by returning other * -1.0 + self.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description field is empty except for the contribution template; it provides no meaningful information about the changeset. Add a brief description of the bug being fixed and the solution implemented to clarify the PR's purpose.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: adding support for unary operators (+x, -x) and mixed expression operations (x + x*x) in the Python API.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@chris-maes chris-maes changed the title Fix incorrect error with x + x*x in Python API Fix incorrect errors with x + x*x, +x, -x in Python API Mar 5, 2026
@chris-maes
Copy link
Contributor Author

/ok to test 4253db3

@Iroy30
Copy link
Member

Iroy30 commented Mar 5, 2026

/ok to test 359c81e

@chris-maes
Copy link
Contributor Author

/merge

@chris-maes
Copy link
Contributor Author

/ok to test 359c81e

@chris-maes
Copy link
Contributor Author

/merge

@chris-maes
Copy link
Contributor Author

/ok to test f7f2301

@rapids-bot rapids-bot bot merged commit c36ae1d into NVIDIA:main Mar 9, 2026
86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants