Skip to content

Commit d6e1c9c

Browse files
Readd type hints
1 parent 57001e7 commit d6e1c9c

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

tidy3d/plugins/smatrix/component_modelers/base.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import os
6-
import typing
76
from abc import ABC, abstractmethod
87
from typing import Optional, Union, get_args
98

@@ -23,6 +22,7 @@
2322
from tidy3d.plugins.smatrix.ports.modal import Port
2423
from tidy3d.plugins.smatrix.ports.rectangular_lumped import LumpedPort
2524
from tidy3d.plugins.smatrix.ports.wave import WavePort
25+
from tidy3d.web import Batch, BatchData
2626

2727
# fwidth of gaussian pulse in units of central frequency
2828
FWIDTH_FRAC = 1.0 / 10
@@ -105,7 +105,7 @@ class AbstractComponentModeler(ABC, Tidy3dBaseModel):
105105
)
106106

107107
# TODO properly refactor, plugins should not have web methods.
108-
batch_cached: typing.Any = pd.Field(
108+
batch_cached: BatchData = pd.Field(
109109
None,
110110
title="Batch (Cached)",
111111
description="DEPRECATED: Optional field to specify ``batch``. Only used as a workaround internally "
@@ -182,7 +182,7 @@ def to_file(self, fname: str) -> None:
182182
super(AbstractComponentModeler, self).to_file(fname=fname) # noqa: UP008
183183

184184
@cached_property
185-
def batch(self):
185+
def batch(self) -> Batch:
186186
""":class:`.Batch` associated with this component modeler."""
187187
# TODO properly refactor, plugins data types should not have web methods.
188188
from tidy3d.web.api.container import Batch
@@ -210,7 +210,7 @@ def batch_path(self) -> str:
210210
return self.batch._batch_path(path_dir=self.path_dir)
211211

212212
@cached_property
213-
def batch_data(self):
213+
def batch_data(self) -> BatchData:
214214
"""The :class:`.BatchData` associated with the simulations run for this component modeler."""
215215
return self.batch.run(path_dir=self.path_dir)
216216

@@ -232,7 +232,7 @@ def _batch_path(self) -> str:
232232
"""Where we store the batch for this :class:`AbstractComponentModeler` instance after the run."""
233233
return os.path.join(self.path_dir, "batch" + str(hash(self)) + ".hdf5")
234234

235-
def _run_sims(self, path_dir: str = DEFAULT_DATA_DIR):
235+
def _run_sims(self, path_dir: str = DEFAULT_DATA_DIR) -> BatchData:
236236
"""Run :class:`.Simulation` for each port and return the batch after saving."""
237237
_ = self.get_path_dir(path_dir)
238238
self.batch.to_file(self._batch_path)
@@ -247,11 +247,11 @@ def get_port_by_name(self, port_name: str) -> Port:
247247
return ports[0]
248248

249249
@abstractmethod
250-
def _construct_smatrix(self, batch_data) -> DataArray:
250+
def _construct_smatrix(self, batch_data: BatchData) -> DataArray:
251251
"""Post process :class:`.BatchData` to generate scattering matrix."""
252252

253253
@abstractmethod
254-
def _internal_construct_smatrix(self, batch_data) -> DataArray:
254+
def _internal_construct_smatrix(self, batch_data: BatchData) -> DataArray:
255255
"""Post process :class:`.BatchData` to generate scattering matrix, for internal use only."""
256256

257257
def run(self, path_dir: str = DEFAULT_DATA_DIR) -> DataArray:
@@ -324,3 +324,6 @@ def sim_data_by_task_name(self, task_name: str) -> SimulationData:
324324
sim_data = self.batch_data[task_name]
325325
config.logging_level = log_level_cache
326326
return sim_data
327+
328+
329+
AbstractComponentModeler.update_forward_refs()

tidy3d/plugins/smatrix/component_modelers/modal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from tidy3d.components.viz import add_ax_if_none, equal_aspect
2020
from tidy3d.exceptions import SetupError
2121
from tidy3d.plugins.smatrix.ports.modal import ModalPortDataArray, Port
22+
from tidy3d.web import BatchData
2223

2324
from .base import FWIDTH_FRAC, AbstractComponentModeler
2425

@@ -276,7 +277,7 @@ def _construct_smatrix(self) -> ModalPortDataArray:
276277
"""Post process :class:`.BatchData` to generate scattering matrix."""
277278
return self._internal_construct_smatrix(batch_data=self.batch_data)
278279

279-
def _internal_construct_smatrix(self, batch_data) -> ModalPortDataArray:
280+
def _internal_construct_smatrix(self, batch_data: BatchData) -> ModalPortDataArray:
280281
"""Post process :class:`.BatchData` to generate scattering matrix, for internal use only."""
281282

282283
max_mode_index_out, max_mode_index_in = self.max_mode_index

tidy3d/plugins/smatrix/component_modelers/terminal.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import os
6-
import typing
76
from typing import Optional, Union
87

98
import numpy as np
@@ -33,6 +32,7 @@
3332
from tidy3d.plugins.smatrix.ports.coaxial_lumped import CoaxialLumpedPort
3433
from tidy3d.plugins.smatrix.ports.rectangular_lumped import LumpedPort
3534
from tidy3d.plugins.smatrix.ports.wave import WavePort
35+
from tidy3d.web import BatchData
3636

3737

3838
class TerminalComponentModeler(AbstractComponentModeler):
@@ -317,7 +317,7 @@ def _construct_smatrix(self) -> TerminalPortDataArray:
317317

318318
return construct_smatrix(self)
319319

320-
def _internal_construct_smatrix(self, batch_data: typing.Any = None) -> TerminalPortDataArray:
320+
def _internal_construct_smatrix(self, batch_data: BatchData = None) -> TerminalPortDataArray:
321321
from tidy3d.plugins.smatrix.local_run import construct_smatrix
322322

323323
return construct_smatrix(self)
@@ -529,3 +529,6 @@ def s_to_z(
529529
from tidy3d.plugins.smatrix.utils import s_to_z
530530

531531
return s_to_z(s_matrix=s_matrix, reference=reference)
532+
533+
534+
TerminalComponentModeler.update_forward_refs()

0 commit comments

Comments
 (0)