Skip to content

Commit 60f9714

Browse files
committed
Simulation._validate_boundary_spec_symmetry() now ignores 'name' attribute.
1 parent 3effb92 commit 60f9714

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- Giving opposite boundaries different names no longer causes a symmetry validator failure.
12+
1013
## [2.9.0rc2] - 2025-07-17
1114

1215
### Added

tests/test_components/test_simulation.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,24 +595,28 @@ def test_validate_symmetry_boundaries():
595595
# simulation with symmetry along an axis should have the same boundaries defined on both sides
596596
td.Simulation(
597597
size=(1, 1, 1),
598-
symmetry=(0, 1, 0),
598+
symmetry=(1, 1, 1),
599599
grid_spec=td.GridSpec.uniform(dl=0.1),
600600
run_time=1e-12,
601601
boundary_spec=td.BoundarySpec(
602602
x=td.Boundary.periodic(),
603-
y=td.Boundary.periodic(),
603+
y=td.Boundary(
604+
# Now give the plus and minus boundaries different names to confirm it does not matter.
605+
plus=td.PML(name="b1"),
606+
minus=td.PML(name="b2"),
607+
),
604608
z=td.Boundary.pml(),
605609
),
606610
)
607-
with pytest.raises(pydantic.ValidationError):
611+
with pytest.raises(pydantic.ValidationError, match="Symmetry"):
608612
td.Simulation(
609613
size=(1, 1, 1),
610-
symmetry=(0, 1, 0),
614+
symmetry=(1, 1, 1),
611615
grid_spec=td.GridSpec.uniform(dl=0.1),
612616
run_time=1e-12,
613617
boundary_spec=td.BoundarySpec(
614618
x=td.Boundary.periodic(),
615-
y=td.Boundary(plus=td.Boundary.pml(), minus=td.Boundary.periodic()),
619+
y=td.Boundary(plus=td.PML(num_layers=10), minus=td.PML(num_layers=20)),
616620
z=td.Boundary.pml(),
617621
),
618622
)

tidy3d/components/simulation.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,17 @@ def num_cells_in_monitor(monitor: Monitor) -> int:
420420
def _validate_boundary_spec_symmetry(cls, val, values):
421421
"""Error if symmetry is imposed along an axis but the boundary conditions are not the same
422422
on both sides."""
423+
424+
def equivalent(plus: BoundarySpec, minus: BoundarySpec) -> bool:
425+
"""Returns whether two boundary conditions are physically identical."""
426+
# Make copies of `plus` and `minus` with the `name` attribute set to "".
427+
plus_cpy = plus.updated_copy(name="")
428+
minus_cpy = minus.updated_copy(name="")
429+
return plus_cpy == minus_cpy
430+
423431
boundaries = [val.x, val.y, val.z]
424432
for ax, symmetry, ax_bounds in zip("xyz", values.get("symmetry"), boundaries):
425-
if symmetry != 0 and ax_bounds.plus != ax_bounds.minus:
433+
if symmetry != 0 and not equivalent(ax_bounds.plus, ax_bounds.minus):
426434
raise ValidationError(
427435
f"Symmetry '{symmetry}' along axis {ax} requires the same boundary "
428436
f"condition on both sides of the axis."

0 commit comments

Comments
 (0)