-
Notifications
You must be signed in to change notification settings - Fork 14
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
SciMLCompat + Enzyme #80
Conversation
Add tests of AD
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #80 +/- ##
=======================================
Coverage 51.77% 51.77%
=======================================
Files 32 32
Lines 3374 3374
=======================================
Hits 1747 1747
Misses 1627 1627 ☔ View full report in Codecov by Sentry. |
This issue needs to be addressed in order to be able to write custom pullback rules for Enzyme |
Not needed anymore after #116 |
This PR implements a useful interface to use
IncompressibleNavierStokes.jl
(INS) in theSciML
ecosystem.Secondarily, this PR proposes some extension to INS to make it compatible with
Enzyme.jl
to perform AD.At the moment this PR is marked as a draft, since there are a series of points that needs to be addressed.
SciML
We make INS compatible with SciML by approximating the DAE structure of the NS equation by using a projection operator.

It is possible to prove that this projection is consistent with the DAE in the presence of constant or periodic boundaries. Here we show for a test run that the SciML implementation has performance comparable to INS:
and that the solution is the same within machine precision

while we confirm that (using$$<10^{-11}$$ for the projected dynamics.
Float64
precision) the divergence remainsEnzyme
We introduce
create_right_hand_side_enzyme
by redefining some of the evaluations performed in INS to comply with Enzyme, in particular with respect to temporary variables (that we precompile inside the functions), avoiding unorthodox functions (likeKernelAbstractions._get_backend()
) in the chain of operation, and enforcing some type stability (in particular avoiding structs and tuples replacing them byComponentArrays
).In
general_Enzyme_benchmark.ipynb
we show the speedup that can be achieved by using Enzyme and we confirm the result for a-priori fitting using INS inEnzyme_vs_Zygote_a-priori.jl
, by obtaining the following result:Efficiently implementing a-posteriori training with INS+SciML+Enzyme is still a work-in-progress.
TODO
Enzyme.autodiff
to finite difference methods using ChainRulesLux.Chain
) to act inside the force rather than the current implementationsrc/enzyme.jl
to confirm that they do not introduce any numerical error over INS