mrdk 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mrdk/__init__.py +31 -0
- mrdk/components/__init__.py +32 -0
- mrdk/components/_arc_heater.py +282 -0
- mrdk/components/_checks.py +94 -0
- mrdk/components/_heater.py +159 -0
- mrdk/components/_marker.py +36 -0
- mrdk/components/chain.py +165 -0
- mrdk/components/edge_coupler.py +82 -0
- mrdk/components/pulley.py +181 -0
- mrdk/components/resonator.py +725 -0
- mrdk/components/resonator_edge.py +755 -0
- mrdk/components/ring.py +245 -0
- mrdk/components/ring_edge.py +492 -0
- mrdk/components/ring_pcr.py +123 -0
- mrdk/die/__init__.py +36 -0
- mrdk/die/__main__.py +20 -0
- mrdk/die/assemble.py +536 -0
- mrdk/die/block.py +160 -0
- mrdk/die/compare.py +106 -0
- mrdk/die/device.py +186 -0
- mrdk/die/edge_row.py +342 -0
- mrdk/die/mask_prep.py +140 -0
- mrdk/die/provenance.py +219 -0
- mrdk/die/resonator_row.py +679 -0
- mrdk/die/rulecheck.py +399 -0
- mrdk/layer_roles.py +221 -0
- mrdk/manifest/__init__.py +13 -0
- mrdk/manifest/manifest.py +258 -0
- mrdk/manifest/records.py +110 -0
- mrdk/py.typed +0 -0
- mrdk/sim/__init__.py +61 -0
- mrdk/sim/coupling.py +640 -0
- mrdk/sim/materials.py +101 -0
- mrdk/sim/modes.py +402 -0
- mrdk/sim/ring_dispersion.py +278 -0
- mrdk-0.1.0.dist-info/METADATA +197 -0
- mrdk-0.1.0.dist-info/RECORD +39 -0
- mrdk-0.1.0.dist-info/WHEEL +4 -0
- mrdk-0.1.0.dist-info/licenses/LICENSE +202 -0
mrdk/__init__.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""mrdk: MicroResonator Design Kit.
|
|
2
|
+
|
|
3
|
+
Flow: physics targets -> layout -> device manifest -> measurement analysis.
|
|
4
|
+
|
|
5
|
+
Units: lengths and wavelengths in um (GDSFactory convention, e.g. 1.55 not 1550);
|
|
6
|
+
frequencies in Hz internally.
|
|
7
|
+
|
|
8
|
+
The base install has no heavy dependencies. Subpackages that need extra
|
|
9
|
+
packages say so in their own docstrings (``mrdk[layout]``, ``mrdk[sim]``).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from mrdk.layer_roles import (
|
|
13
|
+
CSPDK_SIN300,
|
|
14
|
+
GENERIC,
|
|
15
|
+
LayerRoles,
|
|
16
|
+
activate_pdk,
|
|
17
|
+
get_layer_roles,
|
|
18
|
+
register_layer_roles,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
__version__ = "0.1.0"
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"CSPDK_SIN300",
|
|
25
|
+
"GENERIC",
|
|
26
|
+
"LayerRoles",
|
|
27
|
+
"activate_pdk",
|
|
28
|
+
"__version__",
|
|
29
|
+
"get_layer_roles",
|
|
30
|
+
"register_layer_roles",
|
|
31
|
+
]
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Single layout components: rings and racetracks with heaters and pads, couplers, etc.
|
|
2
|
+
|
|
3
|
+
Every component function is decorated with ``@gf.cell``. Components take
|
|
4
|
+
cross-sections by name plus a per-PDK ``LayerRoles`` mapping; layers are never
|
|
5
|
+
hard-coded.
|
|
6
|
+
|
|
7
|
+
Units: lengths and wavelengths in um.
|
|
8
|
+
Requires the ``mrdk[layout]`` extra (gdsfactory).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from mrdk.components.chain import ring_chain
|
|
12
|
+
from mrdk.components.edge_coupler import edge_coupler
|
|
13
|
+
from mrdk.components.pulley import ring_pulley
|
|
14
|
+
from mrdk.components.resonator import BusCoupler, Resonator, resonator_chain
|
|
15
|
+
from mrdk.components.resonator_edge import resonator_edge
|
|
16
|
+
from mrdk.components.ring import ring_adddrop, ring_allpass
|
|
17
|
+
from mrdk.components.ring_edge import ring_edge
|
|
18
|
+
from mrdk.components.ring_pcr import ring_pcr
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"BusCoupler",
|
|
22
|
+
"Resonator",
|
|
23
|
+
"edge_coupler",
|
|
24
|
+
"ring_adddrop",
|
|
25
|
+
"ring_allpass",
|
|
26
|
+
"ring_chain",
|
|
27
|
+
"ring_edge",
|
|
28
|
+
"ring_pcr",
|
|
29
|
+
"resonator_chain",
|
|
30
|
+
"resonator_edge",
|
|
31
|
+
"ring_pulley",
|
|
32
|
+
]
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"""Arc heater around a ring, with vias, routing metal and pads (private helper).
|
|
2
|
+
|
|
3
|
+
The heater is a trace concentric with the ring that covers ``360 - opening_deg`` degrees. The
|
|
4
|
+
opening faces up (+y). Each end continues with a reverse-curvature "wing" of radius
|
|
5
|
+
``radius_away`` until it points straight up, then a straight stub (one trace width, or past
|
|
6
|
+
half the via); a via (if the PDK has one) sits at the end of each stub, and routing metal
|
|
7
|
+
carries each end on to a pad. ``direction=-1`` mirrors all of it to open downwards.
|
|
8
|
+
|
|
9
|
+
Units: lengths in um, angles in degrees.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import math
|
|
13
|
+
|
|
14
|
+
import gdsfactory as gf
|
|
15
|
+
|
|
16
|
+
from mrdk.components._checks import check_pad_clearance
|
|
17
|
+
from mrdk.layer_roles import LayerRoles
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def add_arc_heater(
|
|
21
|
+
c: gf.Component,
|
|
22
|
+
*,
|
|
23
|
+
roles: LayerRoles,
|
|
24
|
+
center: tuple[float, float],
|
|
25
|
+
radius: float,
|
|
26
|
+
heater_width: float | None,
|
|
27
|
+
route_width: float | None,
|
|
28
|
+
radius_away: float,
|
|
29
|
+
opening_deg: float,
|
|
30
|
+
pad_size: tuple[float, float],
|
|
31
|
+
pad_offset: float,
|
|
32
|
+
min_pad_gap: float,
|
|
33
|
+
pad_opening_inset: float,
|
|
34
|
+
port_names: tuple[str, str],
|
|
35
|
+
pad_clearance: float = 0.0,
|
|
36
|
+
direction: int | str = 1,
|
|
37
|
+
pad_min_y: float | None = None,
|
|
38
|
+
straight_length: float = 0.0,
|
|
39
|
+
) -> dict[str, float]:
|
|
40
|
+
"""Draw the arc heater into ``c`` and add two electrical ports (left pad, right pad).
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
c: component to draw into.
|
|
44
|
+
roles: PDK role mapping.
|
|
45
|
+
center: ring centre (x, y) (µm).
|
|
46
|
+
radius: heater centre-line radius (µm).
|
|
47
|
+
heater_width: trace width (µm); None uses the PDK heater cross-section default.
|
|
48
|
+
route_width: routing-metal width (µm); None uses the PDK routing cross-section default.
|
|
49
|
+
radius_away: radius of the reverse-curvature wings at the heater ends (µm).
|
|
50
|
+
opening_deg: angular opening of the arc, centred on +y (degrees, 0 < x < 180).
|
|
51
|
+
pad_size: pad (width, height) (µm).
|
|
52
|
+
pad_offset: distance from each via centre to the bottom edge of its pad (µm).
|
|
53
|
+
min_pad_gap: minimum distance between the two pads (µm); the pads move apart if needed.
|
|
54
|
+
pad_opening_inset: pad-opening inset inside the pad outline (µm), if the roles have one.
|
|
55
|
+
port_names: names of the (left, right) pad ports.
|
|
56
|
+
pad_clearance: minimum distance from each pad to any waveguide already drawn in
|
|
57
|
+
``c`` (µm); 0 skips the check.
|
|
58
|
+
direction: where the opening, leads and pads point: ``1`` or ``"up"`` (+y), ``-1`` or
|
|
59
|
+
``"down"`` (-y, everything mirrored about the ring centre), ``"right"`` (+x) or
|
|
60
|
+
``"left"`` (-x) (the construction turned by 90 degrees, so pads and leads stay
|
|
61
|
+
axis-aligned).
|
|
62
|
+
pad_min_y: if given, the pads' near edge is at least this far from the ring centre
|
|
63
|
+
along the opening direction (µm), moving them further out than ``pad_offset``
|
|
64
|
+
alone would (used to clear a bus).
|
|
65
|
+
straight_length: for a racetrack: length of its straights (µm). The heater is then a
|
|
66
|
+
stadium concentric with the racetrack: its two semicircles are centred at
|
|
67
|
+
(+-straight_length / 2, 0) from ``center``, it runs along the far straight, and
|
|
68
|
+
its opening spans the whole near straight (the coupling region) plus
|
|
69
|
+
``opening_deg / 2`` of each semicircle. 0 draws the plain arc heater.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
``heater_width_um``, ``heater_length_um`` (trace length), ``lead_top_um`` (farthest
|
|
73
|
+
point of the trace towards the opening, including half the width), ``lead_y_um`` (the
|
|
74
|
+
lead point), the pad centre ``pad_center_y_um`` and the pad centres' ``pad_left_x_um``
|
|
75
|
+
and ``pad_right_x_um``, relative to the ring centre (µm). The y values are measured
|
|
76
|
+
along the opening direction (positive towards the opening, whichever way it points).
|
|
77
|
+
The x values are across the opening (local axes turn with ``direction``). The
|
|
78
|
+
electrical ports are on the pads' outer edges, facing the opening direction (90, 270,
|
|
79
|
+
0 or 180 degrees for up, down, right, left).
|
|
80
|
+
"""
|
|
81
|
+
if not 0 < opening_deg < 180:
|
|
82
|
+
raise ValueError("heater opening_deg must be between 0 and 180 degrees")
|
|
83
|
+
if radius_away <= 0 or radius <= 0:
|
|
84
|
+
raise ValueError("heater radius and radius_away must be positive")
|
|
85
|
+
names = {1: "up", -1: "down", "up": "up", "down": "down", "right": "right", "left": "left"}
|
|
86
|
+
if direction not in names:
|
|
87
|
+
raise ValueError("direction must be 1, -1, 'up', 'down', 'right' or 'left'")
|
|
88
|
+
direction = names[direction]
|
|
89
|
+
if straight_length < 0:
|
|
90
|
+
raise ValueError("straight_length must not be negative")
|
|
91
|
+
cx, cy = center
|
|
92
|
+
|
|
93
|
+
# Local coordinates: x across the opening, y along it (positive towards the opening),
|
|
94
|
+
# both from the ring centre. "down" mirrors y; "right" and "left" turn by 90 degrees.
|
|
95
|
+
turned = direction in ("right", "left")
|
|
96
|
+
|
|
97
|
+
def to_abs(x: float, y: float) -> tuple[float, float]:
|
|
98
|
+
if direction == "up":
|
|
99
|
+
return cx + x, cy + y
|
|
100
|
+
if direction == "down":
|
|
101
|
+
return cx + x, cy - y
|
|
102
|
+
if direction == "right":
|
|
103
|
+
return cx + y, cy - x
|
|
104
|
+
return cx - y, cy + x # left
|
|
105
|
+
|
|
106
|
+
def box(x0: float, y0: float, x1: float, y1: float) -> list[tuple[float, float]]:
|
|
107
|
+
"""Axis-aligned rectangle from local bounds."""
|
|
108
|
+
(ax, ay), (bx, by) = to_abs(x0, y0), to_abs(x1, y1)
|
|
109
|
+
xa, xb = sorted((ax, bx))
|
|
110
|
+
ya, yb = sorted((ay, by))
|
|
111
|
+
return [(xa, ya), (xb, ya), (xb, yb), (xa, yb)]
|
|
112
|
+
|
|
113
|
+
hxs = gf.get_cross_section(
|
|
114
|
+
roles.heater, **({} if heater_width is None else {"width": heater_width})
|
|
115
|
+
)
|
|
116
|
+
hw = hxs.width
|
|
117
|
+
rxs = gf.get_cross_section(
|
|
118
|
+
roles.routing_metal, **({} if route_width is None else {"width": route_width})
|
|
119
|
+
)
|
|
120
|
+
rw = rxs.width
|
|
121
|
+
half = opening_deg / 2
|
|
122
|
+
lead_x = radius * math.sin(math.radians(half)) - radius_away * (
|
|
123
|
+
1 - math.sin(math.radians(half))
|
|
124
|
+
)
|
|
125
|
+
if lead_x < hw:
|
|
126
|
+
raise ValueError(
|
|
127
|
+
"heater opening too small: the two ends would come within "
|
|
128
|
+
f"{2 * lead_x:.1f} um of each other; increase opening_deg or reduce radius_away"
|
|
129
|
+
)
|
|
130
|
+
turn = 90 - half # degrees each wing turns, from the arc tangent to straight up
|
|
131
|
+
|
|
132
|
+
# Right wing, outward from the arc end (theta = 90 - half) to the lead point.
|
|
133
|
+
theta_r = math.radians(90 - half)
|
|
134
|
+
heading = theta_r + math.pi / 2 # arc tangent at the right end (counter-clockwise travel)
|
|
135
|
+
p_end = (radius * math.cos(theta_r), radius * math.sin(theta_r))
|
|
136
|
+
wing_c = (
|
|
137
|
+
p_end[0] + radius_away * math.sin(heading),
|
|
138
|
+
p_end[1] - radius_away * math.cos(heading),
|
|
139
|
+
)
|
|
140
|
+
a0 = heading + math.pi / 2
|
|
141
|
+
n_wing = max(int(turn), 2)
|
|
142
|
+
wing = [
|
|
143
|
+
(
|
|
144
|
+
wing_c[0] + radius_away * math.cos(a0 - math.radians(turn) * i / n_wing),
|
|
145
|
+
wing_c[1] + radius_away * math.sin(a0 - math.radians(turn) * i / n_wing),
|
|
146
|
+
)
|
|
147
|
+
for i in range(n_wing + 1)
|
|
148
|
+
] # from the arc end outward to the lead point (heading straight up there)
|
|
149
|
+
# Analytic normals of the wing points (towards the wing centre; at the arc end this equals
|
|
150
|
+
# the ring's outward radial). The wing ends with a straight stub heading straight up: the
|
|
151
|
+
# trace sides are then exactly vertical where they meet the horizontal end cap, so the cap
|
|
152
|
+
# corners are right angles (a curved last chord would tilt). The stub is one trace width
|
|
153
|
+
# long, or longer than half the via if the PDK has one: the via (centred on the stub end)
|
|
154
|
+
# may draw on the heater layer, and its edge must cross the straight stub at right angles,
|
|
155
|
+
# not the curved wing.
|
|
156
|
+
via_cell = gf.get_component(roles.via) if roles.via else None
|
|
157
|
+
via_half = 0.0 if via_cell is None else via_cell.dbbox().height() / 2
|
|
158
|
+
stub = hw if via_cell is None else max(hw, via_half + hw / 2)
|
|
159
|
+
wing_normals = [((wing_c[0] - x) / radius_away, (wing_c[1] - y) / radius_away) for x, y in wing]
|
|
160
|
+
wing = wing + [(wing[-1][0], wing[-1][1] + stub)]
|
|
161
|
+
wing_normals.append(wing_normals[-1])
|
|
162
|
+
s = straight_length / 2 # semicircle centres at (+-s, 0) for a racetrack
|
|
163
|
+
right_wing = [(x + s, y) for x, y in wing]
|
|
164
|
+
left_wing = [(-x - s, y) for x, y in wing]
|
|
165
|
+
left_normals = [(-nx, ny) for nx, ny in wing_normals]
|
|
166
|
+
if s == 0:
|
|
167
|
+
n_arc = max(int(360 - opening_deg), 8)
|
|
168
|
+
arc = [
|
|
169
|
+
(
|
|
170
|
+
radius * math.cos(math.radians(90 + half + (360 - opening_deg) * i / n_arc)),
|
|
171
|
+
radius * math.sin(math.radians(90 + half + (360 - opening_deg) * i / n_arc)),
|
|
172
|
+
)
|
|
173
|
+
for i in range(n_arc + 1)
|
|
174
|
+
] # left end -> counter-clockwise -> right end
|
|
175
|
+
middle = arc[1:-1] # (the wing lists include the arc end points)
|
|
176
|
+
middle_normals = [(x / radius, y / radius) for x, y in middle]
|
|
177
|
+
else:
|
|
178
|
+
# Stadium: down the left semicircle, along the far straight, up the right semicircle.
|
|
179
|
+
n_side = max(int(180 - half), 4)
|
|
180
|
+
left = [math.radians(90 + half + (180 - half) * i / n_side) for i in range(n_side + 1)]
|
|
181
|
+
right = [math.radians(270 + (180 - half) * i / n_side) for i in range(n_side + 1)]
|
|
182
|
+
left_pts = [(-s + radius * math.cos(a), radius * math.sin(a)) for a in left]
|
|
183
|
+
right_pts = [(s + radius * math.cos(a), radius * math.sin(a)) for a in right]
|
|
184
|
+
middle = left_pts[1:] + right_pts[:-1] # the far straight: left_pts[-1] to right_pts[0]
|
|
185
|
+
middle_normals = [(math.cos(a), math.sin(a)) for a in left[1:]] + [
|
|
186
|
+
(math.cos(a), math.sin(a)) for a in right[:-1]
|
|
187
|
+
]
|
|
188
|
+
line = list(reversed(left_wing)) + middle + right_wing
|
|
189
|
+
|
|
190
|
+
# Offset the centre line by +-hw/2 along the exact normal of each point: radial from the
|
|
191
|
+
# (semi)circle centre on the arcs, towards the wing centre on a wing. Normals taken from
|
|
192
|
+
# polygon chords would tilt the end caps and leave acute slivers.
|
|
193
|
+
normals = left_normals[::-1] + middle_normals + wing_normals
|
|
194
|
+
outer_side = [
|
|
195
|
+
to_abs(x + nx * hw / 2, y + ny * hw / 2)
|
|
196
|
+
for (x, y), (nx, ny) in zip(line, normals, strict=True)
|
|
197
|
+
]
|
|
198
|
+
inner_side = [
|
|
199
|
+
to_abs(x - nx * hw / 2, y - ny * hw / 2)
|
|
200
|
+
for (x, y), (nx, ny) in zip(line, normals, strict=True)
|
|
201
|
+
]
|
|
202
|
+
c.add_polygon(outer_side + inner_side[::-1], layer=hxs.layer)
|
|
203
|
+
length = sum(math.hypot(b[0] - a[0], b[1] - a[1]) for a, b in zip(line, line[1:], strict=False))
|
|
204
|
+
|
|
205
|
+
# Vias, routing metal and pads at the two lead points. Each via is centred on the end of the
|
|
206
|
+
# heater trace (enclosure rules are the PDK's concern); pads are drawn on the routing-metal
|
|
207
|
+
# layer because the roles have no separate pad-metal layer.
|
|
208
|
+
metal_layer = rxs.layer
|
|
209
|
+
lead_y = right_wing[-1][1] # local: along the opening direction
|
|
210
|
+
lead_xs = (left_wing[-1][0], right_wing[-1][0]) # local
|
|
211
|
+
drawn_size = (pad_size[1], pad_size[0]) if turned else pad_size
|
|
212
|
+
pad_cell = gf.components.pad(size=drawn_size, layer=metal_layer)
|
|
213
|
+
pad_near = lead_y + pad_offset if pad_min_y is None else max(lead_y + pad_offset, pad_min_y)
|
|
214
|
+
pad_y = pad_near + pad_size[1] / 2 # local
|
|
215
|
+
pad_xs = list(lead_xs)
|
|
216
|
+
shortfall = min_pad_gap - ((pad_xs[1] - pad_size[0] / 2) - (pad_xs[0] + pad_size[0] / 2))
|
|
217
|
+
if shortfall > 0:
|
|
218
|
+
pad_xs = [pad_xs[0] - shortfall / 2, pad_xs[1] + shortfall / 2]
|
|
219
|
+
y_jog = (lead_y + pad_near) / 2 # local: halfway between the lead and the pad
|
|
220
|
+
for name, lead_x, pad_x in zip(port_names, lead_xs, pad_xs, strict=True):
|
|
221
|
+
if via_cell is not None:
|
|
222
|
+
via = c << via_cell
|
|
223
|
+
via.dcenter = to_abs(lead_x, lead_y)
|
|
224
|
+
# Routing metal: out from the via, across if the pad moved, then into the pad.
|
|
225
|
+
segments = [
|
|
226
|
+
(lead_x - rw / 2, lead_y, lead_x + rw / 2, y_jog + rw / 2),
|
|
227
|
+
(pad_x - rw / 2, y_jog - rw / 2, pad_x + rw / 2, pad_y),
|
|
228
|
+
]
|
|
229
|
+
if abs(pad_x - lead_x) > 1e-9:
|
|
230
|
+
segments.append(
|
|
231
|
+
(
|
|
232
|
+
min(lead_x, pad_x) - rw / 2,
|
|
233
|
+
y_jog - rw / 2,
|
|
234
|
+
max(lead_x, pad_x) + rw / 2,
|
|
235
|
+
y_jog + rw / 2,
|
|
236
|
+
)
|
|
237
|
+
)
|
|
238
|
+
for x0, y0, x1, y1 in segments:
|
|
239
|
+
c.add_polygon(box(x0, y0, x1, y1), layer=metal_layer)
|
|
240
|
+
pad = c << pad_cell
|
|
241
|
+
pad.dcenter = to_abs(pad_x, pad_y)
|
|
242
|
+
if roles.pad_opening:
|
|
243
|
+
ox, oy = pad_size[0] - 2 * pad_opening_inset, pad_size[1] - 2 * pad_opening_inset
|
|
244
|
+
c.add_polygon(
|
|
245
|
+
box(pad_x - ox / 2, pad_y - oy / 2, pad_x + ox / 2, pad_y + oy / 2),
|
|
246
|
+
layer=gf.get_layer(roles.pad_opening),
|
|
247
|
+
)
|
|
248
|
+
c.add_port(
|
|
249
|
+
name=name,
|
|
250
|
+
center=to_abs(pad_x, pad_y + pad_size[1] / 2), # on the pad's outer edge
|
|
251
|
+
width=pad_size[0],
|
|
252
|
+
orientation={"up": 90, "down": 270, "right": 0, "left": 180}[direction],
|
|
253
|
+
layer=metal_layer,
|
|
254
|
+
port_type="electrical",
|
|
255
|
+
)
|
|
256
|
+
check_pad_clearance(
|
|
257
|
+
c,
|
|
258
|
+
roles,
|
|
259
|
+
[
|
|
260
|
+
(lambda corners: (corners[0][0], corners[0][1], corners[2][0], corners[2][1]))(
|
|
261
|
+
box(
|
|
262
|
+
x - pad_size[0] / 2,
|
|
263
|
+
pad_y - pad_size[1] / 2,
|
|
264
|
+
x + pad_size[0] / 2,
|
|
265
|
+
pad_y + pad_size[1] / 2,
|
|
266
|
+
)
|
|
267
|
+
)
|
|
268
|
+
for x in pad_xs
|
|
269
|
+
],
|
|
270
|
+
pad_clearance,
|
|
271
|
+
)
|
|
272
|
+
return {
|
|
273
|
+
"heater_width_um": float(hw),
|
|
274
|
+
"heater_length_um": float(length),
|
|
275
|
+
# farthest heater-layer point towards the opening: the trace end (plus half a width of
|
|
276
|
+
# margin) or the via's top, whichever reaches further
|
|
277
|
+
"lead_top_um": float(right_wing[-1][1] + max(hw / 2, via_half)),
|
|
278
|
+
"lead_y_um": float(right_wing[-1][1]),
|
|
279
|
+
"pad_center_y_um": float(pad_y),
|
|
280
|
+
"pad_left_x_um": float(pad_xs[0]),
|
|
281
|
+
"pad_right_x_um": float(pad_xs[1]),
|
|
282
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Shared design checks for components (private): bend radius, minimum feature, pad clearance.
|
|
2
|
+
|
|
3
|
+
Units: lengths in um.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import gdsfactory as gf
|
|
7
|
+
|
|
8
|
+
from mrdk.layer_roles import LayerRoles
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def check_ring_radius(radius: float, cross_section: gf.CrossSection, what: str = "ring") -> None:
|
|
12
|
+
"""Raise if ``radius`` (µm) is below the cross-section's minimum bend radius, if it has one."""
|
|
13
|
+
radius_min = cross_section.radius_min
|
|
14
|
+
if radius_min is not None and radius < radius_min:
|
|
15
|
+
raise ValueError(
|
|
16
|
+
f"{what} radius {radius} um is below the cross-section minimum bend radius "
|
|
17
|
+
f"{radius_min} um"
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def check_min_feature(min_feature: float | None, **widths: float) -> None:
|
|
22
|
+
"""Raise if any named width (µm) is narrower than ``min_feature`` (µm); None skips."""
|
|
23
|
+
if min_feature is None:
|
|
24
|
+
return
|
|
25
|
+
if min_feature <= 0:
|
|
26
|
+
raise ValueError("min_feature must be positive")
|
|
27
|
+
narrow = {name: w for name, w in widths.items() if w < min_feature - 1e-9}
|
|
28
|
+
if narrow:
|
|
29
|
+
listed = ", ".join(f"{name}={w} um" for name, w in narrow.items())
|
|
30
|
+
raise ValueError(f"features narrower than min_feature {min_feature} um: {listed}")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def check_pad_clearance(
|
|
34
|
+
c: gf.Component,
|
|
35
|
+
roles: LayerRoles,
|
|
36
|
+
pad_boxes: list[tuple[float, float, float, float]],
|
|
37
|
+
clearance: float,
|
|
38
|
+
) -> None:
|
|
39
|
+
"""Raise if a pad (x0, y0, x1, y1, µm) comes within ``clearance`` (µm) of a waveguide in ``c``.
|
|
40
|
+
|
|
41
|
+
The waveguide shapes are those already drawn in ``c`` on the waveguide (and edge-coupler)
|
|
42
|
+
layers. A clearance of 0 skips the check.
|
|
43
|
+
"""
|
|
44
|
+
if clearance <= 0:
|
|
45
|
+
return
|
|
46
|
+
kdb = gf.kdb
|
|
47
|
+
dbu = c.kcl.dbu
|
|
48
|
+
waveguides = kdb.Region()
|
|
49
|
+
for xs_name in {roles.waveguide, roles.edge_coupler or roles.waveguide}:
|
|
50
|
+
layer = gf.get_layer(gf.get_cross_section(xs_name).layer)
|
|
51
|
+
waveguides += kdb.Region(c.begin_shapes_rec(layer))
|
|
52
|
+
waveguides.merge()
|
|
53
|
+
for x0, y0, x1, y1 in pad_boxes:
|
|
54
|
+
pad = kdb.Region(kdb.DBox(x0, y0, x1, y1).to_itype(dbu))
|
|
55
|
+
close = pad.separation_check(waveguides, round(clearance / dbu))
|
|
56
|
+
touching = waveguides.interacting(pad)
|
|
57
|
+
if not close.is_empty() or not touching.is_empty():
|
|
58
|
+
distance = (
|
|
59
|
+
0.0 if not touching.is_empty() else min(e.distance() for e in close.each()) * dbu
|
|
60
|
+
)
|
|
61
|
+
raise ValueError(
|
|
62
|
+
f"a heater pad at ({(x0 + x1) / 2:.1f}, {(y0 + y1) / 2:.1f}) um is {distance:.2f} "
|
|
63
|
+
f"um from a waveguide (pad_clearance {clearance} um); move the pads (pad_offset) "
|
|
64
|
+
"or lower pad_clearance"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def check_layer_clearance(
|
|
69
|
+
c: gf.Component, layer, others, clearance: float, what: str, other_what: str
|
|
70
|
+
) -> None:
|
|
71
|
+
"""Raise if shapes of ``layer`` in ``c`` come within ``clearance`` (µm) of ``others``.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
c: the component (all its shapes on ``layer``, at any depth, are checked).
|
|
75
|
+
layer: the layer to check (a gdsfactory layer spec).
|
|
76
|
+
others: a KLayout ``Region`` (database units of ``c``) to keep away from.
|
|
77
|
+
clearance: minimum distance (µm); 0 still rejects overlaps.
|
|
78
|
+
what: name of the checked shapes, for the message (e.g. "heater metal").
|
|
79
|
+
other_what: name of ``others``, for the message (e.g. "the input bus").
|
|
80
|
+
"""
|
|
81
|
+
kdb = gf.kdb
|
|
82
|
+
dbu = c.kcl.dbu
|
|
83
|
+
region = kdb.Region(c.begin_shapes_rec(gf.get_layer(layer))).merged()
|
|
84
|
+
if region.is_empty() or others.is_empty():
|
|
85
|
+
return
|
|
86
|
+
if not region.interacting(others).is_empty():
|
|
87
|
+
raise ValueError(f"{what} overlaps {other_what}")
|
|
88
|
+
if clearance > 0:
|
|
89
|
+
close = region.separation_check(others, round(clearance / dbu))
|
|
90
|
+
if not close.is_empty():
|
|
91
|
+
distance = min(e.distance() for e in close.each()) * dbu
|
|
92
|
+
raise ValueError(
|
|
93
|
+
f"{what} comes within {distance:.2f} um of {other_what} (minimum {clearance} um)"
|
|
94
|
+
)
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"""Shared heater, lead and pad construction for ring components (private).
|
|
2
|
+
|
|
3
|
+
Units: lengths in um.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import math
|
|
7
|
+
|
|
8
|
+
import gdsfactory as gf
|
|
9
|
+
|
|
10
|
+
from mrdk.components._checks import check_pad_clearance
|
|
11
|
+
from mrdk.layer_roles import LayerRoles
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def add_ring_heater(
|
|
15
|
+
c: gf.Component,
|
|
16
|
+
*,
|
|
17
|
+
roles: LayerRoles,
|
|
18
|
+
center: tuple[float, float],
|
|
19
|
+
radius: float,
|
|
20
|
+
width: float,
|
|
21
|
+
bus_distance: float,
|
|
22
|
+
direction: int,
|
|
23
|
+
port_names: tuple[str, str],
|
|
24
|
+
heater_width: float | None,
|
|
25
|
+
heater_radius: float | None,
|
|
26
|
+
heater_clearance: float,
|
|
27
|
+
heater_opening: float,
|
|
28
|
+
pad_size: tuple[float, float],
|
|
29
|
+
pad_pitch: float,
|
|
30
|
+
pad_offset: float,
|
|
31
|
+
pad_opening_inset: float,
|
|
32
|
+
pad_clearance: float = 0.0,
|
|
33
|
+
) -> tuple[float, float, float]:
|
|
34
|
+
"""Add an open-annulus heater around a ring, with Z-shaped leads and two pads.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
c: component to draw into.
|
|
38
|
+
roles: PDK role mapping.
|
|
39
|
+
center: ring centre (x, y) (µm).
|
|
40
|
+
radius: ring radius to the waveguide centre line (µm).
|
|
41
|
+
width: ring waveguide width (µm).
|
|
42
|
+
bus_distance: distance from the ring centre to the nearest bus centre line (µm).
|
|
43
|
+
direction: +1 puts the heater opening, leads and pads above the ring, -1 below.
|
|
44
|
+
port_names: names of the (west, east) pad ports.
|
|
45
|
+
heater_width: trace width (µm); None uses the PDK cross-section default.
|
|
46
|
+
heater_radius: heater centre-line radius (µm); None picks the largest value up to
|
|
47
|
+
``radius`` that keeps ``heater_clearance`` to the bus.
|
|
48
|
+
heater_clearance: minimum distance, heater edge to bus waveguide edge (µm).
|
|
49
|
+
heater_opening: distance between the two heater ends (µm).
|
|
50
|
+
pad_size: pad (width, height) (µm).
|
|
51
|
+
pad_pitch: pad centre-to-centre distance (µm).
|
|
52
|
+
pad_offset: distance from the heater outer edge to the pad edge (µm).
|
|
53
|
+
pad_opening_inset: pad-opening inset inside the pad outline (µm).
|
|
54
|
+
pad_clearance: minimum distance from each pad to any waveguide already drawn in
|
|
55
|
+
``c`` (µm); 0 skips the check.
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
(heater centre-line radius, heater width, heater trace length along the arc), in µm.
|
|
59
|
+
"""
|
|
60
|
+
cx, cy = center
|
|
61
|
+
hxs = gf.get_cross_section(
|
|
62
|
+
roles.heater, **({} if heater_width is None else {"width": heater_width})
|
|
63
|
+
)
|
|
64
|
+
hw = hxs.width
|
|
65
|
+
heater_layer = hxs.layer
|
|
66
|
+
metal_layer = gf.get_cross_section(roles.routing_metal).layer
|
|
67
|
+
half = heater_opening / 2
|
|
68
|
+
# Nearest heater outer edge to the bus is bus_distance - hr - hw/2 from the bus centre.
|
|
69
|
+
hr_max = bus_distance - width / 2 - heater_clearance - hw / 2
|
|
70
|
+
hr = min(radius, hr_max) if heater_radius is None else heater_radius
|
|
71
|
+
if hr > hr_max + 1e-9:
|
|
72
|
+
raise ValueError(
|
|
73
|
+
f"heater (radius {hr} um, width {hw} um) comes within {heater_clearance} um of the "
|
|
74
|
+
f"bus; use heater_radius <= {hr_max:.3f}, a thinner heater or a larger gap"
|
|
75
|
+
)
|
|
76
|
+
if heater_opening < 2 * hw:
|
|
77
|
+
raise ValueError("heater_opening must be at least twice the heater width")
|
|
78
|
+
if hr <= half + hw / 2 or hr <= hw / 2:
|
|
79
|
+
raise ValueError("heater_opening or heater_width is too large for this heater radius")
|
|
80
|
+
if pad_pitch < pad_size[0] + 1e-9:
|
|
81
|
+
raise ValueError("pad_pitch must be larger than the pad width")
|
|
82
|
+
|
|
83
|
+
# Open annulus: from one end of the opening round the far side to the other end.
|
|
84
|
+
# Angles are measured from the opening direction, which is +y (direction=+1) or -y.
|
|
85
|
+
# Each edge ends where it reaches x = +-half, so both end faces are exactly vertical and
|
|
86
|
+
# meet the vertical leads at right angles (a radial cut would leave an acute corner).
|
|
87
|
+
alpha = math.asin(half / hr)
|
|
88
|
+
a0, a1 = math.pi / 2 - alpha, math.pi / 2 + alpha - 2 * math.pi
|
|
89
|
+
n = max(int(abs(a1 - a0) / math.radians(1)), 8) # 1 degree steps: sub-nm facet error
|
|
90
|
+
|
|
91
|
+
def edge(r: float) -> list[tuple[float, float]]:
|
|
92
|
+
e = math.asin(half / r)
|
|
93
|
+
b0, b1 = math.pi / 2 - e, math.pi / 2 + e - 2 * math.pi
|
|
94
|
+
return [
|
|
95
|
+
(
|
|
96
|
+
cx + r * math.cos(b0 + (b1 - b0) * i / n),
|
|
97
|
+
cy + direction * r * math.sin(b0 + (b1 - b0) * i / n),
|
|
98
|
+
)
|
|
99
|
+
for i in range(n + 1)
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
c.add_polygon(edge(hr + hw / 2) + edge(hr - hw / 2)[::-1], layer=heater_layer)
|
|
103
|
+
|
|
104
|
+
y_arc = cy + direction * hr * math.cos(alpha) # arc end centre y
|
|
105
|
+
d_top = hr + hw / 2 # heater outer edge, distance from ring centre along the opening
|
|
106
|
+
y_jog = cy + direction * (d_top + pad_offset / 2)
|
|
107
|
+
y_pad = cy + direction * (d_top + pad_offset + pad_size[1] / 2)
|
|
108
|
+
pad_cell = gf.components.pad(size=pad_size, layer=metal_layer)
|
|
109
|
+
via_cell = gf.get_component(roles.via) if roles.via else None
|
|
110
|
+
for sign, name in ((-1, port_names[0]), (1, port_names[1])):
|
|
111
|
+
x_end, x_pad = cx + sign * half, cx + sign * pad_pitch / 2
|
|
112
|
+
# Z-shaped lead: away from the arc end, across, then to the pad centre.
|
|
113
|
+
for x0, x1, ya, yb in (
|
|
114
|
+
(x_end - hw / 2, x_end + hw / 2, y_arc, y_jog + direction * hw / 2),
|
|
115
|
+
(
|
|
116
|
+
min(x_end, x_pad) - hw / 2,
|
|
117
|
+
max(x_end, x_pad) + hw / 2,
|
|
118
|
+
y_jog - hw / 2,
|
|
119
|
+
y_jog + hw / 2,
|
|
120
|
+
),
|
|
121
|
+
(x_pad - hw / 2, x_pad + hw / 2, y_jog - direction * hw / 2, y_pad),
|
|
122
|
+
):
|
|
123
|
+
y0, y1 = min(ya, yb), max(ya, yb)
|
|
124
|
+
c.add_polygon([(x0, y0), (x1, y0), (x1, y1), (x0, y1)], layer=heater_layer)
|
|
125
|
+
pad = c << pad_cell
|
|
126
|
+
pad.dcenter = (x_pad, y_pad)
|
|
127
|
+
if via_cell is not None:
|
|
128
|
+
via = c << via_cell
|
|
129
|
+
via.dcenter = (x_pad, y_pad)
|
|
130
|
+
if roles.pad_opening:
|
|
131
|
+
ox, oy = pad_size[0] - 2 * pad_opening_inset, pad_size[1] - 2 * pad_opening_inset
|
|
132
|
+
ox0, oy0 = x_pad - ox / 2, y_pad - oy / 2
|
|
133
|
+
c.add_polygon(
|
|
134
|
+
[(ox0, oy0), (ox0 + ox, oy0), (ox0 + ox, oy0 + oy), (ox0, oy0 + oy)],
|
|
135
|
+
layer=gf.get_layer(roles.pad_opening),
|
|
136
|
+
)
|
|
137
|
+
c.add_port(
|
|
138
|
+
name=name,
|
|
139
|
+
center=(x_pad, y_pad),
|
|
140
|
+
width=pad_size[0],
|
|
141
|
+
orientation=90 if direction > 0 else 270,
|
|
142
|
+
layer=metal_layer,
|
|
143
|
+
port_type="electrical",
|
|
144
|
+
)
|
|
145
|
+
check_pad_clearance(
|
|
146
|
+
c,
|
|
147
|
+
roles,
|
|
148
|
+
[
|
|
149
|
+
(
|
|
150
|
+
x - pad_size[0] / 2,
|
|
151
|
+
y_pad - pad_size[1] / 2,
|
|
152
|
+
x + pad_size[0] / 2,
|
|
153
|
+
y_pad + pad_size[1] / 2,
|
|
154
|
+
)
|
|
155
|
+
for x in (cx - pad_pitch / 2, cx + pad_pitch / 2)
|
|
156
|
+
],
|
|
157
|
+
pad_clearance,
|
|
158
|
+
)
|
|
159
|
+
return hr, hw, hr * abs(a1 - a0)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Coupler marker boxes over designed coupling gaps (private helper).
|
|
2
|
+
|
|
3
|
+
``mrdk.die.check`` reports spacing hits inside these boxes as waived. They are drawn only when
|
|
4
|
+
the roles define a ``coupler_marker`` layer.
|
|
5
|
+
|
|
6
|
+
Units: lengths in um.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import math
|
|
10
|
+
|
|
11
|
+
import gdsfactory as gf
|
|
12
|
+
|
|
13
|
+
from mrdk.layer_roles import LayerRoles
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def coupling_half_length(r_outer: float, extent: float, both_curved: bool = False) -> float:
|
|
17
|
+
"""Half-length of the stretch where a ring edge stays within ``extent`` of its gap (µm).
|
|
18
|
+
|
|
19
|
+
Against a straight edge the distance grows as ``s**2 / (2 * r_outer)`` along the coupler;
|
|
20
|
+
against an equal ring as ``s**2 / r_outer``. One ``extent`` is added as margin, because
|
|
21
|
+
KLayout reports whole edge segments of the polygonal ring.
|
|
22
|
+
"""
|
|
23
|
+
factor = 1.0 if both_curved else 2.0
|
|
24
|
+
return math.sqrt(factor * r_outer * extent) + extent
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def add_coupler_marker(
|
|
28
|
+
c: gf.Component, roles: LayerRoles, box: tuple[float, float, float, float]
|
|
29
|
+
) -> None:
|
|
30
|
+
"""Draw ``box`` (x0, y0, x1, y1, µm) on the coupler marker layer, if the roles have one."""
|
|
31
|
+
if roles.coupler_marker is None:
|
|
32
|
+
return
|
|
33
|
+
x0, y0, x1, y1 = box
|
|
34
|
+
c.add_polygon(
|
|
35
|
+
[(x0, y0), (x1, y0), (x1, y1), (x0, y1)], layer=gf.get_layer(roles.coupler_marker)
|
|
36
|
+
)
|