Conversation
Reviewer's GuideAdds a utility to export SAX S-parameter models into Lumerical Interconnect .dat format, including wavelength sweep, optional port remapping, and correct frequency-ordered S-parameter serialization plus a small CLI-style example/verification block. Sequence diagram for sax_to_lumerical_dat example executionsequenceDiagram
actor User
participant sax_to_lumerical_dat
participant SAXModel
participant FileSystem
participant LumericalReader
User->>sax_to_lumerical_dat: call sax_to_lumerical_dat(model, filepath, port_map, wavelength_start, wavelength_stop, wavelength_points, model_kwargs)
activate sax_to_lumerical_dat
sax_to_lumerical_dat->>sax_to_lumerical_dat: build wl array (linspace)
sax_to_lumerical_dat->>SAXModel: model(wl, model_kwargs)
activate SAXModel
SAXModel-->>sax_to_lumerical_dat: sdict[(port_src, port_dst)] -> complex array
deactivate SAXModel
sax_to_lumerical_dat->>sax_to_lumerical_dat: apply port_map to sdict (optional)
sax_to_lumerical_dat->>sax_to_lumerical_dat: infer port_names if None
sax_to_lumerical_dat->>sax_to_lumerical_dat: compute frequencies from wl (reversed)
loop for each src in port_names
loop for each dst in port_names
sax_to_lumerical_dat->>sax_to_lumerical_dat: get sdict[(src, dst)] or zeros
sax_to_lumerical_dat->>sax_to_lumerical_dat: reverse values, compute magnitude and angle
sax_to_lumerical_dat->>sax_to_lumerical_dat: append DAT header and data lines
end
end
sax_to_lumerical_dat->>FileSystem: write_text(joined lines) -> filepath.dat
deactivate sax_to_lumerical_dat
sax_to_lumerical_dat-->>User: return Path(filepath.dat)
User->>LumericalReader: read_sparameters_file(filepath.dat, numports)
activate LumericalReader
LumericalReader->>FileSystem: open and parse DAT file
FileSystem-->>LumericalReader: raw DAT content
LumericalReader-->>User: port_names, F, S
deactivate LumericalReader
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider adding basic validation (e.g., that
wavelength_start < wavelength_stop,wavelength_points > 0, and that the arrays returned insdictall matchlen(wl)) to fail fast on misconfigured sweeps or inconsistent model outputs rather than silently producing malformed DAT files.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider adding basic validation (e.g., that `wavelength_start < wavelength_stop`, `wavelength_points > 0`, and that the arrays returned in `sdict` all match `len(wl)`) to fail fast on misconfigured sweeps or inconsistent model outputs rather than silently producing malformed DAT files.
## Individual Comments
### Comment 1
<location path="gplugins/lumerical/write_sparameters_lumerical_from_sax.py" line_range="81-82" />
<code_context>
+ for src in port_names:
+ for dst in port_names:
+ key = (src, dst)
+ if key in sdict:
+ values = np.asarray(sdict[key], dtype=complex)
+ else:
+ # Missing entries (e.g. reflections) default to zero
</code_context>
<issue_to_address>
**issue (bug_risk):** Validate that each S-parameter vector length matches `wavelength_points` to avoid silent shape mismatches.
`values` is implicitly assumed to have length `n_wl`. If the model returns a different-length array (e.g., from wavelength sweep rounding or a model bug), the output will be malformed without any error. Please add a check like `assert values.shape[0] == n_wl` (or at least log a warning) before reversing and writing so these issues fail fast instead of silently corrupting the DAT file.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if key in sdict: | ||
| values = np.asarray(sdict[key], dtype=complex) |
There was a problem hiding this comment.
issue (bug_risk): Validate that each S-parameter vector length matches wavelength_points to avoid silent shape mismatches.
values is implicitly assumed to have length n_wl. If the model returns a different-length array (e.g., from wavelength sweep rounding or a model bug), the output will be malformed without any error. Please add a check like assert values.shape[0] == n_wl (or at least log a warning) before reversing and writing so these issues fail fast instead of silently corrupting the DAT file.
Summary by Sourcery
Add a utility to export SAX S-parameter models to Lumerical Interconnect DAT files.
New Features:
Tests: