-
Notifications
You must be signed in to change notification settings - Fork 876
Tape recording debug mode #2442
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…l write restart files during runtime (there is a bug, potentially when clearing the tape).
…zation.hpp (to cover RealReverseTag).
…his is a temporary change to avoid false positives when a tag tape is used. They might be unnecessary anyway though.
…te adjoint solver.
6 tasks
6 tasks
…_tape_debug_mode
Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
…m them whether the test case is run in a tapetest stage or not.
…' test case for tape testing.
…tart filenames are extended automatically by the zone number.
pcarruscag
reviewed
Jun 20, 2025
Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
…ature_tape_debug_mode
…ccumulation region by setting further inputs and outputs.
pcarruscag
reviewed
Jun 25, 2025
Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
pcarruscag
approved these changes
Jun 28, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed Changes
Add feature to record a tape for debug purposes (as a tool for AD / discrete adjoint / .. developers), using CoDiPack's
codi::RealReverseTag
.More precisely, instead of using a definition of the
su2double
floating point type that allows us to compute derivatives, we definesu2double = codi::RealReverseTag
by passing the compile flag-Dcodi-tape=Tag
, for instance throughmeson build-tapecheck -Denable-autodiff=true -Dcodi-tape=Tag --buildtype=debug
by which all variables of type
su2double
can instead carry an additional "tag" of typeint
.When using the multizone discrete adjoint solver (for now, any single zone case must be wrapped as such one),
SU2_CFD_AD
that was compiled with-Dcodi-tape=Tag
will automatically start the debug mode, i.e. a new functionCDiscAdjMultizoneDriver::DebugRun()
insideCDiscAdjMultizoneDriver.cpp
that makes use of the tag-option.We can specify two options in the config file,
CHECK_TAPE_TYPE
-- the kind of tape that we want to investigate (FULL_SOLVER_TAPE
orOBJECTIVE_FUNCTION_TAPE
)CHECK_TAPE_VARIABLES
-- the kind of variables that we want to check the selected tape for (SOLVER_VARIABLES
or bothSOLVER_VARIABLES_AND_MESH_COORDINATES
)How does it work?
CDiscAdjMultizoneDriver::DebugRun()
performs two subsequent recordings with different tags.How does this help to uncover recording inconsistencies that could be the cause of wrong derivatives?
Once the test mode detects a mismatch between tags, it will perform a callback (implemented through CoDiPack's
tagErrorCallback
inad_structure.hpp
) .This means that a variable has become active (i.e. dependent on the inputs) during the first recording, and was used in the second recording still carrying its "old" tag 1. In other words, there has been at least one use of this variable without recognizing -- and recording -- its dependency on the inputs. (Detected via the second recording, but being present in any recording, of course.) This can, for instance, happen in case of an improper handling of postprocessing values.
How do I know at which line of the code the mismatch has been detected?
Compiling with debug flag
--buildtype=debug
and setting a breakpoint insidetagErrorCallback
in gdb or cdgb will guide you there ;-)Related Work
This is a (cleaned-up) continuation of #2343.
Supposed to help finding remaining errors in #2317.
PR Checklist
Put an X by all that apply. You can fill this out after submitting the PR. If you have any questions, don't hesitate to ask! We want to help. These are a guide for you to know what the reviewers will be looking for in your contribution.
pre-commit run --all
to format old commits.