-
Notifications
You must be signed in to change notification settings - Fork 66
feat(invdes): added symmetry functions #3043
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
base: develop
Are you sure you want to change the base?
feat(invdes): added symmetry functions #3043
Conversation
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.
5 files reviewed, 4 comments
66ece12 to
ffeb45d
Compare
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/plugins/autograd/invdes/symmetries.py |
ffeb45d to
89c3f6a
Compare
yaugenst-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.
Thanks @mahlau-flex this looks great! Two general comments:
- Could you also add these to
docs/api/plugins/autograd.rstso they are listed in the docs - It would be nice to have an example in the docstrings, which for these simple helpers would be pretty useful and easy enough to do?
89c3f6a to
bcab6fd
Compare
|
@yaugenst-flex I added the requested features. Let me know if you like the style of the examples. |
Looks great! Thanks! |
Added symmetry functions according to https://flow360.atlassian.net/browse/FXC-4347
Greptile Overview
Greptile Summary
This PR adds three symmetry functions (
symmetrize_mirror,symmetrize_rotation,symmetrize_diagonal) for topology optimization in inverse design workflows. These functions enforce known symmetries during optimization by averaging arrays with their transformed versions.symmetrize_mirror: averages with axis-flipped versions for mirror symmetrysymmetrize_rotation: averages over 90° rotations for 4-fold rotational symmetrysymmetrize_diagonal: averages with transpose for diagonal symmetryThe implementation uses autograd-compatible operations (slicing, transpose) to maintain gradient flow. Tests verify gradient correctness, numerical accuracy, and error handling.
Key Issues:
Exceptioninstead ofValueErrorfor input validation (violates codebase pattern)symmetrize_mirrordocstring mentions "ramp projection"Confidence Score: 4/5
Important Files Changed
File Analysis
Exceptioninstead ofValueErrorfor validation, and has copy-paste error in docstringSequence Diagram
sequenceDiagram participant User as User/Optimizer participant Sym as symmetrize_* functions participant AG as Autograd participant Array as NDArray Note over User,Array: Topology Optimization Flow User->>Sym: Call symmetry function (array, params) activate Sym Sym->>Array: Validate array shape (ndim=2) alt Invalid shape Array-->>Sym: Raise Exception Sym-->>User: Error end alt symmetrize_mirror Sym->>Array: Flip array along axis Array-->>Sym: Flipped array Sym->>Sym: Average original + flipped else symmetrize_rotation Sym->>Array: Apply rotations (90°, 180°, 270°) Array-->>Sym: Rotated arrays Sym->>Sym: Average 4 rotations else symmetrize_diagonal Sym->>Array: Transpose array alt Anti-diagonal Array-->>Sym: Flipped transpose else Main diagonal Array-->>Sym: Regular transpose end Sym->>Sym: Average original + transpose end Sym->>AG: Return symmetrized array deactivate Sym Note over User,AG: Gradient Flow (Backpropagation) User->>AG: Compute gradients AG->>Sym: Backward pass through symmetry ops Sym->>Array: Compute VJP (slicing, transpose) Array-->>AG: Gradient tensors AG-->>User: Gradients w.r.t. inputContext used:
dashboard- Uselog.errorinstead ofassertstatements for error handling in production code. (source)