Skip to content

Conversation

@mahlau-flex
Copy link
Contributor

@mahlau-flex mahlau-flex commented Nov 13, 2025

Smoothed projection from the paper https://arxiv.org/pdf/2503.20189

Greptile Overview

Greptile Summary

This PR adds smoothed_projection, a new inverse design projection function that supports subpixel smoothing with β→∞, based on the paper by Alec Hammond (arxiv.org/pdf/2503.20189). The implementation integrates out discontinuities in the projection function, allowing smooth gradient flow even at infinite projection strength.

Key changes:

  • Added smoothed_projection function in projections.py with comprehensive documentation
  • Updated API documentation to include the new function
  • Added test coverage for β=∞ case
  • Properly exported the function in module __all__

Issues found:

  • Minor typos in docstrings and comments that need correction
  • Missing CHANGELOG entry for this user-facing feature addition

Confidence Score: 4/5

  • This PR is safe to merge with minor corrections needed for typos and CHANGELOG entry
  • The implementation is mathematically sound, well-documented, and includes basic test coverage. The function follows established patterns from other projection functions in the codebase. Only minor issues found: spelling errors in docstrings and missing CHANGELOG entry per project guidelines.
  • All files are acceptable but tidy3d/plugins/autograd/invdes/projections.py needs typo corrections

Important Files Changed

File Analysis

Filename Score Overview
tidy3d/plugins/autograd/invdes/projections.py 4/5 Added smoothed_projection function for subpixel smoothing with β→∞ support, well-documented with minor typo
tests/test_plugins/autograd/invdes/test_projections.py 4/5 Added basic test for smoothed_projection with beta=inf, validates discrete output behavior
tidy3d/plugins/autograd/invdes/init.py 5/5 Added smoothed_projection to exports and all list
docs/api/plugins/autograd.rst 5/5 Added documentation reference for smoothed_projection

Sequence Diagram

sequenceDiagram
    participant User
    participant smoothed_projection
    participant tanh_projection
    participant np_gradient
    
    User->>smoothed_projection: array, beta, eta
    Note over smoothed_projection: Assert array.ndim == 2
    smoothed_projection->>tanh_projection: array, beta, eta
    tanh_projection-->>smoothed_projection: rho_projected
    
    smoothed_projection->>np_gradient: array
    np_gradient-->>smoothed_projection: rho_filtered_grad
    
    Note over smoothed_projection: Compute gradient norm<br/>and sanitize for divide-by-zero
    Note over smoothed_projection: Calculate distance d to interface<br/>d = (eta - array) / grad_norm
    Note over smoothed_projection: Determine needs_smoothing:<br/>interface within voxel?
    
    Note over smoothed_projection: Compute fill factors F and F_minus<br/>using analytic expressions
    Note over smoothed_projection: Calculate bounds:<br/>rho_filtered_minus, rho_filtered_plus
    
    smoothed_projection->>tanh_projection: rho_filtered_minus, beta, eta
    tanh_projection-->>smoothed_projection: rho_minus_eff_projected
    smoothed_projection->>tanh_projection: rho_filtered_plus, beta, eta
    tanh_projection-->>smoothed_projection: rho_plus_eff_projected
    
    Note over smoothed_projection: Apply smoothing at interfaces<br/>rho_projected_smoothed = (1-F)*minus + F*plus
    Note over smoothed_projection: Use np.where to select:<br/>smoothed or standard projection
    
    smoothed_projection-->>User: smoothed result
Loading

Context used:

  • Rule from dashboard - Require a changelog entry for any PR that is not purely an internal refactor. (source)

@mahlau-flex mahlau-flex requested review from yaugenst-flex and removed request for yaugenst-flex November 13, 2025 07:59
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@mahlau-flex mahlau-flex force-pushed the FXC-3297-Basic-subpixel-averaging-for-CustomMedium branch from b262065 to 3ac1e93 Compare November 13, 2025 08:07
@github-actions
Copy link
Contributor

github-actions bot commented Nov 13, 2025

Diff Coverage

Diff: origin/develop...HEAD, staged and unstaged changes

  • tidy3d/plugins/autograd/invdes/init.py (100%)
  • tidy3d/plugins/autograd/invdes/projections.py (95.7%): Missing lines 137

Summary

  • Total: 24 lines
  • Missing: 1 line
  • Coverage: 95%

tidy3d/plugins/autograd/invdes/projections.py

Lines 133-141

  133        (2025).
  134     """
  135     # sanity checks
  136     if array.ndim != 2:
! 137         raise ValueError(f"Smoothed projection expects a 2d-array, but got shape {array.shape=}")
  138 
  139     # smoothing kernel is circle (or ellipse for non-uniform grid)
  140     # we choose smoothing kernel with unit area, which is r~=0.56, a bit larger than (arbitrary) default r=0.55 in paper
  141     dx = dy = scaling_factor

Copy link
Collaborator

@yaugenst-flex yaugenst-flex left a 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 is really nice to have!

@mahlau-flex mahlau-flex force-pushed the FXC-3297-Basic-subpixel-averaging-for-CustomMedium branch 4 times, most recently from 5108710 to ccc0834 Compare November 20, 2025 07:46
Copy link
Collaborator

@yaugenst-flex yaugenst-flex left a comment

Choose a reason for hiding this comment

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

Thanks @mahlau-flex looks great! Only minor formatting nits on the docstring.

@mahlau-flex mahlau-flex force-pushed the FXC-3297-Basic-subpixel-averaging-for-CustomMedium branch from ccc0834 to 7d37e5b Compare November 20, 2025 10:06
Copy link
Collaborator

@yaugenst-flex yaugenst-flex left a comment

Choose a reason for hiding this comment

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

LGTM!

@yaugenst-flex yaugenst-flex added this pull request to the merge queue Nov 20, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 20, 2025
@mahlau-flex mahlau-flex force-pushed the FXC-3297-Basic-subpixel-averaging-for-CustomMedium branch from 7d37e5b to b02286a Compare November 20, 2025 11:30
@yaugenst-flex yaugenst-flex added this pull request to the merge queue Nov 21, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 21, 2025
@mahlau-flex mahlau-flex force-pushed the FXC-3297-Basic-subpixel-averaging-for-CustomMedium branch from b02286a to c2399de Compare November 21, 2025 08:38
@yaugenst-flex yaugenst-flex added this pull request to the merge queue Nov 21, 2025
@yaugenst-flex yaugenst-flex removed this pull request from the merge queue due to a manual request Nov 21, 2025
@mahlau-flex mahlau-flex force-pushed the FXC-3297-Basic-subpixel-averaging-for-CustomMedium branch from c2399de to cc5ff01 Compare November 21, 2025 10:03
@mahlau-flex mahlau-flex added this pull request to the merge queue Nov 21, 2025
Merged via the queue into develop with commit 5882680 Nov 21, 2025
19 checks passed
@mahlau-flex mahlau-flex deleted the FXC-3297-Basic-subpixel-averaging-for-CustomMedium branch November 21, 2025 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants