Skip to content

Commit 9cde3a7

Browse files
committed
Remove compose_modeler in favor of Tidy3dBaseModel.from_file
1 parent 98014ee commit 9cde3a7

File tree

3 files changed

+2
-64
lines changed

3 files changed

+2
-64
lines changed

tests/test_plugins/smatrix/test_run_functions.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import json
43
from unittest.mock import MagicMock
54

65
import pydantic.v1 as pd
@@ -14,38 +13,15 @@
1413
make_component_modeler as make_modal_component_modeler,
1514
)
1615
from tidy3d import SimulationDataMap
17-
from tidy3d.components.base import Tidy3dBaseModel
1816
from tidy3d.components.data.sim_data import SimulationData
1917
from tidy3d.plugins.smatrix.data.terminal import TerminalComponentModelerData
2018
from tidy3d.plugins.smatrix.run import (
2119
_run_local,
22-
compose_modeler,
2320
compose_modeler_data,
2421
create_batch,
2522
)
2623

2724

28-
def test_compose_modeler_unsupported_type(tmp_path, monkeypatch):
29-
# Create a dummy HDF5 file path
30-
modeler_file = tmp_path / "dummy_modeler.hdf5"
31-
32-
# Prepare a dummy JSON string with an unsupported type
33-
dummy_json = {"type": "UnsupportedComponentModeler", "some_key": "some_value"}
34-
dummy_json_str = json.dumps(dummy_json)
35-
36-
# Mock Tidy3dBaseModel._json_string_from_hdf5 to return our dummy JSON string
37-
def mock_json_string_from_hdf5(filepath):
38-
if filepath == str(modeler_file):
39-
return dummy_json_str
40-
return ""
41-
42-
monkeypatch.setattr(Tidy3dBaseModel, "_json_string_from_hdf5", mock_json_string_from_hdf5)
43-
44-
# Expect a TypeError when calling compose_modeler with the unsupported type
45-
with pytest.raises(TypeError, match="Unsupported modeler type: str"):
46-
compose_modeler(modeler_file=str(modeler_file))
47-
48-
4925
def test_create_batch(monkeypatch, tmp_path):
5026
# Mock Batch and Batch.to_file
5127
mock_batch_instance = MagicMock()

tidy3d/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from tidy3d.components.base import Tidy3dBaseModel
56
from tidy3d.components.boundary import BroadbandModeABCFitterParam, BroadbandModeABCSpec
67
from tidy3d.components.data.index import SimulationDataMap
78
from tidy3d.components.frequency_extrapolation import LowFrequencySmoothingSpec
@@ -812,6 +813,7 @@ def set_logging_level(level: str) -> None:
812813
"TemperatureData",
813814
"TemperatureMonitor",
814815
"TetrahedralGridDataset",
816+
"Tidy3dBaseModel",
815817
"Transformed",
816818
"TriangleMesh",
817819
"TriangularGridDataset",

tidy3d/plugins/smatrix/run.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from __future__ import annotations
22

3-
import json
4-
from os import PathLike
53
from typing import Any
64

7-
from tidy3d.components.base import Tidy3dBaseModel
85
from tidy3d.components.data.index import SimulationDataMap
96
from tidy3d.log import log
107
from tidy3d.plugins.smatrix.component_modelers.modal import ModalComponentModeler
@@ -18,43 +15,6 @@
1815
DEFAULT_DATA_DIR = "."
1916

2017

21-
def compose_modeler(
22-
modeler_file: PathLike,
23-
) -> ComponentModelerType:
24-
"""Load a component modeler from an HDF5 file.
25-
26-
This function reads an HDF5 file, determines the modeler type
27-
(`ModalComponentModeler` or `TerminalComponentModeler`), and constructs the
28-
corresponding modeler object.
29-
30-
Parameters
31-
----------
32-
modeler_file : PathLike
33-
Path to the HDF5 file containing the modeler definition.
34-
35-
Returns
36-
-------
37-
ComponentModelerType
38-
The loaded `ModalComponentModeler` or `TerminalComponentModeler` object.
39-
40-
Raises
41-
------
42-
TypeError
43-
If the modeler type specified in the file is not supported.
44-
"""
45-
json_str = Tidy3dBaseModel._json_string_from_hdf5(modeler_file)
46-
model_dict = json.loads(json_str)
47-
modeler_type = model_dict["type"]
48-
49-
if modeler_type == "ModalComponentModeler":
50-
modeler = ModalComponentModeler.from_file(modeler_file)
51-
elif modeler_type == "TerminalComponentModeler":
52-
modeler = TerminalComponentModeler.from_file(modeler_file)
53-
else:
54-
raise TypeError(f"Unsupported modeler type: {type(modeler_type).__name__}")
55-
return modeler
56-
57-
5818
def compose_modeler_data(
5919
modeler: ModalComponentModeler | TerminalComponentModeler,
6020
indexed_sim_data: SimulationDataMap,

0 commit comments

Comments
 (0)