-
Notifications
You must be signed in to change notification settings - Fork 274
Description
Describe the bug
For older (still standard) versions of numpy, we fail to create the below constraints. This issue no longer exists for numpy 2.x, but I predict it will be a few years until 1.x becomes non widely used.
The general reason for the error after looking into for a few hours:
At some point when we create the ExprCons object the __nonzero__ function will be called (probably should change this to __bool__ at some point). It is called after the ExprCons object has been initialised and after the richcmp function has finished. My best guess is that it is being called because np is somehow forcing a comparison between the two objects at some point. This problem is avoided when np is on the RHS and we are then comparing our ExprCons object to the np object (therefore using our comparison function, which doesn't exist I guess?). Somehow when it is on the LHS np is returning some actual value instead of something that hides the comparison.
To Reproduce
from pyscipopt import Model
import numpy as np
m = Model()
a = np.array([1, 2, 3], dtype=np.float32)
x = m.addVar()
y = m.addVar()
m.addCons(a[1] <= 2 * x + 3 * y)Expected behavior
A constraint should be added