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

Initial discrete adjoint capability with ERK #559

Open
wants to merge 343 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 117 commits
Commits
Show all changes
343 commits
Select commit Hold shift + click to select a range
96503a8
Merge branch 'feature/sunstepper' into feature/sunadjoint
balos1 Aug 20, 2024
3c3a406
move trystep flahs
balos1 Aug 20, 2024
cbfbd79
cleanup
balos1 Aug 20, 2024
e6815d6
add yp arg
balos1 Aug 20, 2024
c7d3f39
add setstoptime
balos1 Aug 20, 2024
fa21304
rename SUNAdjointSolver
balos1 Aug 20, 2024
32832c1
Merge branch 'feature/sunstepper' into feature/sunadjoint
balos1 Aug 20, 2024
f9a2c49
store time with state data
balos1 Aug 21, 2024
9676a70
add reinit function
balos1 Aug 22, 2024
1e5eac7
rename local variables called adj_solver to adj_stepper
balos1 Aug 22, 2024
0b17693
rename adjoint stepper functions to match sunstepper
balos1 Aug 22, 2024
10d9370
add comment
balos1 Aug 22, 2024
532dd48
minor cleanup
balos1 Aug 22, 2024
27fe770
more cleanup
balos1 Aug 22, 2024
b7d7e08
minor fixes
balos1 Aug 22, 2024
b95404b
Merge branch 'feature/sunstepper' into feature/sunadjoint
balos1 Aug 22, 2024
491765f
add missing SetForcing declaration
balos1 Aug 22, 2024
5229e68
Merge branch 'feature/sunstepper' into feature/sunadjoint
balos1 Aug 22, 2024
bc58f0c
Update src/sundials/sundials_stepper.c
balos1 Aug 22, 2024
14be3e5
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Aug 22, 2024
8e7e08a
wip
balos1 Aug 27, 2024
d80ef7a
wip
balos1 Aug 27, 2024
151a271
fix checkpoint throwaway
balos1 Aug 27, 2024
acdaef3
add missing arkode functions
balos1 Aug 27, 2024
dbc0207
Apply suggestions from code review
balos1 Aug 27, 2024
c7a47b4
Apply suggestions from code review
balos1 Aug 27, 2024
f20affe
remove unused constants
balos1 Aug 27, 2024
b797a1a
rename function
balos1 Aug 27, 2024
d3f8bad
add missing function in docs
balos1 Aug 27, 2024
a0348a2
update function names
balos1 Aug 28, 2024
53c9bcc
add docs for the generic classes from other branch and update
balos1 Aug 28, 2024
75d3d66
add matvec transpose docs
balos1 Aug 28, 2024
e262fb6
Revert y prime argument
Steven-Roberts Aug 29, 2024
7881ddc
Fix compilation warnings
Steven-Roberts Aug 29, 2024
5e03e95
Apply formatter
Steven-Roberts Aug 29, 2024
483a53c
add other missing adjoint docs
balos1 Aug 29, 2024
300f8dc
document new sunmemory function
balos1 Aug 29, 2024
25b366d
clarify
balos1 Aug 29, 2024
7d3274d
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Aug 29, 2024
a5c4b32
fix unit test for checkpoint scheme
balos1 Aug 29, 2024
19827f5
copy test to examples
balos1 Aug 29, 2024
ac0adec
add cvodes example
balos1 Aug 31, 2024
0416868
doc clarifications
balos1 Sep 3, 2024
e5af802
get cost at just T
balos1 Sep 3, 2024
e8d0634
add param sensitivites to cvodes example
balos1 Sep 4, 2024
bdcf634
fix comment
balos1 Sep 4, 2024
40ee734
Merge remote-tracking branch 'origin/develop' into feature/sunstepper
balos1 Sep 4, 2024
2c4d1a7
Merge branch 'feature/sunstepper' into feature/sunadjoint
balos1 Sep 4, 2024
a082c34
Fix freeing of fused vectors
Steven-Roberts Sep 4, 2024
3da5408
cleanup headers
balos1 Sep 4, 2024
806774c
remove unused functions
balos1 Sep 4, 2024
f8b19cc
remove unused functions
balos1 Sep 4, 2024
822bb71
remove unused error code
balos1 Sep 4, 2024
4446183
make sundials_datanode private
balos1 Sep 4, 2024
f9c42b2
remove unused header
balos1 Sep 4, 2024
cb6b0fd
Fix unset variable when creating inner stepper
Steven-Roberts Sep 13, 2024
4e0784a
Merge branch 'develop' into feature/sunstepper
Steven-Roberts Sep 13, 2024
7ba3a87
Merge branch 'develop' into feature/sunstepper
gardner48 Sep 16, 2024
5a110e3
apply formatting
gardner48 Sep 16, 2024
32d6f3d
update f2003 interface
gardner48 Sep 16, 2024
5b2b84e
Merge remote-tracking branch 'origin/develop' into feature/sunadjoint
balos1 Sep 16, 2024
97be184
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Sep 16, 2024
df504e1
apply patches
balos1 Sep 16, 2024
9750b43
remove patch files accidentally committed
balos1 Sep 16, 2024
9eb463e
fix all warnings
balos1 Sep 17, 2024
29f698e
update docs
balos1 Sep 17, 2024
986e782
cast int64_t to long long in printf for portability
balos1 Sep 17, 2024
80e9b84
more long long casts
balos1 Sep 17, 2024
b8ba85a
make them unsigned
balos1 Sep 17, 2024
663cdd1
move declaration
balos1 Sep 17, 2024
1d75d3f
no need to check against 0 with size_t
balos1 Sep 17, 2024
4fd8f4a
link sundials_adjoint in unit tests
balos1 Sep 17, 2024
51763f7
link object files
balos1 Sep 17, 2024
5ea7869
cast capacity
balos1 Sep 17, 2024
dad3fbd
fix integer sizes in hashmap
balos1 Sep 18, 2024
1a9c84f
format and spelling
balos1 Sep 18, 2024
8fb60be
remove comparisons to 0
balos1 Sep 18, 2024
9980090
Changelog
Steven-Roberts Sep 18, 2024
b928595
Merge branch 'develop' into feature/sunstepper
Steven-Roberts Sep 18, 2024
d3ca3b8
Doc fixes
Steven-Roberts Sep 19, 2024
1672e09
Reorder implementation specific methods
Steven-Roberts Sep 19, 2024
12e1c2b
fix typo
balos1 Sep 26, 2024
abf37fb
Merge remote-tracking branch 'origin/develop' into feature/sunadjoint
balos1 Sep 26, 2024
08343ce
fix compiler warnings
balos1 Sep 26, 2024
20b6731
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Sep 26, 2024
319d899
ARKstepCreateSUNStepper -> ARKodeCreateSUNStepper
Steven-Roberts Sep 28, 2024
da6e773
Add missing file
Steven-Roberts Sep 28, 2024
a4fc856
Add missing SUNStepper_SetForcing
Steven-Roberts Sep 28, 2024
cd12b43
swig
Steven-Roberts Sep 28, 2024
c7b6cde
Add missing swig file
Steven-Roberts Sep 28, 2024
0c1b84c
Merge branch 'develop' into feature/sunstepper
Steven-Roberts Sep 30, 2024
d43d59a
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Oct 1, 2024
19621a6
post-merge compile fixes
balos1 Oct 1, 2024
cd1891a
add constant for recompute fail
balos1 Oct 1, 2024
9d32e88
Finish updating docs after ARKodeCreateSUNStepper refactor
Steven-Roberts Oct 2, 2024
01eba9e
Merge branch 'develop' into feature/sunstepper
Steven-Roberts Oct 2, 2024
13e444e
Reference ARKodeCreateSUNStepper in the SUNStepper docs
Steven-Roberts Oct 2, 2024
53f30c2
fix hashmap
balos1 Oct 2, 2024
03e26d6
Revert ops check change
Steven-Roberts Oct 2, 2024
9f6baab
Mention MRIStepInnerStepper_CreateFromSUNStepper in changelog
Steven-Roberts Oct 2, 2024
b1a3dad
Typo fixes
Steven-Roberts Oct 2, 2024
50cb5a1
Remove extra include
Steven-Roberts Oct 2, 2024
905f98f
flush logging queues before aborting
balos1 Oct 2, 2024
ec8bbde
more cleanup
Steven-Roberts Oct 2, 2024
2a05e5d
Move function to make diff nicer
Steven-Roberts Oct 2, 2024
92a7f17
Improve error handling for MRI inner stepper wrapping SUNStepper
Steven-Roberts Oct 2, 2024
1461d63
fix problem from reset change
balos1 Oct 2, 2024
fc47959
a couple pr comments addressed
balos1 Oct 2, 2024
7cd59d6
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Oct 2, 2024
d4228ea
merge
balos1 Oct 2, 2024
24114fe
document constant that was added
balos1 Oct 2, 2024
ef116d5
Merge branch 'feature/sunstepper' of github.com:LLNL/sundials into fe…
Steven-Roberts Oct 2, 2024
eadc5ea
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Oct 2, 2024
68e1d1e
Remove SUNStepper_TryStep
Steven-Roberts Oct 2, 2024
e24ed27
Revert trystep changes for xbraid
Steven-Roberts Oct 2, 2024
aa7ccc1
Apply formatter
Steven-Roberts Oct 2, 2024
ec41dfa
Typo fix
Steven-Roberts Oct 3, 2024
106022a
Add missing period
Steven-Roberts Oct 3, 2024
81fa70f
Make return consistent
Steven-Roberts Oct 3, 2024
f00e158
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Oct 3, 2024
173a1cc
format
balos1 Oct 3, 2024
0e85269
run swig
balos1 Oct 3, 2024
9e95184
Update swig/sundials/fsundials_stepper.i
Steven-Roberts Oct 3, 2024
7158562
Doc style fixes
Steven-Roberts Oct 3, 2024
f9dc452
Merge branch 'feature/sunstepper' of github.com:LLNL/sundials into fe…
Steven-Roberts Oct 3, 2024
9cd7450
generate proper swig interface
balos1 Oct 3, 2024
9d332b4
change uint to int
balos1 Oct 3, 2024
e7e25ab
update reset call
balos1 Oct 3, 2024
ca1bc17
fix compiler warnings
balos1 Oct 3, 2024
43e9be0
add profiler statements
balos1 Oct 3, 2024
01515c4
format
balos1 Oct 3, 2024
766c222
remove uses of size_t that were not needed
balos1 Oct 3, 2024
9041421
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Oct 7, 2024
dcb5e7a
fix some more warnings
balos1 Oct 7, 2024
ac20d73
format
balos1 Oct 7, 2024
e8d65b6
fix warning
balos1 Oct 7, 2024
11220bb
more warnings fixed
balos1 Oct 8, 2024
41c468c
Apply suggestions from code review
balos1 Oct 8, 2024
926caa0
Merge branch 'develop' into feature/sunstepper
Steven-Roberts Oct 8, 2024
ef224be
remove .clangd and add it to gitignore
balos1 Oct 9, 2024
ffb0d25
Apply suggestions from code review
balos1 Oct 9, 2024
2d431e4
Apply suggestions from code review
balos1 Oct 9, 2024
93700d3
swig and format
balos1 Oct 9, 2024
09d0fe1
update docs
balos1 Oct 9, 2024
86e388d
use x.y.z
balos1 Oct 9, 2024
d88dc73
use SUN_RCONST
balos1 Oct 9, 2024
e628c68
fix commented out timer code
balos1 Oct 9, 2024
ec024dc
document naming convention for stlvector
balos1 Oct 9, 2024
57b74d2
fixing linking errors on windows
balos1 Oct 9, 2024
8ef4e82
add obj back sunmemsys
balos1 Oct 9, 2024
a17092a
Apply suggestions from code review
Steven-Roberts Oct 14, 2024
13c7c63
Fix copy paste error in MRIStepInnerStepper_CreateFromSUNStepper example
Steven-Roberts Oct 14, 2024
c333f57
Only call SUNStepper_SetForcingFn if stepper provides setforcing func…
Steven-Roberts Oct 14, 2024
d4846b3
Document support for forcing
Steven-Roberts Oct 14, 2024
cb495dc
Merge branch 'develop' into feature/sunstepper
Steven-Roberts Oct 14, 2024
9641457
Apply formatter
Steven-Roberts Oct 14, 2024
6d7c459
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Oct 18, 2024
c52f9dc
comment out no-stages
balos1 Oct 18, 2024
f9b48ad
doc fixes
balos1 Oct 19, 2024
794327b
spelling
balos1 Oct 21, 2024
f62a1a8
simplify indexing
balos1 Oct 21, 2024
cfaab51
define ASA
balos1 Oct 21, 2024
d00e769
uncomment fsal code
balos1 Oct 21, 2024
5210ca7
guard subvector access
balos1 Oct 21, 2024
2c196f6
clarify subvector size
balos1 Oct 21, 2024
6d62b97
fix inconsistent notation
balos1 Oct 21, 2024
3a8920b
fix missing declaration
balos1 Oct 21, 2024
77abed5
update checkpoint_start_idx to int64_t
balos1 Oct 21, 2024
02aa271
fix param description
balos1 Oct 21, 2024
bba7343
couple of small doc fixes
balos1 Oct 21, 2024
9a8d422
Merge branch 'develop' into feature/sunstepper
Steven-Roberts Oct 22, 2024
0549afd
Apply suggestions from code review
Steven-Roberts Oct 23, 2024
5c3cbf6
Add missing header
Steven-Roberts Oct 25, 2024
06e6875
Remove step_supports_forcing
Steven-Roberts Oct 25, 2024
d29b95e
Revert formatting change
Steven-Roberts Oct 25, 2024
cb456e2
Add public SUNStepper_FullRhs function
Steven-Roberts Oct 25, 2024
65eafd4
Apply suggestions from code review for evolve and one step functions
Steven-Roberts Oct 25, 2024
dcc74c8
Use backticks for arguments
Steven-Roberts Oct 25, 2024
e3a9a42
Remove unused SUNStepper_OneStep
Steven-Roberts Oct 25, 2024
127ff2d
Remove t0 arg from SUNStepper_Evolve
Steven-Roberts Oct 25, 2024
9f483e0
Formatter and swig
Steven-Roberts Oct 25, 2024
51406bc
Moved duplicated SUNStepper overview to shared folder
Steven-Roberts Oct 25, 2024
3c6844b
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Oct 28, 2024
f6b7866
Allow users to specify custom destroy function
Steven-Roberts Oct 28, 2024
10869c6
Add missing SUNStepper_SetDestroyFn definition
Steven-Roberts Oct 28, 2024
ae18e60
NULL destroy operation on creation
Steven-Roberts Oct 28, 2024
4893e19
Make argument names consistent in docs and header
Steven-Roberts Oct 28, 2024
4d238f0
Fix anonymous type linking error
Steven-Roberts Oct 29, 2024
42b1f59
Fix copy paste error
Steven-Roberts Oct 29, 2024
fb6a34e
address documentation issues from review
balos1 Oct 29, 2024
8d42749
remove commented out code
balos1 Oct 29, 2024
91900f5
Add arkProcessError calls to ARKodeCreateSUNStepper
Steven-Roberts Oct 29, 2024
3a26598
Rename SUNStepper Jacobian typedefs
Steven-Roberts Oct 29, 2024
ad41aa0
Add mode argument back to SUNStepper full RHS
Steven-Roberts Oct 29, 2024
76e4537
Update docs for full RHS mode
Steven-Roberts Oct 29, 2024
2e7859e
Swig and format
Steven-Roberts Oct 29, 2024
b72dc5a
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Oct 30, 2024
15b0b7c
add onestep function back
balos1 Oct 30, 2024
3f175d0
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Oct 30, 2024
b71fd0a
post merge fixes
balos1 Oct 30, 2024
da261e7
fix unit tests
balos1 Oct 30, 2024
c84f8d1
apply swig and format
balos1 Oct 30, 2024
aecc502
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Oct 30, 2024
068fbd7
Merge branch 'develop' into feature/sunstepper
balos1 Oct 30, 2024
697e870
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Oct 30, 2024
9973277
move arkInit and ARKodePrintMem back
balos1 Oct 30, 2024
015fc55
typo
balos1 Oct 30, 2024
b31a678
remove TTYPE undef from header
balos1 Oct 30, 2024
44e331e
checck node data in unit test
balos1 Oct 30, 2024
633062b
remove stop_reason in favor of last_flag
balos1 Oct 30, 2024
762dc3f
SUNAdjointCheckpointScheme doc clarification
balos1 Oct 31, 2024
c77132f
add generic ASA overview in ASA section
balos1 Oct 31, 2024
7d17534
rename matvectranspose
balos1 Oct 31, 2024
b7f4794
fix find/replace errors from changing 'basic' to 'fixed'
balos1 Oct 31, 2024
5481820
add band matrix transpose
balos1 Nov 1, 2024
e144a9a
format
balos1 Nov 1, 2024
23d2cb0
format
balos1 Nov 1, 2024
9785909
destroy AT
balos1 Nov 1, 2024
a8811d5
add mattransposevec for sparse matrix
balos1 Nov 1, 2024
758287c
fix more basic/fixed find-replace errors
balos1 Nov 1, 2024
cc49a54
update swig readme to remove reference to old commit
balos1 Nov 1, 2024
80bb41d
format
balos1 Nov 1, 2024
c0a0783
Apply suggestions from code review
balos1 Nov 1, 2024
e0ecd2c
fix spelling
balos1 Nov 1, 2024
4acf8ca
rerun swig
balos1 Nov 1, 2024
164933a
format
balos1 Nov 1, 2024
7237b2c
fix fsal indexing
balos1 Nov 1, 2024
1b18e8c
check error codes
balos1 Nov 1, 2024
f2a9b0d
swig
balos1 Nov 1, 2024
a8ab522
Merge branch 'develop' into feature/sunstepper
balos1 Nov 1, 2024
06e99e3
format
balos1 Nov 2, 2024
eba5765
Basic --> Fixed
balos1 Nov 2, 2024
d386417
reorder tests
balos1 Nov 2, 2024
6cf811a
switch order
balos1 Nov 6, 2024
3b7e733
Merge remote-tracking branch 'origin/feature/sunstepper' into feature…
balos1 Nov 6, 2024
6ff3a78
remove unnecessary if do_adjoint
balos1 Nov 6, 2024
59ea02e
fix matrix compatability check
balos1 Nov 6, 2024
5a5fd64
bump answers
balos1 Nov 6, 2024
b2b8254
loosen tolerances for single precision
balos1 Nov 6, 2024
0be20be
support integration in both directions
balos1 Nov 7, 2024
0e2ae77
fix comments
balos1 Nov 8, 2024
2560fa7
factor out lotka volterra functions into their own header
balos1 Nov 8, 2024
059046b
rename test file
balos1 Nov 8, 2024
3b7d7f3
rename test file
balos1 Nov 8, 2024
bd36a0f
bump answers
balos1 Nov 8, 2024
5526f03
make unit test pass/fail
balos1 Nov 9, 2024
93a9957
format
balos1 Nov 11, 2024
5a78a2a
check backwards answer
balos1 Nov 11, 2024
066fc3c
update output files for new cost function
balos1 Nov 12, 2024
abe96c2
comment out backwards adjoint check
balos1 Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CompileFlags:
balos1 marked this conversation as resolved.
Show resolved Hide resolved
CompilationDatabase: builddir/
62 changes: 62 additions & 0 deletions doc/arkode/guide/source/Mathematics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2126,3 +2126,65 @@ by :math:`\eta_\text{rf}`.

For more information on utilizing relaxation Runge--Kutta methods, see
:numref:`ARKODE.Usage.Relaxation`.


.. _ARKODE.Mathematics.ASA:

Adjoint Sensitivity Analysis
============================

Consider :eq:`ARKODE_IVP_simple_explicit`, but where the ODE also depends on some parameters
:math:`p` (that is, we have :math:`f(t,y,p)`). Now, let :math:`g(y(t_f),p)` be a cost function for
balos1 marked this conversation as resolved.
Show resolved Hide resolved
which we would like to compute the gradients or :math:`\partial g/\partial y(t_0)` and/or
balos1 marked this conversation as resolved.
Show resolved Hide resolved
:math:`\partial g/\partial p`. The adjoint method is one approach to obtaining the gradients that is
particularly efficient when there are relatively few cost functionals and a large number of parameters.
With the adjoint method we solve the adjoint ODEs for :math:`\lambda(t) \in \mathbb{R}^N` and
:math:`\mu(t) \in \mathbb{R}^{N_s}`:
balos1 marked this conversation as resolved.
Show resolved Hide resolved

.. math::
\lambda'(t) &= -f_y^T(t, y, p) \lambda,\quad \lambda(t_F) = g_y^T(y(t_f), p) \\
balos1 marked this conversation as resolved.
Show resolved Hide resolved
\mu'(t) &= -f_p^T(t, y, p) \mu,\quad \mu(t_F) = g_p^T(y(t_f), p), \quad t_f \geq t \geq t_0. \\
balos1 marked this conversation as resolved.
Show resolved Hide resolved

(For a detailed derivation see :cite:p:`hager2000runge,sanduDiscrete2006`). Here :math:`f_y \equiv
\partial f/\partial y` is the Jacobian with respect to the dependent variable and :math:`f_p \equiv
\partial f/\partial p` is the Jacobian with respect to the parameters. The ARKStep module in ARKODE
balos1 marked this conversation as resolved.
Show resolved Hide resolved
provides adjoint sensitivity analysis based on the *discrete* formulation. Given a s-stage explicit
balos1 marked this conversation as resolved.
Show resolved Hide resolved
Runge--Kutta method (as in :eq:`ARKODE_ERK`, but without the embedding), the discrete adjoint works
out to be
balos1 marked this conversation as resolved.
Show resolved Hide resolved

.. math::
\Lambda_i &= h_n f_y^T(t_{n,i}, z_i) \left(b_i \lambda_{n+1} + \sum_{j=i+1}^s a_{j,i}
\Lambda_j \right), \quad \quad i = s, \dots, 1,\\
\nu_i &= h_n f_p^T(t_{n,i}, z_i, p) \left(b_i \lambda_{n+1} + \sum_{j=i}^{s} a_{ji} \nu_j \right) \\
balos1 marked this conversation as resolved.
Show resolved Hide resolved
\lambda_n &= \lambda_{n+1} + \sum_{j=1}^{s} \Lambda_j \\
\mu_i &= \mu_{n+1} + \sum_{j=1}^{s} \nu_j.
balos1 marked this conversation as resolved.
Show resolved Hide resolved
:label: ARKODE_ERK_Adjoint

The result of intergating the adjoint equations with the discrete adjoint of the ARKStep method is
then

.. math::
\frac{\partial g}{\partial y_{(t_0)}} = \lambda_i, \quad
\frac{\partial g}{\partial p} = \mu_i + \lambda_i \left(\frac{\partial y(t_0)}{\partial p} \right).
balos1 marked this conversation as resolved.
Show resolved Hide resolved


Discrete vs. Continuous Adjoint Method
--------------------------------------

At a high level there are two adjoint method approaches that one can use. In the *continuous*
balos1 marked this conversation as resolved.
Show resolved Hide resolved
approach, we derive the sensitivity equations directly from the model and then we integrate them
with a time integration method. This is the approach implemented in the SUNDIALS :ref:`CVODES
<CVODES.Mathematics.ASA>` and :ref:`IDAS <IDAS.Mathematics.ASA>` packages. In the *discrete*
approach, the model equations are discretized with the time integration method first, and then we
derive the adjoints of the discretized equations. It is understood that the continuous adjoint
method can be problematic in the context of optimization problems because the continuous adjoint
method provides an approximation to the gradient of a continuous cost function while the optimizer
is expecting the gradient of the discrete cost function. The discrepancy means that the optimizer
can fail to converge further once it is near a local minimum :cite:p:`giles2000introduction`. One
balos1 marked this conversation as resolved.
Show resolved Hide resolved
the other hand, the discrete adjoint method provides the exact gradient of the discrete cost
function allowing the optimizer to fully converge. Consequently, the discrete adjoint method is
often preferable in optimization despite its own drawbacks -- such as its (relatively) increased
memory usage and the possible introduction of unphysical computational modes
:cite:p:`sirkes1997finite`. This is not to say that the discrete adjoint method is always the better
choice over the continuous adjoint method in optimization. Practical considerations may lead one to
choose the continuous approach.
75 changes: 52 additions & 23 deletions doc/arkode/guide/source/Usage/User_callable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -867,29 +867,30 @@ Optional inputs for ARKODE

.. cssclass:: table-bordered

================================================ ======================================= =======================
Optional input Function name Default
================================================ ======================================= =======================
Return ARKODE parameters to their defaults :c:func:`ARKodeSetDefaults` internal
Set integrator method order :c:func:`ARKodeSetOrder` 4
Set dense output interpolation type (SPRKStep) :c:func:`ARKodeSetInterpolantType` ``ARK_INTERP_LAGRANGE``
Set dense output interpolation type (others) :c:func:`ARKodeSetInterpolantType` ``ARK_INTERP_HERMITE``
Set dense output polynomial degree :c:func:`ARKodeSetInterpolantDegree` 5
Disable time step adaptivity (fixed-step mode) :c:func:`ARKodeSetFixedStep` disabled
Supply an initial step size to attempt :c:func:`ARKodeSetInitStep` estimated
Maximum no. of warnings for :math:`t_n+h = t_n` :c:func:`ARKodeSetMaxHnilWarns` 10
Maximum no. of internal steps before *tout* :c:func:`ARKodeSetMaxNumSteps` 500
Maximum absolute step size :c:func:`ARKodeSetMaxStep` :math:`\infty`
Minimum absolute step size :c:func:`ARKodeSetMinStep` 0.0
Set a value for :math:`t_{stop}` :c:func:`ARKodeSetStopTime` undefined
Interpolate at :math:`t_{stop}` :c:func:`ARKodeSetInterpolateStopTime` ``SUNFALSE``
Disable the stop time :c:func:`ARKodeClearStopTime` N/A
Supply a pointer for user data :c:func:`ARKodeSetUserData` ``NULL``
Maximum no. of ARKODE error test failures :c:func:`ARKodeSetMaxErrTestFails` 7
Set inequality constraints on solution :c:func:`ARKodeSetConstraints` ``NULL``
Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstrFails` 10
================================================ ======================================= =======================

================================================= ======================================= =======================
Optional input Function name Default
================================================= ======================================= =======================
Return ARKODE parameters to their defaults :c:func:`ARKodeSetDefaults` internal
Set integrator method order :c:func:`ARKodeSetOrder` 4
Set dense output interpolation type (SPRKStep) :c:func:`ARKodeSetInterpolantType` ``ARK_INTERP_LAGRANGE``
Set dense output interpolation type (others) :c:func:`ARKodeSetInterpolantType` ``ARK_INTERP_HERMITE``
Set dense output polynomial degree :c:func:`ARKodeSetInterpolantDegree` 5
Disable time step adaptivity (fixed-step mode) :c:func:`ARKodeSetFixedStep` disabled
Supply an initial step size to attempt :c:func:`ARKodeSetInitStep` estimated
Maximum no. of warnings for :math:`t_n+h = t_n` :c:func:`ARKodeSetMaxHnilWarns` 10
Maximum no. of internal steps before *tout* :c:func:`ARKodeSetMaxNumSteps` 500
Maximum absolute step size :c:func:`ARKodeSetMaxStep` :math:`\infty`
Minimum absolute step size :c:func:`ARKodeSetMinStep` 0.0
Set a value for :math:`t_{stop}` :c:func:`ARKodeSetStopTime` undefined
Interpolate at :math:`t_{stop}` :c:func:`ARKodeSetInterpolateStopTime` ``SUNFALSE``
Disable the stop time :c:func:`ARKodeClearStopTime` N/A
Supply a pointer for user data :c:func:`ARKodeSetUserData` ``NULL``
Maximum no. of ARKODE error test failures :c:func:`ARKodeSetMaxErrTestFails` 7
Set inequality constraints on solution :c:func:`ARKodeSetConstraints` ``NULL``
Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstrFails` 10
Set the checkpointing scheme to use (for adjoint) :c:func:`ARKodeSetCheckpointScheme` ``NULL``
Set the checkpointing step index (for adjoint) :c:func:`ARKodeSetCheckpointIndex 0
================================================= ======================================= =======================



Expand Down Expand Up @@ -1397,6 +1398,34 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr
.. versionadded:: 6.1.0


.. c:function:: int ARKodeSetCheckpointScheme(void* arkode_mem, SUNAdjointCheckpointScheme checkpoint_scheme)

Specifies the :c:type:`SUNAdjointCheckpointScheme` to use for saving states
during the forward integration, and loading states during backward integration
of an adjoint system.

:param arkode_mem: pointer to the ARKODE memory block.
:param checkpoint_scheme: the checkpoint scheme to use
balos1 marked this conversation as resolved.
Show resolved Hide resolved
balos1 marked this conversation as resolved.
Show resolved Hide resolved

:retval ARK_SUCCESS: the function exited successfully.
:retval ARK_MEM_NULL: ``arkode_mem`` was ``NULL``.

.. versionadded:: x.x.x
balos1 marked this conversation as resolved.
Show resolved Hide resolved

.. c:function:: int ARKodeSetCheckpointIndex(void* arkode_mem, long int step_index)

Specifies the step index (that is step number) to insert the next checkpoint at.
This is incremented along with the step count, but it is useful to be able to reset
this index during recomputations of missing states during the backward adjoint integration.

:param arkode_mem: pointer to the ARKODE memory block.
:param checkpoint_scheme: the checkpoint scheme to use
balos1 marked this conversation as resolved.
Show resolved Hide resolved

:retval ARK_SUCCESS: the function exited successfully.
:retval ARK_MEM_NULL: ``arkode_mem`` was ``NULL``.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note to self: error for negative value or something before current step?


.. versionadded:: x.x.x


.. _ARKODE.Usage.ARKodeAdaptivityInputTable:

Expand Down
1 change: 1 addition & 0 deletions doc/arkode/guide/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ with support by the `US Department of Energy <http://www.doe.gov>`_,
sunlinsol/index.rst
sunnonlinsol/index.rst
sunadaptcontroller/index.rst
sunadjoint/index.rst
sunmemory/index.rst
sundials/Install_link.rst
Constants
Expand Down
14 changes: 14 additions & 0 deletions doc/arkode/guide/source/sunadjoint/SUNAdjoint_links.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. ----------------------------------------------------------------
SUNDIALS Copyright Start
Copyright (c) 2002-2024, Lawrence Livermore National Security
and Southern Methodist University.
All rights reserved.

See the top-level LICENSE and NOTICE files for details.

SPDX-License-Identifier: BSD-3-Clause
SUNDIALS Copyright End
----------------------------------------------------------------

.. include:: ../../../shared/sunadjoint/SUNAdjointCheckpointScheme.rst
.. include:: ../../../shared/sunadjoint/SUNAdjointStepper.rst
balos1 marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 31 additions & 0 deletions doc/arkode/guide/source/sunadjoint/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
..
----------------------------------------------------------------
SUNDIALS Copyright Start
Copyright (c) 2002-2024, Lawrence Livermore National Security
and Southern Methodist University.
All rights reserved.

See the top-level LICENSE and NOTICE files for details.

SPDX-License-Identifier: BSD-3-Clause
SUNDIALS Copyright End
----------------------------------------------------------------

.. _SUNAdaptController:

###########################
Adjoint Sensitivty Analysis
###########################

.. versionadded:: x.x.x

The ``SUNAdjoint`` API consists of a few customizable modules that provide a framework for adjoint
sensitivity analysis (ASA). The API itself does not implement ASA, but it provides a common
interface for ASA capabilties implemented in the SUNDIALS packages. Right now it supports :ref:`the
ASA capabilties in ARKODE <ARKODE.Mathematics.ASA>`, while the ASA capabilities in :ref:`CVODES
<CVODES.Mathematics.ASA>` and :ref:`IDAS <IDAS.Mathematics.ASA>` must be used directly.

.. toctree::
:maxdepth: 1

SUNAdjoint_links.rst
17 changes: 17 additions & 0 deletions doc/shared/sunadjoint/SUNAdjointCheckpointScheme.rst
balos1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
..
----------------------------------------------------------------
SUNDIALS Copyright Start
Copyright (c) 2002-2024, Lawrence Livermore National Security
and Southern Methodist University.
All rights reserved.

See the top-level LICENSE and NOTICE files for details.

SPDX-License-Identifier: BSD-3-Clause
SUNDIALS Copyright End
----------------------------------------------------------------

.. _SUNAdjoint.CheckpointScheme:

The SUNAdjointCheckpointScheme API
==================================
17 changes: 17 additions & 0 deletions doc/shared/sunadjoint/SUNAdjointStepper.rst
balos1 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: When we eventually support complex-valued data, these transposes will need to be converted to conjugate-transposes.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
..
----------------------------------------------------------------
SUNDIALS Copyright Start
Copyright (c) 2002-2024, Lawrence Livermore National Security
and Southern Methodist University.
All rights reserved.

See the top-level LICENSE and NOTICE files for details.

SPDX-License-Identifier: BSD-3-Clause
SUNDIALS Copyright End
----------------------------------------------------------------

.. _SUNAdjoint.Solver:

The SUNAdjointStepper API
========================
14 changes: 14 additions & 0 deletions doc/shared/sunadjoint/SUNAdjoint_Description.rst
balos1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
..
----------------------------------------------------------------
SUNDIALS Copyright Start
Copyright (c) 2002-2024, Lawrence Livermore National Security
and Southern Methodist University.
All rights reserved.

See the top-level LICENSE and NOTICE files for details.

SPDX-License-Identifier: BSD-3-Clause
SUNDIALS Copyright End
----------------------------------------------------------------

.. _SUNAdjoint.Description:
45 changes: 45 additions & 0 deletions doc/shared/sundials.bib
Original file line number Diff line number Diff line change
Expand Up @@ -2369,3 +2369,48 @@ @article{edwards2014kokkos
issn = {0743-7315},
doi = {10.1016/j.jpdc.2014.07.003}
}

%
% Discrete adjoints
%

@article{giles2000introduction,
title={An introduction to the adjoint approach to design},
author={Giles, Michael B and Pierce, Niles A},
journal={Flow, turbulence and combustion},
volume={65},
number={3},
pages={393--415},
year={2000},
publisher={Springer}
}

@article{sirkes1997finite,
title={Finite difference of adjoint or adjoint of finite difference?},
author={Sirkes, Ziv and Tziperman, Eli},
journal={Monthly weather review},
volume={125},
number={12},
pages={3373--3378},
year={1997}
}

@article{hager2000runge,
title={Runge-Kutta methods in optimal control and the transformed adjoint system},
balos1 marked this conversation as resolved.
Show resolved Hide resolved
author={Hager, William W},
journal={Numerische Mathematik},
volume={87},
pages={247--282},
year={2000},
publisher={Springer}
balos1 marked this conversation as resolved.
Show resolved Hide resolved
}

@article{sanduDiscrete2006,
year = {2006},
title = {{On the Properties of Runge-Kutta Discrete Adjoints}},
balos1 marked this conversation as resolved.
Show resolved Hide resolved
author = {Sandu, Adrian},
journal = {Lecture Notes in Computer Science},
issn = {0302-9743},
doi = {10.1007/11758549_76},
pages = {550--557}
}
balos1 marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions doc/superbuild/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ SUNDIALS License and Notices
sunlinsol/index.rst
sunnonlinsol/index.rst
sunadaptcontroller/index.rst
sunadjoint/index.rst
sunmemory/index.rst
History_link.rst
Changelog_link.rst
Expand Down
14 changes: 14 additions & 0 deletions doc/superbuild/source/sunadjoint/SUNAdjoint_links.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. ----------------------------------------------------------------
SUNDIALS Copyright Start
Copyright (c) 2002-2024, Lawrence Livermore National Security
and Southern Methodist University.
All rights reserved.

See the top-level LICENSE and NOTICE files for details.

SPDX-License-Identifier: BSD-3-Clause
SUNDIALS Copyright End
----------------------------------------------------------------

.. include:: ../../../shared/sunadjoint/SUNAdjointCheckpointScheme.rst
.. include:: ../../../shared/sunadjoint/SUNAdjointStepper.rst
31 changes: 31 additions & 0 deletions doc/superbuild/source/sunadjoint/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
..
----------------------------------------------------------------
SUNDIALS Copyright Start
Copyright (c) 2002-2024, Lawrence Livermore National Security
and Southern Methodist University.
All rights reserved.

See the top-level LICENSE and NOTICE files for details.

SPDX-License-Identifier: BSD-3-Clause
SUNDIALS Copyright End
----------------------------------------------------------------

.. _SUNAdaptController:

###########################
Adjoint Sensitivty Analysis
###########################

.. versionadded:: x.x.x

The ``SUNAdjoint`` API consists of a few customizable modules that provide a framework for adjoint
sensitivity analysis (ASA). The API itself does not implement ASA, but it provides a common
interface for ASA capabilties implemented in the SUNDIALS packages. Right now it supports :ref:`the
ASA capabilties in ARKODE <ARKODE.Mathematics.ASA>`, while the ASA capabilities in :ref:`CVODES
<CVODES.Mathematics.ASA>` and :ref:`IDAS <IDAS.Mathematics.ASA>` must be used directly.

.. toctree::
:maxdepth: 1

SUNAdjoint_links.rst
1 change: 1 addition & 0 deletions examples/arkode/C_petsc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ foreach(example_tuple ${ARKODE_examples})
ANSWER_FILE ${example}.out
EXAMPLE_TYPE ${example_type})


# libraries to link against
target_link_libraries(${example} ${SUNDIALS_LIBS})

Expand Down
Loading
Loading