-
Notifications
You must be signed in to change notification settings - Fork 116
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
WIP: Code matching and Expr generation #183
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
lhs(a::Assignment) = a.lhs | ||
rhs(a::Assignment) = a.rhs | ||
|
||
const (←) = Assignment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to force the user to use Unicode. Can we also alias it to :=
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not a binary operator...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can always use Assignment(a, b)
:-p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha
Hi @shashi , thanks for the pointer! I'm still missing some context.
Will this let the |
https://github.com/SciML/ModelingToolkit.jl/blob/master/src/build_function.jl ^ this code is not pretty
not unless you make them parameters. |
Thanks @shashi . MTK didn't seem set up to have the flexibility I needed, so I haven't really done much with it. Hopefully it can make sense at some point if it becomes more flexible or some functionality is factored out into other packages. |
The problem is that it's too flexible. Some of it needs to be refactored into other dispatches because the sparse array handling overlaps with all of the parallelism choices in a way creates a bit of a mess. And that's not to mention the fact that there's little code reuse between the portions for generating code for C, Stan, and MATLAB. We instead need a way to specify "these are the blocks to keep together" (with cost functional information and locality information that connects to nonlinear tearing) which is separated from the specification of how to parallelize the blocks. The macroeconomics community donated a good set of tests over all of the sparsity stuff: https://github.com/SciML/ModelingToolkit.jl/blob/master/test/build_function_arrayofarray.jl The parallelism is a little undertested so it needs to be careful, but with a few parallelism tests it should be pretty easy to know when a superset has been hit with a nicer functional form. |
But the real issue with |
Can MTK let me specify
It didn't seem to expose interfaces for these. |
Well of course it can always get more features. But it's already a big load of features which is the cause of the refactor.
That's moreso because types are not fully supported in the symbolic system at this point, which is something that needs to get fixed. But it does do this: vectors of vectors and such are exactly what I just pasted tests of.
what do you mean by that?
ParallelForms, targets like CTarget, etc. It can generate code for clusters and it can put equations inside of Stan. That sounds like quite a lot of "how the code is generated" zzzz. |
@ChrisRackauckas Here's the kind of thing I need to be able to do: This uses Soss, MeasureTheory.jl, and SymbolicCodegen.jl |
Yes, the goal is to make it do all of that, plus work with sparsity patterns, automate the parallelism, and make it work with strongly connected components information for tearing. CSE falls into this because we immediately did sparsity -> parallelism, but you cannot easily then apply CSE without breaking parallel code because then you have to know the dependencies, i.e. you can only CSE things that live on the same node, and that needs to change the parallelism. So that's why it needs to take a step back and instead:
The big problem is that in the current design 3 and 4 are flips / intertwined, making 2 almost impossible, because we never did 1. But the goal is, knowing the issues now, solve it correctly by lowering in stages like that. (@shashi did I miss anything? I think that's all of it) |
Ok that's all great, my point was just about flexibility. I needed different functionality to be cleanly separated. Just having one giant |
We noticed 🤣. It outgrew its use. It's Lennie's rabbit and it got too much love until it needs a rewrite, which @shashi is leading since now we know a good scope for it. When it was designed, mixing with Dagger.jl and tearing wasn't even unheard of, we didn't even know it could be a thing. |
It is usually not super useful to have types as parameters, except for dispatch. You can always call |
Co-authored-by: "Yingbo Ma" <[email protected]>
This is true, and that's why we are doing this. and the rewrite. I am thinking more about how we can make it even better and flexible before I merge the PR. |
Starting the effort to release all the tension around build_function here.
Maybe the matchable thing is too fancy, but I like the macro as an experiment at least.
It makes
matchable in the form of:
@rule Hypot(~x, ~y) => hypot(~x, ~y)
Some arguments are vectors, e.g. pairs in
Let
, we need some matchers for vectors, and tuples maybe.We still need some types to represent function outputs of various forms, so that
body
fields inFunc
orLet
can represent: