Skip to content

Conversation

daquinteroflex
Copy link
Collaborator

@daquinteroflex daquinteroflex commented Aug 22, 2025

Greptile Summary

This PR propagates autograd component modeler (CM) changes across the Tidy3D repository by updating submodules, refactoring code organization, and integrating autograd web API support. The key changes include:

  1. Submodule Updates: Updates Git submodules for docs/notebooks and docs/faq to synchronize documentation with the latest autograd CM functionality
  2. Code Reorganization: Moves simulation execution functions (_run_component_modeler and _compose_modeler_data_from_sim_map) from base.py to run.py to separate concerns and avoid circular imports
  3. Autograd Integration: Adds support for autograd-enabled component modeler execution through the web API with new functions that handle simulation data mapping and autograd workflow
  4. Test Updates: Refactors test imports from ComponentModeler to ModalComponentModelerData to align with the new architecture that separates modeler configuration from data/results classes
  5. API Enhancements: Renames functions for better clarity (compose_simulation_data_index to compose_simulation_data_map) and improves error messages

The changes maintain backward compatibility while enabling component modelers to leverage the autograd web API execution path. This is part of a broader architectural shift to separate component modeler configuration from data handling, improving code organization and supporting advanced optimization workflows through autograd.

Important Files Changed

File Changes Summary
Filename Score Overview
docs/notebooks 5/5 Standard submodule update to synchronize notebooks with latest autograd CM changes
docs/faq 4/5 Submodule reference update that results in empty FAQ documentation directory
tidy3d/plugins/smatrix/component_modelers/base.py 4/5 Refactors code by moving simulation functions to run.py and updates type annotations
tests/test_plugins/smatrix/test_component_modeler_autograd.py 4/5 Updates test imports from ComponentModeler to ModalComponentModelerData for new architecture
tidy3d/plugins/smatrix/run.py 4/5 Adds autograd web API integration and new functions for component modeler execution

Confidence score: 4/5

  • This PR is generally safe to merge with some areas requiring attention
  • Score reflects solid refactoring with proper separation of concerns, but potential risks from circular imports and type safety changes
  • Pay close attention to the base.py refactoring and ensure the empty FAQ submodule state is intentional

Sequence Diagram

sequenceDiagram
    participant User
    participant "Component Modeler" as CM
    participant "web.run" as WebRun
    participant "Autograd Engine" as AG
    participant "Batch Runner" as BR
    participant "Emulator/Solver" as Solver

    User->>CM: "build_modal_modeler(scale)"
    CM->>CM: "Create simulation with ports"
    User->>WebRun: "web.run(modeler, local_gradient=True)"
    WebRun->>AG: "_run_async with autograd support"
    AG->>CM: "Generate simulation dictionary"
    CM->>CM: "Create simulations for each port"
    AG->>BR: "Submit batch simulations"
    BR->>Solver: "Run simulations (forward + adjoint)"
    Solver->>BR: "Return simulation data"
    BR->>AG: "Compose simulation data map"
    AG->>CM: "_compose_modeler_data_from_sim_map"
    CM->>CM: "Create ComponentModelerData"
    WebRun->>User: "Return modeler_data with S-matrix"
    User->>User: "Extract S-matrix values for objective"
    User->>AG: "ag.grad(objective)(scale)"
    AG->>AG: "Compute gradients via backpropagation"
    AG->>User: "Return gradient value"
Loading

@daquinteroflex daquinteroflex marked this pull request as ready for review August 22, 2025 14:54
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, 2 comments

Edit Code Review Bot Settings | Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Collaborator

@tylerflex tylerflex left a comment

Choose a reason for hiding this comment

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

Looks good 👍

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.

Minor nit otherwise looks good

@daquinteroflex
Copy link
Collaborator Author

Going to merge and test all runs from your branch

@daquinteroflex daquinteroflex merged commit bd88ce0 into yaugenst-flex/autograd-web-cm Aug 26, 2025
6 checks passed
@daquinteroflex daquinteroflex deleted the dario/autograd-web-cm branch August 26, 2025 09:40
daquinteroflex added a commit that referenced this pull request Aug 26, 2025
* Update to new data name

* Remove polluting scope

* no issue mixing import scope on run.py

* Update tidy3d/plugins/smatrix/component_modelers/base.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* Readd PayType to run.py

* Correct fix

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
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.

3 participants