Skip to content

Conversation

@groberts-flex
Copy link
Contributor

@groberts-flex groberts-flex commented Oct 13, 2025

Recently, a change was made that started causing the runtime warnings to pop up when making the adjoint source dummy source_time for hashing. The warnings look like the one pasted below. The fix is to not use a consistent, but finite width source that covers all the frequencies necessary (if not, validators will fail for some sources like custom field source).

Screenshot 2025-10-13 at 10 59 12 AM

Greptile Overview

Updated On: 2025-10-13 15:01:59 UTC

Greptile Summary

This PR fixes runtime overflow warnings in the adjoint source hashing logic by replacing infinite frequency width with computed finite bounds. The change modifies the dummy adjoint source creation in tidy3d/components/data/sim_data.py to calculate appropriate frequency bounds based on existing adjoint sources rather than using fwidth=inf. The fix determines min_freq_tmp_src and max_freq_tmp_src from the frequency ranges of all adjoint sources, then sets the temporary source's center frequency and width to cover this range. This maintains the original hashing functionality while eliminating numerical overflow warnings that were being triggered during calculations with infinite values.

Important Files Changed

Changed Files
Filename Score Overview
tidy3d/components/data/sim_data.py 4/5 Replaces infinite source width with computed finite frequency bounds in dummy adjoint source creation

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it addresses a specific runtime warning without changing core functionality
  • Score reflects a targeted fix that maintains existing behavior while solving numerical overflow issues; no major algorithmic changes or breaking modifications
  • Pay close attention to the frequency bound calculations to ensure they properly cover all necessary frequency ranges for different source types

Sequence Diagram

sequenceDiagram
    participant User
    participant SimulationData
    participant AdjointSource
    participant GaussianPulse

    User->>SimulationData: "_adjoint_src_width_broadband(adj_srcs)"
    SimulationData->>SimulationData: "extract frequencies from adj_srcs"
    SimulationData->>SimulationData: "calculate middle_f0 = 0.5 * (max + min)"
    SimulationData->>SimulationData: "calculate decay_by_f0_fwidth = middle_f0 / NUM_ADJOINT_FWIDTH_TO_ZERO"
    SimulationData->>SimulationData: "calculate fwidth_to_min_f0 = (middle_f0 - min_f0) / NUM_ADJOINT_FWIDTH_TO_FMIN"
    SimulationData->>SimulationData: "check if fwidth_to_min_f0 > decay_by_f0_fwidth and log warning if needed"
    SimulationData->>SimulationData: "adj_src_fwidth = max(decay_by_f0_fwidth, fwidth_to_min_f0)"
    SimulationData-->>User: "return (middle_f0, adj_src_fwidth)"

    User->>SimulationData: "_make_broadband_source(adj_srcs)"
    SimulationData->>SimulationData: "_adjoint_src_width_broadband(adj_srcs)"
    SimulationData->>SimulationData: "get source_index from normalize_index"
    SimulationData->>GaussianPulse: "updated_copy(amplitude=1.0, phase=0.0)"
    GaussianPulse-->>SimulationData: "src_time_base"
    SimulationData->>GaussianPulse: "updated_copy(freq0=adj_src_f0, fwidth=adj_src_fwidth)"
    GaussianPulse-->>SimulationData: "updated source_time"
    SimulationData->>AdjointSource: "updated_copy(source_time=updated_source_time)"
    AdjointSource-->>SimulationData: "src_broadband"
    SimulationData-->>User: "return src_broadband"
Loading

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.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@groberts-flex groberts-flex force-pushed the hotfix/groberts-flex/runtime_overflow_warning_adjoint_source_width branch from ec2f50c to e9fd255 Compare October 13, 2025 15:02
@github-actions
Copy link
Contributor

Diff Coverage

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

  • tidy3d/components/data/sim_data.py (100%)

Summary

  • Total: 5 lines
  • Missing: 0 lines
  • Coverage: 100%

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 @groberts-flex! LGTM but need to update the commit message (fix: )

@yaugenst-flex yaugenst-flex force-pushed the hotfix/groberts-flex/runtime_overflow_warning_adjoint_source_width branch from e9fd255 to 8225e62 Compare October 14, 2025 09:13
@groberts-flex groberts-flex force-pushed the hotfix/groberts-flex/runtime_overflow_warning_adjoint_source_width branch from 8225e62 to 2945e18 Compare October 14, 2025 11:55
@groberts-flex groberts-flex added this pull request to the merge queue Oct 14, 2025
Merged via the queue into develop with commit 2077675 Oct 14, 2025
25 checks passed
@groberts-flex groberts-flex deleted the hotfix/groberts-flex/runtime_overflow_warning_adjoint_source_width branch October 14, 2025 14:42
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