From 72cdcd7bb11ec449bddd1db2d76d20c29c860584 Mon Sep 17 00:00:00 2001 From: Christopher Maes Date: Wed, 4 Mar 2026 16:38:20 -0800 Subject: [PATCH 1/3] Fix incorrect error with x + x*x in Python API --- python/cuopt/cuopt/linear_programming/problem.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/cuopt/cuopt/linear_programming/problem.py b/python/cuopt/cuopt/linear_programming/problem.py index baf9716191..43ee07a11a 100644 --- a/python/cuopt/cuopt/linear_programming/problem.py +++ b/python/cuopt/cuopt/linear_programming/problem.py @@ -204,6 +204,8 @@ def __add__(self, other): return LinearExpression([self, other], [1.0, 1.0], 0.0) case LinearExpression(): return other + self + case QuadraticExpression(): + return other + self case _: raise ValueError( "Cannot add type %s to variable" % type(other).__name__ From 4253db3a957362d0191d1a9ca2c7320a59d15ec3 Mon Sep 17 00:00:00 2001 From: Christopher Maes Date: Wed, 4 Mar 2026 16:45:49 -0800 Subject: [PATCH 2/3] Fix incorrect error with +x or -x in Python API --- python/cuopt/cuopt/linear_programming/problem.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/cuopt/cuopt/linear_programming/problem.py b/python/cuopt/cuopt/linear_programming/problem.py index 43ee07a11a..bb9430e5ca 100644 --- a/python/cuopt/cuopt/linear_programming/problem.py +++ b/python/cuopt/cuopt/linear_programming/problem.py @@ -195,6 +195,12 @@ def getVariableName(self): """ return self.VariableName + def __neg__(self): + return LinearExpression([self], [-1.0], 0.0) + + def __pos__(self): + return self + def __add__(self, other): match other: case int() | float(): From d21f55f116c5ca6ce803ec0fab2d9b98cdeca62b Mon Sep 17 00:00:00 2001 From: Ishika Roy <41401566+Iroy30@users.noreply.github.com> Date: Thu, 5 Mar 2026 10:30:01 -0600 Subject: [PATCH 3/3] Update problem.py --- python/cuopt/cuopt/linear_programming/problem.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/cuopt/cuopt/linear_programming/problem.py b/python/cuopt/cuopt/linear_programming/problem.py index bb9430e5ca..80cb83ee6f 100644 --- a/python/cuopt/cuopt/linear_programming/problem.py +++ b/python/cuopt/cuopt/linear_programming/problem.py @@ -229,6 +229,8 @@ def __sub__(self, other): case LinearExpression(): # self - other -> other * -1.0 + self return other * -1.0 + self + case QuadraticExpression(): + return other * -1.0 + self case _: raise ValueError( "Cannot subtract type %s from variable"