-
Notifications
You must be signed in to change notification settings - Fork 1
[WIP] Implement rewrite validator #55
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
base: main
Are you sure you want to change the base?
Conversation
Not to confuse it with the nonlocal insertion
@Keno does the code in |
test/validation.jl
Outdated
sciml_prob = DiffEqBase.get_concrete_problem(our_prob, true); | ||
f_compressed = sciml_prob.f.f | ||
f_compressed(residuals_compressed, du_compressed, u_compressed, p, t) | ||
# XXX: `ddt(x₁)` gets substituted by `x₁ *ᵢ x₂` for the last equation after scheduling. |
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 briefly mentioned it in our last call, but I'm not sure I understand how we should work around that assuming that the overall approach is correct. Codegen looks at the past du
for the first equation but then looks at its expected value (i.e. its RHS) for the last equation, even though we are using ddt(x1)
in both expressions.
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.
For linear equations, you can't compare the residuals directly, since ssrm rewrites them. However, you can reconstitute them uniquely from the state vector, since the total_incidence has the coefficients. Sorry, I think I forgot to mention that detail in the issue.
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 see, so that tells us how to reconstruct the residual for the linear equation x₃ - x₁
.
However, the equations I wrote about in #55 (comment) were ddt(x₁) - x₁ * x₂
and x₄ * x₄ - ddt(x₁)
, which are each using a different value for ddt(x₁)
after scheduling. Would you have any pointers on how to deal with that?
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.
The values should be numerically equal up to tolerance (in an on-manifold state vector), so it shouldn't matter.
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.
Do we want to require the u
/du
we provide for testing to be on-manifold? That sounds like a reasonable requirement, but perhaps it might be good to also check that outside of this condition the optimized version behaves similarly to the unoptimized version, unless that doesn't affect the correctness of our solutions.
I need to read it in more detail, some initial comments are that I don't think we should be using RHSSpec for this, since the ABI is different. The other is that in this mode, we should probably also not do the IPO/argument transform and then in particular, the ABI needs to retain all the original arguments (in addition to the vectors that you have). Because of those two points then, there should also not be a TornCacheKey for this, since there's always only one specialization for this (for each method instance). In general, I think you're on the right track though. |
That makes sense, thanks. IIUC,
To make sure I understand: by IPO/argument transform, do you mean the flattening transform, or/and another one? Then my understanding is that because we don't flatten, we must pass around all arguments because the callees will need them whole (which is a consequence of not performing SICM). Is that correct? |
Yes
Yes, the flattening and the nonlinear replacement rewrite. Although it's a little bit tricky, because the latter introduces extra equations, so you may want to run it anyway and just copy the IR before it finishes (and then the introduced extra equations just don't show up in the IR and end up as 0).
Yes, the code data flow (and code itself, frankly) is exactly the same as the original code, except that all the functions have a few extra arguments to magically synthesize the correct return value for |
This includes a refactor that considers mapping to states, instead of individual mappings into u/du vectors
Closes #47.
This PR is based on #54, for a clean view of the changes see the comparison against that PR.
This is still largely a work in progress, I am just putting it here for discussion.