-
Notifications
You must be signed in to change notification settings - Fork 518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Python macros to accelerate Pyomo expression kernels #1161
Comments
Here's a publication describing a similar idea for ML: https://www.sysml.cc/doc/2019/194.pdf |
Carl noted that we should consider having a generic mechanism for users to create a canonical-like expression, which should have a noticable impact on model writers. |
I think, if we are smart, this could set the bar for how much faster we could be on the expression creation and manipulation side. If we had an efficient way to build the canonical directly (with left, body, right as well), this would be the target for other efficient expression building. |
This is different from, but strongly related to, templates. See #1153, which I am about to flush out. |
Archived on the master Performance Proposals Issue (#1430). Closing this performance proposal until active development has begun. |
One of the key ideas exploited in Julia's JuMP package is macros. These rewrite the Julia expression tree to optimize the creation of Julia data structures for JuMP constraints and expressions.
The macropy package provides support for similar syntactic macros in Python. Pyomo could leverage this capability to optimize the execution of expression construction.
Specifically, a decorator could be created for rule functions that replace them with functions that are reworked using syntactic macro operations to streamline the execution of expression setup. Consider the following rule:
def rule(model, i)
return 2*model.x[i] == model.y[i]
model.c = Constraint(range(1000000), rule=rule)
In every call to
rule
, Pyomo creates an expression tree. In so doing, Pyomo incrementally recognizes the monomial term 2*x[i], and it incrementally combines the LHS and RHS. This rule would be more efficiently written by directly creating the expression objects, rather than doing operator overloading.Other developers have made a similar observation, and specifically they have noted that directly creating Pyomo's linear expression object leads to a significant speed-up in the construction of exprssions. We can automate this activity using syntactic macros.
NOTE:
The text was updated successfully, but these errors were encountered: