Higher order implicit ad for roots#542
Conversation
|
Nvm, impressive. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #542 +/- ##
==========================================
+ Coverage 77.62% 77.69% +0.07%
==========================================
Files 369 370 +1
Lines 32831 32903 +72
==========================================
+ Hits 25484 25564 +80
+ Misses 7347 7339 -8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Noticed a bug with IFTDuals and SVector y as input. Currently uploading a fix for this |
|
Errors are unrelated, but i would like to see an all-green CI in this PR in particular. there are a lot of EoS that have a subproblem inside, and could benefit from good implicit (high-order) function theorem solver. for example (without checking the code):
I'm going to open an issue tracking those subproblems. |
|
I have ran the CI actions on my local fork and some errors popped up with flash derivatives. Upon further inspection I have found a few issues, first being that I used inplace
Fully agree on this point and this was the intended purpose of the development of this tool, but in my case focusing mainly on SAFT |
|
@longemen3000 I have implemented the fixes on my side and should be fine now. The CI's should be re-run, I pushed slightly early, when the new version wasn't registered yet There is quite a lot of performance on the table for the mixed tags case when working with multiple partials and/or vectors. Don't know when I'll have time to improve the performance for that, but will look at it at some point |
|
most test pass (including That performance left in the table is in Clapeyron or IFTDuals? if there is anything i can help in that regard, let me know. In particular, regarding the linear solver part, If i remember correctly, each LU instance allocates a In particular, the association algorithm as it is, is not the best in terms of allocations, but in terms of runtime speed. So, more allocations are not that important (if the speed is more or less the same). The SVector approach needs to be limited because it makes the function type-unstable (the result type depends on the value of the arguments.) |
I am confident that it should succeed in all cases. The tests I have for mixed tags considers all cases, all combinations of scalar and vector inputs and outputs. These tests for IFTDuals passes so the derivative logic is fine, there may be bugs with the utils however (i.e. dual promotion/demotions and obtaining the common dual type of args from generic structures) but does not seem to be the case currently.
Performance with IFTDuals. During the recursive process we constructs intermediate buffer arrays for the storage of duals. These buffers are short lived as we only use them to loop through the partials, solve each partial and then stack the result into a dual. Lets say we have want to solve function store_ift_cache(y::Y, BNi::B, neg_A, PT=Partials{N,V}) where {T,V<:Real,N,DT<:Dual{T,V,N},Y<:AbstractVector{V},B<:AbstractVector{DT}} # offload logic to be more efficient with storage types
dual_cache = Matrix{V}(undef, length(y), N)
for i in 1:N
BNi_i = extract_partials_(BNi, i) # get nested Duals
dy = extract_partials_(y, i) # get nested Duals
dual_cache[:, i] .= ift_(dy, BNi_i, neg_A)
end
return make_dual(y, DT, PT, dual_cache) # construct Dual numbers
endHere
The LU factorization is always reused. That is for a vector
Just for my sanity, I thought type instability occurs when the compiler cannot infer the types (either input or return) of variables. Since these are known (as part of the signature) I was under the impression that the SVector construction would be faster. |
|
My decision for now is to merge this, and stabilize performance along the way. Even in the worst case, using IFTDuals is a clear improvement over the the existent IFT solver |
Adds IFTDuals as a dependency which handles the differentiation of root finders, with reference to #502. We can now handle mixed tags and higher order implicit AD efficiently. I took quite a lot of inspiration from the
Solversmodule to make the code non-allocating where possible.Additionally, adjusted the association term to use
__gradients_for_root_findersto handle AD where we do not have a closed form solution for the fraction of non-bonded sites,X.