Repository navigation
Conversation
…r unary expressions Remove Python math module and use libc.math for C-level functions (fabs, exp, log, sqrt, sin, cos). Refactor unary expression evaluation by introducing specific subclasses (AbsExpr, ExpExpr, LogExpr, SqrtExpr, SinExpr, CosExpr) with dedicated evaluate methods using C functions, replacing the generic UnaryExpr implementation.
Update UnaryExpr type stubs to include concrete expression subclasses for more precise type annotations. This change refines the return type of __abs__ and introduces new expression classes. - Change __abs__ return type from GenExpr to AbsExpr - Add AbsExpr, ExpExpr, LogExpr, SqrtExpr, SinExpr, and CosExpr classes - All new classes inherit from UnaryExpr
Return a string from VarExpr.__repr__ VarExpr.__repr__ returned the wrapped Variable object instead of its name. Since Variable defines __repr__ but no __str__, str() on it fell back to __repr__, handed the non-string object back, and str.__str__ raised TypeError: __str__ returned non-string (type pyscipopt.scip.Variable). SumExpr and ProdExpr render their children with map(str, ...), so any VarExpr reached by buildGenExprObj or GenExpr.__add__/__mul__ blew up -- e.g. str(abs(x)), str(sqrt(x) * -1), and repr(2**x) vs repr(exp(x * log(2))). PowExpr and the unary __repr__ methods relied on the same implicit str(), so the leaf node is now responsible for returning a real string. Also annotate the __repr__ return type as str. @
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1259 +/- ##
==========================================
- Coverage 57.91% 57.71% -0.20%
==========================================
Files 26 27 +1
Lines 5807 5969 +162
==========================================
+ Hits 3363 3445 +82
- Misses 2444 2524 +80 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Codecov CI error on upstream: codecov/codecov-action#1975 |
| '''Note: none of these expressions should be polynomial''' | ||
| return INFINITY | ||
|
|
||
| def getOp(self): |
There was a problem hiding this comment.
I think there should still be a comfortable way for users to access this information. It's currently used in https://github.com/feloopy/feloopy, for example.
There was a problem hiding this comment.
This is a breaking change for downstream.
Before
After
from pyscipopt.scip import LogExpr, ExpExpr, SinExpr, CosExpr, SqrtExpr
if isinstance(expr, LogExpr): return log(child)
elif isinstance(expr, ExpExpr): return exp(child)If we merge Expr (without Op) and GenExpr (with Op), we need to drop the Op attribute.
For a breaking change, we can add a deprecation warning in version 6.2.2 and remove it in 6.3.x.
There was a problem hiding this comment.
Some bugs I found.
SumExpr.coefswas removed
if isinstance(expr, SumExpr):
result = Expr()
result = result + expr.constant
for coef, child in zip(expr.coefs, expr.children):
result = result + coef * _remap_scip_expr(child, var_map)
return result- PySCIPOpt doesn't have a tan function.
elif op == 'tan':
from pyscipopt.scip import tan as scip_fnThere was a problem hiding this comment.
@Zeroto521 A deprecation warning would be nice, yes, thank you.
There was a problem hiding this comment.
@k-tafakkori Hey! We're planning on merging some things that should impact your work on feloopy. Nothing too major, just giving you a heads up.
This change assigns explicit operator tags to expression objects such as sum, product, abs, exp, log, and trig functions, and exposes them via GenExpr.getOp(). It updates ExprLike constructors and constant/unary expression initialization so operator metadata stays consistent across copied and wrapped expressions. The corresponding type stubs in scip.pyi are also updated for the new Operator API.
Since we have all
UnaryExprsubclasses (abs, log, exp, sin, cos), we can drop theGenExpr._opattribute and usetypeinstead.