replace infinite source width in dummy adjoint source time to avoid runtime warning for overflow error #2886
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.
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).
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.pyto calculate appropriate frequency bounds based on existing adjoint sources rather than usingfwidth=inf. The fix determinesmin_freq_tmp_srcandmax_freq_tmp_srcfrom 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
tidy3d/components/data/sim_data.pyConfidence score: 4/5
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"