Skip to content

Commit eb1e9ed

Browse files
Gregory RobertsGregory Roberts
Gregory Roberts
authored and
Gregory Roberts
committed
feat[frontend]: rng in pytest and test cleanup
1 parent 33642e7 commit eb1e9ed

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

tests/test_components/test_viz.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Tests visualization operations."""
22

33
import matplotlib.pyplot as plt
4-
import numpy as np
54
import pydantic.v1 as pd
65
import pytest
76
import tidy3d as td
@@ -147,13 +146,11 @@ def plot_with_viz_spec(alpha, facecolor, edgecolor=None, use_viz_spec=True):
147146
plt.show()
148147

149148

150-
def plot_with_multi_viz_spec(alphas, facecolors, edgecolors, use_viz_spec=True):
149+
def plot_with_multi_viz_spec(alphas, facecolors, edgecolors, rng, use_viz_spec=True):
151150
"""
152151
Helper function for plotting simulations with multiple visulation specs via simluation
153152
plotting function.
154153
"""
155-
np.random.seed(3726423)
156-
157154
viz_specs = [
158155
td.VisualizationSpec(
159156
facecolor=facecolors[idx], edgecolor=edgecolors[idx], alpha=alphas[idx]
@@ -169,8 +166,8 @@ def plot_with_multi_viz_spec(alphas, facecolors, edgecolors, use_viz_spec=True):
169166

170167
structures = []
171168
for idx in range(0, len(viz_specs)):
172-
center = tuple(list(np.random.uniform(-3, 3, 2)) + [0])
173-
size = tuple(np.random.uniform(1, 2, 3))
169+
center = tuple(list(rng.uniform(-3, 3, 2)) + [0])
170+
size = tuple(rng.uniform(1, 2, 3))
174171
box = td.Box(center=center, size=size)
175172

176173
structures.append(td.Structure(geometry=box, medium=media[idx]))
@@ -180,12 +177,6 @@ def plot_with_multi_viz_spec(alphas, facecolors, edgecolors, use_viz_spec=True):
180177
run_time=1e-12,
181178
structures=structures,
182179
grid_spec=td.GridSpec(wavelength=1.0),
183-
boundary_spec=td.BoundarySpec(
184-
x=td.Boundary.pml(num_layers=20),
185-
),
186-
shutoff=1e-6,
187-
courant=0.8,
188-
subpixel=False,
189180
)
190181

191182
sim.plot(z=0.0)
@@ -217,7 +208,7 @@ def test_plot_from_structure_local():
217208

218209

219210
@pytest.mark.skip(reason="Skipping test for CI, but useful for debugging locally with graphics.")
220-
def test_plot_multi_from_structure_local():
211+
def test_plot_multi_from_structure_local(rng):
221212
"""
222213
Local test for visualizing output when creating multiple structures with variety of
223214
visualization specs.
@@ -226,10 +217,12 @@ def test_plot_multi_from_structure_local():
226217
alphas=[0.5, 0.75, 0.25, 0.4],
227218
facecolors=["red", "green", "blue", "orange"],
228219
edgecolors=["black", "cyan", "magenta", "brown"],
220+
rng=rng,
229221
)
230222
plot_with_multi_viz_spec(
231223
alphas=[0.5, 0.75, 0.25, 0.4],
232224
facecolors=["red", "green", "blue", "orange"],
233225
edgecolors=["black", "cyan", "magenta", "brown"],
226+
rng=rng,
234227
use_viz_spec=False,
235228
)

0 commit comments

Comments
 (0)