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 "
@@ -168,8 +174,10 @@ def to_file(self, fname: str) -> None:
168
174
super (AbstractComponentModeler , self ).to_file (fname = fname ) # noqa: UP008
169
175
170
176
@cached_property
171
- def batch (self ) -> Batch :
177
+ def batch (self ):
172
178
""":class:`.Batch` associated with this component modeler."""
179
+ # TODO properly refactor, plugins data types should not have web methods.
180
+ from tidy3d .web .api .container import Batch
173
181
174
182
if self .batch_cached is not None :
175
183
return self .batch_cached
@@ -194,7 +202,7 @@ def batch_path(self) -> str:
194
202
return self .batch ._batch_path (path_dir = self .path_dir )
195
203
196
204
@cached_property
197
- def batch_data (self ) -> BatchData :
205
+ def batch_data (self ):
198
206
"""The :class:`.BatchData` associated with the simulations run for this component modeler."""
199
207
return self .batch .run (path_dir = self .path_dir )
200
208
@@ -216,7 +224,7 @@ def _batch_path(self) -> str:
216
224
"""Where we store the batch for this :class:`AbstractComponentModeler` instance after the run."""
217
225
return os .path .join (self .path_dir , "batch" + str (hash (self )) + ".hdf5" )
218
226
219
- def _run_sims (self , path_dir : str = DEFAULT_DATA_DIR ) -> BatchData :
227
+ def _run_sims (self , path_dir : str = DEFAULT_DATA_DIR ):
220
228
"""Run :class:`.Simulation` for each port and return the batch after saving."""
221
229
_ = self .get_path_dir (path_dir )
222
230
self .batch .to_file (self ._batch_path )
@@ -231,11 +239,11 @@ def get_port_by_name(self, port_name: str) -> Port:
231
239
return ports [0 ]
232
240
233
241
@abstractmethod
234
- def _construct_smatrix (self , batch_data : BatchData ) -> DataArray :
242
+ def _construct_smatrix (self , batch_data ) -> DataArray :
235
243
"""Post process :class:`.BatchData` to generate scattering matrix."""
236
244
237
245
@abstractmethod
238
- def _internal_construct_smatrix (self , batch_data : BatchData ) -> DataArray :
246
+ def _internal_construct_smatrix (self , batch_data ) -> DataArray :
239
247
"""Post process :class:`.BatchData` to generate scattering matrix, for internal use only."""
240
248
241
249
def run (self , path_dir : str = DEFAULT_DATA_DIR ) -> DataArray :
0 commit comments