Skip to content

Commit f494751

Browse files
committed
fix: solve most warnings in test suite & some deprecation warnings too
1 parent 7e2bcda commit f494751

File tree

14 files changed

+69
-36
lines changed

14 files changed

+69
-36
lines changed

tests/test_components/test_autograd.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,10 +2321,16 @@ def objective(center, size):
23212321
sim_data = run_emulated(sim, task_name="adjoint_test")
23222322
return postprocess(sim_data)
23232323

2324-
with AssertLogLevel("WARNING", contains_str="autograd tracer"):
2324+
with (
2325+
AssertLogLevel("WARNING", contains_str="autograd tracer"),
2326+
pytest.warns(UserWarning, match="Output seems independent of input."),
2327+
):
23252328
grad = ag.grad(objective, argnum=0)(base_sim.center, base_sim.size)
23262329

2327-
with AssertLogLevel("WARNING", contains_str="autograd tracer"):
2330+
with (
2331+
AssertLogLevel("WARNING", contains_str="autograd tracer"),
2332+
pytest.warns(UserWarning, match="Output seems independent of input."),
2333+
):
23282334
grad = ag.grad(objective, argnum=1)(base_sim.center, base_sim.size)
23292335

23302336

tests/test_components/test_heat_charge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,16 +1476,16 @@ def test_gaussian_doping_get_contrib():
14761476

14771477
coords = {"x": [0], "y": [0], "z": [0]}
14781478
contrib = box._get_contrib(coords)
1479-
assert np.isclose(float(contrib), max_N, rtol=1e-6)
1479+
assert np.isclose(contrib.item(), max_N, rtol=1e-6)
14801480

14811481
coords = {"x": [0.5], "y": [0], "z": [0]}
14821482
contrib = box._get_contrib(coords)
1483-
assert np.isclose(float(contrib), min_N, rtol=1e-6)
1483+
assert np.isclose(contrib.item(), min_N, rtol=1e-6)
14841484

14851485
coords = {"x": [0.5 - width / 2], "y": [0], "z": [0]}
14861486
contrib = box._get_contrib(coords)
14871487
expected_value = max_N * np.exp(-width * width / 4 / box.sigma / box.sigma / 2)
1488-
assert np.isclose(float(contrib), expected_value, rtol=1e-6)
1488+
assert np.isclose(contrib.item(), expected_value, rtol=1e-6)
14891489

14901490

14911491
def test_gaussian_doping_get_contrib_2d_coords():

tests/test_plugins/test_microwave.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def test_microstrip_models():
402402
freqs = Frequency(start=1, stop=1, npoints=1, unit="ghz")
403403
mline = MLine(frequency=freqs, w=width, h=height, t=thickness, ep_r=eps_r, disp="none")
404404

405-
assert np.isclose(Z0, mline.Z0[0])
405+
assert np.isclose(Z0, mline.z0[0])
406406
assert np.isclose(eps_eff, mline.ep_reff[0])
407407

408408
# Check end effect length computation
@@ -414,7 +414,7 @@ def test_microstrip_models():
414414
Z0, eps_eff = mw.models.microstrip.compute_line_params(eps_r, width, height, thickness)
415415
mline = MLine(frequency=freqs, w=width, h=height, t=thickness, ep_r=eps_r, disp="none")
416416

417-
assert np.isclose(Z0, mline.Z0[0])
417+
assert np.isclose(Z0, mline.z0[0])
418418
assert np.isclose(eps_eff, mline.ep_reff[0])
419419

420420

@@ -667,7 +667,7 @@ def test_lobe_measurer_validation():
667667

668668
Urad = np.cos(theta) + 1j * np.sin(theta)
669669
# Raise error when radiation pattern is complex
670-
with pytest.raises(pd.ValidationError):
670+
with pytest.raises(pd.ValidationError), pytest.warns(np.exceptions.ComplexWarning):
671671
mw.LobeMeasurer(
672672
angle=theta,
673673
radiation_pattern=Urad,
@@ -794,4 +794,3 @@ def test_lobe_plots(min_value):
794794
_, ax = plt.subplots(1, 1, subplot_kw={"projection": "polar"})
795795
ax.plot(theta, Urad, "k")
796796
lobe_measurer.plot(0, ax)
797-
plt.show()

tests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ def get_spatial_coords_dict(simulation: td.Simulation, monitor: td.Monitor, fiel
11401140

11411141
def run_emulated(simulation: td.Simulation, path=None, **kwargs) -> td.SimulationData:
11421142
"""Emulates a simulation run."""
1143-
from scipy.ndimage.filters import gaussian_filter
1143+
from scipy.ndimage import gaussian_filter
11441144

11451145
x = kwargs.get("x0", 1.0)
11461146

tidy3d/components/data/unstructured/triangular.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,5 +675,5 @@ def get_cell_volumes(self):
675675
v0 = self.points[self.cells.sel(vertex_index=0)]
676676
e01 = self.points[self.cells.sel(vertex_index=1)] - v0
677677
e02 = self.points[self.cells.sel(vertex_index=2)] - v0
678-
679-
return 0.5 * np.abs(np.cross(e01, e02))
678+
areas = e01[:, 0] * e02[:, 1] - e01[:, 1] * e02[:, 0]
679+
return 0.5 * np.abs(areas)

tidy3d/components/geometry/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,7 @@ def _do_intersections_tilted_plane(
20322032
section = mesh.section(plane_origin=origin, plane_normal=normal)
20332033
if section is None:
20342034
return []
2035-
path, _ = section.to_planar(to_2D=to_2D)
2035+
path, _ = section.to_2D(to_2D=to_2D)
20362036
return path.polygons_full
20372037

20382038
def intersections_plane(

tidy3d/components/geometry/mesh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def intersections_tilted_plane(
550550
section = self.trimesh.section(plane_origin=origin, plane_normal=normal)
551551
if section is None:
552552
return []
553-
path, _ = section.to_planar(to_2D=to_2D)
553+
path, _ = section.to_2D(to_2D=to_2D)
554554
return path.polygons_full
555555

556556
def intersections_plane(
@@ -603,7 +603,7 @@ def intersections_plane(
603603
permutation = self.unpop_axis(identity[2], identity[0:2], axis=axis)
604604
mapping[:3, :3] = np.array(permutation).T
605605

606-
section2d, _ = section.to_planar(to_2D=mapping)
606+
section2d, _ = section.to_2D(to_2D=mapping)
607607
return list(section2d.polygons_full)
608608

609609
except ValueError as e:

tidy3d/components/geometry/polyslab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def _do_intersections_tilted_plane(
634634
section = mesh.section(plane_origin=origin, plane_normal=normal)
635635
if section is None:
636636
return []
637-
path, _ = section.to_planar(to_2D=to_2D)
637+
path, _ = section.to_2D(to_2D=to_2D)
638638
return path.polygons_full
639639

640640
def _intersections_normal(self, z: float):

tidy3d/components/geometry/primitives.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def _do_intersections_tilted_plane(
468468
section = mesh.section(plane_origin=origin, plane_normal=normal)
469469
if section is None:
470470
return []
471-
path, _ = section.to_planar(to_2D=to_2D)
471+
path, _ = section.to_2D(to_2D=to_2D)
472472
return path.polygons_full
473473

474474
def _intersections_normal(self, z: float):

tidy3d/components/geometry/triangulation.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ def update_convexity(vertices: list[Vertex], i: int) -> int:
6060
"""
6161
result = -1 if vertices[i].convexity == 0.0 else 0
6262
j = (i + 1) % len(vertices)
63-
vertices[i].convexity = np.cross(
64-
vertices[i].coordinate - vertices[i - 1].coordinate,
65-
vertices[j].coordinate - vertices[i].coordinate,
63+
vertices[i].convexity = np.linalg.det(
64+
[
65+
vertices[i].coordinate - vertices[i - 1].coordinate,
66+
vertices[j].coordinate - vertices[i].coordinate,
67+
]
6668
)
6769
if vertices[i].convexity == 0.0:
6870
result += 1
@@ -87,7 +89,8 @@ def is_inside(
8789
Flag indicating if the vertex is inside the triangle.
8890
"""
8991
return all(
90-
np.cross(triangle[i] - triangle[i - 1], vertex - triangle[i - 1]) > 0 for i in range(3)
92+
np.linalg.det([triangle[i] - triangle[i - 1], vertex - triangle[i - 1]]) > 0
93+
for i in range(3)
9194
)
9295

9396

0 commit comments

Comments
 (0)