Skip to content

Commit ea3b4cb

Browse files
committed
passing: monitor, packaging, parameter_perturbation, perturbation_medium, scene, sidewall
1 parent 22dffbc commit ea3b4cb

10 files changed

Lines changed: 71 additions & 68 deletions

File tree

tests/test_components/test_medium.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,10 +760,8 @@ def test_nonlinear_medium():
760760
modulated = td.Medium(permittivity=2, modulation_spec=modulation_spec)
761761
with pytest.raises(pd.ValidationError):
762762
td.Medium2D(ss=medium, tt=medium)
763-
# with pytest.raises(pd.ValidationError):
764-
# td.Medium2D(ss=modulated, tt=modulated)
765-
td.Medium2D(ss=modulated, tt=modulated)
766-
return
763+
with pytest.raises(pd.ValidationError):
764+
td.Medium2D(ss=modulated, tt=modulated)
767765

768766
# some parameters must be real now, unless we use old implementation
769767
_ = td.TwoPhotonAbsorption(beta=1j, use_complex_fields=True)

tests/test_components/test_monitor.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Tests monitors."""
22

33
import numpy as np
4-
import pydantic.v1 as pydantic
4+
import pydantic as pd
55
import pytest
66
import tidy3d as td
77
from tidy3d.exceptions import SetupError, ValidationError
@@ -10,7 +10,7 @@
1010

1111

1212
def test_stop_start():
13-
with pytest.raises(pydantic.ValidationError):
13+
with pytest.raises(pd.ValidationError):
1414
td.FluxTimeMonitor(size=(1, 1, 0), name="f", start=2, stop=1)
1515

1616

@@ -57,13 +57,13 @@ def test_downsampled():
5757

5858

5959
def test_excluded_surfaces_flat():
60-
with pytest.raises(pydantic.ValidationError):
60+
with pytest.raises(pd.ValidationError):
6161
_ = td.FluxMonitor(size=(1, 1, 0), name="f", freqs=[1e12], exclude_surfaces=("x-",))
6262

6363

6464
def test_fld_mnt_freqs_none():
6565
"""Test that validation errors if freqs=[None]."""
66-
with pytest.raises(pydantic.ValidationError):
66+
with pytest.raises(pd.ValidationError):
6767
td.FieldMonitor(center=(0, 0, 0), size=(0, 0, 0), freqs=[None], name="test")
6868

6969

@@ -147,7 +147,7 @@ def test_fieldproj_surfaces():
147147
def test_fieldproj_surfaces_in_simulaiton():
148148
# test error if all projection surfaces are outside the simulation domain
149149
M = td.FieldProjectionAngleMonitor(size=(3, 3, 3), theta=[1], phi=[0], name="f", freqs=[2e12])
150-
with pytest.raises(pydantic.ValidationError):
150+
with pytest.raises(pd.ValidationError):
151151
_ = td.Simulation(
152152
size=(2, 2, 2),
153153
run_time=1e-12,
@@ -159,13 +159,13 @@ def test_fieldproj_surfaces_in_simulaiton():
159159
_ = td.Simulation(
160160
size=(2, 2, 2),
161161
run_time=1e-12,
162-
monitors=[M],
162+
monitors=(M,),
163163
grid_spec=td.GridSpec.uniform(0.1),
164164
)
165165

166166
# error when the surfaces that are in are excluded
167-
M = M.updated_copy(exclude_surfaces=["x-", "x+"])
168-
with pytest.raises(pydantic.ValidationError):
167+
M = M.updated_copy(exclude_surfaces=("x-", "x+"))
168+
with pytest.raises(pd.ValidationError):
169169
_ = td.Simulation(
170170
size=(2, 2, 2),
171171
run_time=1e-12,
@@ -176,11 +176,11 @@ def test_fieldproj_surfaces_in_simulaiton():
176176

177177
def test_fieldproj_kspace_range():
178178
# make sure ux, uy are in [-1, 1] for k-space projection monitors
179-
with pytest.raises(pydantic.ValidationError):
179+
with pytest.raises(pd.ValidationError):
180180
_ = td.FieldProjectionKSpaceMonitor(
181181
size=(2, 0, 2), ux=[0.1, 2], uy=[0], name="f", freqs=[2e12], proj_axis=1
182182
)
183-
with pytest.raises(pydantic.ValidationError):
183+
with pytest.raises(pd.ValidationError):
184184
_ = td.FieldProjectionKSpaceMonitor(
185185
size=(2, 0, 2), ux=[0.1, 0.2], uy=[1.1], name="f", freqs=[2e12], proj_axis=1
186186
)
@@ -209,12 +209,12 @@ def test_fieldproj_window():
209209
points = np.linspace(0, 10, 100)
210210
_ = M.window_function(points, window_size, window_minus, window_plus, 2)
211211
# do not allow a window size larger than 1
212-
with pytest.raises(pydantic.ValidationError):
212+
with pytest.raises(pd.ValidationError):
213213
_ = td.FieldProjectionAngleMonitor(
214214
size=(2, 0, 2), theta=[1, 2], phi=[0], name="f", freqs=[2e12], window_size=(0.2, 1.1)
215215
)
216216
# do not allow non-zero windows for volume monitors
217-
with pytest.raises(pydantic.ValidationError):
217+
with pytest.raises(pd.ValidationError):
218218
_ = td.FieldProjectionAngleMonitor(
219219
size=(2, 1, 2), theta=[1, 2], phi=[0], name="f", freqs=[2e12], window_size=(0.2, 0)
220220
)
@@ -239,7 +239,7 @@ def test_storage_sizes(proj_mnt):
239239
def test_monitor_freqs_empty():
240240
# errors when no frequencies supplied
241241

242-
with pytest.raises(pydantic.ValidationError):
242+
with pytest.raises(pd.ValidationError):
243243
_ = td.FieldMonitor(
244244
size=(td.inf, td.inf, td.inf),
245245
freqs=[],
@@ -323,7 +323,7 @@ def test_diffraction_validators():
323323
y=td.Boundary.periodic(),
324324
z=td.Boundary.pml(),
325325
)
326-
with pytest.raises(pydantic.ValidationError):
326+
with pytest.raises(pd.ValidationError):
327327
_ = td.Simulation(
328328
size=(2, 2, 2),
329329
run_time=1e-12,
@@ -334,7 +334,7 @@ def test_diffraction_validators():
334334
)
335335

336336
# ensure error if monitor isn't infinite in two directions
337-
with pytest.raises(pydantic.ValidationError):
337+
with pytest.raises(pd.ValidationError):
338338
_ = td.DiffractionMonitor(size=[td.inf, 4, 0], freqs=[1e12], name="de")
339339

340340

@@ -391,11 +391,11 @@ def test_monitor():
391391
def test_monitor_plane():
392392
# make sure flux, mode and diffraction monitors fail with non planar geometries
393393
for size in ((0, 0, 0), (1, 0, 0), (1, 1, 1)):
394-
with pytest.raises(pydantic.ValidationError):
394+
with pytest.raises(pd.ValidationError):
395395
td.ModeMonitor(size=size, freqs=FREQS, modes=[])
396-
with pytest.raises(pydantic.ValidationError):
396+
with pytest.raises(pd.ValidationError):
397397
td.ModeSolverMonitor(size=size, freqs=FREQS, modes=[])
398-
with pytest.raises(pydantic.ValidationError):
398+
with pytest.raises(pd.ValidationError):
399399
td.DiffractionMonitor(size=size, freqs=FREQS, name="de")
400400

401401

tests/test_components/test_parameter_perturbation.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import matplotlib.pyplot as plt
44
import numpy as np
5-
import pydantic.v1 as pydantic
65
import pytest
76
import tidy3d as td
7+
from pydantic import ValidationError
88

99
from ..utils import AssertLogLevel, cartesian_to_unstructured
1010

@@ -38,14 +38,14 @@ def test_heat_perturbation():
3838
# test complex type detection
3939
assert not perturb.is_complex
4040

41-
with pytest.raises(pydantic.ValidationError):
41+
with pytest.raises(ValidationError):
4242
perturb = td.LinearHeatPerturbation(
4343
coeff=0.01,
4444
temperature_ref=-300,
4545
temperature_range=(200, 400),
4646
)
4747

48-
with pytest.raises(pydantic.ValidationError):
48+
with pytest.raises(ValidationError):
4949
perturb = td.LinearHeatPerturbation(
5050
coeff=0.01,
5151
temperature_ref=300,
@@ -134,7 +134,7 @@ def test_heat_perturbation():
134134
assert test_value_out == perturb_data.data[2]
135135

136136
# test not allowed interpolation method
137-
with pytest.raises(pydantic.ValidationError):
137+
with pytest.raises(ValidationError):
138138
perturb = td.CustomHeatPerturbation(
139139
perturbation_values=perturb_data,
140140
interp_method="quadratic",
@@ -159,7 +159,7 @@ def test_charge_perturbation():
159159
# test complex type detection
160160
assert not perturb.is_complex
161161

162-
with pytest.raises(pydantic.ValidationError):
162+
with pytest.raises(ValidationError):
163163
perturb = td.LinearChargePerturbation(
164164
electron_coeff=1e-21,
165165
electron_ref=0,
@@ -169,7 +169,7 @@ def test_charge_perturbation():
169169
hole_range=(0, 0.5e20),
170170
)
171171

172-
with pytest.raises(pydantic.ValidationError):
172+
with pytest.raises(ValidationError):
173173
perturb = td.LinearChargePerturbation(
174174
electron_coeff=1e-21,
175175
electron_ref=0,
@@ -341,7 +341,7 @@ def test_sample(perturb):
341341
assert test_value_out == perturb_data[-1, -1].item()
342342

343343
# test not allowed interpolation method
344-
with pytest.raises(pydantic.ValidationError):
344+
with pytest.raises(ValidationError):
345345
perturb = td.CustomChargePerturbation(
346346
perturbation_values=perturb_data,
347347
interp_method="quadratic",
@@ -668,9 +668,7 @@ def test_delta_model():
668668
coeffs_4 = np.array([7.4e-22, 1.245, 5.43e-20, 1.153, 7.25e-21, 0.991, 9.99e-18, 0.839])
669669

670670
averaged_vals = (coeffs_3_5 + coeffs_4) / 2
671-
interpolated_results = [
672-
value.item() for _, value in delta_model._coeffs_at_ref_freq.data_vars.items()
673-
]
671+
interpolated_results = [v.item() for v in delta_model._coeffs_at_ref_freq.data.flat]
674672
error = np.abs(np.mean(averaged_vals - np.array(interpolated_results)))
675673

676674
assert error < 1e-16

tests/test_components/test_perturbation_medium.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Tests mediums."""
22

33
import numpy as np
4-
import pydantic.v1 as pydantic
54
import pytest
65
import tidy3d as td
6+
from pydantic import ValidationError
77

88
from ..utils import AssertLogLevel, cartesian_to_unstructured
99

@@ -103,7 +103,7 @@ def test_perturbation_medium(unstructured):
103103
assert cmed.allow_gain == pmed.allow_gain
104104

105105
# permittivity < 1
106-
with pytest.raises(pydantic.ValidationError):
106+
with pytest.raises(ValidationError):
107107
_ = pmed.perturbed_copy(1.1 * temperature)
108108

109109
# conductivity validators
@@ -133,19 +133,19 @@ def test_perturbation_medium(unstructured):
133133
for pmed in [pmed_direct, pmed_perm, pmed_index]:
134134
cmed = pmed.perturbed_copy(0.9 * temperature) # positive conductivity
135135
assert not cmed.subpixel
136-
with pytest.raises(pydantic.ValidationError):
136+
with pytest.raises(ValidationError):
137137
_ = pmed.perturbed_copy(1.1 * temperature) # negative conductivity
138138

139139
# negative conductivity but allow gain
140140
pmed = td.PerturbationMedium(conductivity_perturbation=pp_real, allow_gain=True)
141141
_ = pmed.perturbed_copy(1.1 * temperature)
142142

143143
# complex perturbation
144-
with pytest.raises(pydantic.ValidationError):
144+
with pytest.raises(ValidationError):
145145
pmed = td.PerturbationMedium(permittivity=3, permittivity_perturbation=pp_complex)
146146

147147
# overdefinition
148-
with pytest.raises(pydantic.ValidationError):
148+
with pytest.raises(ValidationError):
149149
_ = td.PerturbationMedium(
150150
permittivity=1.21,
151151
permittivity_perturbation=pp_real,
@@ -258,18 +258,18 @@ def test_perturbation_medium(unstructured):
258258
assert cmed.allow_gain == pmed.allow_gain
259259

260260
# eps_inf < 0
261-
with pytest.raises(pydantic.ValidationError):
261+
with pytest.raises(ValidationError):
262262
_ = pmed.perturbed_copy(1.1 * temperature)
263263

264264
# mismatch between base parameter and perturbations
265-
with pytest.raises(pydantic.ValidationError):
265+
with pytest.raises(ValidationError):
266266
pmed = td.PerturbationPoleResidue(
267267
poles=[(1j, 3), (2j, 4)],
268268
poles_perturbation=[(None, pp_real)],
269269
)
270270

271271
# overdefinition
272-
with pytest.raises(pydantic.ValidationError):
272+
with pytest.raises(ValidationError):
273273
_ = td.PerturbationPoleResidue(
274274
eps_inf=1.21,
275275
poles=[(1j, 3), (2j, 4)],

tests/test_components/test_scene.py

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

33
import matplotlib.pyplot as plt
44
import numpy as np
5-
import pydantic.v1 as pd
65
import pytest
76
import tidy3d as td
7+
from pydantic import ValidationError
88
from tidy3d.components.scene import MAX_GEOMETRY_COUNT, MAX_NUM_MEDIUMS
99

1010
from ..utils import SIM_FULL, cartesian_to_unstructured
@@ -44,7 +44,7 @@ def test_scene_init():
4444

4545

4646
def test_validate_components_none():
47-
assert SCENE._validate_num_mediums(val=None) is None
47+
assert type(SCENE)._validate_num_mediums(val=None) is None
4848

4949

5050
def test_plot_eps():
@@ -113,7 +113,7 @@ def test_structure_alpha():
113113
new_structs = [
114114
td.Structure(geometry=s.geometry, medium=SCENE_FULL.medium) for s in SCENE_FULL.structures
115115
]
116-
S2 = SCENE_FULL.copy(update=dict(structures=new_structs))
116+
S2 = SCENE_FULL.copy(update=dict(structures=tuple(new_structs)))
117117
_ = S2.plot_structures_eps(x=0, alpha=0.5)
118118
plt.close()
119119

@@ -155,7 +155,7 @@ def test_num_mediums():
155155
structures=structures,
156156
)
157157

158-
with pytest.raises(pd.ValidationError):
158+
with pytest.raises(ValidationError):
159159
structures.append(
160160
td.Structure(geometry=td.Box(size=(1, 1, 1)), medium=td.Medium(permittivity=i + 2))
161161
)
@@ -191,7 +191,7 @@ def _test_names_default():
191191

192192

193193
def test_names_unique():
194-
with pytest.raises(pd.ValidationError):
194+
with pytest.raises(ValidationError):
195195
_ = td.Scene(
196196
structures=[
197197
td.Structure(
@@ -305,5 +305,5 @@ def test_max_geometry_validation():
305305
medium=td.Medium(permittivity=2.0),
306306
),
307307
]
308-
with pytest.raises(pd.ValidationError, match=f" {MAX_GEOMETRY_COUNT + 2} "):
308+
with pytest.raises(ValidationError, match=f" {MAX_GEOMETRY_COUNT + 2} "):
309309
_ = td.Scene(structures=not_fine)

0 commit comments

Comments
 (0)