Skip to content

Commit 1a438fb

Browse files
authored
Merge pull request #102 from gdsfactory/test/improve-test-suite
test: remove redundant tests, add workflow integration tests
2 parents ac8e7e0 + eec6316 commit 1a438fb

8 files changed

Lines changed: 683 additions & 382 deletions

File tree

src/gsim/palace/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def _configure_ports_on_component(self, stack: LayerStack) -> None: # noqa: ARG
651651
raise ValueError("No component set")
652652

653653
# Configure regular ports
654-
for port_config in self.ports:
654+
for port_config in self.ports or []:
655655
if self.simulation_type != "driven":
656656
port_config.excited = False
657657
if port_config.name is None:
@@ -698,7 +698,7 @@ def _configure_ports_on_component(self, stack: LayerStack) -> None: # noqa: ARG
698698
gf_port.info["capacitance"] = port_config.capacitance
699699

700700
# Configure CPW ports
701-
for cpw_config in self.cpw_ports:
701+
for cpw_config in self.cpw_ports or []:
702702
# Find the single gdsfactory port at the signal center
703703
gf_port = None
704704
for p in component.ports:

src/gsim/palace/mesh/config_generator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ def generate_palace_config(
4949
"""
5050
from gsim.palace.ports.config import PortGeometry
5151

52-
if simulation_type not in ("driven", "eigenmode", "electrostatics"):
52+
if simulation_type not in (
53+
"driven",
54+
"eigenmode",
55+
"electrostatic",
56+
"electrostatics",
57+
):
5358
raise ValueError(f"Unsupported simulation type: {simulation_type}")
5459

5560
# Use driven_config if provided, otherwise fall back to legacy parameters

tests/meep/test_meep_models.py

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
WavelengthConfig,
1818
)
1919
from gsim.meep.models.config import (
20-
LayerStackEntry,
21-
MaterialData,
22-
PortData,
2320
StoppingConfig,
2421
SymmetryEntry,
2522
)
@@ -180,88 +177,6 @@ def test_to_json(self, tmp_path):
180177
assert data["stopping"]["run_after_sources"] == 200.0
181178

182179

183-
class TestPortData:
184-
"""Test PortData model."""
185-
186-
def test_creation(self):
187-
p = PortData(
188-
name="o1",
189-
center=[0.0, 0.0, 0.11],
190-
orientation=0.0,
191-
width=0.5,
192-
normal_axis=0,
193-
direction="-",
194-
is_source=True,
195-
)
196-
assert p.name == "o1"
197-
assert p.is_source
198-
199-
def test_model_dump(self):
200-
p = PortData(
201-
name="o1",
202-
center=[0.0, 0.0, 0.11],
203-
orientation=180.0,
204-
width=0.5,
205-
normal_axis=0,
206-
direction="+",
207-
)
208-
d = p.model_dump()
209-
assert d["name"] == "o1"
210-
assert d["direction"] == "+"
211-
212-
213-
class TestLayerStackEntry:
214-
"""Test LayerStackEntry model."""
215-
216-
def test_creation(self):
217-
entry = LayerStackEntry(
218-
layer_name="core",
219-
gds_layer=[1, 0],
220-
zmin=0.0,
221-
zmax=0.22,
222-
material="si",
223-
)
224-
assert entry.layer_name == "core"
225-
assert entry.gds_layer == [1, 0]
226-
assert entry.sidewall_angle == 0.0
227-
228-
def test_with_sidewall_angle(self):
229-
entry = LayerStackEntry(
230-
layer_name="core",
231-
gds_layer=[1, 0],
232-
zmin=0.0,
233-
zmax=0.22,
234-
material="si",
235-
sidewall_angle=10.0,
236-
)
237-
assert entry.sidewall_angle == 10.0
238-
239-
def test_model_dump(self):
240-
entry = LayerStackEntry(
241-
layer_name="clad",
242-
gds_layer=[2, 0],
243-
zmin=-0.5,
244-
zmax=0.5,
245-
material="SiO2",
246-
)
247-
d = entry.model_dump()
248-
assert d["layer_name"] == "clad"
249-
assert d["gds_layer"] == [2, 0]
250-
251-
252-
class TestMaterialData:
253-
"""Test MaterialData model."""
254-
255-
def test_creation(self):
256-
m = MaterialData(refractive_index=3.47)
257-
assert m.refractive_index == 3.47
258-
assert m.extinction_coeff == 0.0
259-
260-
def test_with_extinction(self):
261-
m = MaterialData(refractive_index=3.47, extinction_coeff=0.01)
262-
assert m.extinction_coeff == 0.01
263-
264-
265180
# ---------------------------------------------------------------------------
266181
# Port extraction tests
267182
# ---------------------------------------------------------------------------
@@ -521,34 +436,6 @@ def test_to_dict_omits_zero_angle(self):
521436
assert "sidewall_angle" not in d
522437

523438

524-
# ---------------------------------------------------------------------------
525-
# Import test
526-
# ---------------------------------------------------------------------------
527-
528-
529-
class TestImportWithoutMeep:
530-
"""Verify module imports work without meep installed."""
531-
532-
def test_import_all_public_api(self):
533-
from gsim.meep import (
534-
DomainConfig,
535-
ResolutionConfig,
536-
SimConfig,
537-
Simulation,
538-
SourceConfig,
539-
SParameterResult,
540-
WavelengthConfig,
541-
)
542-
543-
assert WavelengthConfig is not None
544-
assert DomainConfig is not None
545-
assert ResolutionConfig is not None
546-
assert SParameterResult is not None
547-
assert SimConfig is not None
548-
assert SourceConfig is not None
549-
assert Simulation is not None
550-
551-
552439
# ---------------------------------------------------------------------------
553440
# DomainConfig tests
554441
# ---------------------------------------------------------------------------
@@ -1088,6 +975,7 @@ def test_build_sim_overlay(self):
1088975
import numpy as np
1089976

1090977
from gsim.common.geometry_model import GeometryModel, Prism
978+
from gsim.meep.models.config import PortData
1091979
from gsim.meep.overlay import build_sim_overlay
1092980

1093981
gm = GeometryModel(

tests/meep/test_simulation.py

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
from gsim.meep import (
99
FDTD,
1010
Domain,
11-
Geometry,
1211
Material,
1312
ModeSource,
1413
Simulation,
15-
Symmetry,
1614
)
1715

1816
# ---------------------------------------------------------------------------
@@ -23,15 +21,6 @@
2321
class TestMaterial:
2422
"""Tests for the Material model."""
2523

26-
def test_basic(self):
27-
m = Material(n=3.47)
28-
assert m.n == 3.47
29-
assert m.k == 0.0
30-
31-
def test_with_extinction(self):
32-
m = Material(n=3.47, k=0.01)
33-
assert m.k == 0.01
34-
3524
def test_n_must_be_positive(self):
3625
with pytest.raises(ValidationError):
3726
Material(n=0)
@@ -41,65 +30,9 @@ def test_k_must_be_non_negative(self):
4130
Material(n=1.5, k=-0.1)
4231

4332

44-
class TestModeSource:
45-
"""Tests for the ModeSource model."""
46-
47-
def test_defaults(self):
48-
s = ModeSource()
49-
assert s.port is None
50-
assert s.wavelength == 1.55
51-
assert s.wavelength_span == 0.1
52-
assert s.num_freqs == 11
53-
54-
def test_custom(self):
55-
s = ModeSource(port="o1", wavelength=1.31, wavelength_span=0.05, num_freqs=21)
56-
assert s.port == "o1"
57-
assert s.wavelength == 1.31
58-
assert s.wavelength_span == 0.05
59-
assert s.num_freqs == 21
60-
61-
62-
class TestDomain:
63-
"""Tests for the Domain model."""
64-
65-
def test_defaults(self):
66-
d = Domain()
67-
assert d.pml == 1.0
68-
assert d.margin == 0.5
69-
assert d.margin_z_above == 0.5
70-
assert d.margin_z_below == 0.5
71-
assert d.port_margin == 0.5
72-
assert d.extend_ports == 0.0
73-
assert d.source_port_offset == 0.1
74-
assert d.distance_source_to_monitors == 0.2
75-
assert d.symmetries == []
76-
77-
def test_custom(self):
78-
d = Domain(pml=0.5, margin=0.2, port_margin=0.3)
79-
assert d.pml == 0.5
80-
assert d.margin == 0.2
81-
assert d.port_margin == 0.3
82-
83-
def test_symmetries(self):
84-
d = Domain(symmetries=[Symmetry(direction="Y", phase=-1)])
85-
assert len(d.symmetries) == 1
86-
assert d.symmetries[0].direction == "Y"
87-
assert d.symmetries[0].phase == -1
88-
89-
9033
class TestStoppingFields:
9134
"""Tests for the FDTD stopping criteria."""
9235

93-
def test_defaults(self):
94-
f = FDTD()
95-
assert f.stopping == "energy_decay"
96-
assert f.max_time == 2000.0
97-
assert f.stopping_threshold == 0.01
98-
assert f.stopping_min_time == 100.0
99-
assert f.stopping_component == "Ey"
100-
assert f.stopping_dt == 20.0
101-
assert f.stopping_monitor_port is None
102-
10336
def test_fixed_mode(self):
10437
f = FDTD(stopping="fixed", max_time=100)
10538
assert f.stopping == "fixed"
@@ -137,42 +70,11 @@ def test_invalid_mode(self):
13770
class TestFDTD:
13871
"""Tests for the FDTD model."""
13972

140-
def test_defaults(self):
141-
f = FDTD()
142-
assert f.resolution == 32
143-
assert f.stopping == "energy_decay"
144-
assert f.max_time == 2000.0
145-
assert f.subpixel is False
146-
assert f.simplify_tol == 0.0
147-
148-
def test_with_custom_stopping(self):
149-
f = FDTD(stopping="field_decay", stopping_threshold=1e-4)
150-
assert f.stopping == "field_decay"
151-
assert f.stopping_threshold == 1e-4
152-
15373
def test_resolution_custom(self):
15474
f = FDTD(resolution=64)
15575
assert f.resolution == 64
15676

15777

158-
class TestFDTDDiagnostics:
159-
"""Tests for the FDTD diagnostics settings."""
160-
161-
def test_defaults(self):
162-
f = FDTD()
163-
assert f.save_geometry is True
164-
assert f.save_fields is True
165-
assert f.save_animation is False
166-
assert f.preview_only is False
167-
assert f.verbose_interval == 0
168-
169-
def test_custom(self):
170-
f = FDTD(save_animation=True, verbose_interval=5.0, preview_only=True)
171-
assert f.save_animation is True
172-
assert f.verbose_interval == 5.0
173-
assert f.preview_only is True
174-
175-
17678
# ---------------------------------------------------------------------------
17779
# Material normalization
17880
# ---------------------------------------------------------------------------
@@ -502,42 +404,3 @@ def test_diagnostics_translation(self):
502404
cfg = sim._diagnostics_config()
503405
assert cfg.save_animation is True
504406
assert cfg.preview_only is True
505-
506-
507-
# ---------------------------------------------------------------------------
508-
# Import tests
509-
# ---------------------------------------------------------------------------
510-
511-
512-
class TestImports:
513-
"""Tests for importing the new declarative API."""
514-
515-
def test_import_all_new_api(self):
516-
from gsim.meep import (
517-
FDTD,
518-
Domain,
519-
Material,
520-
ModeSource,
521-
Simulation,
522-
Symmetry,
523-
)
524-
525-
assert all(
526-
cls is not None
527-
for cls in [
528-
Domain,
529-
FDTD,
530-
Geometry,
531-
Material,
532-
ModeSource,
533-
Simulation,
534-
Symmetry,
535-
]
536-
)
537-
538-
def test_simulation_instantiation(self):
539-
sim = Simulation()
540-
assert sim.geometry.component is None
541-
assert sim.materials == {}
542-
assert sim.monitors == []
543-
assert sim.solver.resolution == 32

0 commit comments

Comments
 (0)