Skip to content

Commit 53193a8

Browse files
dbochkov-flexcomputemomchil-flex
authored andcommitted
dummy version updater for base simulation
1 parent f4b87ca commit 53193a8

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

tests/test_components/test_eme.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ def make_eme_sim():
8686
return sim
8787

8888

89+
def test_sim_version_update(log_capture):
90+
sim = make_eme_sim()
91+
sim_dict = sim.dict()
92+
sim_dict["version"] = "ancient_version"
93+
94+
with AssertLogLevel(log_capture, "WARNING"):
95+
sim_new = td.EMESimulation.parse_obj(sim_dict)
96+
97+
assert sim_new.version == td.__version__
98+
99+
89100
def test_eme_grid():
90101
sim_geom = td.Box(size=(4, 4, 4), center=(0, 0, 0))
91102
axis = 2

tests/test_components/test_heat.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,17 @@ def test_relative_min_dl_warning(log_capture):
552552
)
553553

554554

555+
def test_sim_version_update(log_capture):
556+
heat_sim = make_heat_sim()
557+
heat_sim_dict = heat_sim.dict()
558+
heat_sim_dict["version"] = "ancient_version"
559+
560+
with AssertLogLevel(log_capture, "WARNING"):
561+
heat_sim_new = td.HeatSimulation.parse_obj(heat_sim_dict)
562+
563+
assert heat_sim_new.version == td.__version__
564+
565+
555566
@pytest.mark.parametrize("zero_dim_axis", [None, 0, 2])
556567
def test_symmetry_expanded(zero_dim_axis):
557568
symmetry_center = [2, 0.5, 0]

tidy3d/components/base_sim/simulation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ class AbstractSimulation(Box, ABC):
104104

105105
""" Validating setup """
106106

107+
@pd.root_validator(pre=True)
108+
def _update_simulation(cls, values):
109+
"""Update the simulation if it is an earlier version."""
110+
111+
# dummy upgrade of version number
112+
# this should be overriden by each simulation class if needed
113+
current_version = values.get("version")
114+
if current_version != __version__ and current_version is not None:
115+
log.warning(f"updating {cls.__name__} from {current_version} to {__version__}")
116+
values["version"] = __version__
117+
return values
118+
107119
# make sure all names are unique
108120
_unique_monitor_names = assert_unique_names("monitors")
109121
_unique_structure_names = assert_unique_names("structures")

0 commit comments

Comments
 (0)