-
Notifications
You must be signed in to change notification settings - Fork 5
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
add AD (Enzyme) support via EnzymeExt #129
Conversation
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Joshua Lampert <[email protected]>
Co-authored-by: Joshua Lampert <[email protected]>
* Add Bézier entry * Missing comma, added newline * Make item implicitly Unitful * Make test item explicit to avoid reference errors * Formatting * Reformat range * Apply format suggestion --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.
This looks pretty nice already. Great to see that Enzyme works pretty much out of the box. I only have some minor comments/suggestions.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## diff-select #129 +/- ##
===============================================
- Coverage 95.87% 94.57% -1.31%
===============================================
Files 17 17
Lines 291 295 +4
===============================================
Hits 279 279
- Misses 12 16 +4 ☔ View full report in Codecov by Sentry. |
@kylebeggs is there any chance you’re better at |
I don't think anyone is actually good at git rebase haha. I'll give it a shot. Sometimes I find it easier to just make a new PR when there the current PR changes aren't too sparse like this one. I'm traveling this weekend so it'll be Monday. |
It always sounds easy enough in practice but fails miserably for me. I just went through the same with #114 which became #130 lol. No worries on timeline. I think the additions here look good. |
@mikeingold I will still work on this in the sense that a few of the tests error and need to address that, but will wait until #131 is done to not further complicate the rebasing. |
Sounds good. Sorry again for the surprise complication. I’m really looking forward to |
@mikeingold @JoshuaLampert Any ideas on how to go about adding the tests? Maybe wrpa the current tests in |
tl;dr-up-front: I'm not sure what the best answer is. I don't think we necessarily need exhaustive coverage of the entire combination space of: integrand function output types, geometry types, integration rule type and settings, differentiation method, floating point precision spec, etc. It would be nice, but could lead to a combinatorial explosion at test time. The |
Another option would be to have separate jobs for the different backends. Meshes.jl does something similar by setting an environment variable, see here and here and here. This would save us some CI time and the different jobs can fail and succeed independently of each other making it easier to investigate where a problem is if a job fails. |
@mikeingold I think that is a sufficient approach. @JoshuaLampert I initially tried to go this route, but I realized there is no good way to run the test suite locally in that manner. I guess you can set the variable and then run the macro that runs all the tests in the REPL? |
Honestly, I think the easiest would be to just change the analogue of this line locally from |
I decided to try the route of full integration tests. If we decide the additional tests will extend the total test time too much, we can just test |
# float settings | ||
AD = if isCI | ||
if ENV["AD"] == "FiniteDifference" | ||
FiniteDifference() |
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.
Currently, one snag with this approach is that several of the geometries with specialization
methods are edge cases that use integral
methods with hard-coded Analytical
differentials. Trying to integrate those geometries with any other DifferentiationMethod
is guaranteed to throw an error.
This was one of the reasons I was hoping to just eliminate Analytical
altogether. They're faster for a couple of specific geometry types, but at the cost of a fair bit of added complexity. There was some benefit in code/math reduction, but largely it was to eliminate these cases where diff_method
isn't truly supported.
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'm planning to write up a Discussion post with my thoughts, and some historical context, on our unit test structure/organization. I suspect it might be adequate to just add a single new test to each geometry's standard test set, something like
# For most geometries, or @test_throws where it currently fails
@test integral(f, geometry, GaussLegendre(100); diff_method=AutoEnzyme())
I think the impact of this new diff_method
should be apparent for any integral of each geometry type, which would make re-running all of them redundant. And, especially with other recent performance and CI runtime improvements, we currently have a little CI runtime to spare.
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.
Currently, one snag with this approach is that several of the geometries with specialization methods are edge cases that use integral methods with hard-coded Analytical differentials. Trying to integrate those geometries with any other DifferentiationMethod is guaranteed to throw an error.
I left those tests to use integral
, not the integral_test
functions I created in Setup
, this is not an issue.
This was one of the reasons I was hoping to just eliminate Analytical altogether. They're faster for a couple of specific geometry types, but at the cost of a fair bit of added complexity. There was some benefit in code/math reduction, but largely it was to eliminate these cases where diff_method isn't truly supported.
Personally, I think the added complexity is worth the speed. But that is just my opinion.
I suspect it might be adequate to just add a single new test to each geometry's standard test set, something like
This makes sense. I will change to this approach.
Adds support to calculate the jacobian via Enzyme autodiff #35 . This is done by adding a package extension for Enzyme,
EnzymeExt
.