3
3
from __future__ import annotations
4
4
5
5
import os
6
+ import typing
6
7
from abc import ABC , abstractmethod
7
8
from typing import Optional , Union , get_args
8
9
22
23
from tidy3d .plugins .smatrix .ports .modal import Port
23
24
from tidy3d .plugins .smatrix .ports .rectangular_lumped import LumpedPort
24
25
from tidy3d .plugins .smatrix .ports .wave import WavePort
25
- from tidy3d .web .api .container import Batch , BatchData
26
26
27
27
# fwidth of gaussian pulse in units of central frequency
28
28
FWIDTH_FRAC = 1.0 / 10
35
35
class AbstractComponentModeler (ABC , Tidy3dBaseModel ):
36
36
"""Tool for modeling devices and computing port parameters."""
37
37
38
+ name : str = pd .Field (
39
+ "" ,
40
+ title = "Simulation" ,
41
+ description = "Simulation describing the device without any sources present." ,
42
+ )
38
43
simulation : Simulation = pd .Field (
39
44
...,
40
45
title = "Simulation" ,
@@ -99,7 +104,8 @@ class AbstractComponentModeler(ABC, Tidy3dBaseModel):
99
104
"If not supplied, uses default for the current front end version." ,
100
105
)
101
106
102
- batch_cached : Batch = pd .Field (
107
+ # TODO properly refactor, plugins should not have web methods.
108
+ batch_cached : typing .Any = pd .Field (
103
109
None ,
104
110
title = "Batch (Cached)" ,
105
111
description = "Optional field to specify ``batch``. Only used as a workaround internally "
@@ -176,8 +182,10 @@ def to_file(self, fname: str) -> None:
176
182
super (AbstractComponentModeler , self ).to_file (fname = fname ) # noqa: UP008
177
183
178
184
@cached_property
179
- def batch (self ) -> Batch :
185
+ def batch (self ):
180
186
""":class:`.Batch` associated with this component modeler."""
187
+ # TODO properly refactor, plugins data types should not have web methods.
188
+ from tidy3d .web .api .container import Batch
181
189
182
190
if self .batch_cached is not None :
183
191
return self .batch_cached
@@ -202,7 +210,7 @@ def batch_path(self) -> str:
202
210
return self .batch ._batch_path (path_dir = self .path_dir )
203
211
204
212
@cached_property
205
- def batch_data (self ) -> BatchData :
213
+ def batch_data (self ):
206
214
"""The :class:`.BatchData` associated with the simulations run for this component modeler."""
207
215
return self .batch .run (path_dir = self .path_dir )
208
216
@@ -224,7 +232,7 @@ def _batch_path(self) -> str:
224
232
"""Where we store the batch for this :class:`AbstractComponentModeler` instance after the run."""
225
233
return os .path .join (self .path_dir , "batch" + str (hash (self )) + ".hdf5" )
226
234
227
- def _run_sims (self , path_dir : str = DEFAULT_DATA_DIR ) -> BatchData :
235
+ def _run_sims (self , path_dir : str = DEFAULT_DATA_DIR ):
228
236
"""Run :class:`.Simulation` for each port and return the batch after saving."""
229
237
_ = self .get_path_dir (path_dir )
230
238
self .batch .to_file (self ._batch_path )
@@ -239,11 +247,11 @@ def get_port_by_name(self, port_name: str) -> Port:
239
247
return ports [0 ]
240
248
241
249
@abstractmethod
242
- def _construct_smatrix (self , batch_data : BatchData ) -> DataArray :
250
+ def _construct_smatrix (self , batch_data ) -> DataArray :
243
251
"""Post process :class:`.BatchData` to generate scattering matrix."""
244
252
245
253
@abstractmethod
246
- def _internal_construct_smatrix (self , batch_data : BatchData ) -> DataArray :
254
+ def _internal_construct_smatrix (self , batch_data ) -> DataArray :
247
255
"""Post process :class:`.BatchData` to generate scattering matrix, for internal use only."""
248
256
249
257
def run (self , path_dir : str = DEFAULT_DATA_DIR ) -> DataArray :
0 commit comments