def test_connect_bundle_waypointsC(): import pp from pp.component import Port ys1 = np.array([0, 5, 10, 15, 20, 60, 70, 80, 120, 125]) ys2 = np.array([0, 5, 10, 20, 25, 30, 40, 55, 60, 65]) - 500.0 N = ys1.size ports1 = [Port("A_{}".format(i), (0, ys1[i]), 0.5, 0) for i in range(N)] ports2 = [ Port("B_{}".format(i), (600, ys2[i]), 0.5, 180) for i in range(N) ] top_cell = pp.Component() way_points = [ ports1[0].position, ports1[0].position + (200, 0), ports1[0].position + (200, -200), ports1[0].position + (400, -200), (ports1[0].x + 400, ports2[0].y), ports2[0].position, ] elements = connect_bundle_waypoints(ports1, ports2, way_points) top_cell.add(elements) return top_cell
def test_connect_bundle_waypointsA(): import pp from pp.component import Port xs1 = np.arange(10) * 5 - 500.0 N = xs1.size ys2 = np.array([0, 5, 10, 20, 25, 30, 40, 55, 60, 75]) + 500.0 ports1 = [Port("A_{}".format(i), (xs1[i], 0), 0.5, 90) for i in range(N)] ports2 = [Port("B_{}".format(i), (0, ys2[i]), 0.5, 180) for i in range(N)] top_cell = pp.Component() p0 = ports1[0].position + (22, 0) way_points = [ p0, p0 + (0, 100), p0 + (200, 100), p0 + (200, -200), p0 + (0, -200), p0 + (0, -350), p0 + (400, -350), (p0[0] + 400, ports2[-1].y), ports2[-1].position, ] elements = connect_bundle_waypoints(ports1, ports2, way_points) top_cell.add(elements) return top_cell
def test_connect_bundle_waypointsB(): import pp from pp.component import Port ys1 = np.array([0, 5, 10, 15, 30, 40, 50, 60]) + 0.0 ys2 = np.array([0, 10, 20, 30, 70, 90, 110, 120]) + 500.0 N = ys1.size ports1 = [Port("A_{}".format(i), (0, ys1[i]), 0.5, 0) for i in range(N)] ports2 = [ Port("B_{}".format(i), (500, ys2[i]), 0.5, 180) for i in range(N) ] p0 = ports1[0].position + (0, 22.5) top_cell = pp.Component() way_points = [ p0, p0 + (200, 0), p0 + (200, -200), p0 + (400, -200), (p0[0] + 400, ports2[0].y), ports2[0].position, ] elements = connect_bundle_waypoints(ports1, ports2, way_points) top_cell.add(elements) return top_cell
def test_connect_bundle_waypointsB(data_regression): from pp.component import Port ys1 = np.array([0, 5, 10, 15, 30, 40, 50, 60]) + 0.0 ys2 = np.array([0, 10, 20, 30, 70, 90, 110, 120]) + 500.0 N = ys1.size ports1 = [Port("A_{}".format(i), (0, ys1[i]), 0.5, 0) for i in range(N)] ports2 = [ Port("B_{}".format(i), (500, ys2[i]), 0.5, 180) for i in range(N) ] p0 = ports1[0].position + (0, 22.5) c = pp.Component("B") way_points = [ p0, p0 + (200, 0), p0 + (200, -200), p0 + (400, -200), (p0[0] + 400, ports2[0].y), ports2[0].position, ] routes = connect_bundle_waypoints(ports1, ports2, way_points) lengths = np.zeros_like(routes, dtype=float) for i, route in enumerate(routes): c.add(route["references"]) lengths[i] = route["settings"]["length"] lengths = {str(i): i for i in lengths} # data_regression.check(lengths) return c
def test_connect_bundle_waypointsA(data_regression): from pp.component import Port xs1 = np.arange(10) * 5 - 500.0 N = xs1.size ys2 = np.array([0, 5, 10, 20, 25, 30, 40, 55, 60, 75]) + 500.0 ports1 = [Port("A_{}".format(i), (xs1[i], 0), 0.5, 90) for i in range(N)] ports2 = [Port("B_{}".format(i), (0, ys2[i]), 0.5, 180) for i in range(N)] c = pp.Component("A") p0 = ports1[0].position + (22, 0) way_points = [ p0, p0 + (0, 100), p0 + (200, 100), p0 + (200, -200), p0 + (0, -200), p0 + (0, -350), p0 + (400, -350), (p0[0] + 400, ports2[-1].y), ports2[-1].position, ] routes = connect_bundle_waypoints(ports1, ports2, way_points) lengths = np.zeros_like(routes) for i, route in enumerate(routes): c.add(route["references"]) lengths[i] = route["settings"]["length"] lengths = {str(i): i for i in lengths} data_regression.check(lengths) return c
def test_connect_bundle_waypointsC(): from pp.component import Port ys1 = np.array([0, 5, 10, 15, 20, 60, 70, 80, 120, 125]) ys2 = np.array([0, 5, 10, 20, 25, 30, 40, 55, 60, 65]) - 500.0 N = ys1.size ports1 = [Port("A_{}".format(i), (0, ys1[i]), 0.5, 0) for i in range(N)] ports2 = [ Port("B_{}".format(i), (600, ys2[i]), 0.5, 180) for i in range(N) ] c = pp.Component() way_points = [ ports1[0].position, ports1[0].position + (200, 0), ports1[0].position + (200, -200), ports1[0].position + (400, -200), (ports1[0].x + 400, ports2[0].y), ports2[0].position, ] routes = connect_bundle_waypoints(ports1, ports2, way_points) lengths = [ 1082.832, 1082.832, 1082.832, 1077.832, 1077.832, 1112.832, 1112.832, 1107.832, 1142.832, 1142.832, ] for route, length in zip(routes, lengths): c.add(route["references"]) # print(route["settings"]["length"]) assert route["settings"]["length"] == length return c
def test_connect_bundle_waypointsD(): from pp.component import Port ys1 = np.array([0, 5, 10, 20, 25, 30, 40, 55, 60, 75]) + 100.0 ys2 = np.array([0, -5, -10, -20, -25, -30, -40, -55, -60, -75]) + 500.0 N = ys1.size ports1 = [Port("A_{}".format(i), (0, ys1[i]), 0.5, 0) for i in range(N)] ports2 = [Port("B_{}".format(i), (0, ys2[i]), 0.5, 0) for i in range(N)] def _mean_y(ports): return np.mean([p.y for p in ports]) yc1 = _mean_y(ports1) yc2 = _mean_y(ports2) c = pp.Component() way_points = [(0, yc1), (200, yc1), (200, yc2), (0, yc2)] routes = connect_bundle_waypoints(ports1, ports2, way_points) lengths = [ 855.416, 835.416, 815.416, 775.416, 755.416, 735.416, 695.416, 635.416, 615.416, 555.416, ] for route, length in zip(routes, lengths): c.add(route["references"]) # print(route["settings"]["length"]) assert route["settings"]["length"] == length return c
def test_connect_bundle_waypointsD(): import pp from pp.component import Port ys1 = np.array([0, 5, 10, 20, 25, 30, 40, 55, 60, 75]) + 100.0 ys2 = np.array([0, -5, -10, -20, -25, -30, -40, -55, -60, -75]) + 500.0 N = ys1.size ports1 = [Port("A_{}".format(i), (0, ys1[i]), 0.5, 0) for i in range(N)] ports2 = [Port("B_{}".format(i), (0, ys2[i]), 0.5, 0) for i in range(N)] def _mean_y(ports): return np.mean([p.y for p in ports]) yc1 = _mean_y(ports1) yc2 = _mean_y(ports2) top_cell = pp.Component() way_points = [(0, yc1), (200, yc1), (200, yc2), (0, yc2)] elements = connect_bundle_waypoints(ports1, ports2, way_points) top_cell.add(elements) return top_cell
def test_manhattan(): from pp.components.bend_circular import bend_circular from pp.component import Port top_cell = pp.Component() inputs = [ Port("in1", (10, 5), 0.5, 90), Port("in2", (-10, 20), 0.5, 0), Port("in3", (10, 30), 0.5, 0), Port("in4", (-10, -5), 0.5, 90), ] outputs = [ Port("in1", (90, -60), 0.5, 180), Port("in2", (-100, 20), 0.5, 0), Port("in3", (100, -25), 0.5, 0), Port("in4", (-150, -65), 0.5, 270), ] for input_port, output_port in zip(inputs, outputs): # input_port = Port("input_port", (10,5), 0.5, 90) # output_port = Port("output_port", (90,-60), 0.5, 180) bend = bend_circular(radius=5.0) pp.ports.add_port_markers(bend) cell = route_manhattan( input_port, output_port, bend, waveguide, start_straight=5.0, end_straight=5.0, ) top_cell.add(cell) return top_cell
def import_phidl_component(component: Device, **kwargs) -> Component: """ returns a gdsfactory Component from a phidl Device or function """ D = call_if_func(component, **kwargs) D_copy = Component(name=D._internal_name) D_copy.info = copy.deepcopy(D.info) for ref in D.references: new_ref = ComponentReference( device=ref.parent, origin=ref.origin, rotation=ref.rotation, magnification=ref.magnification, x_reflection=ref.x_reflection, ) new_ref.owner = D_copy D_copy.add(new_ref) for alias_name, alias_ref in D.aliases.items(): if alias_ref == ref: D_copy.aliases[alias_name] = new_ref for p in D.ports.values(): D_copy.add_port( port=Port( name=p.name, midpoint=p.midpoint, width=p.width, orientation=p.orientation, parent=p.parent, ) ) for poly in D.polygons: D_copy.add_polygon(poly) for label in D.labels: D_copy.add_label( text=label.text, position=label.position, layer=(label.layer, label.texttype), ) return D_copy