34
34
class WebContainer (Tidy3dBaseModel , ABC ):
35
35
"""Base class for :class:`Job` and :class:`Batch`, technically not used"""
36
36
37
+ from abc import abstractmethod
38
+
37
39
@staticmethod
38
- def _check_path_dir (path_dir : str ) -> None :
39
- """Make sure ``path_dir`` exists and create one if not."""
40
- location = os .path .dirname (path_dir )
41
- if len (location ) > 0 and not os .path .exists (location ):
42
- os .makedirs (location , exist_ok = True )
40
+ @abstractmethod
41
+ def _check_path_dir (path : str ) -> None :
42
+ """Make sure local output directory exists and create it if not."""
43
+ pass
43
44
44
45
@staticmethod
45
46
def _check_folder (folder_name : str ) -> None :
@@ -205,7 +206,6 @@ def to_file(self, fname: str) -> None:
205
206
-------
206
207
>>> simulation.to_file(fname='folder/sim.json') # doctest: +SKIP
207
208
"""
208
-
209
209
task_id_cached = self ._cached_properties .get ("task_id" )
210
210
self = self .updated_copy (task_id_cached = task_id_cached )
211
211
super (Job , self ).to_file (fname = fname ) # noqa: UP008
@@ -223,7 +223,6 @@ def run(self, path: str = DEFAULT_DATA_PATH) -> SimulationDataType:
223
223
Union[:class:`.SimulationData`, :class:`.HeatSimulationData`, :class:`.EMESimulationData`]
224
224
Object containing simulation results.
225
225
"""
226
-
227
226
self .upload ()
228
227
self .start ()
229
228
self .monitor ()
@@ -305,7 +304,7 @@ def download(self, path: str = DEFAULT_DATA_PATH) -> None:
305
304
----
306
305
To load the data after download, use :meth:`Job.load`.
307
306
"""
308
- self ._check_path_dir (path_dir = path )
307
+ self ._check_path_dir (path = path )
309
308
web .download (task_id = self .task_id , path = path , verbose = self .verbose )
310
309
311
310
def load (self , path : str = DEFAULT_DATA_PATH ) -> SimulationDataType :
@@ -321,7 +320,7 @@ def load(self, path: str = DEFAULT_DATA_PATH) -> SimulationDataType:
321
320
Union[:class:`.SimulationData`, :class:`.HeatSimulationData`, :class:`.EMESimulationData`]
322
321
Object containing simulation results.
323
322
"""
324
- self ._check_path_dir (path_dir = path )
323
+ self ._check_path_dir (path = path )
325
324
data = web .load (task_id = self .task_id , path = path , verbose = self .verbose )
326
325
if isinstance (self .simulation , ModeSolver ):
327
326
self .simulation ._patch_data (data = data )
@@ -366,6 +365,19 @@ def estimate_cost(self, verbose: bool = True) -> float:
366
365
"""
367
366
return web .estimate_cost (self .task_id , verbose = verbose , solver_version = self .solver_version )
368
367
368
+ @staticmethod
369
+ def _check_path_dir (path : str ) -> None :
370
+ """Make sure parent directory of ``path`` exists and create it if not.
371
+
372
+ Parameters
373
+ ----------
374
+ path : str
375
+ Path to file to be created (including filename).
376
+ """
377
+ parent_dir = os .path .dirname (path )
378
+ if len (parent_dir ) > 0 and not os .path .exists (parent_dir ):
379
+ os .makedirs (parent_dir , exist_ok = True )
380
+
369
381
370
382
class BatchData (Tidy3dBaseModel , Mapping ):
371
383
"""
@@ -1030,3 +1042,15 @@ def estimate_cost(self, verbose: bool = True) -> float:
1030
1042
console .log ("Could not get estimated batch cost!" )
1031
1043
1032
1044
return batch_cost
1045
+
1046
+ @staticmethod
1047
+ def _check_path_dir (path_dir : str ) -> None :
1048
+ """Make sure ``path_dir`` exists and create it if not.
1049
+
1050
+ Parameters
1051
+ ----------
1052
+ path_dir : str
1053
+ Directory path where files will be saved.
1054
+ """
1055
+ if len (path_dir ) > 0 and not os .path .exists (path_dir ):
1056
+ os .makedirs (path_dir , exist_ok = True )
0 commit comments