Skip to content

Commit 8e2b3b7

Browse files
Copilotmomchil-flex
andcommitted
Make path parameter optional instead of defaulting to simulation_data.hdf5
Co-authored-by: momchil-flex <92756559+momchil-flex@users.noreply.github.com>
1 parent afba5a7 commit 8e2b3b7

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

tidy3d/web/api/webapi.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,29 @@
8383
}
8484

8585

86-
def _get_default_path(task_id: str, provided_path: PathLike) -> Path:
86+
def _get_default_path(task_id: str, provided_path: Optional[PathLike]) -> Path:
8787
"""Get the appropriate default path based on task type.
8888
89-
If the user provided a non-default path, returns it as-is.
90-
Otherwise, returns the task-type-specific default filename.
89+
If the user provided a path, returns it as-is.
90+
If no path is provided (None), returns the task-type-specific default filename.
9191
9292
Parameters
9393
----------
9494
task_id : str
9595
Unique identifier of task on server.
96-
provided_path : PathLike
97-
Path provided by the user.
96+
provided_path : Optional[PathLike]
97+
Path provided by the user, or None to use task-type default.
9898
9999
Returns
100100
-------
101101
Path
102102
The appropriate path to use for this task type.
103103
"""
104-
path = Path(provided_path)
104+
# If user provided a path, respect it exactly
105+
if provided_path is not None:
106+
return Path(provided_path)
105107

106-
# If user provided a custom path (not the generic default), respect it
107-
if path.name not in {"simulation_data.hdf5", "simulation_data.hdf5.gz"}:
108-
return path
109-
110-
# Determine task type
108+
# Determine task type for default filename
111109
if _is_modeler_batch(task_id):
112110
task_type = "RF"
113111
else:
@@ -117,11 +115,7 @@ def _get_default_path(task_id: str, provided_path: PathLike) -> Path:
117115
# Get the task-type-specific default filename
118116
default_filename = DEFAULT_DATA_FILENAME.get(task_type, "simulation_data.hdf5")
119117

120-
# Preserve .gz extension if present
121-
if path.name.endswith(".gz") and not default_filename.endswith(".gz"):
122-
default_filename += ".gz"
123-
124-
return path.with_name(default_filename)
118+
return Path(default_filename)
125119

126120

127121
def _get_url(task_id: str) -> str:
@@ -338,7 +332,7 @@ def run(
338332
simulation: WorkflowType,
339333
task_name: Optional[str] = None,
340334
folder_name: str = "default",
341-
path: PathLike = "simulation_data.hdf5",
335+
path: Optional[PathLike] = None,
342336
callback_url: Optional[str] = None,
343337
verbose: bool = True,
344338
progress_callback_upload: Optional[Callable[[float], None]] = None,
@@ -364,8 +358,9 @@ def run(
364358
Name of task. If not provided, a default name will be generated.
365359
folder_name : str = "default"
366360
Name of folder to store task on web UI.
367-
path : PathLike = "simulation_data.hdf5"
361+
path : Optional[PathLike] = None
368362
Path to download results file (.hdf5), including filename.
363+
If not provided, uses a task-type-specific default filename.
369364
callback_url : str = None
370365
Http PUT url to receive simulation finish event. The body content is a json file with
371366
fields ``{'id', 'status', 'name', 'workUnit', 'solverVersion'}``.
@@ -390,7 +385,7 @@ def run(
390385
It affects only simulations from vGPU licenses and does not impact simulations using FlexCredits.
391386
lazy : bool = False
392387
Whether to load the actual data (``lazy=False``) or return a proxy that loads
393-
the data when accessed (``lazy=True``).
388+
the data when accessed (``lazy=True`).
394389
395390
Returns
396391
-------
@@ -1055,7 +1050,7 @@ def abort(task_id: TaskId) -> Optional[TaskInfo]:
10551050
@wait_for_connection
10561051
def download(
10571052
task_id: TaskId,
1058-
path: PathLike = "simulation_data.hdf5",
1053+
path: Optional[PathLike] = None,
10591054
verbose: bool = True,
10601055
progress_callback: Optional[Callable[[float], None]] = None,
10611056
) -> None:
@@ -1065,8 +1060,9 @@ def download(
10651060
----------
10661061
task_id : str
10671062
Unique identifier of task on server. Returned by :meth:`upload`.
1068-
path : PathLike = "simulation_data.hdf5"
1063+
path : Optional[PathLike] = None
10691064
Download path to .hdf5 data file (including filename).
1065+
If not provided, uses a task-type-specific default filename.
10701066
verbose : bool = True
10711067
If ``True``, will print progressbars and status, otherwise, will run silently.
10721068
progress_callback : Callable[[float], None] = None
@@ -1189,7 +1185,7 @@ def download_log(
11891185
@wait_for_connection
11901186
def load(
11911187
task_id: Optional[TaskId],
1192-
path: PathLike = "simulation_data.hdf5",
1188+
path: Optional[PathLike] = None,
11931189
replace_existing: bool = True,
11941190
verbose: bool = True,
11951191
progress_callback: Optional[Callable[[float], None]] = None,
@@ -1215,8 +1211,10 @@ def load(
12151211
----------
12161212
task_id : Optional[str] = None
12171213
Unique identifier of task on server. Returned by :meth:`upload`. If None, file is assumed to exist already from cache.
1218-
path : PathLike
1214+
path : Optional[PathLike] = None
12191215
Download path to .hdf5 data file (including filename).
1216+
If not provided and task_id is given, uses a task-type-specific default filename.
1217+
If not provided and task_id is None, defaults to "simulation_data.hdf5".
12201218
replace_existing : bool = True
12211219
Downloads the data even if path exists (overwriting the existing).
12221220
verbose : bool = True
@@ -1236,7 +1234,8 @@ def load(
12361234
if task_id is not None:
12371235
path = _get_default_path(task_id, path)
12381236
else:
1239-
path = Path(path)
1237+
# When no task_id, use provided path or fall back to generic default
1238+
path = Path(path) if path is not None else Path("simulation_data.hdf5")
12401239

12411240
if task_id is None:
12421241
if not path.exists():

0 commit comments

Comments
 (0)