-
Notifications
You must be signed in to change notification settings - Fork 50
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 source creation #2282
Merged
yaugenst-flex
merged 1 commit into
develop
from
groberts-flex/fix_adjoint_traced_fields
Feb 28, 2025
+13
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
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.
could this be an alternative approach? (only new code is "clearing" the
data
of untraced fields)I suppose a downside of this is that it introduces an additional copy, but maybe because it is shallow it is not so bad? Upside is that it's bit simpler to understand.
Just a thought, I think what you have also works.
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.
Thanks for the suggestion, I like the upside of easier to understand.
The issue I'm running into with this approach is we actually are needing to clear certain fields in each monitor data according to the data_fields_vjp keys instead of just the whole data associated with a monitor. The monitor name is not a key into the data_fields_vjp because that key contains information on a specific field in the monitor data (i.e. - an example of one of the keys in data_fields_vjp looks like ('data', 0, 'Ex'))
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.
oh right, I've already forgotten a bit how this data is stored. I guess it could look rather like
or does that not work either?
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.
side note: might need to make sure
traced_indices
is sorted before iterating through it to avoid potential issues.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.
traced_indices = {index for _, index, * in data_fields_vjp.keys()}
Is the
*
here intended to also be a_
?This isn't working when I test it either because while it strips the index correctly to pull out a specific monitor data from the simulation data, it still doesn't zero out fields inside that monitor data that are not present in the vjp data. Those non zero'd fields then get turned into adjoint sources.
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.
sorry, it should be a
*_
, basically to unpack everything after theindex
oh, interesting. Yea maybe in that case what you propose is ultimately the correct approach. thanks for going through that with me. I think it makes sense now. I've started somewhat forgetting how all of this works after spending more time away from it.
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.
Gotcha, that makes sense on the syntax - I hadn't used that unpack before!
And definitely, no problem! I'm definitely still getting up to speed with a lot of how all this stuff is passed around and connects to the autograd library. It's quite the feat how seamless this stuff is for the user! I'm open to other approaches to this as well, but keeping with how the current adjoint source creation works inside monitor data, this was the best way I could come up with for now that seemed to get the job done. Yannick and I discussed this morning a potential different approach this morning in our 1:1 of using the vjp data directly to create the adjoint sources instead of filling in the monitor data as an intermediate.