Skip to content

Commit 8f478bd

Browse files
committed
pydantic v2 (wip)
add somefiles replacing v1 more replacements copy methods and ordering of basemodel update get_submodels_by_hash basemodel done (except for docs) basemodel and modespec done slowly but surely.. progress next batch going going getting started on medium more refactoring new structure for medium.py add medium why it no work fix medium upgrade material library most of it first pass add pydantic-settings fixes to validators, mutable assignment, ...: remove skip_if_fields_missing cleaning up types & type serializaton fix printing and serialization of autograd types more type serialization updates Fix traced ndarray serialization fix equality check in basemodel fix some v1 leftovers fix some tests fix equality check sim_data tests passing make serializer more robust and another fix for equality comparison fix warn if none validators Check for pydantic v2 ValidationErrors Canonicalize coordinate handling of unstructured datasets Simulation data tests passing material library tests passing fix bad name fix material libray -> library lotsa fixes, tests_web & test_package passing fix remaining web test warnings everything importable for doctests rebase, wip fix mutation safer ndarray coercion and expressions fix working on post init validation fix multiphysics medium attribute lookup remove test script from vcs doctests passing fix NedeljkovicSorefMashanovich fix non-component tests fix tracer serialization remove unnecessary to_static call the smallest changes really do take the longest all of test_IO passing fix caching and copy update docstring for __init_subclass__ passing: IO, base, beam, boundaries, custom, eme, field_projection, geometry, log passing: grid, grid_spec, heat, heat_charge, layerrefinement, lumped_element, medium passing: meshgenerate, microwave, mode passing: monitor, packaging, parameter_perturbation, perturbation_medium, scene, sidewall passing: expressions passing: smatrix, array_factor, design, dispersion_fitter, microwave, mode_solver wip: adjoint & invdes passing: source, structure, time_modulation passing: types add helpers to filter model fields add tests for new basemodel helpers small fixes wip: autograd fix waveguide passing: autograd rebase fixes no more post-init validators fix dataarray json schema rework array constraints wip: adjoint ruff chore(github): improve script to determine test scope (#2510) * chore(github): add script to determine whether a PR was already approved This step results in a full test suite run if an already approved PR receives changes to prevent breaking the main branch. * cancel parallel triggers of the remote tests * fix group assignment * add python version to group assignment fix bug when inserting snapping points near sim min boundary fix contains check for lumped element, which was too strict (#2511) fix[web]: use dedicated endpoint for `web.delete_old()` Upgrade ruff 0.5.5 -> 0.11.11 Run `ruff check . --fix` Run `ruff format .` Move test-specifc `ruff.toml` to `per-file-ignores` Sort test imports Import `Literal` from `typing` Force `from __future__ import annotations` import Rewrite `dict()` as literal (2x faster) Disallow function calls in default arguments Be intentional about exception context Upgrade all (compatible) generics to built-in types Sort `__all__` blocks Enable `RUF` ruleset Prefer tuple unpacking over concatenation Forbid implicit optional No explicit string concatenation Remove unnecessary `pass` statements Remove unnecessary parantheses on raised exceptions Disallow relative imports from parent modules Remove unused import aliases Add lint rule comments Revert "Disallow function calls in default arguments" This reverts commit 12a0a6a. Fix some stragglers Updated ruff version in workflow Lint `data/` dirs rebase fixes sentinel pattern for function calls in default arguments rebase fixes fix python 3.9 compat same behavior as v1 for `FreqArray` Also updating FieldDataset in monitor_data/charge.py Make `FreqArray` pure `ArrayFloat1D` remove old material_libray.py replace deprecated symbols disable adjoint plugin pin pydantic>2.8 fixing warnings fix modesolver validators Updating TriangularGridDataset.normal_axis and TemperatureData validator Warning adjoint removal in apidocs pin pydantic>=2.9, fix literal types
1 parent 0157ce9 commit 8f478bd

File tree

239 files changed

+7619
-14729
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

239 files changed

+7619
-14729
lines changed

docs/api/plugins/adjoint.rst

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/api/plugins/index.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Plugins
22
=======
33

4+
.. warning::
5+
6+
|:warning:| The 'adjoint' plugin (legacy JAX-based adjoint plugin)
7+
was deprecated in Tidy3D 'v2.7.0' and is disabled as of 'v2.9.0'.
8+
49
.. toctree::
510
:hidden:
611

@@ -10,7 +15,6 @@ Plugins
1015
./smatrix
1116
./resonance
1217
./autograd
13-
./adjoint
1418
./invdes
1519
./design
1620
./waveguide
@@ -23,8 +27,7 @@ Plugins
2327
.. include:: /api/plugins/smatrix.rst
2428
.. include:: /api/plugins/resonance.rst
2529
.. include:: /api/plugins/autograd.rst
26-
.. include:: /api/plugins/adjoint.rst
2730
.. include:: /api/plugins/invdes.rst
2831
.. include:: /api/plugins/design.rst
2932
.. include:: /api/plugins/waveguide.rst
30-
.. include:: /api/plugins/microwave.rst
33+
.. include:: /api/plugins/microwave.rst

poetry.lock

Lines changed: 0 additions & 7753 deletions
This file was deleted.

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ numpy = "*"
3434
matplotlib = "*"
3535
shapely = "^2.0"
3636
pandas = "*"
37-
pydantic = "^2.0"
37+
pydantic = ">=2.9,<3"
3838
PyYAML = "*"
3939
dask = "*"
4040
toml = "*"
@@ -291,7 +291,12 @@ required-imports = ["from __future__ import annotations"]
291291

292292
[tool.pytest.ini_options]
293293
# TODO: remove --assert=plain when https://github.com/scipy/scipy/issues/22236 is resolved
294-
addopts = "--cov=tidy3d --doctest-modules -n auto --dist worksteal --assert=plain -m 'not numerical' "
294+
# TODO(yaugenst-flex): Revisit adjoint plugin for pydantic v2
295+
addopts = """
296+
--doctest-modules -n auto --dist worksteal --assert=plain -m 'not numerical' \
297+
--ignore=tests/test_plugins/test_adjoint.py \
298+
--ignore=tidy3d/plugins/adjoint/
299+
"""
295300
markers = [
296301
"numerical: marks numerical tests for adjoint gradients that require running simulations (deselect with '-m \"not numerical\"')",
297302
]

tests/test_components/test_IO.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
# Store an example of every minor release simulation to test updater in the future
2626
SIM_DIR = "tests/sims"
27+
SIM_STATIC = SIM.to_static()
2728

2829

2930
@pytest.fixture
@@ -69,14 +70,14 @@ def test_simulation_load_export(split_string, tmp_path):
6970
major, minor, patch = __version__.split(".")
7071
path = os.path.join(tmp_path, f"simulation_{major}_{minor}_{patch}.json")
7172
path_hdf5 = os.path.join(tmp_path, f"simulation_{major}_{minor}_{patch}.h5")
72-
SIM.to_file(path)
73-
SIM.to_hdf5(path_hdf5)
73+
SIM_STATIC.to_file(path)
74+
SIM_STATIC.to_hdf5(path_hdf5)
7475
SIM2 = td.Simulation.from_file(path)
7576
SIM_HDF5 = td.Simulation.from_hdf5(path_hdf5)
76-
assert set_datasets_to_none(SIM)._json_string == SIM2._json_string, (
77+
assert set_datasets_to_none(SIM_STATIC)._json_string == SIM2._json_string, (
7778
"original and loaded simulations are not the same"
7879
)
79-
assert SIM == SIM_HDF5, "original and loaded from hdf5 simulations are not the same"
80+
assert SIM_STATIC == SIM_HDF5, "original and loaded from hdf5 simulations are not the same"
8081

8182

8283
def test_simulation_load_export_yaml(tmp_path):
@@ -104,30 +105,30 @@ def test_component_load_export_yaml(tmp_path):
104105

105106
def test_simulation_load_export_hdf5(split_string, tmp_path):
106107
path = str(tmp_path / "simulation.hdf5")
107-
SIM.to_file(path)
108+
SIM_STATIC.to_file(path)
108109
SIM2 = td.Simulation.from_file(path)
109-
assert SIM == SIM2, "original and loaded simulations are not the same"
110+
assert SIM_STATIC == SIM2, "original and loaded simulations are not the same"
110111

111112

112113
def test_simulation_load_export_hdf5_gz(split_string, tmp_path):
113114
path = str(tmp_path / "simulation.hdf5.gz")
114-
SIM.to_file(path)
115+
SIM_STATIC.to_file(path)
115116
SIM2 = td.Simulation.from_file(path)
116-
assert SIM == SIM2, "original and loaded simulations are not the same"
117+
assert SIM_STATIC == SIM2, "original and loaded simulations are not the same"
117118

118119

119120
def test_simulation_load_export_hdf5_explicit(split_string, tmp_path):
120121
path = str(tmp_path / "simulation.hdf5")
121-
SIM.to_hdf5(path)
122+
SIM_STATIC.to_hdf5(path)
122123
SIM2 = td.Simulation.from_hdf5(path)
123-
assert SIM == SIM2, "original and loaded simulations are not the same"
124+
assert SIM_STATIC == SIM2, "original and loaded simulations are not the same"
124125

125126

126127
def test_simulation_load_export_hdf5_gz_explicit(split_string, tmp_path):
127128
path = str(tmp_path / "simulation.hdf5.gz")
128-
SIM.to_hdf5_gz(path)
129+
SIM_STATIC.to_hdf5_gz(path)
129130
SIM2 = td.Simulation.from_hdf5_gz(path)
130-
assert SIM == SIM2, "original and loaded simulations are not the same"
131+
assert SIM_STATIC == SIM2, "original and loaded simulations are not the same"
131132

132133

133134
def test_simulation_load_export_pckl(tmp_path):
@@ -192,7 +193,7 @@ def test_validation_speed(tmp_path):
192193
for i in range(n):
193194
new_structure = SIM.structures[0].copy(update={"name": str(i)})
194195
new_structures.append(new_structure)
195-
S = SIM.copy(update={"structures": new_structures})
196+
S = SIM.copy(update={"structures": tuple(new_structures)})
196197

197198
S.to_file(path)
198199
time_start = time()
@@ -226,7 +227,9 @@ def test_simulation_updater(sim_file):
226227
def test_yaml(tmp_path):
227228
path = str(tmp_path / "simulation.json")
228229
SIM.to_file(path)
230+
SIM.to_file("simulation.json")
229231
sim = td.Simulation.from_file(path)
232+
230233
path1 = str(tmp_path / "simulation.yaml")
231234
sim.to_yaml(path1)
232235
sim1 = td.Simulation.from_yaml(path1)

tests/test_components/test_apodization.py

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

55
import matplotlib.pyplot as plt
6-
import pydantic.v1 as pydantic
76
import pytest
7+
from pydantic import ValidationError
88

99
import tidy3d as td
1010

@@ -17,27 +17,27 @@ def test_apodization():
1717

1818

1919
def test_end_lt_start():
20-
with pytest.raises(pydantic.ValidationError):
20+
with pytest.raises(ValidationError):
2121
_ = td.ApodizationSpec(start=2, end=1, width=0.2)
2222

2323

2424
def test_no_width():
25-
with pytest.raises(pydantic.ValidationError):
25+
with pytest.raises(ValidationError):
2626
_ = td.ApodizationSpec(start=1, end=2)
27-
with pytest.raises(pydantic.ValidationError):
27+
with pytest.raises(ValidationError):
2828
_ = td.ApodizationSpec(start=1)
29-
with pytest.raises(pydantic.ValidationError):
29+
with pytest.raises(ValidationError):
3030
_ = td.ApodizationSpec(end=2)
3131

3232

3333
def test_negative_times():
34-
with pytest.raises(pydantic.ValidationError):
34+
with pytest.raises(ValidationError):
3535
_ = td.ApodizationSpec(start=-2, end=-1, width=0.2)
3636

37-
with pytest.raises(pydantic.ValidationError):
37+
with pytest.raises(ValidationError):
3838
_ = td.ApodizationSpec(start=1, end=2, width=-0.2)
3939

40-
with pytest.raises(pydantic.ValidationError):
40+
with pytest.raises(ValidationError):
4141
_ = td.ApodizationSpec(start=1, end=2, width=0)
4242

4343

0 commit comments

Comments
 (0)