Skip to content
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

Fix bugs in jacobian approximation #96

Merged
merged 28 commits into from
Oct 4, 2024
Merged

Fix bugs in jacobian approximation #96

merged 28 commits into from
Oct 4, 2024

Conversation

mikeingold
Copy link
Owner

@mikeingold mikeingold commented Sep 30, 2024

Completed

  • Discovered and fixed a bug that reduced accuracy of some integral calculations.
  • Discovered and fixed a bug causing Floating point argument FP not working for Float32 #74.
  • Improved performance of jacobian function, leading to a performance improvement of about 10% in most integral calculations.
  • Unit tests
    • Added combinations.jl tests for Box in (parametric) 1D, 2D, and 3D.
    • Enabled verbose for auto_tests.jl sets, allowing for direct comparison of runtimes versus combinations.jl tests.
    • Removed all Box tests from auto_tests.jl as now obsoleted.

Copy link

codecov bot commented Oct 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (a445f66) to head (9fcaedc).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #96   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines          269       258   -11     
=========================================
- Hits           269       258   -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mikeingold
Copy link
Owner Author

Whoa. It looks like these tests uncovered a bug that somehow the auto tests weren't finding. For some reason the Jacobian calculation is using a central finite diff near the interval boundaries. The conditional inside ∂ₙr! is supposed to switch to left or right finite diff when that close to the domain boundaries to prevent this.

@mikeingold
Copy link
Owner Author

mikeingold commented Oct 1, 2024 via email

@mikeingold mikeingold changed the title Add tests for Box Fix bug in jacobian approximation Oct 1, 2024
@mikeingold
Copy link
Owner Author

mikeingold commented Oct 2, 2024 via email

@mikeingold mikeingold changed the title Fix bug in jacobian approximation Fix bugs in jacobian approximation Oct 2, 2024
@mikeingold mikeingold marked this pull request as ready for review October 2, 2024 23:35
src/differentiation.jl Outdated Show resolved Hide resolved
src/differentiation.jl Outdated Show resolved Hide resolved
@mikeingold
Copy link
Owner Author

I never cease to be amazed how drastically even just a few allocations can slow down code. I ran some @benchmarks and for a 3D Box the mean execution time for jacobian drops by an order of magnitude with this code change.

mikeingold and others added 2 commits October 3, 2024 10:36
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@JoshuaLampert JoshuaLampert linked an issue Oct 3, 2024 that may be closed by this pull request
@JoshuaLampert
Copy link
Collaborator

JoshuaLampert commented Oct 3, 2024

That's really good news. Thanks a lot @mikeingold. Great work! You say you fixed a bug that lead to reduced accuracy. How big was the loss of accuracy approximately? Can we maybe make some tolerances more strict after this fix?

@mikeingold
Copy link
Owner Author

That's really good news. Thanks a lot @mikeingold. Great work! You say you fixed a bug that lead to reduced accuracy. How big was the loss of accuracy approximately? Can we maybe make some tolerances more strict after this fix?

I'm honestly a bit puzzled that this bug didn't cause test failures across the board.

Essentially, for a parametricly-3D geometry, the Jacobian should have been finding tangent-like vectors in the parametric directions [1, 0, 0], [0, 1, 0], [0, 0, 1]... but in my mind the bug would have instead been finding tangents in the directions [1, 0, 0], [1, 1, 0], [1, 1, 1]. Then the differential element gets calculated via the outer products of all of these. Somehow, it seems like the difference was so small that it didn't even fail most tests with default precision.

@mikeingold
Copy link
Owner Author

Either way, this is a significantly-improved version of the jacobian function. It performs exactly the same work without all the extra abstraction and without all of the extra allocations. On my machine, the old jacobian runs in a mean time of around 8 us, while the new one is around 800 ns. At the aggregate level this seems to have reduced CI time by roughly 10%.

Longer-term I'd like to re-evaluate all of the explicit rtol values and rules, e.g. GaussLegendre(100) is just a holdover from the auto-tests that seemed to be good enough to universally pass all unit tests. Also, weirdly, the current Box in 2D tests seem to take twice as long as the Box in 3D tests.

@mikeingold
Copy link
Owner Author

Did you see the comment I made earlier about anonymous function arguments? I think it got rolled into a resolved review.

Copy link
Collaborator

@JoshuaLampert JoshuaLampert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's indeed strange that this bug didn't cause more trouble before, but anyway. I made a small suggestion regarding the anonymous function, but it's also not ideal. Otherwise this looks good to me. Thanks again!

src/differentiation.jl Outdated Show resolved Hide resolved
src/differentiation.jl Outdated Show resolved Hide resolved
@mikeingold
Copy link
Owner Author

Once this gets merged, I'll get #98 merged and release a v0.14.1.

@mikeingold mikeingold merged commit e969029 into main Oct 4, 2024
14 checks passed
@mikeingold mikeingold deleted the box-tests branch October 4, 2024 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Floating point argument FP not working for Float32
2 participants