Skip to content

Commit e87ce81

Browse files
authored
Merge pull request #567 from gdsfactory/fix_tidy3d_holes_and_update
Fix tidy3d holes and update tidy3d
2 parents 7197051 + 46c76b5 commit e87ce81

7 files changed

Lines changed: 5728 additions & 82 deletions

File tree

.github/workflows/test_code.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
matrix:
2323
plugin: [femwell, gmsh, meow, sax, tidy3d, klayout, vlsir]
2424
os: [ubuntu-latest]
25-
python-version: [3.11]
25+
python-version: [3.12]
2626
exclude:
2727
- plugin: femwell
2828
os: macos-latest

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ gplugins/klayout/layers.lyp
1212
gplugins/klayout/tech.lyt
1313
notebooks/luminescent_runs/
1414

15-
uv.lock
16-
1715
# C extensions
1816
*.csv
1917
*.npz

gplugins/common/base_models/component.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,3 @@ def get_layer_bbox(
248248
def get_layer_center(self, layername: str) -> tuple[float, float, float]:
249249
bbox = self.get_layer_bbox(layername)
250250
return tuple(np.mean(bbox, axis=0))
251-
252-
def get_vertices(self, layer_name: str, buffer: float = 0.0):
253-
poly = self.polygons[layer_name].buffer(buffer, join_style="mitre")
254-
match poly:
255-
case MultiPolygon():
256-
verts = tuple(tuple(p.exterior.coords) for p in poly.geoms)
257-
case Polygon():
258-
verts = (tuple(poly.exterior.coords),)
259-
case _:
260-
raise TypeError(f"Invalid polygon type: {type(poly)}")
261-
return verts

gplugins/tidy3d/component.py

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from gdsfactory.pdk import get_layer_stack
2828
from gdsfactory.technology import LayerStack
2929
from pydantic import NonNegativeFloat
30+
from tidy3d.components.geometry.base import from_shapely
3031
from tidy3d.components.types import Symmetry
3132
from tidy3d.plugins.smatrix import ComponentModeler, Port
3233

@@ -80,28 +81,26 @@ class Tidy3DComponent(LayeredComponentBase):
8081
reference_plane: Literal["bottom", "middle", "top"] = "middle"
8182

8283
@cached_property
83-
def polyslabs(self) -> dict[str, tuple[td.PolySlab, ...]]:
84+
def polyslabs(self) -> dict[str, tuple[td.Geometry, ...]]:
8485
"""Returns a dictionary of PolySlab instances for each layer in the component.
8586
8687
Returns:
8788
dict[str, tuple[td.PolySlab, ...]]: A dictionary mapping layer names to tuples of PolySlab instances.
8889
"""
8990
slabs = {}
9091
layers = sort_layers(self.geometry_layers, sort_by="mesh_order", reverse=True)
91-
9292
for name, layer in layers.items():
9393
bbox = self.get_layer_bbox(name)
94-
slabs[name] = tuple(
95-
td.PolySlab(
96-
vertices=v,
97-
axis=2,
98-
slab_bounds=(bbox[0][2], bbox[1][2]),
99-
sidewall_angle=np.deg2rad(layer.sidewall_angle),
100-
reference_plane=self.reference_plane,
101-
dilation=self.dilation,
102-
)
103-
for v in self.get_vertices(name)
94+
shape = self.polygons[name].buffer(distance=0.0, join_style="mitre")
95+
geom = from_shapely(
96+
shape,
97+
axis=2,
98+
slab_bounds=(bbox[0][2], bbox[1][2]),
99+
dilation=self.dilation,
100+
sidewall_angle=np.deg2rad(layer.sidewall_angle),
101+
reference_plane=self.reference_plane,
104102
)
103+
slabs[name] = geom
105104

106105
return slabs
107106

@@ -113,19 +112,14 @@ def structures(self) -> list[td.Structure]:
113112
list[td.Structure]: A list of Structure instances.
114113
"""
115114
structures = []
116-
for name, polys in self.polyslabs.items():
117-
structures.extend(
118-
[
119-
td.Structure(
120-
geometry=poly,
121-
medium=self.material_mapping[
122-
self.geometry_layers[name].material
123-
],
124-
name=f"{name}_{idx}",
125-
)
126-
for idx, poly in enumerate(polys)
127-
]
115+
for name, poly in self.polyslabs.items():
116+
structure = td.Structure(
117+
geometry=poly,
118+
medium=self.material_mapping[self.geometry_layers[name].material],
119+
name=name,
128120
)
121+
structures.append(structure)
122+
129123
return structures
130124

131125
def get_ports(
@@ -366,24 +360,23 @@ def plot_slice(
366360
for name, layer in layers.items():
367361
if name not in self.polyslabs:
368362
continue
369-
polys = self.polyslabs[name]
370-
371-
for idx, poly in enumerate(polys):
372-
axis, position = poly.parse_xyz_kwargs(x=x, y=y, z=z)
373-
xlim, ylim = poly._get_plot_limits(axis=axis, buffer=0)
374-
xmin, xmax = min(xmin, xlim[0]), max(xmax, xlim[1])
375-
ymin, ymax = min(ymin, ylim[0]), max(ymax, ylim[1])
376-
for shape in poly.intersections_plane(x=x, y=y, z=z):
377-
_shape = td.Geometry.evaluate_inf_shape(shape)
378-
patch = td.components.viz.polygon_patch(
379-
_shape,
380-
facecolor=colors[name],
381-
edgecolor="k",
382-
linewidth=0.5,
383-
label=name if idx == 0 else None,
384-
zorder=order_map[layer.mesh_order],
385-
)
386-
ax.add_artist(patch)
363+
poly = self.polyslabs[name]
364+
365+
axis, position = poly.parse_xyz_kwargs(x=x, y=y, z=z)
366+
xlim, ylim = poly._get_plot_limits(axis=axis, buffer=0)
367+
xmin, xmax = min(xmin, xlim[0]), max(xmax, xlim[1])
368+
ymin, ymax = min(ymin, ylim[0]), max(ymax, ylim[1])
369+
for idx, shape in enumerate(poly.intersections_plane(x=x, y=y, z=z)):
370+
_shape = td.Geometry.evaluate_inf_shape(shape)
371+
patch = td.components.viz.polygon_patch(
372+
_shape,
373+
facecolor=colors[name],
374+
edgecolor="k",
375+
linewidth=0.5,
376+
label=name if idx == 0 else None,
377+
zorder=order_map[layer.mesh_order],
378+
)
379+
ax.add_artist(patch)
387380

388381
size = list(self.size)
389382
cmin = list(self.bbox[0])
@@ -713,8 +706,8 @@ def write_sparameters_batch(
713706
center_z="core",
714707
# plot_simulation_x=10,
715708
# plot_simulation_layer_name="core",
716-
# plot_epsilon=True,
717-
filepath="straight2",
709+
plot_epsilon=True,
710+
# filepath="straight2",
718711
# plot_mode_port_name="o1",
719712
# plot_mode_index=1,
720713
# mode_spec=mode_spec,

gplugins/tidy3d/tests/test_plot_simulation_grating_coupler.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@
88
fiber_port_name = "o2"
99

1010

11-
def test_plot_simulation_grating_coupler() -> None:
12-
"""Checks simulation for a grating_coupler_elliptical_arbitrary in 2D."""
13-
c = gf.components.grating_coupler_elliptical_arbitrary(
14-
widths=(0.343,) * 25, gaps=(0.345,) * 25
15-
)
16-
gt.write_sparameters_grating_coupler(
17-
component=c,
18-
is_3d=False,
19-
fiber_angle_deg=20,
20-
fiber_xoffset=0,
21-
dirpath=PATH.sparameters_repo,
22-
run=False,
23-
)
24-
25-
2611
if __name__ == "__main__":
2712
c = gf.components.grating_coupler_elliptical_arbitrary(
2813
widths=(0.343,) * 25, gaps=(0.345,) * 25

pyproject.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ classifiers = [
1313
"Operating System :: OS Independent"
1414
]
1515
dependencies = [
16-
"gdsfactory>=9.0.0",
16+
"gdsfactory>=9.3.5",
1717
"pint",
1818
"gdstk",
1919
"tqdm",
@@ -34,10 +34,9 @@ dev = [
3434
"pytest",
3535
"pytest-cov",
3636
"pytest_regressions",
37-
"pyswarms",
38-
"autograd"
37+
"pyswarms"
3938
]
40-
devsim = ["devsim", "pyvista<=0.43.8", "tidy3d>=2.7.8,<2.8"]
39+
devsim = ["devsim", "pyvista<=0.43.8", "tidy3d>=2.8.2,<2.9"]
4140
docs = ["jupytext", "matplotlib", "jupyter-book~=1.0", "pyvista[all]<=0.43.8"]
4241
femwell = ["femwell~=0.1.11", "meshwell~=1.0.7"]
4342
gfviz = ["jinja2", "fastapi", "shapely", "natsort"]
@@ -59,9 +58,8 @@ meow = [
5958
"jax>=0.4.26",
6059
"jaxlib>=0.4.26",
6160
"flax>=0.8.2",
62-
"meow-sim>=0.11,<0.13",
63-
"tidy3d>=2.7.8,<2.8",
64-
"scipy<=1.14.1"
61+
"meow-sim>=0.12,<0.13",
62+
"tidy3d>=2.8.2,<2.9"
6563
]
6664
sax = [
6765
"jax>=0.4.26",
@@ -73,7 +71,7 @@ sax = [
7371
"ray"
7472
]
7573
schematic = ["bokeh", "ipywidgets", "natsort"]
76-
tidy3d = ["tidy3d>=2.7.8,<2.8", "meshio", "numpy", "meshwell~=1.0.7"]
74+
tidy3d = ["tidy3d>=2.8.2,<2.9", "meshio", "numpy", "meshwell~=1.0.7"]
7775
vlsir = ["vlsir", "vlsirtools"]
7876

7977
[tool.codespell]
@@ -93,7 +91,7 @@ strict = true
9391
reportUnusedExpression = false
9492

9593
[tool.pytest.ini_options]
96-
addopts = '--tb=short'
94+
addopts = "--assert=plain"
9795
norecursedirs = [
9896
"extra/*.py",
9997
'gplugins/devsim',

0 commit comments

Comments
 (0)