gdsfactory / kfactory

gdsfactory with a klayout backend
https://gdsfactory.github.io/kfactory/
MIT License
27 stars 10 forks source link

use_mirror flag in connect does not behave as expected #392

Closed tvt173 closed 3 weeks ago

tvt173 commented 3 weeks ago

Describe the bug The expectation, as I understand it, is that when use_mirror = True, the connect transformation should respect any previous mirror transformations applied to the instance before connecting. This does not seem to be true. Also, it seems like there is different behavior when the port is provided by name or as an actual port (I can see in the code that when it is specified by name it gets p = self.cell.ports[port] rather than p = self.ports[port]. This is a mistake, no?).

To Reproduce Try running the script below:

import gdsfactory as gf

@gf.cell
def mirror_and_connect(from_name: bool = False, use_mirror: bool = True, apply_mirror: bool = True):
    c = gf.Component()
    i1 = c.add_ref(gf.c.straight(), "i1")
    i2 = c.add_ref(gf.c.bend_circular(), "i2")

    if apply_mirror:
        i2.dmirror()

    if from_name:
        port = "o2"
    else:
        port = i2.ports["o2"]

    i2.connect(port, i1.ports["o2"], use_mirror=use_mirror, mirror=False)
    return c

if __name__ == "__main__":
    samples = []
    for from_name in True, False:
        for use_mirror in True, False:
            for apply_mirror in True, False:
                cc = mirror_and_connect(from_name=from_name, use_mirror=use_mirror, apply_mirror=apply_mirror)
                samples.append(cc)
    c = gf.grid(samples)
    c.show()

Expected behavior

  1. Toggling from_name should have no effect. Results should be the same in either case.
  2. Toggling use_mirror when apply_mirror is True should cause the bend to mirrored or not
  3. Toggling apply_mirror when use_mirror is True should cause the bend to mirrored or not
  4. Toggling apply_mirror when use_mirror is False should have no effect
  5. Toggling use_mirror when apply_mirror is False should have no effect

In all cases the two components should be connected.

Screenshots Shit's all over the place... image

sebastian-goeldi commented 3 weeks ago

With test

image