-
Notifications
You must be signed in to change notification settings - Fork 153
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 flag for activating robust calculation of expand_derivatives #1353
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #1353 +/- ##
===========================================
+ Coverage 3.98% 79.01% +75.03%
===========================================
Files 50 51 +1
Lines 4771 4880 +109
===========================================
+ Hits 190 3856 +3666
+ Misses 4581 1024 -3557 ☔ View full report in Codecov by Sentry. |
Why is a recalculation of occursin required? That seems like a bug that should just be addressed directly. |
It definitely is a bug, but no one was able to fix it until now, maybe because of #1126 (comment). I spent two nights trying to pin down the problem, but not being able to print intermediate values without affecting the process itself makes this really tedious/complicated. I decided implementing this workaround is much simpler and I think necessary, until some hero hunts this one down. I think the Problem is, that there actually are cases where recalculation is necessary because the expression tree can change between the creation of Line 189 in 8c518c2
Line 257 in 8c518c2
Line 186 in 8c518c2
After that point, |
Have you tried debugging/reproducing this by using the sorted arguments instead of unsorted? |
I think the occursin tree code can just be removed, but that changes the time complexity of this function... If you want to find more cases, I'd look into running more tests using fuzz.jl and fuzzlib.jl right now I believe it just runs simplify tests.. |
I agree that trying to debug the issue would be the best solution. But I don't know when somebody will do that and until then I would like to have a working way to calculate my derivatives, which currently is not possible. |
I did a take on actually solving the problem. I think the Problem is that subtrees of a differential are themself expanded multiple times, once before the differential is executed and then another time to execute the chain rule for the differential on the subtrees. I removed the second expansion by moving the actual execution of a differential to a separate function This fixes the test cases and the results with and without the robust flag agree. There are still two calls to |
This provides a workaround for issues #1126 and #1262 by adding a flag
robust
that if set, forces expand_derivatives to always recalculateoccurrences
.It also adds tests that check if the examples from the issues are actually solved. These tests also show that
expand_derivatives
can return a wrong result without throwing any error. Line 372 to 375 intests/diff.jl
:I set the robust flag to false per default but since the result of the non-robust version is not reliable it should be considered if setting it to true should be the default.