- 
                Notifications
    
You must be signed in to change notification settings  - Fork 65
 
chore: Remove deprecated complex fields nonlinearity #2941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1d48843    to
    c487be8      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
20 files reviewed, 2 comments
c487be8    to
    4e0546b      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
20 files reviewed, no comments
          
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
 Summary
 tidy3d/components/medium.pyLines 630-638   630     @pd.validator("models", always=True)
  631     def _consistent_models(cls, val):
  632         """Ensure that parameters shared between models are consistent."""
  633         if val is None:
! 634             return val
  635         n0 = None
  636         for model in val:
  637             if isinstance(model, (KerrNonlinearity, TwoPhotonAbsorption)):
  638                 if model.n0 is not None: | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice cleanup. @yaugenst this is breaking compatibility of course but I suggested going through with it because we've had deprecation warnings for a while, and it's both not correct to use complex fields and making planned expansions harder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @caseyflex LGTM. Agree with @momchil-flex it's fine here especially since it has been deprecated for a while. My only minor nit is that it'd be better to be more specific about when something is going to be removed, but that's not for this PR to sort out 😬
4e0546b    to
    07e462f      
    Compare
  
    07e462f    to
    ec12186      
    Compare
  
    
This old implementation has been deprecated since v2.8. It is time to remove support for it.
Some other changes:
Greptile Overview
Updated On: 2025-10-29 19:37:06 UTC
Greptile Summary
This PR removes the deprecated
use_complex_fieldsparameter from nonlinear models (TwoPhotonAbsorptionandKerrNonlinearity), completing the transition to the real-field implementation introduced in Tidy3D v2.8. The changes simplify the codebase by:betaandn2fields fromComplextofloattypes (real-valued only)n0fromOptional[Complex]toOptional[float]_consistent_modelsvalidator to ensuren0is consistent across modelsThe implementation is clean and thorough, with consistent updates across code, schemas, and tests. One minor issue was found: an error message is missing the actual value of
n0in the interpolation.Confidence Score: 4/5
tidy3d/components/medium.py:640-642for the error message formatting fixImportant Files Changed
File Analysis
use_complex_fieldsfield and associated validation logic fromTwoPhotonAbsorptionandKerrNonlinearity. Simplified type signatures to use only real numbers. Found one error message formatting issue.use_complex_fields=True. Clean removal with no issues.use_complex_fieldsand changebetaandn2from complex to real number types.Sequence Diagram
sequenceDiagram participant User participant TwoPhotonAbsorption participant KerrNonlinearity participant NonlinearSpec participant Medium participant Simulation Note over TwoPhotonAbsorption,KerrNonlinearity: Removed use_complex_fields field Note over TwoPhotonAbsorption: beta: Complex → float Note over KerrNonlinearity: n2: Complex → float Note over TwoPhotonAbsorption: n0: Optional[Complex] → Optional[float] Note over KerrNonlinearity: n0: Optional[Complex] → Optional[float] User->>TwoPhotonAbsorption: Create with beta (real only) TwoPhotonAbsorption->>TwoPhotonAbsorption: Remove _validate_beta_real TwoPhotonAbsorption->>TwoPhotonAbsorption: Simplify _validate_medium TwoPhotonAbsorption-->>User: Instance created User->>KerrNonlinearity: Create with n2 (real only) KerrNonlinearity->>KerrNonlinearity: Remove _validate_n2_real KerrNonlinearity->>KerrNonlinearity: Remove _validate_medium_freqs KerrNonlinearity-->>User: Instance created User->>NonlinearSpec: Create with models NonlinearSpec->>NonlinearSpec: Remove _consistent_old_complex_fields NonlinearSpec->>NonlinearSpec: Add _consistent_models (validates n0) NonlinearSpec-->>User: Spec created User->>Medium: Create with nonlinear_spec Medium->>NonlinearSpec: Validate models Medium-->>User: Medium created User->>Simulation: Create with nonlinear medium Simulation->>Simulation: Remove use_complex_fields warning Simulation-->>User: Simulation ready