Skip to content

Commit c844375

Browse files
Copilotmomchil-flex
authored andcommitted
Initial plan
1 parent 23364ac commit c844375

File tree

1 file changed

+68
-22
lines changed

1 file changed

+68
-22
lines changed

tidy3d/web/api/webapi.py

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,55 @@
6868
"VOLUME_MESH": "VolumeMesher",
6969
}
7070

71+
# map task_type to default data filename
72+
DEFAULT_DATA_FILENAME = {
73+
"FDTD": "simulation_data.hdf5",
74+
"MODE_SOLVER": "simulation_data.hdf5",
75+
"MODE": "simulation_data.hdf5",
76+
"EME": "simulation_data.hdf5",
77+
"HEAT": "simulation_data.hdf5",
78+
"HEAT_CHARGE": "simulation_data.hdf5",
79+
"VOLUME_MESH": "simulation_data.hdf5",
80+
"COMPONENT_MODELER": "cm_data.hdf5",
81+
"TERMINAL_COMPONENT_MODELER": "cm_data.hdf5",
82+
"RF": "cm_data.hdf5",
83+
}
84+
85+
86+
def _get_default_path(task_id: str, provided_path: Optional[PathLike]) -> Path:
87+
"""Get the appropriate default path based on task type.
88+
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.
91+
92+
Parameters
93+
----------
94+
task_id : str
95+
Unique identifier of task on server.
96+
provided_path : Optional[PathLike]
97+
Path provided by the user, or None to use task-type default.
98+
99+
Returns
100+
-------
101+
Path
102+
The appropriate path to use for this task type.
103+
"""
104+
# If user provided a path, respect it exactly
105+
if provided_path is not None:
106+
return Path(provided_path)
107+
108+
# Determine task type for default filename
109+
if _is_modeler_batch(task_id):
110+
task_type = "RF"
111+
else:
112+
task_info = get_info(task_id)
113+
task_type = task_info.taskType
114+
115+
# Get the task-type-specific default filename
116+
default_filename = DEFAULT_DATA_FILENAME.get(task_type, "simulation_data.hdf5")
117+
118+
return Path(default_filename)
119+
71120

72121
def _get_url(task_id: str) -> str:
73122
"""Get the URL for a task on our server."""
@@ -279,7 +328,7 @@ def run(
279328
simulation: WorkflowType,
280329
task_name: Optional[str] = None,
281330
folder_name: str = "default",
282-
path: PathLike = "simulation_data.hdf5",
331+
path: Optional[PathLike] = None,
283332
callback_url: Optional[str] = None,
284333
verbose: bool = True,
285334
progress_callback_upload: Optional[Callable[[float], None]] = None,
@@ -305,8 +354,9 @@ def run(
305354
Name of task. If not provided, a default name will be generated.
306355
folder_name : str = "default"
307356
Name of folder to store task on web UI.
308-
path : PathLike = "simulation_data.hdf5"
357+
path : Optional[PathLike] = None
309358
Path to download results file (.hdf5), including filename.
359+
If not provided, uses a task-type-specific default filename.
310360
callback_url : str = None
311361
Http PUT url to receive simulation finish event. The body content is a json file with
312362
fields ``{'id', 'status', 'name', 'workUnit', 'solverVersion'}``.
@@ -331,7 +381,7 @@ def run(
331381
It affects only simulations from vGPU licenses and does not impact simulations using FlexCredits.
332382
lazy : bool = False
333383
Whether to load the actual data (``lazy=False``) or return a proxy that loads
334-
the data when accessed (``lazy=True``).
384+
the data when accessed (``lazy=True`).
335385
336386
Returns
337387
-------
@@ -996,7 +1046,7 @@ def abort(task_id: TaskId) -> Optional[TaskInfo]:
9961046
@wait_for_connection
9971047
def download(
9981048
task_id: TaskId,
999-
path: PathLike = "simulation_data.hdf5",
1049+
path: Optional[PathLike] = None,
10001050
verbose: bool = True,
10011051
progress_callback: Optional[Callable[[float], None]] = None,
10021052
) -> None:
@@ -1006,23 +1056,19 @@ def download(
10061056
----------
10071057
task_id : str
10081058
Unique identifier of task on server. Returned by :meth:`upload`.
1009-
path : PathLike = "simulation_data.hdf5"
1059+
path : Optional[PathLike] = None
10101060
Download path to .hdf5 data file (including filename).
1061+
If not provided, uses a task-type-specific default filename.
10111062
verbose : bool = True
10121063
If ``True``, will print progressbars and status, otherwise, will run silently.
10131064
progress_callback : Callable[[float], None] = None
10141065
Optional callback function called when downloading file with ``bytes_in_chunk`` as argument.
10151066
10161067
"""
1017-
path = Path(path)
1068+
# Get the appropriate default path based on task type
1069+
path = _get_default_path(task_id, path)
10181070

10191071
if _is_modeler_batch(task_id):
1020-
# Use a more descriptive default filename for component modeler downloads.
1021-
# If the caller left the default as 'simulation_data.hdf5', prefer 'cm_data.hdf5'.
1022-
# TODO: seems like the default should then be maybe set to None and defined somewhere else
1023-
# per task type?
1024-
if path.name == "simulation_data.hdf5":
1025-
path = path.with_name("cm_data.hdf5")
10261072
BatchTask(task_id).get_data_hdf5(
10271073
remote_data_file_gz=CM_DATA_HDF5_GZ,
10281074
to_file=path,
@@ -1135,7 +1181,7 @@ def download_log(
11351181
@wait_for_connection
11361182
def load(
11371183
task_id: Optional[TaskId],
1138-
path: PathLike = "simulation_data.hdf5",
1184+
path: Optional[PathLike] = None,
11391185
replace_existing: bool = True,
11401186
verbose: bool = True,
11411187
progress_callback: Optional[Callable[[float], None]] = None,
@@ -1161,8 +1207,10 @@ def load(
11611207
----------
11621208
task_id : Optional[str] = None
11631209
Unique identifier of task on server. Returned by :meth:`upload`. If None, file is assumed to exist already from cache.
1164-
path : PathLike
1210+
path : Optional[PathLike] = None
11651211
Download path to .hdf5 data file (including filename).
1212+
If not provided and task_id is given, uses a task-type-specific default filename.
1213+
If not provided and task_id is None, defaults to "simulation_data.hdf5".
11661214
replace_existing : bool = True
11671215
Downloads the data even if path exists (overwriting the existing).
11681216
verbose : bool = True
@@ -1178,14 +1226,12 @@ def load(
11781226
Union[:class:`.SimulationData`, :class:`.HeatSimulationData`, :class:`.EMESimulationData`]
11791227
Object containing simulation data.
11801228
"""
1181-
path = Path(path)
1182-
# For component modeler batches, default to a clearer filename if the default was used.
1183-
if (
1184-
task_id
1185-
and _is_modeler_batch(task_id)
1186-
and path.name in {"simulation_data.hdf5", "simulation_data.hdf5.gz"}
1187-
):
1188-
path = path.with_name(path.name.replace("simulation", "cm"))
1229+
# Get the appropriate default path based on task type
1230+
if task_id is not None:
1231+
path = _get_default_path(task_id, path)
1232+
else:
1233+
# When no task_id, use provided path or fall back to generic default
1234+
path = Path(path) if path is not None else Path("simulation_data.hdf5")
11891235

11901236
if task_id is None:
11911237
if not path.exists():

0 commit comments

Comments
 (0)