Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Bend Generation Error in FlexPath #262

Open
Daasein opened this issue Jul 14, 2024 · 1 comment
Open

Bug: Bend Generation Error in FlexPath #262

Daasein opened this issue Jul 14, 2024 · 1 comment

Comments

@Daasein
Copy link

Daasein commented Jul 14, 2024

Hi,

I encountered an issue while drawing my own racetrack resonator using the FlexPath method (I'm aware of the gdstk.racetrack implementation, but please bear with me as this issue is quite peculiar).

Here's what I did: I used FlexPath to draw a closed loop and utilized the bend_radius parameter to generate the arc. It looks good when drawing a single resonator, but when I draw multiple resonators in an array, problems arise.

Here is my code:

# define Waveguide
def waveguide(x, y, w, l, layer):
    start_point = (x, y - w / 2)
    end_point = (x + l, y + w / 2)
    wg = gdstk.rectangle(start_point, end_point, layer=layer)
    return wg


# define racetrack
def racetrack(x, y, w, lc, radius, layer):
    points = [
        (x, y),
        (x + lc / 2 + radius, y),
        (x + lc / 2 + radius, y + radius),
        (x + lc / 2 + radius, y + radius * 2),
        (x - lc / 2 - radius, y + radius * 2),
        (x - lc / 2 - radius, y + radius),
        (x - lc / 2 - radius, y),
        (x, y),
    ]
    racetrack = gdstk.FlexPath(points, width=w, bend_radius=radius, layer=layer)
    return racetrack


# define resonator, it is a combination of waveguide and racetrack
def resonator(x, y, w, lc, radius, x_span, gap, layer):
    wg = waveguide(x, y, w, x_span, layer)
    racetrack1 = racetrack(x + x_span / 2, y + gap + w, w, lc, radius, layer)
    return wg, racetrack1

lib = gdstk.Library()
cell = lib.new_cell("Resonator")
for i in range(10):
    for j in range(10):
        cell.add(*resonator(i * 100, j * 100, 0.5, 3, 15, 55, 0.2, 3))
lib.write_gds("first.gds", max_points=10000)

Here is what I got:
image
The upper bend of the racetrack didn't generate properly in the 2nd row. If you change the step of j, the issue appears in different rows. I believe the problem lies in how I've defined the racetrack. Here is a drawing to illustrate my definition of racetrack points:
522A484D-33A6-40FF-BA4A-29F66D5791B3
Due to the two continuous bends in my definition, when the y-values of the point set for the racetrack reach certain values, some floating-point number exceptions occur.

I understand that this isn't the optimal way to draw a racetrack, but I believe it highlights a potential area for improving the robustness of FlexPath.

Thank you

@heitzmann
Copy link
Owner

Yes, this is a fundamental limit of floating point math. Unfortunately I cannot take the time to rewrite the whole library to use integer coordinates. On the other hand it should be very easy to change your racetrack functions to use 90° and 180° arcs. I can't see a way around it using the built-in points argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants