-
Notifications
You must be signed in to change notification settings - Fork 125
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
Feature/sunadjoint #559
base: feature/sunstepper
Are you sure you want to change the base?
Feature/sunadjoint #559
Changes from all commits
9a7d535
046f415
db94c67
016245d
8c4da04
a0d5f45
a06b948
58972db
33fe88b
d62ea21
08c5d0a
1f1a9cc
40c8a4e
8414874
5deb32b
05b66ef
252c209
7098fae
5b967be
98345fc
3c70ba3
f9058c0
b73bb93
176f6ef
eb73930
775e494
8cd39c5
ef39ccc
686502d
d5fc523
1b0214e
f60605f
c8cee39
0c2d6e1
fb10d2c
3f3a089
8f3be15
5bcedb7
97dccfe
cf179bb
1b6d949
e713b75
01f3fc8
03fd436
10fe266
71fb1a6
dc94972
0d05e04
34ab37e
16f4abd
1a996e1
a9a99a6
58657ce
0fdbc94
e47b231
de54b5f
69b6384
de6098c
665e82f
94fc60d
ae569f8
ee16765
0411579
b012d53
e3e66cb
244731c
03d12bc
7868c52
274814e
aee58a9
cc72d5d
b856458
5f5bd2a
f66c760
31a944e
49da6e7
cc8a94c
9360eea
2c7916e
ec0170a
96503a8
fa21304
32832c1
f9a2c49
9676a70
1e5eac7
0b17693
10d9370
532dd48
27fe770
b95404b
5229e68
14be3e5
8e7e08a
d80ef7a
151a271
acdaef3
dbc0207
c7a47b4
f20affe
b797a1a
d3f8bad
a0348a2
53c9bcc
75d3d66
483a53c
300f8dc
25b366d
7d3274d
a5c4b32
19827f5
ac0adec
0416868
e5af802
e8d0634
bdcf634
2c4d1a7
3da5408
806774c
f8b19cc
822bb71
4446183
f9c42b2
5b2b84e
97be184
df504e1
9750b43
9eb463e
29f698e
986e782
80e9b84
b8ba85a
663cdd1
1d75d3f
4fd8f4a
51763f7
5ea7869
dad3fbd
1a9c84f
8fb60be
abf37fb
08343ce
20b6731
d43d59a
19621a6
cd1891a
53f30c2
905f98f
1461d63
fc47959
7cd59d6
d4228ea
eadc5ea
f00e158
173a1cc
0e85269
9cd7450
9d332b4
e7e25ab
ca1bc17
43e9be0
01515c4
766c222
9041421
dcb5e7a
ac20d73
e8d65b6
11220bb
41c468c
ef224be
ffb0d25
2d431e4
93700d3
09d0fe1
86e388d
d88dc73
e628c68
ec024dc
57b74d2
8ef4e82
6d7c459
c52f9dc
f9b48ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
.. _ARKODE.Usage.ARKStep.ASA: | ||
|
||
Adjoint Sensitivity Analysis | ||
============================ | ||
|
||
The previous sections discuss using ARKStep for the integration of forward ODE models. | ||
This section discusses how to use ARKStep for adjoint sensitivity analysis as introduced | ||
in :numref:`ARKODE.Mathematics.ASA`. To use ARKStep for ASA, users simply setup the forward | ||
integration as usual (following :numref:`ARKODE.Usage.Skeleton`) with one exception: | ||
a :c:type:`SUNAdjointCheckpointScheme` object must be created and passed to | ||
:c:func:`ARKodeSetAdjointCheckpointScheme` before the call to the :c:func:`ARKodeEvolve` | ||
function. After the forward model integration code, a :c:type:`SUNAdjointStepper` object | ||
can be created for the adjoint model integration by calling :c:func:`ARKStepCreateAdjointStepper`. | ||
The code snippet below demonstrates these steps in brief and the example code | ||
``examples/arkode/C_serial/ark_lotka_volterra_asa.c`` demonstrates these steps in detail. | ||
|
||
.. code-block:: C | ||
|
||
// 1. Create a SUNAdjointCheckpointScheme object | ||
|
||
// 2. Setup ARKStep for forward integration | ||
|
||
// 3. Attach the SUNAdjointCheckpointScheme | ||
|
||
// 4. Evolve the forward model | ||
|
||
// 5. Create the SUNAdjointStepper | ||
|
||
// 6. Setup the adjoint model | ||
|
||
// 7. Evolve the adjoint model | ||
|
||
// 8. Cleanup | ||
Comment on lines
+19
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these supposed to be "code snippets" (as stated in the paragraph above)? |
||
|
||
|
||
|
||
User Callable Functions | ||
----------------------- | ||
|
||
This section describes ARKStep-specific user-callable functions for performing | ||
adjoint sensitivity analysis with methods with ARKStep. | ||
|
||
.. c:function:: int ARKStepCreateAdjointStepper(void* arkode_mem, N_Vector sf, SUNAdjointStepper* adj_stepper_ptr) | ||
|
||
Creates a :c:type:`SUNAdjointStepper` object compatible with the provided ARKStep instance for | ||
integrating the adjoint sensitivity system :eq:`ARKODE_DISCRETE_ADJOINT`. | ||
|
||
:param arkode_mem: a pointer to the ARKStep memory block. | ||
:param sf: the sensitivity vector holding the adjoint system terminal condition. | ||
This must be an instance of the ManyVector ``N_Vector`` implementation with two subvectors. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self: If you only need sensitivities w.r.t. initial conditions, can the subvector for parameters have length 0? |
||
The first subvector must hold :math:`\partial g/\partial y |_{t=t_f} \in \mathbb{R}^N` and the second subvector must hold :math:`\partial g / \partial p |_{t=t_f} \in \mathbb{R}^d`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also inconsistent usage of evaluation bar vs time as a argument to the Jacobian function |
||
:param adj_stepper_ptr: the newly created :c:type:`SUNAdjointStepper` object. | ||
|
||
:return: | ||
* ``ARK_SUCCESS`` if successful | ||
* ``ARK_MEM_FAIL`` if a memory allocation failed | ||
* ``ARK_ILL_INPUT`` if an argument has an illegal value. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ are specific to ARKStep. | |
User_callable | ||
Relaxation | ||
XBraid | ||
ASA |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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:`ARKodeSetAdjointCheckpointScheme` ``NULL`` | ||||||
Set the checkpointing step index (for adjoint) :c:func:`ARKodeSetAdjointCheckpointIndex` 0 | ||||||
================================================= ========================================== ======================= | ||||||
|
||||||
|
||||||
|
||||||
|
@@ -1397,6 +1398,34 @@ Set max number of constraint failures :c:func:`ARKodeSetMaxNumConstr | |||||
.. versionadded:: 6.1.0 | ||||||
|
||||||
|
||||||
.. c:function:: int ARKodeSetAdjointCheckpointScheme(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. | ||||||
|
||||||
:retval ARK_SUCCESS: the function exited successfully. | ||||||
:retval ARK_MEM_NULL: ``arkode_mem`` was ``NULL``. | ||||||
|
||||||
.. versionadded:: x.y.z | ||||||
|
||||||
.. c:function:: int ARKodeSetAdjointCheckpointIndex(void* arkode_mem, long int step_index) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the SUNAdjointStepper, the step index is of type |
||||||
|
||||||
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
:retval ARK_SUCCESS: the function exited successfully. | ||||||
:retval ARK_MEM_NULL: ``arkode_mem`` was ``NULL``. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.y.z | ||||||
|
||||||
|
||||||
.. _ARKODE.Usage.ARKodeAdaptivityInputTable: | ||||||
|
||||||
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.. | ||
---------------------------------------------------------------- | ||
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: | ||
|
||
############################ | ||
Adjoint Sensitivity Analysis | ||
############################ | ||
|
||
.. versionadded:: x.y.z | ||
|
||
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 capabilities implemented in the SUNDIALS packages. Right now it supports :ref:`the | ||
ASA capabilities 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. | ||
*Users should read the package specific sections on ASA capabilities before this section.* | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
SUNAdjoint_links.rst |
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.
I don't think ASA is defined yet. I only see it in the SUNAdjoint section which is much later in the docs