Skip to content

[BUG] [python] Bad operand type when manipulating single variables #926

@mtanneau

Description

@mtanneau

Describe the bug

The cuOpt python API errors when building an expression starting with <op>x, where x is a Variable and <op> is a unary operator such as + or -.

Steps/Code to reproduce bug

from cuopt.linear_programming.problem import Problem, CONTINUOUS, MINIMIZE
from cuopt.linear_programming.solver_settings import SolverSettings

problem = Problem("lp")
x = problem.addVariable(lb=0.0, vtype=CONTINUOUS, name="x")
y = problem.addVariable(lb=0.0, vtype=CONTINUOUS, name="y")

# The following commands will error with message
#     bad operand type for unary -: 'Variable'
# More generally, any expression that starts with `-x` or `+x` will error
-x
+x

problem.addConstraint( x >= 0)  # OK
problem.addConstraint(+x >= 0)  # not OK
problem.addConstraint(-x <= 0)  # not OK

problem.addConstraint(-x + y <= 1)  # not OK
problem.addConstraint( y - x <= 1)  # ... but this is OK
# Adding explicit coeffs works
problem.addConstraint(-1 * x + y <= 1)  

problem.setObjective(-x, sense=MINIMIZE)  # also errors within objective

Expected behavior

I expect that -x or +x would return a LinearExpression object

Environment details (please complete the following information):

  • Environment location: DGX Spark with GB10 GPU and CUDA 13
  • Method of cuOpt install: python virtual environment with uv, then install via pip as in official instructions.

Additional context

While the error materializes in calls to addConstraint and setObjective, the root cause appears to be in the underlying expression construction/manipulation.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions