Skip to content

Conversation

@caseyflex
Copy link
Contributor

@caseyflex caseyflex commented Dec 2, 2025

Replaces #3024.

This PR extends EMECoefficientDataset to store additional data:

  • cell interface S matrices
  • mode overlaps
  • n_complex and flux of EME modes

Furthermore, instead of using a monitor, this data is always stored in EMESimulationData.coeffs (it is always computed and is not very large) as long as EMESimulation.store_coeffs is True (the default). So EMECoefficientMonitor is deprecated.

Greptile Overview

Greptile Summary

This PR extends EMECoefficientDataset to store additional EME solver data including interface S-matrices, mode overlaps, complex propagation indices, and mode flux. Instead of using a monitor, this data is now always stored in EMESimulationData.coeffs when EMESimulation.store_coeffs=True (the default), deprecating EMECoefficientMonitor.

Key Changes:

  • Added EMEInterfaceSMatrixDataArray and EMEFluxDataArray data array classes
  • Created EMEInterfaceSMatrixDataset and EMEOverlapDataset to organize interface data
  • Extended EMECoefficientDataset with optional fields: n_complex, flux, interface_smatrices, overlaps
  • Implemented normalized_copy cached property for flux-normalized coefficients and S-matrices
  • Added store_coeffs boolean field to EMESimulation (defaults to True)
  • Deprecated EMECoefficientMonitor with appropriate warning message
  • Added coeffs field to EMESimulationData to store the coefficient dataset
  • Comprehensive test coverage for new functionality including normalization tests

The implementation follows established patterns in the codebase and provides useful debugging/optimization data to users without requiring explicit monitor configuration.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is clean, follows established patterns, has comprehensive test coverage, and properly handles backward compatibility through deprecation warnings. All previously reported issues have been addressed, and the changes are well-documented with appropriate type hints and docstrings.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
tidy3d/components/data/data_array.py 5/5 Added two new EME data array classes (EMEInterfaceSMatrixDataArray and EMEFluxDataArray) with proper dimensions and units. Clean implementation following existing patterns.
tidy3d/components/eme/data/dataset.py 4/5 Extended EMECoefficientDataset with new optional fields (interface S-matrices, overlaps, n_complex, flux) and added normalized_copy property for flux normalization. Implementation is solid with proper null checks.
tidy3d/components/eme/simulation.py 5/5 Added store_coeffs boolean field (defaults to True) and deprecation warning for EMECoefficientMonitor. Simple and appropriate changes.
tidy3d/components/eme/data/sim_data.py 5/5 Added optional coeffs field to store EMECoefficientDataset. Straightforward addition with proper typing and documentation.
tests/test_components/test_eme.py 5/5 Added comprehensive test coverage for new data arrays and datasets, including normalization tests. Tests follow existing patterns and verify the new functionality properly.

Sequence Diagram

sequenceDiagram
    participant User
    participant EMESimulation
    participant Solver as EME Solver
    participant EMESimulationData
    participant EMECoefficientDataset
    
    User->>EMESimulation: Create simulation with store_coeffs=True
    User->>EMESimulation: Run simulation
    EMESimulation->>Solver: Execute EME solver
    
    Note over Solver: Compute mode coefficients (A, B)
    Note over Solver: Compute interface S-matrices
    Note over Solver: Compute mode overlaps
    Note over Solver: Compute n_complex and flux
    
    Solver->>EMECoefficientDataset: Create dataset with all coefficients
    EMECoefficientDataset->>EMECoefficientDataset: Store A, B coefficients
    EMECoefficientDataset->>EMECoefficientDataset: Store interface_smatrices
    EMECoefficientDataset->>EMECoefficientDataset: Store overlaps
    EMECoefficientDataset->>EMECoefficientDataset: Store n_complex, flux
    
    Solver->>EMESimulationData: Create simulation data
    EMESimulationData->>EMESimulationData: Store smatrix
    EMESimulationData->>EMESimulationData: Store coeffs (if store_coeffs=True)
    EMESimulationData->>EMESimulationData: Store port_modes
    EMESimulationData->>EMESimulationData: Store monitor data
    
    EMESimulationData-->>User: Return results
    
    alt User wants normalized coefficients
        User->>EMECoefficientDataset: Access normalized_copy property
        EMECoefficientDataset->>EMECoefficientDataset: Normalize A, B by sqrt(flux)
        EMECoefficientDataset->>EMECoefficientDataset: Normalize S12, S21 by sqrt(flux ratio)
        EMECoefficientDataset->>EMECoefficientDataset: Set flux=None to prevent double normalization
        EMECoefficientDataset-->>User: Return normalized dataset
    end
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.

7 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

Diff Coverage

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

  • tidy3d/components/data/data_array.py (100%)
  • tidy3d/components/eme/data/dataset.py (100%)
  • tidy3d/components/eme/data/sim_data.py (100%)
  • tidy3d/components/eme/simulation.py (100%)

Summary

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

@caseyflex
Copy link
Contributor Author

@greptile

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.

8 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@caseyflex caseyflex force-pushed the casey/emelocaldata branch 3 times, most recently from d4e40a8 to 54f45d3 Compare December 2, 2025 23:15
@caseyflex
Copy link
Contributor Author

@greptile

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.

9 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@caseyflex
Copy link
Contributor Author

@greptile

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.

9 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

@caseyflex
Copy link
Contributor Author

@greptile

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.

9 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

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.

Nice!

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 looks good! Just some questions on compatibility.

@caseyflex caseyflex force-pushed the casey/emelocaldata branch 2 times, most recently from bbdef0b to d0f925f Compare December 9, 2025 20:59
@caseyflex
Copy link
Contributor Author

@greptile

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.

9 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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