Speed up sol[UnaryExpr] via C-level math and refactor UnaryExpr - #1224
Speed up sol[UnaryExpr] via C-level math and refactor UnaryExpr#1224Zeroto521 wants to merge 18 commits into
sol[UnaryExpr] via C-level math and refactor UnaryExpr#1224Conversation
…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
UnaryExpr
UnaryExprUnaryExpr
UnaryExprsol[UnaryExpr] via C-level math and refactor UnaryExpr
|
By the way, @Zeroto521 , out of curiosity. Are you also using PySCIPOpt for your work, or are you just speeding things up for fun? |
|
80% of the OR problems I encounter use commercial solvers or our closure algorithms for large-scale, speed-critical cases, while the rest use open-source ones for small tasks and research. |
| def __abs__(self) -> UnaryExpr: | ||
| if self._op == "abs": | ||
| return <UnaryExpr>self.copy() | ||
| return UnaryExpr(Operator.fabs, self) |
There was a problem hiding this comment.
ExprLike.__abs__ can replace UnaryExpr(Operator.fabs, self)
|
I see @Zeroto521 , thank you! We're actually in the process of collecting users of SCIP "in the wild", particularly in industry. Would it be possible for us to reference the work you're doing? We can talk via email, if you prefer: joao.goncalves.dionisio@gmail.com |
|
Hey @Zeroto521 , just wanted to let you know that I'm going to be quite busy until the end of August, but by then I will be able to take a proper look at the repo. Are there other changes you're planning on making? |
Yeah, I've already finished the basic version (drop |
| from libc.math cimport cos as c_cos | ||
| from libc.math cimport exp as c_exp | ||
| from libc.math cimport fabs as c_fabs | ||
| from libc.math cimport INFINITY |
There was a problem hiding this comment.
This version of INFINITY doesn't have any Python object runtime cost
This branch is 1.45x faster than master.