Component#
A Component
is like an empty canvas, where you can add polygons, references to other Components and ports (to connect to other components)
In gdsfactory all dimensions are in microns
Polygons#
You can add polygons to different layers. By default all units in gdsfactory are in um.
import gdsfactory as gf
# Create a blank component (essentially an empty GDS cell with some special features)
c = gf.Component()
p1 = c.add_polygon([(-8, -6), (6, 8), (7, 17), (9, 5)], layer=(1, 0))
c.write_gds("demo.gds") # write it to a GDS file. You can open it in klayout.
c.show() # show it in klayout
c.plot() # plot it in jupyter notebook
2025-01-27 23:15:09.839 | WARNING | kfactory.kcell:show:8768 - Could not connect to klive server
Exercise :
Make a component similar to the one above that has a second polygon in layer (2, 0)
c = gf.Component()
# Create some new geometry from the functions available in the geometry library
t = gf.components.text("Hello!")
r = gf.components.rectangle(size=(5, 10), layer=(2, 0))
# Add references to the new geometry to c, our blank component
text1 = c.add_ref(t) # Add the text we created as a reference
# Using the << operator (identical to add_ref()), add the same geometry a second time
text2 = c << t
r = c << r # Add the rectangle we created
# Now that the geometry has been added to "c", we can move everything around:
text1.movey(25)
text2.move((5, 30))
text2.drotate(45)
r.movex(-15)
print(c)
c.plot()
vinsts=[] info=Info() kcl=KCLayout(name='DEFAULT', layout=<klayout.dbcore.Layout object at 0x7f2a0487aad0>, layer_enclosures=LayerEnclosureModel(root={'5c226817': LayerEnclosure(layer_sections={}, main_layer=SLAB150 (2/0), yaml_tag='!Enclosure')}), cross_sections={'5c226817_10000': SymmetricalCrossSection(width=10000, enclosure=LayerEnclosure(layer_sections={}, main_layer=SLAB150 (2/0), yaml_tag='!Enclosure'), name='5c226817_10000'), '5c226817_5000': SymmetricalCrossSection(width=5000, enclosure=LayerEnclosure(layer_sections={}, main_layer=SLAB150 (2/0), yaml_tag='!Enclosure'), name='5c226817_5000')}, enclosure=KCellEnclosure(enclosures=LayerEnclosureCollection(enclosures=[])), library=<klayout.dbcore.Library object at 0x7f2a04894870>, factories={'taper': <function taper at 0x7f29ef27e020>, 'bend_s_bezier': <function bend_s_bezier_factory.<locals>.bend_s_bezier at 0x7f29fb1b36a0>, 'bend_circular': <function bend_circular at 0x7f29ef27c4a0>, 'bend_euler': <function bend_euler at 0x7f29ef27cea0>, 'bend_s_euler': <function bend_s_euler_factory.<locals>.bend_s_euler at 0x7f29f98ee840>, 'straight': <function straight at 0x7f29ef105580>, 'rotate': <function rotate at 0x7f29efe36c00>, 'from_image': <function from_image at 0x7f29ef828ae0>, 'floorplan_with_block_letters': <function floorplan_with_block_letters at 0x7f29ef3d7560>, 'bend_circular_heater': <function bend_circular_heater at 0x7f29ef27c720>, 'bend_euler_s': <function bend_euler_s at 0x7f29ef27cd60>, 'bezier': <function bezier at 0x7f29ef27d440>, 'bend_s': <function bend_s at 0x7f29ef27d620>, 'add_fiber_array_optical_south_electrical_north': <function add_fiber_array_optical_south_electrical_north at 0x7f29ef27d8a0>, 'ramp': <function ramp at 0x7f29ef27dda0>, 'taper_strip_to_ridge': <function taper_strip_to_ridge at 0x7f29ef27e0c0>, 'taper_strip_to_ridge_trenches': <function taper_strip_to_ridge_trenches at 0x7f29ef27e340>, 'taper_sc_nc': <function taper_sc_nc at 0x7f29ef27e480>, 'taper_adiabatic': <function taper_adiabatic at 0x7f29ef27e7a0>, 'taper_cross_section': <function taper_cross_section at 0x7f29ef27e980>, 'taper_from_csv': <function taper_from_csv at 0x7f29ef27eb60>, 'taper_parabolic': <function taper_parabolic at 0x7f29ef27eca0>, 'add_termination': <function add_termination at 0x7f29ef27e840>, 'add_trenches': <function add_trenches at 0x7f29ef27eac0>, 'array': <function array at 0x7f29ef27ee80>, 'copy_layers': <function copy_layers at 0x7f29ef27f380>, 'extend_ports_list': <function extend_ports_list at 0x7f29ef27f4c0>, 'extend_ports': <function extend_ports at 0x7f29ef27f7e0>, 'pack_doe': <function pack_doe at 0x7f29ef27fce0>, 'pack_doe_grid': <function pack_doe_grid at 0x7f29ef2b8180>, 'splitter_chain': <function splitter_chain at 0x7f29ef2b82c0>, 'mzi': <function mzi at 0x7f29ef2205e0>, 'mzi_lattice': <function mzi_lattice at 0x7f29ef2b8900>, 'mzi_lattice_mmi': <function mzi_lattice_mmi at 0x7f29ef2b8a40>, 'mzi_pads_center': <function mzi_pads_center at 0x7f29ef2b8cc0>, 'mzit': <function mzit at 0x7f29ef2b8ea0>, 'mzit_lattice': <function mzit_lattice at 0x7f29ef2b8fe0>, 'splitter_tree': <function splitter_tree at 0x7f29ef2b8b80>, 'coupler_symmetric': <function coupler_symmetric at 0x7f29ef2b91c0>, 'coupler_straight': <function coupler_straight at 0x7f29ef2b9300>, 'coupler': <function coupler at 0x7f29ef2b9440>, 'coupler90': <function coupler90 at 0x7f29ef2b9620>, 'coupler90bend': <function coupler90bend at 0x7f29ef2b96c0>, 'coupler_adiabatic': <function coupler_adiabatic at 0x7f29ef2b99e0>, 'coupler_asymmetric': <function coupler_asymmetric at 0x7f29ef2b9c60>, 'coupler_bent_half': <function coupler_bent_half at 0x7f29ef2b9f80>, 'coupler_bent': <function coupler_bent at 0x7f29ef2ba0c0>, 'coupler_broadband': <function coupler_broadband at 0x7f29ef2ba340>, 'coupler_full': <function coupler_full at 0x7f29ef2ba520>, 'coupler_ring': <function coupler_ring at 0x7f29ef2ba7a0>, 'coupler_straight_asymmetric': <function coupler_straight_asymmetric at 0x7f29ef2baa20>, 'align_wafer': <function align_wafer at 0x7f29ef2bade0>, 'add_frame': <function add_frame at 0x7f29ef2bae80>, 'die': <function die at 0x7f29ef2bb1a0>, 'die_with_pads': <function die_with_pads at 0x7f29ef2bb380>, 'seal_ring': <function seal_ring at 0x7f29ef2bb560>, 'seal_ring_segmented': <function seal_ring_segmented at 0x7f29ef2bb6a0>, 'wafer': <function wafer at 0x7f29ef2bb880>, 'free_propagation_region': <function free_propagation_region at 0x7f29ef2bbce0>, 'awg': <function awg at 0x7f29ef2bbd80>, 'dbr_cell': <function dbr_cell at 0x7f29ef2d40e0>, 'dbr': <function dbr at 0x7f29ef2d4220>, 'dbr_tapered': <function dbr_tapered at 0x7f29ef2d44a0>, 'bbox': <function bbox at 0x7f29ef2d4c20>, 'C': <function C at 0x7f29ef2d4e00>, 'circle': <function circle at 0x7f29ef2d4fe0>, 'compass': <function compass at 0x7f29ef2d5260>, 'cross': <function cross at 0x7f29ef2d5440>, 'ellipse': <function ellipse at 0x7f29ef2d5620>, 'fiducial_squares': <function fiducial_squares at 0x7f29ef2d5760>, 'L': <function L at 0x7f29ef2d5940>, 'nxn': <function nxn at 0x7f29ef2d5b20>, 'rectangle': <function rectangle at 0x7f29ef2d5d00>, 'rectangles': <function rectangles at 0x7f29ef2d5e40>, 'regular_polygon': <function regular_polygon at 0x7f29ef2d5f80>, 'triangle': <function triangle at 0x7f29ef2d6160>, 'triangle2': <function triangle2 at 0x7f29ef2d62a0>, 'triangle4': <function triangle4 at 0x7f29ef2d63e0>, 'fiber': <function fiber at 0x7f29ef2d5da0>, 'fiber_array': <function fiber_array at 0x7f29ef2d6480>, 'crossing_arm': <function crossing_arm at 0x7f29ef104ea0>, 'crossing': <function crossing at 0x7f29ef104fe0>, 'crossing_linear_taper': <function crossing_linear_taper at 0x7f29ef105120>, 'crossing_etched': <function crossing_etched at 0x7f29ef105260>, 'crossing45': <function crossing45 at 0x7f29ef1053a0>, 'straight_array': <function straight_array at 0x7f29ef105800>, 'wire_straight': <function wire_straight at 0x7f29ef105940>, 'straight_heater_doped_rib': <function straight_heater_doped_rib at 0x7f29ef105d00>, 'straight_heater_doped_strip': <function straight_heater_doped_strip at 0x7f29ef105ee0>, 'straight_heater_meander': <function straight_heater_meander at 0x7f29ef106200>, 'via': <function via at 0x7f29ef106a20>, 'via_circular': <function via_circular at 0x7f29ef106b60>, 'via_chain': <function via_chain at 0x7f29ef106e80>, 'via_corner': <function via_corner at 0x7f29ef107060>, 'via_stack': <function via_stack at 0x7f29ef107240>, 'via_stack_corner45': <function via_stack_corner45 at 0x7f29ef107380>, 'via_stack_corner45_extended': <function via_stack_corner45_extended at 0x7f29ef1074c0>, 'via_stack_with_offset': <function via_stack_with_offset at 0x7f29ef107600>, 'straight_heater_meander_doped': <function straight_heater_meander_doped at 0x7f29ef106700>, 'straight_heater_metal_undercut': <function straight_heater_metal_undercut at 0x7f29ef107560>, 'straight_heater_metal_simple': <function straight_heater_metal_simple at 0x7f29ef107880>, 'straight_piecewise': <function straight_piecewise at 0x7f29ef1079c0>, 'straight_pin': <function straight_pin at 0x7f29ef107a60>, 'straight_pin_slot': <function straight_pin_slot at 0x7f29ef107ce0>, 'wire_corner': <function wire_corner at 0x7f29ef107f60>, 'wire_corner45': <function wire_corner45 at 0x7f29ef12c0e0>, 'wire_corner_sections': <function wire_corner_sections at 0x7f29ef12c180>, 'loop_mirror': <function loop_mirror at 0x7f29ef2d6340>, 'mode_converter': <function mode_converter at 0x7f29ef12dbc0>, 'polarization_splitter_rotator': <function polarization_splitter_rotator at 0x7f29ef12dee0>, 'terminator': <function terminator at 0x7f29ef12e480>, 'grating_coupler_array': <function grating_coupler_array at 0x7f29ef12e700>, 'grating_coupler_dual_pol': <function grating_coupler_dual_pol at 0x7f29ef12ea20>, 'grating_coupler_elliptical': <function grating_coupler_elliptical at 0x7f29ef12f060>, 'grating_coupler_elliptical_arbitrary': <function grating_coupler_elliptical_arbitrary at 0x7f29ef12f2e0>, 'grating_coupler_elliptical_uniform': <function grating_coupler_elliptical_uniform at 0x7f29ef12f560>, 'grating_coupler_elliptical_lumerical': <function grating_coupler_elliptical_lumerical at 0x7f29ef12f6a0>, 'grating_coupler_elliptical_trenches': <function grating_coupler_elliptical_trenches at 0x7f29ef12f740>, 'grating_coupler_loss': <function grating_coupler_loss at 0x7f29ef12fb00>, 'grating_coupler_rectangular': <function grating_coupler_rectangular at 0x7f29ef12fce0>, 'grating_coupler_rectangular_arbitrary': <function grating_coupler_rectangular_arbitrary at 0x7f29ef12ff60>, 'grating_coupler_tree': <function grating_coupler_tree at 0x7f29ef150220>, 'mmi': <function mmi at 0x7f29ef150540>, 'mmi1x2': <function mmi1x2 at 0x7f29ef150860>, 'mmi1x2_with_sbend': <function mmi1x2_with_sbend at 0x7f29ef150a40>, 'mmi2x2': <function mmi2x2 at 0x7f29ef150d60>, 'mmi2x2_with_sbend': <function mmi2x2_with_sbend at 0x7f29ef150ea0>, 'mmi_90degree_hybrid': <function mmi_90degree_hybrid at 0x7f29ef151080>, 'mmi_tapered': <function mmi_tapered at 0x7f29ef1513a0>, 'pad': <function pad at 0x7f29ef151620>, 'pad_array': <function pad_array at 0x7f29ef1518a0>, 'pad_gsg_short': <function pad_gsg_short at 0x7f29ef151b20>, 'pads_shorted': <function pads_shorted at 0x7f29ef151da0>, 'rectangle_with_slits': <function rectangle_with_slits at 0x7f29ef151ee0>, 'cavity': <function cavity at 0x7f29ef152160>, 'cdsem_all': <function cdsem_all at 0x7f29ef1523e0>, 'cdsem_bend180': <function cdsem_bend180 at 0x7f29ef1525c0>, 'cdsem_coupler': <function cdsem_coupler at 0x7f29ef152700>, 'cdsem_straight': <function cdsem_straight at 0x7f29ef152a20>, 'cdsem_straight_density': <function cdsem_straight_density at 0x7f29ef152b60>, '_bendu_double': <function _bendu_double at 0x7f29ef152de0>, '_straight_double': <function _straight_double at 0x7f29ef152f20>, 'cutback_2x2': <function cutback_2x2 at 0x7f29ef153060>, 'cutback_bend': <function cutback_bend at 0x7f29ef153420>, 'cutback_bend90': <function cutback_bend90 at 0x7f29ef153560>, 'staircase': <function staircase at 0x7f29ef1536a0>, 'cutback_bend180': <function cutback_bend180 at 0x7f29ef1537e0>, 'cutback_component': <function cutback_component at 0x7f29ef153920>, 'cutback_splitter': <function cutback_splitter at 0x7f29ef153ce0>, 'greek_cross': <function greek_cross at 0x7f29ef153e20>, 'greek_cross_with_pads': <function greek_cross_with_pads at 0x7f29ef1940e0>, 'litho_calipers': <function litho_calipers at 0x7f29ef1942c0>, 'litho_ruler': <function litho_ruler at 0x7f29ef1945e0>, 'litho_steps': <function litho_steps at 0x7f29ef1947c0>, 'resistance_meander': <function resistance_meander at 0x7f29ef194900>, 'resistance_sheet': <function resistance_sheet at 0x7f29ef194ae0>, 'verniers': <function verniers at 0x7f29ef194cc0>, 'text': <function text at 0x7f29ef1959e0>, 'text_lines': <function text_lines at 0x7f29ef195bc0>, 'text_klayout': <function text_klayout at 0x7f29ef195d00>, 'text_freetype': <function text_freetype at 0x7f29ef196020>, 'pixel_array': <function pixel_array at 0x7f29ef1962a0>, 'text_rectangular': <function text_rectangular at 0x7f29ef1963e0>, 'text_rectangular_multi_layer': <function text_rectangular_multi_layer at 0x7f29ef196520>, 'pixel': <function pixel at 0x7f29ef194fe0>, 'qrcode': <function qrcode at 0x7f29ef196200>, 'version_stamp': <function version_stamp at 0x7f29ef1965c0>, 'disk': <function disk at 0x7f29ef196b60>, 'disk_heater': <function disk_heater at 0x7f29ef196ca0>, 'ring': <function ring at 0x7f29ef196f20>, 'ring_crow': <function ring_crow at 0x7f29ef197100>, 'ring_crow_couplers': <function ring_crow_couplers at 0x7f29ef197240>, 'ring_double': <function ring_double at 0x7f29ef197420>, 'ring_double_bend_coupler': <function ring_double_bend_coupler at 0x7f29ef197740>, 'ring_double_heater': <function ring_double_heater at 0x7f29ef197880>, 'ring_double_pn': <function ring_double_pn at 0x7f29ef197ba0>, 'ring_single_pn': <function ring_single_pn at 0x7f29ef197ce0>, 'ring_single': <function ring_single at 0x7f29ef197ec0>, 'ring_single_array': <function ring_single_array at 0x7f29ef197f60>, 'coupler_bend': <function coupler_bend at 0x7f29ef1e8180>, 'coupler_ring_bend': <function coupler_ring_bend at 0x7f29ef1e82c0>, 'ring_single_bend_coupler': <function ring_single_bend_coupler at 0x7f29ef1e8400>, 'ring_single_dut': <function ring_single_dut at 0x7f29ef1e85e0>, 'delay_snake': <function delay_snake at 0x7f29ef1e8860>, 'delay_snake2': <function delay_snake2 at 0x7f29ef1e8a40>, 'delay_snake_sbend': <function delay_snake_sbend at 0x7f29ef1e8cc0>, 'spiral': <function spiral at 0x7f29ef1e8f40>, 'spiral_double': <function spiral_double at 0x7f29ef1e9120>, 'spiral_racetrack': <function spiral_racetrack at 0x7f29ef1e93a0>, 'spiral_racetrack_fixed_length': <function spiral_racetrack_fixed_length at 0x7f29ef1e94e0>, 'spiral_racetrack_heater_metal': <function spiral_racetrack_heater_metal at 0x7f29ef1e96c0>, 'spiral_racetrack_heater_doped': <function spiral_racetrack_heater_doped at 0x7f29ef1e9800>, 'spiral_inductor': <function spiral_inductor at 0x7f29ef1e9940>, 'hline': <function hline at 0x7f29ef1e9bc0>, 'optimal_90deg': <function optimal_90deg at 0x7f29ef1e9d00>, 'optimal_hairpin': <function optimal_hairpin at 0x7f29ef1ea020>, 'optimal_step': <function optimal_step at 0x7f29ef1ea160>, 'snspd': <function snspd at 0x7f29ef1ea340>, 'interdigital_capacitor': <function interdigital_capacitor at 0x7f29ef1ea520>, 'ge_detector_straight_si_contacts': <function ge_detector_straight_si_contacts at 0x7f29ef1ea7a0>, 'edge_coupler_silicon': <function edge_coupler_silicon at 0x7f29ef1eaa20>, 'edge_coupler_array': <function edge_coupler_array at 0x7f29ef1eab60>, 'edge_coupler_array_with_loopback': <function edge_coupler_array_with_loopback at 0x7f29ef1eaca0>}, virtual_factories={'virtual_bend_circular': <function virtual_bend_circular_factory.<locals>.virtual_bend_circular at 0x7f29f98ef740>, 'bend_euler': <function virtual_bend_euler_factory.<locals>.bend_euler at 0x7f29f98ef9c0>, 'virtual_straight': <function virtual_straight_factory.<locals>.virtual_straight at 0x7f29f98efc40>, 'bend_circular_all_angle': <function bend_circular_all_angle at 0x7f29ef27c5e0>, 'bend_euler_all_angle': <function bend_euler_all_angle at 0x7f29ef27d120>, 'straight_all_angle': <function straight_all_angle at 0x7f29ef1056c0>}, kcells={0: Unnamed_0: ports [], 0 instances, 1: Unnamed_1: ports [], 3 instances, 2: text_THello!_S10_P0_0_Jleft_LWG: ports [], 0 instances, 3: Unnamed_3: ports [], 0 instances, 4: rectangle_S5_10_L2_0_CF_5b7c41dd: ports ['e1', 'e2', 'e3', 'e4'], 0 instances, 5: compass_S5_10_L2_0_PTel_ed85c3e2: ports ['e1', 'e2', 'e3', 'e4'], 0 instances}, layers=<aenum 'LAYER'>, infos=LayerInfos(), layer_stack=LayerStack(layers={}), netlist_layer_mapping={}, sparameters_path=None, interconnect_cml_path=None, constants=Constants(), rename_function=<function rename_clockwise_multi at 0x7f2a04844ae0>, info=Info(), settings=KCellSettings(version='0.23.2', klayout_version='0.29.11', meta_format='v3'), future_cell_name=None, decorators=<kfactory.decorators.Decorators object at 0x7f2a0487ecd0>) function_name=None basename=None boundary=None insts=<gdsfactory.component.ComponentReferences object at 0x7f29d4ffd650> size_info=<kfactory.kcell.SizeInfo object at 0x7f29d4fff750> dsize_info=<kfactory.kcell.DSizeInfo object at 0x7f29d4ffdd90> routes={}
c = gf.Component()
p1 = gf.kdb.DPolygon([(-8, -6), (6, 8), (7, 17), (9, 5)]) # DPolygons are in um
p2 = p1.sized(2)
c.add_polygon(p1, layer=(1, 0))
c.add_polygon(p2, layer=(2, 0))
c.plot()
For operating boolean operations Klayout Regions are very useful.
Notice that Many Klayout objects are in Database Units (DBU) which usually is 1nm, therefore we need to convert a DPolygon (in um) to DBU.
c = gf.Component()
p1 = gf.kdb.DPolygon([(-8, -6), (6, 8), (7, 17), (9, 5)])
r1 = gf.kdb.Region(p1.to_itype(gf.kcl.dbu)) # convert from um to DBU
r2 = r1.sized(2000) # in DBU
r3 = r2 - r1
c.add_polygon(r3, layer=(2, 0))
c.plot()
c = gf.Component()
p1 = [(-8, -6), (6, 8), (7, 17), (9, 5)]
s1 = c.add_polygon(p1, layer=(1, 0))
r1 = gf.kdb.Region(s1.polygon)
r2 = r1.sized(2000) # in DBU, 1 DBU = 1 nm, size it by 2000 nm = 2um
r3 = r2 - r1
c.add_polygon(r3, layer=(2, 0))
c.plot()
Connect ports#
Components can have a “Port” that allows you to connect ComponentReferences together like legos.
You can write a simple function to make a rectangular straight, assign ports to the ends, and then connect those rectangles together.
Notice that connect
transform each reference but things won’t remain connected if you move any of the references afterwards.
def straight(length=10, width: float = 1, layer=(1, 0)):
c = gf.Component()
c.add_polygon([(0, 0), (length, 0), (length, width), (0, width)], layer=layer)
c.add_port(
name="o1", center=(0, width / 2), width=width, orientation=180, layer=layer
)
c.add_port(
name="o2", center=(length, width / 2), width=width, orientation=0, layer=layer
)
return c
c = gf.Component()
wg1 = c << straight(length=6, width=2.5, layer=(1, 0))
wg2 = c << straight(length=6, width=2.5, layer=(2, 0))
wg3 = c << straight(length=15, width=2.5, layer=(3, 0))
wg2.movey(10)
wg2.drotate(10)
wg3.movey(20)
wg3.drotate(15)
c.plot()
wg2.movex(10)
Unnamed_9: ports ['o1', 'o2'], vinsts=[] info=Info() kcl=KCLayout(name='DEFAULT', layout=<klayout.dbcore.Layout object at 0x7f2a0487aad0>, layer_enclosures=LayerEnclosureModel(root={'5c226817': LayerEnclosure(layer_sections={}, main_layer=SLAB150 (2/0), yaml_tag='!Enclosure'), '78687732': LayerEnclosure(layer_sections={}, main_layer=WG (1/0), yaml_tag='!Enclosure'), '56396fc8': LayerEnclosure(layer_sections={}, main_layer=SLAB90 (3/0), yaml_tag='!Enclosure')}), cross_sections={'5c226817_10000': SymmetricalCrossSection(width=10000, enclosure=LayerEnclosure(layer_sections={}, main_layer=SLAB150 (2/0), yaml_tag='!Enclosure'), name='5c226817_10000'), '5c226817_5000': SymmetricalCrossSection(width=5000, enclosure=LayerEnclosure(layer_sections={}, main_layer=SLAB150 (2/0), yaml_tag='!Enclosure'), name='5c226817_5000'), '78687732_2500': SymmetricalCrossSection(width=2500, enclosure=LayerEnclosure(layer_sections={}, main_layer=WG (1/0), yaml_tag='!Enclosure'), name='78687732_2500'), '5c226817_2500': SymmetricalCrossSection(width=2500, enclosure=LayerEnclosure(layer_sections={}, main_layer=SLAB150 (2/0), yaml_tag='!Enclosure'), name='5c226817_2500'), '56396fc8_2500': SymmetricalCrossSection(width=2500, enclosure=LayerEnclosure(layer_sections={}, main_layer=SLAB90 (3/0), yaml_tag='!Enclosure'), name='56396fc8_2500')}, enclosure=KCellEnclosure(enclosures=LayerEnclosureCollection(enclosures=[])), library=<klayout.dbcore.Library object at 0x7f2a04894870>, factories={'taper': <function taper at 0x7f29ef27e020>, 'bend_s_bezier': <function bend_s_bezier_factory.<locals>.bend_s_bezier at 0x7f29fb1b36a0>, 'bend_circular': <function bend_circular at 0x7f29ef27c4a0>, 'bend_euler': <function bend_euler at 0x7f29ef27cea0>, 'bend_s_euler': <function bend_s_euler_factory.<locals>.bend_s_euler at 0x7f29f98ee840>, 'straight': <function straight at 0x7f29ef105580>, 'rotate': <function rotate at 0x7f29efe36c00>, 'from_image': <function from_image at 0x7f29ef828ae0>, 'floorplan_with_block_letters': <function floorplan_with_block_letters at 0x7f29ef3d7560>, 'bend_circular_heater': <function bend_circular_heater at 0x7f29ef27c720>, 'bend_euler_s': <function bend_euler_s at 0x7f29ef27cd60>, 'bezier': <function bezier at 0x7f29ef27d440>, 'bend_s': <function bend_s at 0x7f29ef27d620>, 'add_fiber_array_optical_south_electrical_north': <function add_fiber_array_optical_south_electrical_north at 0x7f29ef27d8a0>, 'ramp': <function ramp at 0x7f29ef27dda0>, 'taper_strip_to_ridge': <function taper_strip_to_ridge at 0x7f29ef27e0c0>, 'taper_strip_to_ridge_trenches': <function taper_strip_to_ridge_trenches at 0x7f29ef27e340>, 'taper_sc_nc': <function taper_sc_nc at 0x7f29ef27e480>, 'taper_adiabatic': <function taper_adiabatic at 0x7f29ef27e7a0>, 'taper_cross_section': <function taper_cross_section at 0x7f29ef27e980>, 'taper_from_csv': <function taper_from_csv at 0x7f29ef27eb60>, 'taper_parabolic': <function taper_parabolic at 0x7f29ef27eca0>, 'add_termination': <function add_termination at 0x7f29ef27e840>, 'add_trenches': <function add_trenches at 0x7f29ef27eac0>, 'array': <function array at 0x7f29ef27ee80>, 'copy_layers': <function copy_layers at 0x7f29ef27f380>, 'extend_ports_list': <function extend_ports_list at 0x7f29ef27f4c0>, 'extend_ports': <function extend_ports at 0x7f29ef27f7e0>, 'pack_doe': <function pack_doe at 0x7f29ef27fce0>, 'pack_doe_grid': <function pack_doe_grid at 0x7f29ef2b8180>, 'splitter_chain': <function splitter_chain at 0x7f29ef2b82c0>, 'mzi': <function mzi at 0x7f29ef2205e0>, 'mzi_lattice': <function mzi_lattice at 0x7f29ef2b8900>, 'mzi_lattice_mmi': <function mzi_lattice_mmi at 0x7f29ef2b8a40>, 'mzi_pads_center': <function mzi_pads_center at 0x7f29ef2b8cc0>, 'mzit': <function mzit at 0x7f29ef2b8ea0>, 'mzit_lattice': <function mzit_lattice at 0x7f29ef2b8fe0>, 'splitter_tree': <function splitter_tree at 0x7f29ef2b8b80>, 'coupler_symmetric': <function coupler_symmetric at 0x7f29ef2b91c0>, 'coupler_straight': <function coupler_straight at 0x7f29ef2b9300>, 'coupler': <function coupler at 0x7f29ef2b9440>, 'coupler90': <function coupler90 at 0x7f29ef2b9620>, 'coupler90bend': <function coupler90bend at 0x7f29ef2b96c0>, 'coupler_adiabatic': <function coupler_adiabatic at 0x7f29ef2b99e0>, 'coupler_asymmetric': <function coupler_asymmetric at 0x7f29ef2b9c60>, 'coupler_bent_half': <function coupler_bent_half at 0x7f29ef2b9f80>, 'coupler_bent': <function coupler_bent at 0x7f29ef2ba0c0>, 'coupler_broadband': <function coupler_broadband at 0x7f29ef2ba340>, 'coupler_full': <function coupler_full at 0x7f29ef2ba520>, 'coupler_ring': <function coupler_ring at 0x7f29ef2ba7a0>, 'coupler_straight_asymmetric': <function coupler_straight_asymmetric at 0x7f29ef2baa20>, 'align_wafer': <function align_wafer at 0x7f29ef2bade0>, 'add_frame': <function add_frame at 0x7f29ef2bae80>, 'die': <function die at 0x7f29ef2bb1a0>, 'die_with_pads': <function die_with_pads at 0x7f29ef2bb380>, 'seal_ring': <function seal_ring at 0x7f29ef2bb560>, 'seal_ring_segmented': <function seal_ring_segmented at 0x7f29ef2bb6a0>, 'wafer': <function wafer at 0x7f29ef2bb880>, 'free_propagation_region': <function free_propagation_region at 0x7f29ef2bbce0>, 'awg': <function awg at 0x7f29ef2bbd80>, 'dbr_cell': <function dbr_cell at 0x7f29ef2d40e0>, 'dbr': <function dbr at 0x7f29ef2d4220>, 'dbr_tapered': <function dbr_tapered at 0x7f29ef2d44a0>, 'bbox': <function bbox at 0x7f29ef2d4c20>, 'C': <function C at 0x7f29ef2d4e00>, 'circle': <function circle at 0x7f29ef2d4fe0>, 'compass': <function compass at 0x7f29ef2d5260>, 'cross': <function cross at 0x7f29ef2d5440>, 'ellipse': <function ellipse at 0x7f29ef2d5620>, 'fiducial_squares': <function fiducial_squares at 0x7f29ef2d5760>, 'L': <function L at 0x7f29ef2d5940>, 'nxn': <function nxn at 0x7f29ef2d5b20>, 'rectangle': <function rectangle at 0x7f29ef2d5d00>, 'rectangles': <function rectangles at 0x7f29ef2d5e40>, 'regular_polygon': <function regular_polygon at 0x7f29ef2d5f80>, 'triangle': <function triangle at 0x7f29ef2d6160>, 'triangle2': <function triangle2 at 0x7f29ef2d62a0>, 'triangle4': <function triangle4 at 0x7f29ef2d63e0>, 'fiber': <function fiber at 0x7f29ef2d5da0>, 'fiber_array': <function fiber_array at 0x7f29ef2d6480>, 'crossing_arm': <function crossing_arm at 0x7f29ef104ea0>, 'crossing': <function crossing at 0x7f29ef104fe0>, 'crossing_linear_taper': <function crossing_linear_taper at 0x7f29ef105120>, 'crossing_etched': <function crossing_etched at 0x7f29ef105260>, 'crossing45': <function crossing45 at 0x7f29ef1053a0>, 'straight_array': <function straight_array at 0x7f29ef105800>, 'wire_straight': <function wire_straight at 0x7f29ef105940>, 'straight_heater_doped_rib': <function straight_heater_doped_rib at 0x7f29ef105d00>, 'straight_heater_doped_strip': <function straight_heater_doped_strip at 0x7f29ef105ee0>, 'straight_heater_meander': <function straight_heater_meander at 0x7f29ef106200>, 'via': <function via at 0x7f29ef106a20>, 'via_circular': <function via_circular at 0x7f29ef106b60>, 'via_chain': <function via_chain at 0x7f29ef106e80>, 'via_corner': <function via_corner at 0x7f29ef107060>, 'via_stack': <function via_stack at 0x7f29ef107240>, 'via_stack_corner45': <function via_stack_corner45 at 0x7f29ef107380>, 'via_stack_corner45_extended': <function via_stack_corner45_extended at 0x7f29ef1074c0>, 'via_stack_with_offset': <function via_stack_with_offset at 0x7f29ef107600>, 'straight_heater_meander_doped': <function straight_heater_meander_doped at 0x7f29ef106700>, 'straight_heater_metal_undercut': <function straight_heater_metal_undercut at 0x7f29ef107560>, 'straight_heater_metal_simple': <function straight_heater_metal_simple at 0x7f29ef107880>, 'straight_piecewise': <function straight_piecewise at 0x7f29ef1079c0>, 'straight_pin': <function straight_pin at 0x7f29ef107a60>, 'straight_pin_slot': <function straight_pin_slot at 0x7f29ef107ce0>, 'wire_corner': <function wire_corner at 0x7f29ef107f60>, 'wire_corner45': <function wire_corner45 at 0x7f29ef12c0e0>, 'wire_corner_sections': <function wire_corner_sections at 0x7f29ef12c180>, 'loop_mirror': <function loop_mirror at 0x7f29ef2d6340>, 'mode_converter': <function mode_converter at 0x7f29ef12dbc0>, 'polarization_splitter_rotator': <function polarization_splitter_rotator at 0x7f29ef12dee0>, 'terminator': <function terminator at 0x7f29ef12e480>, 'grating_coupler_array': <function grating_coupler_array at 0x7f29ef12e700>, 'grating_coupler_dual_pol': <function grating_coupler_dual_pol at 0x7f29ef12ea20>, 'grating_coupler_elliptical': <function grating_coupler_elliptical at 0x7f29ef12f060>, 'grating_coupler_elliptical_arbitrary': <function grating_coupler_elliptical_arbitrary at 0x7f29ef12f2e0>, 'grating_coupler_elliptical_uniform': <function grating_coupler_elliptical_uniform at 0x7f29ef12f560>, 'grating_coupler_elliptical_lumerical': <function grating_coupler_elliptical_lumerical at 0x7f29ef12f6a0>, 'grating_coupler_elliptical_trenches': <function grating_coupler_elliptical_trenches at 0x7f29ef12f740>, 'grating_coupler_loss': <function grating_coupler_loss at 0x7f29ef12fb00>, 'grating_coupler_rectangular': <function grating_coupler_rectangular at 0x7f29ef12fce0>, 'grating_coupler_rectangular_arbitrary': <function grating_coupler_rectangular_arbitrary at 0x7f29ef12ff60>, 'grating_coupler_tree': <function grating_coupler_tree at 0x7f29ef150220>, 'mmi': <function mmi at 0x7f29ef150540>, 'mmi1x2': <function mmi1x2 at 0x7f29ef150860>, 'mmi1x2_with_sbend': <function mmi1x2_with_sbend at 0x7f29ef150a40>, 'mmi2x2': <function mmi2x2 at 0x7f29ef150d60>, 'mmi2x2_with_sbend': <function mmi2x2_with_sbend at 0x7f29ef150ea0>, 'mmi_90degree_hybrid': <function mmi_90degree_hybrid at 0x7f29ef151080>, 'mmi_tapered': <function mmi_tapered at 0x7f29ef1513a0>, 'pad': <function pad at 0x7f29ef151620>, 'pad_array': <function pad_array at 0x7f29ef1518a0>, 'pad_gsg_short': <function pad_gsg_short at 0x7f29ef151b20>, 'pads_shorted': <function pads_shorted at 0x7f29ef151da0>, 'rectangle_with_slits': <function rectangle_with_slits at 0x7f29ef151ee0>, 'cavity': <function cavity at 0x7f29ef152160>, 'cdsem_all': <function cdsem_all at 0x7f29ef1523e0>, 'cdsem_bend180': <function cdsem_bend180 at 0x7f29ef1525c0>, 'cdsem_coupler': <function cdsem_coupler at 0x7f29ef152700>, 'cdsem_straight': <function cdsem_straight at 0x7f29ef152a20>, 'cdsem_straight_density': <function cdsem_straight_density at 0x7f29ef152b60>, '_bendu_double': <function _bendu_double at 0x7f29ef152de0>, '_straight_double': <function _straight_double at 0x7f29ef152f20>, 'cutback_2x2': <function cutback_2x2 at 0x7f29ef153060>, 'cutback_bend': <function cutback_bend at 0x7f29ef153420>, 'cutback_bend90': <function cutback_bend90 at 0x7f29ef153560>, 'staircase': <function staircase at 0x7f29ef1536a0>, 'cutback_bend180': <function cutback_bend180 at 0x7f29ef1537e0>, 'cutback_component': <function cutback_component at 0x7f29ef153920>, 'cutback_splitter': <function cutback_splitter at 0x7f29ef153ce0>, 'greek_cross': <function greek_cross at 0x7f29ef153e20>, 'greek_cross_with_pads': <function greek_cross_with_pads at 0x7f29ef1940e0>, 'litho_calipers': <function litho_calipers at 0x7f29ef1942c0>, 'litho_ruler': <function litho_ruler at 0x7f29ef1945e0>, 'litho_steps': <function litho_steps at 0x7f29ef1947c0>, 'resistance_meander': <function resistance_meander at 0x7f29ef194900>, 'resistance_sheet': <function resistance_sheet at 0x7f29ef194ae0>, 'verniers': <function verniers at 0x7f29ef194cc0>, 'text': <function text at 0x7f29ef1959e0>, 'text_lines': <function text_lines at 0x7f29ef195bc0>, 'text_klayout': <function text_klayout at 0x7f29ef195d00>, 'text_freetype': <function text_freetype at 0x7f29ef196020>, 'pixel_array': <function pixel_array at 0x7f29ef1962a0>, 'text_rectangular': <function text_rectangular at 0x7f29ef1963e0>, 'text_rectangular_multi_layer': <function text_rectangular_multi_layer at 0x7f29ef196520>, 'pixel': <function pixel at 0x7f29ef194fe0>, 'qrcode': <function qrcode at 0x7f29ef196200>, 'version_stamp': <function version_stamp at 0x7f29ef1965c0>, 'disk': <function disk at 0x7f29ef196b60>, 'disk_heater': <function disk_heater at 0x7f29ef196ca0>, 'ring': <function ring at 0x7f29ef196f20>, 'ring_crow': <function ring_crow at 0x7f29ef197100>, 'ring_crow_couplers': <function ring_crow_couplers at 0x7f29ef197240>, 'ring_double': <function ring_double at 0x7f29ef197420>, 'ring_double_bend_coupler': <function ring_double_bend_coupler at 0x7f29ef197740>, 'ring_double_heater': <function ring_double_heater at 0x7f29ef197880>, 'ring_double_pn': <function ring_double_pn at 0x7f29ef197ba0>, 'ring_single_pn': <function ring_single_pn at 0x7f29ef197ce0>, 'ring_single': <function ring_single at 0x7f29ef197ec0>, 'ring_single_array': <function ring_single_array at 0x7f29ef197f60>, 'coupler_bend': <function coupler_bend at 0x7f29ef1e8180>, 'coupler_ring_bend': <function coupler_ring_bend at 0x7f29ef1e82c0>, 'ring_single_bend_coupler': <function ring_single_bend_coupler at 0x7f29ef1e8400>, 'ring_single_dut': <function ring_single_dut at 0x7f29ef1e85e0>, 'delay_snake': <function delay_snake at 0x7f29ef1e8860>, 'delay_snake2': <function delay_snake2 at 0x7f29ef1e8a40>, 'delay_snake_sbend': <function delay_snake_sbend at 0x7f29ef1e8cc0>, 'spiral': <function spiral at 0x7f29ef1e8f40>, 'spiral_double': <function spiral_double at 0x7f29ef1e9120>, 'spiral_racetrack': <function spiral_racetrack at 0x7f29ef1e93a0>, 'spiral_racetrack_fixed_length': <function spiral_racetrack_fixed_length at 0x7f29ef1e94e0>, 'spiral_racetrack_heater_metal': <function spiral_racetrack_heater_metal at 0x7f29ef1e96c0>, 'spiral_racetrack_heater_doped': <function spiral_racetrack_heater_doped at 0x7f29ef1e9800>, 'spiral_inductor': <function spiral_inductor at 0x7f29ef1e9940>, 'hline': <function hline at 0x7f29ef1e9bc0>, 'optimal_90deg': <function optimal_90deg at 0x7f29ef1e9d00>, 'optimal_hairpin': <function optimal_hairpin at 0x7f29ef1ea020>, 'optimal_step': <function optimal_step at 0x7f29ef1ea160>, 'snspd': <function snspd at 0x7f29ef1ea340>, 'interdigital_capacitor': <function interdigital_capacitor at 0x7f29ef1ea520>, 'ge_detector_straight_si_contacts': <function ge_detector_straight_si_contacts at 0x7f29ef1ea7a0>, 'edge_coupler_silicon': <function edge_coupler_silicon at 0x7f29ef1eaa20>, 'edge_coupler_array': <function edge_coupler_array at 0x7f29ef1eab60>, 'edge_coupler_array_with_loopback': <function edge_coupler_array_with_loopback at 0x7f29ef1eaca0>}, virtual_factories={'virtual_bend_circular': <function virtual_bend_circular_factory.<locals>.virtual_bend_circular at 0x7f29f98ef740>, 'bend_euler': <function virtual_bend_euler_factory.<locals>.bend_euler at 0x7f29f98ef9c0>, 'virtual_straight': <function virtual_straight_factory.<locals>.virtual_straight at 0x7f29f98efc40>, 'bend_circular_all_angle': <function bend_circular_all_angle at 0x7f29ef27c5e0>, 'bend_euler_all_angle': <function bend_euler_all_angle at 0x7f29ef27d120>, 'straight_all_angle': <function straight_all_angle at 0x7f29ef1056c0>}, kcells={0: Unnamed_0: ports [], 0 instances, 1: Unnamed_1: ports [], 3 instances, 2: text_THello!_S10_P0_0_Jleft_LWG: ports [], 0 instances, 3: Unnamed_3: ports [], 0 instances, 4: rectangle_S5_10_L2_0_CF_5b7c41dd: ports ['e1', 'e2', 'e3', 'e4'], 0 instances, 5: compass_S5_10_L2_0_PTel_ed85c3e2: ports ['e1', 'e2', 'e3', 'e4'], 0 instances, 6: Unnamed_6: ports [], 0 instances, 7: Unnamed_7: ports [], 0 instances, 8: Unnamed_8: ports [], 0 instances, 9: Unnamed_9: ports [], 3 instances, 10: Unnamed_10: ports ['o1', 'o2'], 0 instances, 11: Unnamed_11: ports ['o1', 'o2'], 0 instances, 12: Unnamed_12: ports ['o1', 'o2'], 0 instances}, layers=<aenum 'LAYER'>, infos=LayerInfos(), layer_stack=LayerStack(layers={}), netlist_layer_mapping={}, sparameters_path=None, interconnect_cml_path=None, constants=Constants(), rename_function=<function rename_clockwise_multi at 0x7f2a04844ae0>, info=Info(), settings=KCellSettings(version='0.23.2', klayout_version='0.29.11', meta_format='v3'), future_cell_name=None, decorators=<kfactory.decorators.Decorators object at 0x7f2a0487ecd0>) function_name=None basename=None boundary=None insts=<gdsfactory.component.ComponentReferences object at 0x7f29d013b8d0> size_info=<kfactory.kcell.SizeInfo object at 0x7f29d013aa90> dsize_info=<kfactory.kcell.DSizeInfo object at 0x7f29d013bc10> routes={}
Now we can connect everything together using the ports:
Each straight has two ports: ‘o1’ and ‘o2’, respectively on the East and West sides of the rectangular straight component. These are arbitrary names defined in our straight() function above
# Let's keep wg1 in place on the bottom, and connect the other straights to it.
# To do that, on wg2 we'll grab the "o1" port and connect it to the "o2" on wg1:
wg2.connect("o1", wg1.ports["o2"], allow_layer_mismatch=True)
# Next, on wg3 let's grab the "o1" port and connect it to the "o2" on wg2:
wg3.connect("o1", wg2.ports["o2"], allow_layer_mismatch=True)
c.plot()
Ports can be added by copying existing ports. In the example below, ports are added at the component-level on c from the existing ports of children wg1 and wg3 (i.e. eastmost and westmost ports)
c.add_port("o1", port=wg1.ports["o1"])
c.add_port("o2", port=wg3.ports["o2"])
c.plot()
You can show the ports by adding port pins with triangular shape or using the show_ports plugin
c.draw_ports()
c.plot()
Also you can visualize ports in klayout as the ports are stored in the GDS cell metadata.
Move and rotate Instances#
You can move, rotate, and reflect component instances.
There are two main types of movement:
Using Integer DataBaseUnits (DBU) (default), in most foundries, 1 DBU = 1nm
Using Decimals Floats. Where 1.0 represents 1.0um
c = gf.Component()
wg1 = c << straight(length=1, layer=(1, 0))
wg2 = c << straight(length=2, layer=(2, 0))
wg3 = c << straight(length=3, layer=(3, 0))
# Shift the second straight we created over by dx = 2, dy = 2 um. D stands for Decimal
wg2.move((2.0, 2.0))
# Then, move again the third straight by 3um
wg3.movex(3) # equivalent to wg3.move(3)
c.plot()
You can also define the positions relative to other references.
c = gf.Component()
wg1 = c << straight(length=1, layer=(1, 0))
wg2 = c << straight(length=2, layer=(2, 0))
wg3 = c << straight(length=3, layer=(3, 0))
# Shift the second straight we created over so that the xmin matches wg1.xmax
wg2.xmin = wg1.xmax
# Then, leave a 1um gap with on the last straight
wg3.xmin = wg2.xmax + 1
c.plot()
Ports#
Your straights wg1/wg2/wg3 are references to other waveguide components.
If you want to add ports to the new Component c
you can use add_port
, where you can create a new port or use a reference to an existing port from the underlying reference.
You can access the ports of a Component or ComponentReference
import gdsfactory as gf
def straight(length: float = 10, width: float = 1, layer=(1, 0)):
c = gf.Component()
c.add_polygon([(0, 0), (length, 0), (length, width), (0, width)], layer=layer)
c.add_port(
name="o1", center=(0, width / 2), width=width, orientation=180, layer=layer
)
c.add_port(
name="o2", center=(length, width / 2), width=width, orientation=0, layer=layer
)
return c
s = straight(length=10)
s.draw_ports()
s.pprint_ports()
s
┏━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━┓ ┃ name ┃ width ┃ orientation ┃ layer ┃ center ┃ port_type ┃ ┡━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━┩ │ o1 │ 1.0 │ 180.0 │ WG (1/0) │ (0.0, 0.5) │ optical │ │ o2 │ 1.0 │ 0.0 │ WG (1/0) │ (10.0, 0.5) │ optical │ └──────┴───────┴─────────────┴──────────┴─────────────┴───────────┘
References#
Now that your component c
is a multi-straight component, you can add references to that component in a new blank Component c2
, then add two references and shift one to see the movement.
c2 = gf.Component()
wg1 = straight(length=10)
wg2 = straight(length=10, layer=(2, 0))
mwg1_ref = c2.add_ref(wg1)
mwg2_ref = c2.add_ref(wg2)
mwg2_ref.movex(10)
c2.plot()
# Like before, let's connect mwg1 and mwg2 together
mwg1_ref.connect(port="o2", other=mwg2_ref.ports["o1"], allow_layer_mismatch=True)
c2.plot()
Labels#
You can add abstract GDS labels to annotate your Components, in order to record information
directly into the final GDS file without putting any extra geometry onto any layer
This label will display in a GDS viewer, but will not be rendered or printed
like the polygons created by gf.components.text()
.
c2.add_label(text="First label", position=mwg1_ref.dcenter)
c2.add_label(text="Second label", position=mwg2_ref.dcenter)
# labels are useful for recording information
c2.add_label(
text=f"The x size of this\nlayout is {c2.xsize}",
position=(c2.x, c2.y),
layer=(10, 0),
)
c2.plot()
Another simple example
c = gf.Component()
r = c << gf.components.rectangle(size=(1, 1))
r.x = 0
r.y = 0
c.add_label(
text="Demo label",
position=(0, 0),
layer=(1, 0),
)
c.plot()
Boolean shapes#
If you want to subtract one shape from another, merge two shapes, or
perform an XOR on them, you can do that with the boolean()
function.
The operation
argument should be {not, and, or, xor, ‘A-B’, ‘B-A’, ‘A+B’}.
Note that ‘A+B’ is equivalent to ‘or’, ‘A-B’ is equivalent to ‘not’, and
‘B-A’ is equivalent to ‘not’ with the operands switched
c = gf.Component()
e1 = c.add_ref(gf.components.ellipse(layer=(2, 0)))
e2 = c.add_ref(gf.components.ellipse(radii=(10, 6), layer=(2, 0))).movex(2)
e3 = c.add_ref(gf.components.ellipse(radii=(10, 4), layer=(2, 0))).movex(5)
c.plot()
c2 = gf.boolean(A=e2, B=e1, operation="not", layer=(2, 0))
c2.plot()
Move Reference by port#
c = gf.Component()
mmi = c.add_ref(gf.components.mmi1x2())
bend = c.add_ref(gf.components.bend_circular(layer=(1, 0)))
c.plot()
bend.connect("o1", mmi.ports["o2"]) # connects follow Source -> Destination syntax
c.plot()
Mirror reference#
By default the mirror works along the y-axis.
c = gf.Component()
mmi = c.add_ref(gf.components.mmi1x2())
bend = c.add_ref(gf.components.bend_circular())
bend.connect(
"o1", mmi.ports["o2"], mirror=True
) # connects follow Source -> Destination syntax
c.plot()
Write#
You can write your Component to:
GDS file (Graphical Database System) or OASIS for chips.
gerber for PCB.
STL for 3d printing.
import gdsfactory as gf
c = gf.components.cross()
c.write_gds("demo.gds")
c.plot()
You can see the GDS file in Klayout viewer.
Sometimes you also want to save the GDS together with metadata (settings, port names, widths, locations …) in YAML
c.write_gds("demo.gds", with_metadata=True)
PosixPath('demo.gds')
OASIS is a newer format that can store CAD files and that reduces the size.
c.write("demo.oas")
You can also save it as STL for 3D printing or for device level simulations. For that you need to extrude the polygons using the information in the LayerStack.
gf.export.to_stl(c, "demo.stl")
Write PosixPath('/home/runner/work/gdsfactory/gdsfactory/notebooks/demo_1_0.stl') zmin = 0.000, height = 0.220
scene = c.to_3d()
scene.show()