-
Notifications
You must be signed in to change notification settings - Fork 66
FXC-3004-container-aware-web-run-returning-lazy-results #2880
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
base: develop
Are you sure you want to change the base?
FXC-3004-container-aware-web-run-returning-lazy-results #2880
Conversation
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.
10 files reviewed, 1 comment
c9a5088
to
5217204
Compare
5217204
to
145debb
Compare
Diff CoverageDiff: origin/develop...HEAD, staged and unstaged changes
Summary
tidy3d/web/api/run.pyLines 42-54 42 _collect_by_hash(v, found)
43 return found
44 if isinstance(node, dict):
45 if any(isinstance(k, WorkflowType) for k in node.keys()):
! 46 raise ValueError("Dict keys must not be simulations.")
47 for v in node.values():
48 _collect_by_hash(v, found)
49 return found
! 50 raise TypeError(f"Unsupported element in container: {type(node)!r}")
51
52
53 def _reconstruct_by_hash(node: RunInput, h2data: dict[str, WorkflowDataType]) -> RunOutput:
54 """Replaces each leaf node (simulation) with its corresponding data object. Lines 72-80 72 if isinstance(n, list):
73 return [_recur(v) for v in n]
74 if isinstance(n, dict):
75 return {k: _recur(v) for k, v in n.items()}
! 76 raise TypeError(f"Unsupported element in reconstruction: {type(n)!r}")
77
78 return _recur(node)
79 Lines 87-95 87 """
88 has_modeler = any(isinstance(sim, ComponentModelerType) for sim in simulations)
89
90 if has_modeler and len(simulations) > 1:
! 91 raise ValueError(
92 "web.run() does not support ComponentModelerTypes when submitting multiple simulations."
93 )
94 Lines 232-240 232 Underlying autograd batch submission implementation.
233 """
234 h2sim: dict[str, WorkflowType] = _collect_by_hash(simulation)
235 if not h2sim:
! 236 raise ValueError("No simulation data found in simulation input.")
237
238 _check_simulation_types(list(h2sim.values()))
239
240 key_prefix = "" |
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 @marcorudolphflex this is great! I left a couple of comments, nothing too major.
145debb
to
e03175a
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.
Additional Comments (1)
-
tidy3d/plugins/smatrix/run.py
, line 160-181 (link)syntax: Docstring describes the old implementation and mentions returning
ComponentModelerDataType
but the function now returnstuple[SimulationMap, dict[str, Any]]
Context Used: Rule from
dashboard
- Keep docstrings and comments synchronized with code changes to ensure they are always accurate and n... (source)
12 files reviewed, 3 comments
7f259d2
to
853a2b0
Compare
853a2b0
to
337db93
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.
So it seems the main issue is maintaining compatibility of the old webapi.run functionality in the new run_async in autograd with the new workflow as they were not directly interchangeable before. Probably we can update some tests to catch this, but I am working on this in my PR
Hmm more things are going on
Goal
Extend web.run (and only the surfaces that already wrap it - autograd entry points, CLI helpers, Job/Batch, run_async) so the API accepts arbitrary Python containers and returns SimulationData lazily in the same structure, relying on the lazy-load.
Implementation
Open questions:
If same simulation is submitted multiple times, the sim_data objects of these simulations are the same - should we make copies?
Greptile Overview
Updated On: 2025-10-10 15:52:48 UTC
Greptile Summary
This PR implements a major enhancement to the
web.run()
API, making it container-aware so it can accept arbitrary Python containers (lists, tuples, dictionaries) containing simulation objects and return results in the same nested structure. The implementation introduces a unified interface that maintains backward compatibility while adding powerful batch processing capabilities.The core change is a new
tidy3d/web/api/run.py
module that serves as a container-aware wrapper. This wrapper intelligently delegates to the existing legacyrun
function for single simulations and torun_async
for multiple simulations. The implementation uses hash-based deduplication to avoid running identical simulations multiple times, optimizing performance when the same simulation appears in different parts of the input structure.A new
lazy
parameter has been added throughout the web API stack, allowing users to control whether simulation data is loaded immediately (eager) or deferred until first access (lazy). The lazy loading behavior defaults toFalse
for single simulations (maintaining existing behavior) andTrue
for batch runs (more efficient for large operations).The changes extend across multiple layers including the main web interface, autograd entry points, container classes (Job, Batch, BatchData), and asynchronous operations. Path parameter interpretation has also been enhanced to treat paths as directories for multiple runs and filenames for single runs, providing intuitive behavior based on input type.
Important Files Changed
Changed Files
tidy3d/web/api/run.py
tidy3d/web/api/container.py
tests/test_web/test_webapi.py
tidy3d/web/api/webapi.py
tidy3d/web/api/asynchronous.py
tidy3d/web/api/autograd/autograd.py
tidy3d/web/api/autograd/engine.py
tidy3d/web/__init__.py
tests/test_web/test_webapi_mode.py
CHANGELOG.md
tidy3d/plugins/smatrix/run.py
tidy3d/packaging.py
Confidence score: 3/5
tidy3d/web/api/run.py
which contains debugging print statements that violate coding standardsSequence Diagram
Context used:
dashboard
- Remove temporary debugging code (print() calls), commented-out code, and other workarounds before fi... (source)