-
Notifications
You must be signed in to change notification settings - Fork 65
Refactor default path handling to use task-type configuration with optional path parameter and optimized API calls #2993
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: momchil/rf_refactor
Are you sure you want to change the base?
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.
@copilot I'm not too happy with silently overwriting the default "simulation_data.hdf5", maybe the user wanted that. I feel like the path should just be optional (there may be many methods where it's currently set to simulation_data.hdf5 though, explore all that will need to change) and if not provided then we use the default mapping.
tidy3d/web/api/webapi.py
Outdated
|
|
||
| # If user provided a custom path (not the generic default), respect it | ||
| if path.name not in {"simulation_data.hdf5", "simulation_data.hdf5.gz"}: | ||
| return path |
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.
@copilot I'm not too happy with silently overwriting the default "simulation_data.hdf5", maybe the user wanted that. I feel like the path should just be optional (there may be many methods where it's currently set to simulation_data.hdf5 though, explore all that will need to change) and if not provided then we use the default mapping.
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.
Changed the approach: path parameter is now Optional[PathLike] = None instead of having a default value. When path=None (not provided), the task-type-specific default is used. When a path is explicitly provided (including "simulation_data.hdf5"), it's respected exactly without any silent overwriting. (commit 8e2b3b7)
Changed the approach: |
|
What do you think @daquintero @yaugenst ? I didn't like that in the previous CM integration introduced by Dario, the |
4bed382 to
0fee7a6
Compare
0fee7a6 to
23364ac
Compare
8e2b3b7 to
c844375
Compare
|
@marcorudolphflex i think this affects local cache right? could you take a look |
tidy3d/web/api/webapi.py
Outdated
| """ | ||
| path = Path(path) | ||
| # Get the appropriate default path based on task type | ||
| path = _get_default_path(task_id, path) |
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.
Whenever path=None, this calls get_info(), which will do an API call, and then we call get_info() below again. Same thing in load(). I guess _get_default_path could return some structured data so we don't have to call the API again? Otherwise we've just doubled latency.
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.
Fixed by refactoring _get_default_path() to return a tuple with path, batch status, and task type. Now when path=None, we make only 1 API call instead of 2-3. The returned info is reused in download() and load() to avoid redundant get_info() calls. (commit dc5ddf9)
tidy3d/web/api/webapi.py
Outdated
| # Get the appropriate default path based on task type | ||
| path = _get_default_path(task_id, path) | ||
|
|
||
| if _is_modeler_batch(task_id): |
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.
Similar here, the _is_modeler_batch should be redundant at this point.
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.
Fixed. The _is_modeler_batch() check is now done once in _get_default_path() and the result is returned and reused, eliminating the redundant call. (commit dc5ddf9)
Yup. If a simulation is loaded from the cache with Good news: We currently store the original task_id (from the cached run), get this Cheaper alternative: we could store the task type in the cache entry and provide it to |
|
@copilot Check |
This didn't seem to take effect, but I was anyway planning to ask copilot to do this locally.
I feel like the second option is better? |
Co-authored-by: momchil-flex <92756559+momchil-flex@users.noreply.github.com>
Changed |
c45cf5f to
98014ee
Compare
Addresses feedback to extract hardcoded default filename logic into a task-type-specific configuration pattern, with path parameter now optional to respect user-provided values. Also optimizes to eliminate redundant API calls.
Changes
Added
DEFAULT_DATA_FILENAMEdictionary: Maps task types to their default data filenames ("simulation_data.hdf5"for FDTD/MODE_SOLVER/etc.,"cm_data.hdf5"for RF/COMPONENT_MODELER)Created
_get_default_path()helper: Determines appropriate filename based on task type. When path isNone, uses task-type-specific default. When path is provided, respects it exactly without overwriting. Returns a tuple(Path, bool, Optional[str])containing path, batch status, and task type to avoid redundant API calls.Made path parameter optional: Changed
path: PathLike = "simulation_data.hdf5"topath: Optional[PathLike] = Noneindownload(),load(),run(),Job.download(), andJob.load()functionsOptimized API calls: Refactored
download()andload()to reuse task information from_get_default_path(), eliminating redundantget_info()and_is_modeler_batch()calls. Reduces API calls from 2-3 to 1 whenpath=None(50-67% latency reduction).Refactored logic: Replaced hardcoded conditional logic with centralized helper function
Behavior
Before:
After:
Benefits
DEFAULT_DATA_FILENAMEPerformance Impact
download()/load()operationdownload()/load()operation✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.