@@ -124,7 +124,7 @@ def _task_dict_to_url_bullet_list(data_dict: dict) -> str:
124124 return "\n " .join ([f"- { key } : '{ value } '" for key , value in data_dict .items ()])
125125
126126
127- def _get_simulation_data_from_cache_entry (entry : CacheEntry , path : str ) -> bool :
127+ def _copy_simulation_data_from_cache_entry (entry : CacheEntry , path : str ) -> bool :
128128 if entry is not None :
129129 try :
130130 entry .materialize (Path (path ))
@@ -137,18 +137,39 @@ def _get_simulation_data_from_cache_entry(entry: CacheEntry, path: str) -> bool:
137137def restore_simulation_if_cached (
138138 simulation : WorkflowType ,
139139 path : str ,
140- use_cache : Optional [bool ],
141- reduce_simulation : Literal ["auto" , True , False ],
140+ use_cache : Optional [bool ] = None ,
141+ reduce_simulation : Literal ["auto" , True , False ] = "auto" ,
142142) -> bool :
143143 simulation_cache = resolve_simulation_cache (use_cache )
144- loaded_from_cache = False
144+ copied_from_cache = False
145145 if simulation_cache is not None :
146146 sim_for_cache = simulation
147147 if isinstance (simulation , (ModeSolver , ModeSimulation )):
148148 sim_for_cache = get_reduced_simulation (simulation , reduce_simulation )
149149 entry = simulation_cache .try_fetch (simulation = sim_for_cache )
150- loaded_from_cache = _get_simulation_data_from_cache_entry (entry , path )
151- return loaded_from_cache
150+ if entry is not None :
151+ copied_from_cache = _copy_simulation_data_from_cache_entry (entry , path )
152+ return copied_from_cache
153+
154+
155+ def load_simulation_if_cached (
156+ simulation : WorkflowType ,
157+ path : str ,
158+ use_cache : Optional [bool ] = None ,
159+ reduce_simulation : Literal ["auto" , True , False ] = "auto" ,
160+ ) -> Optional [WorkflowDataType ]:
161+ restored = restore_simulation_if_cached (simulation , path , use_cache , reduce_simulation )
162+ if restored :
163+ data = load (
164+ task_id = None ,
165+ path = path ,
166+ from_cache = True ,
167+ )
168+ if isinstance (simulation , ModeSolver ):
169+ simulation ._patch_data (data = data )
170+ return data
171+ else :
172+ return None
152173
153174
154175@wait_for_connection
@@ -256,11 +277,11 @@ def run(
256277 :meth:`tidy3d.web.api.container.Batch.monitor`
257278 Monitor progress of each of the running tasks.
258279 """
259- loaded_from_cache = restore_simulation_if_cached (
280+ copied_from_cache = restore_simulation_if_cached (
260281 simulation = simulation , path = path , use_cache = use_cache , reduce_simulation = reduce_simulation
261282 )
262283
263- if not loaded_from_cache :
284+ if not copied_from_cache :
264285 task_id = upload (
265286 simulation = simulation ,
266287 task_name = task_name ,
@@ -291,7 +312,7 @@ def run(
291312 verbose = verbose ,
292313 progress_callback = progress_callback_download ,
293314 use_cache = use_cache ,
294- from_cache = loaded_from_cache ,
315+ from_cache = copied_from_cache ,
295316 lazy = lazy ,
296317 )
297318
0 commit comments