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

Conversation

balos1
Copy link
Member

@balos1 balos1 commented Aug 27, 2024

No description provided.

Copy link
Collaborator

@drreynolds drreynolds left a comment

Choose a reason for hiding this comment

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

I just went through the documentation updates. I'll look through the code soon.

doc/arkode/guide/source/Mathematics.rst Outdated Show resolved Hide resolved
doc/arkode/guide/source/Mathematics.rst Outdated Show resolved Hide resolved
doc/arkode/guide/source/Mathematics.rst Outdated Show resolved Hide resolved
doc/arkode/guide/source/Mathematics.rst Outdated Show resolved Hide resolved
doc/arkode/guide/source/Mathematics.rst Outdated Show resolved Hide resolved
doc/arkode/guide/source/Mathematics.rst Outdated Show resolved Hide resolved
doc/arkode/guide/source/Mathematics.rst Outdated Show resolved Hide resolved
doc/shared/sunadjoint/SUNAdjointStepper.rst Show resolved Hide resolved
doc/shared/sunadjoint/SUNAdjoint_Description.rst Outdated Show resolved Hide resolved
@drreynolds drreynolds self-requested a review August 27, 2024 15:04
Co-authored-by: Daniel R. Reynolds <reynolds@smu.edu>
Copy link
Collaborator

@drreynolds drreynolds left a comment

Choose a reason for hiding this comment

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

A few minor changes on the added/updated content, and I did see one of my previous comments that may still require investigation (inside doc/arkode/guide/source/Usage/ARKStep/ASA.rst)

:param cs: The :c:type:`SUNAdjointCheckpointScheme` object
:param step_num: the step number of the checkpoint
:param stage_num: the stage number of the checkpoint
:param t: the time of the checkpoint
Copy link
Collaborator

Choose a reason for hiding this comment

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

t is not an argument to this function

Suggested change
:param t: the time of the checkpoint

(or if it is, then the signature above needs to be fixed)

:param keep: Keep data stored even after it is not needed anymore.
:param sunctx: The :c:type:`SUNContext` for the simulation.
:param check_scheme_ptr: Pointer to the newly constructed object.
:return: A :c:type:`SUNErrCode` indicating success or failure.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need a preceding blank line (like the other .. c:function:: blocks above)?

Suggested change
:return: A :c:type:`SUNErrCode` indicating success or failure.
:return: A :c:type:`SUNErrCode` indicating success or failure.


.. c:member:: SUNMatrix Jac

Matrix data for the Jacobian :math:`df/dy`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I apologize in advance, but the math professor in me needs these Jacobians to be denoted correctly (since $f$ is a function of multiple inputs, and $d$ typically represents the total derivative). I'll "suggest" the relevant changes here and below.

Suggested change
Matrix data for the Jacobian :math:`df/dy`.
Matrix data for the Jacobian :math:`\partial f/\partial y`.

Copy link
Member Author

@balos1 balos1 Nov 13, 2024

Choose a reason for hiding this comment

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

Good catch. It was not in :math: originally, it was plain text so\partial was not used. When I just did a find/replace to add the :math: I overlooked this.


.. c:member:: SUNMatrix JacP

Matrix data for the Jacobian :math:`df/dp`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Matrix data for the Jacobian :math:`df/dp`.
Matrix data for the Jacobian :math:`\partial f/\partial p`.


.. c:member:: SUNRhsJacFn JacFn

Jacobian function pointer to evaluate :math:`df/dy`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Jacobian function pointer to evaluate :math:`df/dy`.
Jacobian function pointer to evaluate :math:`\partial f/\partial y`.

Comment on lines +215 to +219
Sets the function pointers to evaluate :math:`(df/dy)^T v` and :math:`(df/dp)^T v`

:param adj_stepper: The SUNAdjointStepper object.
:param Jvp: function that evaluates :math:`(df/dy)^T v`.
:param JPvp: function that evaluates :math:`(df/dp)^T v`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Sets the function pointers to evaluate :math:`(df/dy)^T v` and :math:`(df/dp)^T v`
:param adj_stepper: The SUNAdjointStepper object.
:param Jvp: function that evaluates :math:`(df/dy)^T v`.
:param JPvp: function that evaluates :math:`(df/dp)^T v`.
Sets the function pointers to evaluate :math:`(\partial f/\partial y)^T v` and :math:`(\partial f/\partial p)^T v`
:param adj_stepper: The SUNAdjointStepper object.
:param Jvp: function that evaluates :math:`(\partial f/\partial y)^T v`.
:param JPvp: function that evaluates :math:`(\partial f/\partial p)^T v`.

Comment on lines +227 to +231
Sets the function pointers to evaluate :math:`v^T (df/dy)` and :math:`v^T (df/dp)`

:param adj_stepper: The SUNAdjointStepper object.
:param Jvp: function that evaluates :math:`v^T (df/dy)`.
:param JPvp: function that evaluates :math:`v^T (df/dp)`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Sets the function pointers to evaluate :math:`v^T (df/dy)` and :math:`v^T (df/dp)`
:param adj_stepper: The SUNAdjointStepper object.
:param Jvp: function that evaluates :math:`v^T (df/dy)`.
:param JPvp: function that evaluates :math:`v^T (df/dp)`.
Sets the function pointers to evaluate :math:`v^T (\partial f/\partial y)` and :math:`v^T (\partial f/\partial p)`
:param adj_stepper: The SUNAdjointStepper object.
:param Jvp: function that evaluates :math:`v^T (\partial f/\partial y)`.
:param JPvp: function that evaluates :math:`v^T (\partial f/\partial p)`.

Comment on lines +177 to +180
Performs the matrix-vector product *y \gets A^Tx*. It should
only be called with vectors *x* and *y* that are compatible with
the matrix *A^T* -- both in storage type and dimensions. The return
value denotes the success/failure of the operation:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these use :math: mode?

Suggested change
Performs the matrix-vector product *y \gets A^Tx*. It should
only be called with vectors *x* and *y* that are compatible with
the matrix *A^T* -- both in storage type and dimensions. The return
value denotes the success/failure of the operation:
Performs the matrix-vector product :math:`y \gets A^Tx`. It should
only be called with vectors :math:`x` and :math:`y` that are compatible with
the matrix :math:`A^T` -- both in storage type and dimensions. The return
value denotes the success/failure of the operation:

Comment on lines +51 to +56
# "ark_test_erkadjoint.cpp\;--check-freq 1 --no-stages\;"
# "ark_test_erkadjoint.cpp\;--check-freq 2 --no-stages\;"
# "ark_test_erkadjoint.cpp\;--check-freq 5 --no-stages\;"
# "ark_test_erkadjoint.cpp\;--check-freq 1 --dont-keep --no-stages\;"
# "ark_test_erkadjoint.cpp\;--check-freq 2 --dont-keep --no-stages\;"
# "ark_test_erkadjoint.cpp\;--check-freq 5 --dont-keep --no-stages\;"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these just be deleted from the file instead of commented out?

Suggested change
# "ark_test_erkadjoint.cpp\;--check-freq 1 --no-stages\;"
# "ark_test_erkadjoint.cpp\;--check-freq 2 --no-stages\;"
# "ark_test_erkadjoint.cpp\;--check-freq 5 --no-stages\;"
# "ark_test_erkadjoint.cpp\;--check-freq 1 --dont-keep --no-stages\;"
# "ark_test_erkadjoint.cpp\;--check-freq 2 --dont-keep --no-stages\;"
# "ark_test_erkadjoint.cpp\;--check-freq 5 --dont-keep --no-stages\;"

Comment on lines +514 to +521
// TODO(CJB): figure out why ForwardDiff, CVODES, and ERK adjoint all differ
// if (check_sensitivities_backward(sf))
// {
// fprintf(stderr,
// ">>> FAILURE: adjoint solution does not match correct answer\n");
// return -1;
// };
// printf(">>> PASS\n");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this "TODO(CJB)" still relevant, or should the comment and associated code be deleted?

Base automatically changed from feature/sunstepper to develop November 22, 2024 01:58
@balos1 balos1 changed the title Feature/sunadjoint Initial discrete adjoint capability with ERK Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants