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 Adjoint Sensitivities #237

Merged
merged 5 commits into from
Feb 8, 2024
Merged

Fix Adjoint Sensitivities #237

merged 5 commits into from
Feb 8, 2024

Conversation

mjohnson541
Copy link
Collaborator

Issue #235 seems to suggest the issue may be resolved by updating to SciMLSensitivities.jl.

@hwpang hwpang marked this pull request as draft November 14, 2023 17:05
@mjohnson541 mjohnson541 marked this pull request as ready for review February 5, 2024 00:01
@mjohnson541 mjohnson541 force-pushed the fix_adjoint_sens branch 2 times, most recently from 8bbe639 to 4a4f16c Compare February 7, 2024 17:32
Copy link

codecov bot commented Feb 7, 2024

Codecov Report

Attention: 51 lines in your changes are missing coverage. Please review.

Comparison is base (eed1896) 49.82% compared to head (e80bb70) 49.70%.
Report is 30 commits behind head on main.

Files Patch % Lines
src/ReactionMechanismSimulator.jl 0.00% 23 Missing ⚠️
src/Simulation.jl 52.00% 12 Missing ⚠️
src/Parse.jl 57.14% 9 Missing ⚠️
src/fluxdiagrams.jl 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #237      +/-   ##
==========================================
- Coverage   49.82%   49.70%   -0.13%     
==========================================
  Files          31       31              
  Lines        8086     8138      +52     
==========================================
+ Hits         4029     4045      +16     
- Misses       4057     4093      +36     

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

@mjohnson541
Copy link
Collaborator Author

Ultimately, the nasty error message was a red herring. However, I did resolve it by changing the typing for getadjointsensitivities. The real issue I suspect is that in SciMLSensitivity.jl at too tight of absolute tolerances the CVODE_BDF adjoint solve fails returning an integration that only accounts for the early trajectory of the adjoint solve resulting in nonsense sensitivities. CVODE_BDF does give a warning when this happens, but I think it's one that we're used to ignoring. Reducing the absolute tolerances a little resolves this issue for all tests.

Copy link
Contributor

@hwpang hwpang left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -459,8 +459,8 @@ By default uses the InterpolatingAdjoint algorithm with vector Jacobian products
this assumes no changes in code branching during simulation, if that were to become no longer true, the Tracker
based alternative algorithm is slower, but avoids this concern.
"""
function getadjointsensitivities(bsol::Q, target::String, solver::W; sensalg::W2=InterpolatingAdjoint(autojacvec=ReverseDiffVJP(false)),
abstol::Float64=1e-6, reltol::Float64=1e-3, normalize=true, kwargs...) where {Q,W,W2}
function getadjointsensitivities(bsol::Simulation, target::String, solver; sensalg=InterpolatingAdjoint(autojacvec=ReverseDiffVJP(false)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we remove typing for W and W2?

@@ -561,7 +562,7 @@ function getadjointsensitivities(bsol::Simulation, target::String, solver; sensa
dpadj ./= bsol.sol(bsol.sol.t[end])[ind]
end
end
return dpadj
return dpadj::LinearAlgebra.Adjoint{Float64, Vector{Float64}}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised that this is needed

@hwpang hwpang merged commit be21539 into main Feb 8, 2024
2 of 4 checks passed
@hwpang hwpang deleted the fix_adjoint_sens branch February 8, 2024 13:59
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.

2 participants