Skip to content

Commit

Permalink
dummy version updater for base simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
dbochkov-flexcompute authored and momchil-flex committed Jul 10, 2024
1 parent f4b87ca commit 53193a8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/test_components/test_eme.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ def make_eme_sim():
return sim


def test_sim_version_update(log_capture):
sim = make_eme_sim()
sim_dict = sim.dict()
sim_dict["version"] = "ancient_version"

with AssertLogLevel(log_capture, "WARNING"):
sim_new = td.EMESimulation.parse_obj(sim_dict)

assert sim_new.version == td.__version__


def test_eme_grid():
sim_geom = td.Box(size=(4, 4, 4), center=(0, 0, 0))
axis = 2
Expand Down
11 changes: 11 additions & 0 deletions tests/test_components/test_heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,17 @@ def test_relative_min_dl_warning(log_capture):
)


def test_sim_version_update(log_capture):
heat_sim = make_heat_sim()
heat_sim_dict = heat_sim.dict()
heat_sim_dict["version"] = "ancient_version"

with AssertLogLevel(log_capture, "WARNING"):
heat_sim_new = td.HeatSimulation.parse_obj(heat_sim_dict)

assert heat_sim_new.version == td.__version__


@pytest.mark.parametrize("zero_dim_axis", [None, 0, 2])
def test_symmetry_expanded(zero_dim_axis):
symmetry_center = [2, 0.5, 0]
Expand Down
12 changes: 12 additions & 0 deletions tidy3d/components/base_sim/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ class AbstractSimulation(Box, ABC):

""" Validating setup """

@pd.root_validator(pre=True)
def _update_simulation(cls, values):
"""Update the simulation if it is an earlier version."""

# dummy upgrade of version number
# this should be overriden by each simulation class if needed
current_version = values.get("version")
if current_version != __version__ and current_version is not None:
log.warning(f"updating {cls.__name__} from {current_version} to {__version__}")
values["version"] = __version__
return values

# make sure all names are unique
_unique_monitor_names = assert_unique_names("monitors")
_unique_structure_names = assert_unique_names("structures")
Expand Down

0 comments on commit 53193a8

Please sign in to comment.