-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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 |
It looks like I accidentally introduced this bug with commit #8d5f81a in
v0.13.5, where I generalized the `jacobian` function to allow `ts::V` where
`V<:Union{AbstractVector, Tuple}`. The internal finite-diff functions made
use of a re-usable buffer vector that was no longer being re-zero'd between
usages. This should have resulted in inaccurate `differential` results, so
I'm surprised that the impact was apparently so small that tests still
passed (though a few received slightly-increased `atol`/`rtol` values).
TODO (maybe in a new branch/PR):
- Overhaul jacobian's finite-diff code: eliminate re-usable buffer without
new allocations
- Re-run prior tests to determine whether explicit/relaxed tolerances are
still required
…On Tue, Oct 1, 2024 at 10:08 AM github-actions[bot] < ***@***.***> wrote:
***@***.***[bot]* commented on this pull request.
------------------------------
In test/combinations.jl
<#96 (comment)>
:
> +
+ # Vector integrand
+ vsol = fill(sol, 3)
+ @test integral(fv, box, GaussLegendre(100))≈vsol rtol=1e-6
+ @test integral(fv, box, GaussKronrod()) ≈ vsol
+ @test integral(fv, box, HAdaptiveCubature()) ≈ vsol
+
+ # Integral aliases
+ @test lineintegral(f, box) ≈ sol
+ @test_throws "not supported" surfaceintegral(f, box)
+ @test_throws "not supported" volumeintegral(f, box)
+end
+
***@***.*** "Meshes.Box 2D" setup=[Setup] begin
+ a = π
+ box = Box(Point(0,0), Point(a,a))
*[JuliaFormatter]* reported by reviewdog
<https://github.com/reviewdog/reviewdog> 🐶
⬇️ Suggested change
- box = Box(Point(0,0), Point(a,a))
+ box = Box(Point(0, 0), Point(a, a))
—
Reply to this email directly, view it on GitHub
<#96 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA657OQXLL32INRTF46YBL3ZZKUEHAVCNFSM6AAAAABPELP43CVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGNBQGQ4DKMRTGY>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Good news! It looks like the current rewrite of jacobian fixes Issue #74.
It turns out the issue was caused by the default epsilon value being
specified as a Float64. When testing with `FP=BigFloat` this value was
being promoted to BigFloat anyway, but when testing with `FP=Float32` this
caused the parametric coordinates to be promoted to Float64.
…On Tue, Oct 1, 2024 at 7:29 PM github-actions[bot] ***@***.***> wrote:
***@***.***[bot]* commented on this pull request.
------------------------------
In test/combinations.jl
<#96 (comment)>
:
> + @test_throws "not supported" volumeintegral(f, box)
+end
+
***@***.*** "Meshes.Box 3D" setup=[Setup] begin
+ a = π
+ box = Box(Point(0, 0, 0), Point(a, a, a))
+
+ function f(p::P) where {P <: Meshes.Point}
+ x, y, z = ustrip.((p.coords.x, p.coords.y, p.coords.z))
+ (sqrt(a^2 - x^2) + sqrt(a^2 - y^2) + sqrt(a^2 - z^2)) * u"Ω/m^3"
+ end
+ fv(p) = fill(f(p), 3)
+
+ # Scalar integrand
+ sol = 3a^2 * (π * a^2 / 4) * u"Ω"
+ @test integral(f, box, GaussLegendre(100))≈sol
*[JuliaFormatter]* reported by reviewdog
<https://github.com/reviewdog/reviewdog> 🐶
⬇️ Suggested change
- @test integral(f, box, GaussLegendre(100))≈sol
+ @test integral(f, box, GaussLegendre(100)) ≈ sol
------------------------------
In test/combinations.jl
<#96 (comment)>
:
> +
+ function f(p::P) where {P <: Meshes.Point}
+ x, y, z = ustrip.((p.coords.x, p.coords.y, p.coords.z))
+ (sqrt(a^2 - x^2) + sqrt(a^2 - y^2) + sqrt(a^2 - z^2)) * u"Ω/m^3"
+ end
+ fv(p) = fill(f(p), 3)
+
+ # Scalar integrand
+ sol = 3a^2 * (π * a^2 / 4) * u"Ω"
+ @test integral(f, box, GaussLegendre(100))≈sol
+ @test_throws "not supported" integral(f, box, GaussKronrod())
+ @test integral(f, box, HAdaptiveCubature()) ≈ sol
+
+ # Vector integrand
+ vsol = fill(sol, 3)
+ @test integral(fv, box, GaussLegendre(100))≈vsol
*[JuliaFormatter]* reported by reviewdog
<https://github.com/reviewdog/reviewdog> 🐶
⬇️ Suggested change
- @test integral(fv, box, GaussLegendre(100))≈vsol
+ @test integral(fv, box, GaussLegendre(100)) ≈ vsol
—
Reply to this email directly, view it on GitHub
<#96 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA657OSFPUFHXQHE265NJSTZZMV7PAVCNFSM6AAAAABPELP43CVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGNBRGYZDCOJQGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I never cease to be amazed how drastically even just a few allocations can slow down code. I ran some |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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 |
Either way, this is a significantly-improved version of the Longer-term I'd like to re-evaluate all of the explicit |
Did you see the comment I made earlier about anonymous function arguments? I think it got rolled into a resolved review. |
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'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!
Once this gets merged, I'll get #98 merged and release a v0.14.1. |
Completed
FP
not working forFloat32
#74.jacobian
function, leading to a performance improvement of about 10% in most integral calculations.combinations.jl
tests forBox
in (parametric) 1D, 2D, and 3D.verbose
forauto_tests.jl
sets, allowing for direct comparison of runtimes versuscombinations.jl
tests.Box
tests fromauto_tests.jl
as now obsoleted.