Skip to content

Commit 3aeee84

Browse files
fix(geometry): remove validators on the number of geometries in ClipOperation
1 parent 2ce5542 commit 3aeee84

File tree

4 files changed

+92
-92
lines changed

4 files changed

+92
-92
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5252
### Changed
5353
- Improved performance of antenna metrics calculation by utilizing cached wave amplitude calculations instead of recomputing wave amplitudes for each port excitation in the `TerminalComponentModelerData`.
5454
- Changed hashing method in `Tidy3dBaseModel` from sha256 to md5.
55-
- Allowing for more geometries in a ClipOperation geometry.
55+
- Removed validators on limiting the number of geometries in a ClipOperation geometry.
5656
- Improved the speed of computing `Box` shape derivatives when used inside a `GeometryGroup`.
5757
- All RF and microwave specific components now inherit from `MicrowaveBaseModel`.
5858
- `DirectivityMonitor` now forces `far_field_approx` to `True`, which was previously configurable.

tests/test_components/test_scene.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pytest
1010

1111
import tidy3d as td
12-
from tidy3d.components.scene import MAX_GEOMETRY_COUNT, MAX_NUM_MEDIUMS
12+
from tidy3d.components.scene import MAX_NUM_MEDIUMS
1313
from tidy3d.components.viz import STRUCTURE_EPS_CMAP, STRUCTURE_EPS_CMAP_R
1414
from tidy3d.exceptions import SetupError
1515

@@ -333,37 +333,37 @@ def test_perturbed_mediums_copy(unstructured, z):
333333
assert isinstance(new_scene.structures[0].medium, td.CustomPoleResidue)
334334

335335

336-
def test_max_geometry_validation():
337-
too_many = [td.Box(size=(1, 1, 1)) for _ in range(MAX_GEOMETRY_COUNT + 1)]
338-
339-
fine = [
340-
td.Structure(
341-
geometry=td.ClipOperation(
342-
operation="union",
343-
geometry_a=td.Box(size=(1, 1, 1)),
344-
geometry_b=td.GeometryGroup(geometries=too_many),
345-
),
346-
medium=td.Medium(permittivity=2.0),
347-
),
348-
td.Structure(
349-
geometry=td.GeometryGroup(geometries=too_many),
350-
medium=td.Medium(permittivity=2.0),
351-
),
352-
]
353-
_ = td.Scene(structures=fine)
354-
355-
not_fine = [
356-
td.Structure(
357-
geometry=td.ClipOperation(
358-
operation="difference",
359-
geometry_a=td.Box(size=(1, 1, 1)),
360-
geometry_b=td.GeometryGroup(geometries=too_many),
361-
),
362-
medium=td.Medium(permittivity=2.0),
363-
),
364-
]
365-
with pytest.raises(pd.ValidationError, match=f" {MAX_GEOMETRY_COUNT + 2} "):
366-
_ = td.Scene(structures=not_fine)
336+
# def test_max_geometry_validation():
337+
# too_many = [td.Box(size=(1, 1, 1)) for _ in range(MAX_GEOMETRY_COUNT + 1)]
338+
339+
# fine = [
340+
# td.Structure(
341+
# geometry=td.ClipOperation(
342+
# operation="union",
343+
# geometry_a=td.Box(size=(1, 1, 1)),
344+
# geometry_b=td.GeometryGroup(geometries=too_many),
345+
# ),
346+
# medium=td.Medium(permittivity=2.0),
347+
# ),
348+
# td.Structure(
349+
# geometry=td.GeometryGroup(geometries=too_many),
350+
# medium=td.Medium(permittivity=2.0),
351+
# ),
352+
# ]
353+
# _ = td.Scene(structures=fine)
354+
355+
# not_fine = [
356+
# td.Structure(
357+
# geometry=td.ClipOperation(
358+
# operation="difference",
359+
# geometry_a=td.Box(size=(1, 1, 1)),
360+
# geometry_b=td.GeometryGroup(geometries=too_many),
361+
# ),
362+
# medium=td.Medium(permittivity=2.0),
363+
# ),
364+
# ]
365+
# with pytest.raises(pd.ValidationError, match=f" {MAX_GEOMETRY_COUNT + 2} "):
366+
# _ = td.Scene(structures=not_fine)
367367

368368

369369
def test_structure_manual_priority():

tests/test_components/test_simulation.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import tidy3d as td
1515
from tidy3d.components import simulation
16-
from tidy3d.components.scene import MAX_GEOMETRY_COUNT, MAX_NUM_MEDIUMS
16+
from tidy3d.components.scene import MAX_NUM_MEDIUMS
1717
from tidy3d.components.simulation import MAX_NUM_SOURCES
1818
from tidy3d.exceptions import SetupError, Tidy3dError, Tidy3dKeyError
1919
from tidy3d.plugins.mode import ModeSolver
@@ -673,38 +673,38 @@ def test_validate_mnt_size(monkeypatch):
673673
s._validate_monitor_size()
674674

675675

676-
def test_max_geometry_validation():
677-
gs = td.GridSpec(wavelength=1.0)
678-
too_many = [td.Box(size=(1, 1, 1)) for _ in range(MAX_GEOMETRY_COUNT + 1)]
679-
680-
fine = [
681-
td.Structure(
682-
geometry=td.ClipOperation(
683-
operation="union",
684-
geometry_a=td.Box(size=(1, 1, 1)),
685-
geometry_b=td.GeometryGroup(geometries=too_many),
686-
),
687-
medium=td.Medium(permittivity=2.0),
688-
),
689-
td.Structure(
690-
geometry=td.GeometryGroup(geometries=too_many),
691-
medium=td.Medium(permittivity=2.0),
692-
),
693-
]
694-
_ = td.Simulation(size=(1, 1, 1), run_time=1, grid_spec=gs, structures=fine)
695-
696-
not_fine = [
697-
td.Structure(
698-
geometry=td.ClipOperation(
699-
operation="difference",
700-
geometry_a=td.Box(size=(1, 1, 1)),
701-
geometry_b=td.GeometryGroup(geometries=too_many),
702-
),
703-
medium=td.Medium(permittivity=2.0),
704-
),
705-
]
706-
with pytest.raises(pydantic.ValidationError, match=f" {MAX_GEOMETRY_COUNT + 2} "):
707-
_ = td.Simulation(size=(1, 1, 1), run_time=1, grid_spec=gs, structures=not_fine)
676+
# def test_max_geometry_validation():
677+
# gs = td.GridSpec(wavelength=1.0)
678+
# too_many = [td.Box(size=(1, 1, 1)) for _ in range(MAX_GEOMETRY_COUNT + 1)]
679+
680+
# fine = [
681+
# td.Structure(
682+
# geometry=td.ClipOperation(
683+
# operation="union",
684+
# geometry_a=td.Box(size=(1, 1, 1)),
685+
# geometry_b=td.GeometryGroup(geometries=too_many),
686+
# ),
687+
# medium=td.Medium(permittivity=2.0),
688+
# ),
689+
# td.Structure(
690+
# geometry=td.GeometryGroup(geometries=too_many),
691+
# medium=td.Medium(permittivity=2.0),
692+
# ),
693+
# ]
694+
# _ = td.Simulation(size=(1, 1, 1), run_time=1, grid_spec=gs, structures=fine)
695+
696+
# not_fine = [
697+
# td.Structure(
698+
# geometry=td.ClipOperation(
699+
# operation="difference",
700+
# geometry_a=td.Box(size=(1, 1, 1)),
701+
# geometry_b=td.GeometryGroup(geometries=too_many),
702+
# ),
703+
# medium=td.Medium(permittivity=2.0),
704+
# ),
705+
# ]
706+
# with pytest.raises(pydantic.ValidationError, match=f" {MAX_GEOMETRY_COUNT + 2} "):
707+
# _ = td.Simulation(size=(1, 1, 1), run_time=1, grid_spec=gs, structures=not_fine)
708708

709709

710710
def test_no_monitor():

tidy3d/components/scene.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
TriangularGridDataset,
4040
UnstructuredGridDataset,
4141
)
42-
from .geometry.base import Box, ClipOperation, GeometryGroup
43-
from .geometry.utils import flatten_groups, merging_geometries_on_plane, traverse_geometries
42+
from .geometry.base import Box
43+
from .geometry.utils import merging_geometries_on_plane
4444
from .grid.grid import Coords, Grid
4545
from .material.multi_physics import MultiPhysicsMedium
4646
from .medium import (
@@ -82,8 +82,8 @@
8282
# maximum number of mediums supported
8383
MAX_NUM_MEDIUMS = 65530
8484

85-
# maximum geometry count in a single structure
86-
MAX_GEOMETRY_COUNT = 5000
85+
# # maximum geometry count in a single structure
86+
# MAX_GEOMETRY_COUNT = 5000
8787

8888
# warn and error out if the same medium is present in too many structures
8989
WARN_STRUCTURES_PER_MEDIUM = 200
@@ -175,28 +175,28 @@ def _validate_mediums(cls, val):
175175

176176
return val
177177

178-
@pd.validator("structures", always=True)
179-
def _validate_num_geometries(cls, val):
180-
"""Error if too many geometries in a single structure."""
181-
182-
if val is None:
183-
return val
184-
185-
for i, structure in enumerate(val):
186-
for geometry in flatten_groups(structure.geometry, flatten_transformed=True):
187-
count = sum(
188-
1
189-
for g in traverse_geometries(geometry)
190-
if not isinstance(g, (GeometryGroup, ClipOperation))
191-
)
192-
if count > MAX_GEOMETRY_COUNT:
193-
raise SetupError(
194-
f"Structure at 'structures[{i}]' has {count} geometries that cannot be "
195-
f"flattened. A maximum of {MAX_GEOMETRY_COUNT} is supported due to "
196-
f"preprocessing performance."
197-
)
198-
199-
return val
178+
# @pd.validator("structures", always=True)
179+
# def _validate_num_geometries(cls, val):
180+
# """Error if too many geometries in a single structure."""
181+
182+
# if val is None:
183+
# return val
184+
185+
# for i, structure in enumerate(val):
186+
# for geometry in flatten_groups(structure.geometry, flatten_transformed=True):
187+
# count = sum(
188+
# 1
189+
# for g in traverse_geometries(geometry)
190+
# if not isinstance(g, (GeometryGroup, ClipOperation))
191+
# )
192+
# if count > MAX_GEOMETRY_COUNT:
193+
# raise SetupError(
194+
# f"Structure at 'structures[{i}]' has {count} geometries that cannot be "
195+
# f"flattened. A maximum of {MAX_GEOMETRY_COUNT} is supported due to "
196+
# f"preprocessing performance."
197+
# )
198+
199+
# return val
200200

201201
@pd.validator("structures", always=True)
202202
def _validate_structures_per_medium(cls, val):

0 commit comments

Comments
 (0)