-
Notifications
You must be signed in to change notification settings - Fork 66
refc[adjoint]: Refactor PoleResidue derivative calculation #2585
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
Conversation
4033adc to
8c478c4
Compare
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.
3 files reviewed, 2 comments
Edit PR Review Bot Settings | Greptile
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
|
tylerflex
left a comment
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.
approved, thanks yannick!
8c478c4 to
3ffca81
Compare
groberts-flex
left a comment
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.
great, I like this! like the simplification and re-use!
The derivative logic for both `PoleResidue` and the spatially-varying `CustomPoleResidue` has been refactored to use an analytical formula. This is achieved by: - Replacing the `autograd`-based implementations in both classes with the analytical formulas for the pole-residue model derivatives. - Creating a single, shared `staticmethod` (`_get_vjps_from_params`) in the base `PoleResidue` class to house this logic. - Updating the `_compute_derivatives` methods in both classes to be simple wrappers that call this new helper.
3ffca81 to
a280a6d
Compare
This PR removes the "mysterious" factors in the adjoint gradient calculation for
CustomPoleResidueand refactors the derivative logic for bothPoleResidueandCustomPoleResidue. Tested on the gold nanoantenna notebook.The PR removes more code than it adds so you know it's good 😉
Greptile Summary
Refactors adjoint gradient calculations for PoleResidue models to use analytical derivatives instead of automatic differentiation, improving mathematical precision and code clarity.
tidy3d/components/medium.pyfor PoleResidue calculations_get_vjps_from_paramshelper method to consolidate derivative logic for both PoleResidue and CustomPoleResiduetests/test_autograd.pyto properly handle complex conjugates