@@ -70,7 +70,7 @@ class AbstractComponentModeler(ABC, Tidy3dBaseModel):
70
70
"near zero frequency. Setting this to ``False`` results in an unmodified Gaussian "
71
71
"pulse spectrum which can have a nonzero DC component." ,
72
72
)
73
-
73
+
74
74
@pd .validator ("simulation" , always = True )
75
75
def _sim_has_no_sources (cls , val ):
76
76
"""Make sure simulation has no sources as they interfere with tool."""
@@ -101,117 +101,13 @@ def _task_name(port: Port, mode_index: Optional[int] = None) -> str:
101
101
return f"smatrix_{ port .name } _{ mode_index } "
102
102
return f"smatrix_{ port .name } "
103
103
104
- @cached_property
105
- def sim_dict (self ) -> dict [str , Simulation ]:
106
- """Generate all the :class:`.Simulation` objects for the S matrix calculation."""
107
-
108
- def to_file (self , fname : str ) -> None :
109
- """Exports :class:`AbstractComponentModeler` instance to .yaml, .json, or .hdf5 file
110
-
111
- Parameters
112
- ----------
113
- fname : str
114
- Full path to the .yaml or .json file to save the :class:`AbstractComponentModeler` to.
115
-
116
- Example
117
- -------
118
- >>> modeler.to_file(fname='folder/sim.json') # doctest: +SKIP
119
- """
120
-
121
- batch_cached = self ._cached_properties .get ("batch" )
122
- if batch_cached is not None :
123
- jobs_cached = batch_cached ._cached_properties .get ("jobs" )
124
- if jobs_cached is not None :
125
- jobs = {}
126
- for key , job in jobs_cached .items ():
127
- task_id = job ._cached_properties .get ("task_id" )
128
- jobs [key ] = job .updated_copy (task_id_cached = task_id )
129
- batch_cached = batch_cached .updated_copy (jobs_cached = jobs )
130
- self = self .updated_copy (batch_cached = batch_cached )
131
- super (AbstractComponentModeler , self ).to_file (fname = fname ) # noqa: UP008
132
-
133
- @cached_property
134
- def batch (self ) -> Batch :
135
- """:class:`.Batch` associated with this component modeler."""
136
- # TODO properly refactor, plugins data types should not have web methods.
137
- from tidy3d .web .api .container import Batch
138
-
139
- if self .batch_cached is not None :
140
- return self .batch_cached
141
-
142
- # first try loading the batch from file, if it exists
143
- batch_path = self ._batch_path
144
-
145
- if os .path .exists (batch_path ):
146
- return Batch .from_file (fname = batch_path )
147
-
148
- return Batch (
149
- simulations = self .sim_dict ,
150
- folder_name = self .folder_name ,
151
- callback_url = self .callback_url ,
152
- verbose = self .verbose ,
153
- solver_version = self .solver_version ,
154
- )
155
-
156
- @cached_property
157
- def batch_path (self ) -> str :
158
- """Path to the batch saved to file."""
159
- return self .batch ._batch_path (path_dir = self .path_dir )
160
-
161
- @cached_property
162
- def batch_data (self ) -> BatchData :
163
- """The :class:`.BatchData` associated with the simulations run for this component modeler."""
164
- return self .batch .run (path_dir = self .path_dir )
165
-
166
- def get_path_dir (self , path_dir : str ) -> None :
167
- """Check whether the supplied 'path_dir' matches the internal field value."""
168
-
169
- if path_dir != self .path_dir and path_dir != DEFAULT_DATA_DIR :
170
- raise ValueError (
171
- f"'path_dir' of '{ path_dir } ' passed, but 'ComponentModeler.path_dir' is "
172
- f"{ self .path_dir } . Moving forward, only the 'ComponentModeler.path_dir' will be "
173
- "used internally, please update your scripts accordingly to avoid passing this "
174
- "value to methods. "
175
- )
176
-
177
- return self .path_dir
178
-
179
- @cached_property
180
- def _batch_path (self ) -> str :
181
- """Where we store the batch for this :class:`AbstractComponentModeler` instance after the run."""
182
- return os .path .join (self .path_dir , "batch" + str (hash (self )) + ".hdf5" )
183
-
184
- def _run_sims (self , path_dir : str = DEFAULT_DATA_DIR ) -> BatchData :
185
- """Run :class:`.Simulation` for each port and return the batch after saving."""
186
- _ = self .get_path_dir (path_dir )
187
- self .batch .to_file (self ._batch_path )
188
- batch_data = self .batch_data
189
- return batch_data
190
-
191
104
def get_port_by_name (self , port_name : str ) -> Port :
192
105
"""Get the port from the name."""
193
106
ports = [port for port in self .ports if port .name == port_name ]
194
107
if len (ports ) == 0 :
195
108
raise Tidy3dKeyError (f'Port "{ port_name } " not found.' )
196
109
return ports [0 ]
197
110
198
- @abstractmethod
199
- def _construct_smatrix (self , batch_data : BatchData ) -> DataArray :
200
- """Post process :class:`.BatchData` to generate scattering matrix."""
201
-
202
- @abstractmethod
203
- def _internal_construct_smatrix (self , batch_data : BatchData ) -> DataArray :
204
- """Post process :class:`.BatchData` to generate scattering matrix, for internal use only."""
205
-
206
- def run (self , path_dir : str = DEFAULT_DATA_DIR ) -> DataArray :
207
- """Solves for the scattering matrix of the system."""
208
- _ = self .get_path_dir (path_dir )
209
- return self ._construct_smatrix ()
210
-
211
- def load (self , path_dir : str = DEFAULT_DATA_DIR ) -> DataArray :
212
- """Load a scattering matrix from saved :class:`.BatchData` object."""
213
- return self .run (path_dir = path_dir )
214
-
215
111
@staticmethod
216
112
def inv (matrix : DataArray ):
217
113
"""Helper to invert a port matrix."""
@@ -266,13 +162,4 @@ def _shift_value_signed(self, port: Union[Port, WavePort]) -> float:
266
162
new_pos = grid_centers [shifted_index ]
267
163
return new_pos - port_position
268
164
269
- def sim_data_by_task_name (self , task_name : str ) -> SimulationData :
270
- """Get the simulation data by task name, avoids emitting warnings from the ``Simulation``."""
271
- log_level_cache = config .logging_level
272
- config .logging_level = "ERROR"
273
- sim_data = self .batch_data [task_name ]
274
- config .logging_level = log_level_cache
275
- return sim_data
276
-
277
-
278
165
AbstractComponentModeler .update_forward_refs ()
0 commit comments