-
Notifications
You must be signed in to change notification settings - Fork 67
Set default path names #3079
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?
Set default path names #3079
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.
5 files reviewed, 1 comment
| resolved_path, is_batch, task_type = _get_default_path(task_id, path) | ||
| task = TaskFactory.get(task_id, verbose=False) |
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.
logic: redundant TaskFactory.get() call defeats optimization purpose - _get_default_path() already fetches task at line 107, should return and reuse it
| resolved_path, is_batch, task_type = _get_default_path(task_id, path) | |
| task = TaskFactory.get(task_id, verbose=False) | |
| resolved_path, is_batch, task_type, task = _get_default_path(task_id, path) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: tidy3d/web/api/webapi.py
Line: 1045:1046
Comment:
**logic:** redundant `TaskFactory.get()` call defeats optimization purpose - `_get_default_path()` already fetches task at line 107, should return and reuse it
```suggestion
resolved_path, is_batch, task_type, task = _get_default_path(task_id, path)
```
How can I resolve this? If you propose a fix, please make it concise.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.
Pull request overview
This pull request introduces default path names for different task types, eliminating the need for users to specify the path parameter when downloading simulation results. The default filename is automatically determined based on the task type (e.g., simulation_data.hdf5 for FDTD simulations, cm_data.hdf5 for component modeler tasks).
Key changes:
- Added task-type-specific default filenames that are automatically selected when
path=None - Modified API signatures to make
pathparameter optional inrun(),download(),load(), and related methods - Introduced helper functions to determine the appropriate default filename based on task type
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tidy3d/web/api/webapi.py | Added DEFAULT_DATA_FILENAME mapping and default_data_filename() function; introduced _get_default_path() helper; updated run(), download(), load(), and restore_simulation_if_cached() to support optional path parameter with type-specific defaults |
| tidy3d/web/api/container.py | Added _task_type_hint() and _resolve_output_path() helper methods to Job class; updated run(), download(), and load() methods to handle optional path parameter; added _cached_task_type attribute for tracking task types from cache |
| tidy3d/web/api/autograd/engine.py | Updated _run_tidy3d() to use default path resolution when path is not provided |
| tidy3d/web/api/autograd/autograd.py | Updated run() function to resolve default paths based on simulation stub type |
| docs/api/microwave/component_modeler.rst | Added documentation noting that component modeler results default to cm_data.hdf5 when path is omitted |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| resolved_path, is_batch, task_type = _get_default_path(task_id, path) | ||
| task = TaskFactory.get(task_id, verbose=False) |
Copilot
AI
Dec 11, 2025
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.
The task is fetched twice: once inside _get_default_path at line 107 and again here at line 1046. This is inefficient as it makes two network calls to retrieve the same task information. Consider modifying _get_default_path to return the task object as well, or refactor to avoid the duplicate fetch.
|
|
||
| if provided_path is not None: | ||
| path = Path(provided_path) | ||
| return path, is_batch, None |
Copilot
AI
Dec 11, 2025
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.
When provided_path is not None, the function returns task_type=None (line 115). However, this means callers like download() will need to fetch the task type again (lines 1057-1059). Consider always fetching the task type regardless of whether a path is provided, to avoid the extra get_info call in the download function.
| return path, is_batch, None | |
| if is_batch: | |
| task_type = "RF" | |
| else: | |
| task_info = get_info(task_id, verbose=False) | |
| task_type = getattr(task_info, "taskType", None) | |
| return path, is_batch, task_type |
|
|
||
| try: | ||
| return Tidy3dStub(simulation=self.simulation).get_type() | ||
| except Exception: |
Copilot
AI
Dec 11, 2025
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.
The exception handler catches all exceptions and returns None, which may hide legitimate errors like import errors or attribute errors. Consider catching only the specific exception that indicates the task type cannot be determined (e.g., TypeError, AttributeError) to avoid masking unexpected errors.
| except Exception: | |
| except (AttributeError, TypeError): |
| is_batch = False | ||
| task_type = None | ||
|
|
Copilot
AI
Dec 11, 2025
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.
Variable is_batch is not used.
| is_batch = False | |
| task_type = None |
| task_type = None | ||
|
|
Copilot
AI
Dec 11, 2025
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.
Variable task_type is not used.
| task_type = None |
Replaces #2993
@yaugenst @marcorudolphflex @daquintero probably too ambitious to aim for 2.10. :D
Greptile Overview
Greptile Summary
Refactors path handling to use task-type-specific defaults when path is omitted, replacing hardcoded logic with centralized
DEFAULT_DATA_FILENAMEconfiguration. Key changes include making the path parameter optional inrun(),download(), andload()functions, with defaults ofsimulation_data.hdf5for FDTD/MODE/EME/HEAT tasks andcm_data.hdf5for component modeler tasks.Major improvements:
DEFAULT_DATA_FILENAMEdictionary mapping_get_default_path()helper function to centralize path resolution logicJobclass methods and autograd integration to support optional pathsIssues found:
download()function defeats the optimization purpose -_get_default_path()fetches the task butdownload()fetches it again immediately afterConfidence Score: 3/5
TaskFactory.get()call indownload()defeats the stated 50-67% API latency optimization goal. The logic is sound and backwards-compatible, but this performance regression needs addressing.tidy3d/web/api/webapi.py- the redundant API call in thedownload()function needs to be fixed to achieve the promised performance improvementsImportant Files Changed
File Analysis
DEFAULT_DATA_FILENAMEmapping and helper functions; refactoreddownload(),load(), andrun()to use optional path with task-type defaults. Contains redundant API call indownload()function.Jobclass methods (run(),download(),load()) to support optional path parameter; added_task_type_hint()and_resolve_output_path()helper methods. Clean implementation with proper caching support.Sequence Diagram
sequenceDiagram participant User participant API as web.download()/load() participant Helper as _get_default_path() participant TaskFactory participant Server as get_info() User->>API: download(task_id, path=None) API->>Helper: _get_default_path(task_id, None) Helper->>TaskFactory: get(task_id) TaskFactory-->>Helper: task object Helper->>Helper: Check if BatchTask alt is BatchTask Helper->>Helper: task_type = "RF" else not BatchTask Helper->>Server: get_info(task_id) Server-->>Helper: task_info Helper->>Helper: Extract taskType end Helper->>Helper: default_data_filename(task_type) Helper-->>API: (Path, is_batch, task_type) API->>TaskFactory: get(task_id) [REDUNDANT] TaskFactory-->>API: task object API->>API: Download data to resolved_path