Skip to content

Conversation

@caseyflex
Copy link
Contributor

@caseyflex caseyflex commented Jan 16, 2026

This PR:

  • Adds EMECoefficientMonitor.fields which can be a list of some of "A", "B", "overlaps", "interface_smatrices", "n_complex", and "flux"
  • By default this is just ("A", "B") so the default behavior is unchanged. But now the other fields are also supported
  • This unifies the behavior with EMESimulationData.coeffs which is like the full monitor but with no downsampling. EMECoefficientMonitor supports downsampling via eme_cell_interval_space, num_sweep, and num_modes.
  • The memory computation and validation has also been unified and the warnings have been clarified for this and for the port modes.

Note

Unifies EME coefficient handling and storage estimation while enabling selective coefficient capture.

  • EMECoefficientMonitor: adds fields ("A", "B", "n_complex", "flux", "interface_smatrices", "overlaps"); storage_size() rewritten to be field- and sweep-aware and to use virtual EME cells
  • Sweeps: introduces sweep_modes/interfaces/cells flags on sweep specs; all EME monitor storage_size() methods now accept sweep_spec and respect per-monitor num_sweep limits
  • Simulation integration: adds coeffs_full_monitor and includes it in _monitors_full when store_coeffs=True; removes manual coeff size math in favor of monitor-based sizing
  • Data model: EMESimulationData.coeffs accepts EMECoefficientData | EMECoefficientDataset
  • Validation & warnings: per-monitor size map updated; specific warnings for large coeffs and port modes; schema updated to expose fields
  • Tests: cover default/custom fields, zero-storage edge case, sweep-specific scaling, per-monitor limits, and inclusion logic
  • Docs/Changelog: CHANGELOG entry for new monitor fields

Written by Cursor Bugbot for commit d0975a4. This will update automatically on new commits. Configure here.

Greptile Summary

This PR unifies the handling of EME coefficients by adding a configurable fields property to EMECoefficientMonitor that supports the same fields as EMESimulationData.coeffs ("A", "B", "n_complex", "flux", "interface_smatrices", "overlaps"). The default behavior remains unchanged with fields=("A", "B"), but users can now select additional fields with the benefit of downsampling via eme_cell_interval_space, num_sweep, and num_modes.

Key changes:

  • Added EMECoefficientMonitor.fields property with comprehensive field selection options
  • Refactored storage size calculation to be field-aware and accurate for each coefficient type
  • Unified memory validation logic by moving coefficient storage from manual calculation to the monitor-based system
  • Improved warning messages to distinguish between store_coeffs and store_port_modes warnings
  • Changed EMESimulationData.coeffs type from EMECoefficientDataset to EMECoefficientData for consistency with monitor data architecture
  • Added comprehensive tests covering field selection, storage calculation, and monitor inclusion logic

The implementation correctly calculates storage sizes for each field type based on their respective dimensionalities (cells, modes, interfaces, sweeps).

Confidence Score: 4/5

  • This PR is safe to merge with one minor docstring correction needed
  • The implementation is solid with comprehensive tests and proper refactoring. The storage calculation logic is mathematically correct for each field type. Only one syntax issue was found: an incorrect docstring on coeffs_full_monitor that states it returns a mode solver monitor when it actually returns a coefficient monitor. This is a documentation issue that doesn't affect functionality but should be fixed for clarity.
  • tidy3d/components/eme/simulation.py needs a docstring correction on line 594-595

Important Files Changed

Filename Overview
tidy3d/components/eme/monitor.py Added fields property to EMECoefficientMonitor with correct storage size calculation logic
tidy3d/components/eme/simulation.py Unified coefficient monitoring logic with improved validation and clearer warnings, but has incorrect docstring
tests/test_components/test_eme.py Added comprehensive tests for new fields functionality, storage calculation, and monitor inclusion logic

Sequence Diagram

sequenceDiagram
    participant User
    participant EMESimulation
    participant EMECoefficientMonitor
    participant storage_size
    participant validate_pre_upload
    
    User->>EMESimulation: Create simulation with store_coeffs=True
    EMESimulation->>EMECoefficientMonitor: Create coeffs_full_monitor
    Note over EMECoefficientMonitor: fields=("A", "B") by default<br/>num_sweep=None (all sweeps)
    
    User->>EMECoefficientMonitor: Optionally set custom fields
    Note over EMECoefficientMonitor: fields can include:<br/>"A", "B", "n_complex",<br/>"flux", "interface_smatrices",<br/>"overlaps"
    
    User->>EMESimulation: Call validate_pre_upload()
    EMESimulation->>EMESimulation: Build _monitors_full
    Note over EMESimulation: Includes coeffs_full_monitor<br/>if store_coeffs=True
    
    EMESimulation->>storage_size: Calculate storage for each monitor
    storage_size->>EMECoefficientMonitor: Calculate bytes based on fields
    Note over EMECoefficientMonitor: Adds bytes for each field:<br/>- A/B: 2*cells*modes²<br/>- n_complex/flux: cells*modes<br/>- interface_smatrices: 4*(cells-1)*modes²<br/>- overlaps: cells*modes² + 2*(cells-1)*modes²
    
    EMECoefficientMonitor-->>storage_size: Return total bytes
    storage_size-->>validate_pre_upload: Return size
    
    validate_pre_upload->>validate_pre_upload: Check if size > WARN_COEFF_DATA_SIZE_GB
    alt Size exceeds warning threshold
        validate_pre_upload->>User: Warn: coeffs storage too large
    end
    
    validate_pre_upload-->>User: Validation complete
Loading

@caseyflex caseyflex force-pushed the casey/emecoeffsunify branch from 336364d to d27b9fc Compare January 16, 2026 23:18
@caseyflex caseyflex changed the title chore: Unify handling of EMECoefficientMonitor and EMESimulationData.… chore: Unify handling of EME coefficients Jan 16, 2026
@caseyflex caseyflex marked this pull request as ready for review January 16, 2026 23:21
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.

5 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@caseyflex caseyflex force-pushed the casey/emecoeffsunify branch from d27b9fc to 132076e Compare January 16, 2026 23:25
@caseyflex caseyflex changed the title chore: Unify handling of EME coefficients chore: Unify handling of EME coefficients (FXC-4311) Jan 16, 2026
@caseyflex caseyflex force-pushed the casey/emecoeffsunify branch from 132076e to f982375 Compare January 16, 2026 23:32
cursor[bot]

This comment was marked as outdated.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2026

Diff Coverage

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

  • tidy3d/components/eme/data/sim_data.py (100%)
  • tidy3d/components/eme/monitor.py (100%)
  • tidy3d/components/eme/simulation.py (100%)
  • tidy3d/components/eme/sweep.py (100%)

Summary

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

@caseyflex caseyflex force-pushed the casey/emecoeffsunify branch from f982375 to 7305ea0 Compare January 17, 2026 00:25
Copy link
Collaborator

@momchil-flex momchil-flex left a comment

Choose a reason for hiding this comment

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

This is probably a feat not a chore :)

@caseyflex caseyflex force-pushed the casey/emecoeffsunify branch from 7305ea0 to d118b2e Compare January 19, 2026 21:28
@caseyflex caseyflex changed the title chore: Unify handling of EME coefficients (FXC-4311) feat: Unify handling of EME coefficients (FXC-4311) Jan 19, 2026
@caseyflex caseyflex force-pushed the casey/emecoeffsunify branch 2 times, most recently from 71a4b4c to d947e26 Compare January 19, 2026 21:33
@caseyflex
Copy link
Contributor Author

@momchil-flex changed to a feat.

It changes the schema -- when should we merge it?

@momchil-flex
Copy link
Collaborator

Soon, hopefully before the end of the week we'll move the version to 2.11.0dev1.

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 @caseyflex just a couple clarifying questions

@caseyflex caseyflex force-pushed the casey/emecoeffsunify branch from d947e26 to d0975a4 Compare January 22, 2026 23:42
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@caseyflex caseyflex added this pull request to the merge queue Jan 28, 2026
Merged via the queue into develop with commit cbf7f6b Jan 28, 2026
108 of 112 checks passed
@caseyflex caseyflex deleted the casey/emecoeffsunify branch January 28, 2026 18:23
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.

4 participants