@@ -71,57 +71,6 @@ class AbstractComponentModeler(ABC, Tidy3dBaseModel):
71
71
"pulse spectrum which can have a nonzero DC component." ,
72
72
)
73
73
74
- folder_name : str = pd .Field (
75
- "default" ,
76
- title = "Folder Name" ,
77
- description = "Name of the folder for the tasks on web." ,
78
- )
79
-
80
- verbose : bool = pd .Field (
81
- False ,
82
- title = "Verbosity" ,
83
- description = "Whether the :class:`.AbstractComponentModeler` should print status and progressbars." ,
84
- )
85
-
86
- callback_url : str = pd .Field (
87
- None ,
88
- title = "Callback URL" ,
89
- description = "Http PUT url to receive simulation finish event. "
90
- "The body content is a json file with fields "
91
- "``{'id', 'status', 'name', 'workUnit', 'solverVersion'}``." ,
92
- )
93
-
94
- path_dir : str = pd .Field (
95
- DEFAULT_DATA_DIR ,
96
- title = "Directory Path" ,
97
- description = "Base directory where data and batch will be downloaded." ,
98
- )
99
-
100
- solver_version : str = pd .Field (
101
- None ,
102
- title = "Solver Version" ,
103
- description_str = "Custom solver version to use. "
104
- "If not supplied, uses default for the current front end version." ,
105
- )
106
-
107
- # TODO properly refactor, plugins should not have web methods.
108
- batch_cached : Batch = pd .Field (
109
- None ,
110
- title = "Batch (Cached)" ,
111
- description = "DEPRECATED: Optional field to specify ``batch``. Only used as a workaround internally "
112
- "so that ``batch`` is written when ``.to_file()`` and then the proper batch is loaded "
113
- "from ``.from_file()``. We recommend leaving unset as setting this field along with "
114
- "fields that were not used to create the task will cause errors." ,
115
- )
116
-
117
- @pd .root_validator (pre = False )
118
- def _warn_deprecation_2_10 (cls , values ):
119
- log .warning (
120
- "ℹ️ ⚠️ Backwards compatibility will be broken for all the ComponentModeler classes in tidy3d version 2.10. Migration documentation will be provided, and existing functionality can be accessed in a different way." ,
121
- log_once = True ,
122
- )
123
- return values
124
-
125
74
@pd .validator ("simulation" , always = True )
126
75
def _sim_has_no_sources (cls , val ):
127
76
"""Make sure simulation has no sources as they interfere with tool."""
@@ -152,117 +101,13 @@ def _task_name(port: Port, mode_index: Optional[int] = None) -> str:
152
101
return f"smatrix_{ port .name } _{ mode_index } "
153
102
return f"smatrix_{ port .name } "
154
103
155
- @cached_property
156
- def sim_dict (self ) -> dict [str , Simulation ]:
157
- """Generate all the :class:`.Simulation` objects for the S matrix calculation."""
158
-
159
- def to_file (self , fname : str ) -> None :
160
- """Exports :class:`AbstractComponentModeler` instance to .yaml, .json, or .hdf5 file
161
-
162
- Parameters
163
- ----------
164
- fname : str
165
- Full path to the .yaml or .json file to save the :class:`AbstractComponentModeler` to.
166
-
167
- Example
168
- -------
169
- >>> modeler.to_file(fname='folder/sim.json') # doctest: +SKIP
170
- """
171
-
172
- batch_cached = self ._cached_properties .get ("batch" )
173
- if batch_cached is not None :
174
- jobs_cached = batch_cached ._cached_properties .get ("jobs" )
175
- if jobs_cached is not None :
176
- jobs = {}
177
- for key , job in jobs_cached .items ():
178
- task_id = job ._cached_properties .get ("task_id" )
179
- jobs [key ] = job .updated_copy (task_id_cached = task_id )
180
- batch_cached = batch_cached .updated_copy (jobs_cached = jobs )
181
- self = self .updated_copy (batch_cached = batch_cached )
182
- super (AbstractComponentModeler , self ).to_file (fname = fname ) # noqa: UP008
183
-
184
- @cached_property
185
- def batch (self ) -> Batch :
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
189
-
190
- if self .batch_cached is not None :
191
- return self .batch_cached
192
-
193
- # first try loading the batch from file, if it exists
194
- batch_path = self ._batch_path
195
-
196
- if os .path .exists (batch_path ):
197
- return Batch .from_file (fname = batch_path )
198
-
199
- return Batch (
200
- simulations = self .sim_dict ,
201
- folder_name = self .folder_name ,
202
- callback_url = self .callback_url ,
203
- verbose = self .verbose ,
204
- solver_version = self .solver_version ,
205
- )
206
-
207
- @cached_property
208
- def batch_path (self ) -> str :
209
- """Path to the batch saved to file."""
210
- return self .batch ._batch_path (path_dir = self .path_dir )
211
-
212
- @cached_property
213
- def batch_data (self ) -> BatchData :
214
- """The :class:`.BatchData` associated with the simulations run for this component modeler."""
215
- return self .batch .run (path_dir = self .path_dir )
216
-
217
- def get_path_dir (self , path_dir : str ) -> None :
218
- """Check whether the supplied 'path_dir' matches the internal field value."""
219
-
220
- if path_dir != self .path_dir and path_dir != DEFAULT_DATA_DIR :
221
- raise ValueError (
222
- f"'path_dir' of '{ path_dir } ' passed, but 'ComponentModeler.path_dir' is "
223
- f"{ self .path_dir } . Moving forward, only the 'ComponentModeler.path_dir' will be "
224
- "used internally, please update your scripts accordingly to avoid passing this "
225
- "value to methods. "
226
- )
227
-
228
- return self .path_dir
229
-
230
- @cached_property
231
- def _batch_path (self ) -> str :
232
- """Where we store the batch for this :class:`AbstractComponentModeler` instance after the run."""
233
- return os .path .join (self .path_dir , "batch" + str (hash (self )) + ".hdf5" )
234
-
235
- def _run_sims (self , path_dir : str = DEFAULT_DATA_DIR ) -> BatchData :
236
- """Run :class:`.Simulation` for each port and return the batch after saving."""
237
- _ = self .get_path_dir (path_dir )
238
- self .batch .to_file (self ._batch_path )
239
- batch_data = self .batch_data
240
- return batch_data
241
-
242
104
def get_port_by_name (self , port_name : str ) -> Port :
243
105
"""Get the port from the name."""
244
106
ports = [port for port in self .ports if port .name == port_name ]
245
107
if len (ports ) == 0 :
246
108
raise Tidy3dKeyError (f'Port "{ port_name } " not found.' )
247
109
return ports [0 ]
248
110
249
- @abstractmethod
250
- def _construct_smatrix (self , batch_data : BatchData ) -> DataArray :
251
- """Post process :class:`.BatchData` to generate scattering matrix."""
252
-
253
- @abstractmethod
254
- def _internal_construct_smatrix (self , batch_data : BatchData ) -> DataArray :
255
- """Post process :class:`.BatchData` to generate scattering matrix, for internal use only."""
256
-
257
- def run (self , path_dir : str = DEFAULT_DATA_DIR ) -> DataArray :
258
- """Solves for the scattering matrix of the system."""
259
- _ = self .get_path_dir (path_dir )
260
- return self ._construct_smatrix ()
261
-
262
- def load (self , path_dir : str = DEFAULT_DATA_DIR ) -> DataArray :
263
- """Load a scattering matrix from saved :class:`.BatchData` object."""
264
- return self .run (path_dir = path_dir )
265
-
266
111
@staticmethod
267
112
def inv (matrix : DataArray ):
268
113
"""Helper to invert a port matrix."""
@@ -317,13 +162,4 @@ def _shift_value_signed(self, port: Union[Port, WavePort]) -> float:
317
162
new_pos = grid_centers [shifted_index ]
318
163
return new_pos - port_position
319
164
320
- def sim_data_by_task_name (self , task_name : str ) -> SimulationData :
321
- """Get the simulation data by task name, avoids emitting warnings from the ``Simulation``."""
322
- log_level_cache = config .logging_level
323
- config .logging_level = "ERROR"
324
- sim_data = self .batch_data [task_name ]
325
- config .logging_level = log_level_cache
326
- return sim_data
327
-
328
-
329
165
AbstractComponentModeler .update_forward_refs ()
0 commit comments