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-20 22:52:30.457 | WARNING | kfactory.kcell:show:8757 - 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 0x7f5aec395810>, 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 0x7f5aec3953b0>, factories={'taper': <function taper at 0x7f5ad6d71bc0>, 'bend_s_bezier': <function bend_s_bezier_factory.<locals>.bend_s_bezier at 0x7f5ae14b3f60>, 'bend_circular': <function bend_circular at 0x7f5ad6d17f60>, 'bend_euler': <function bend_euler at 0x7f5ad6d70a40>, 'bend_s_euler': <function bend_s_euler_factory.<locals>.bend_s_euler at 0x7f5ae14ca520>, 'straight': <function straight at 0x7f5ad6df9120>, 'rotate': <function rotate at 0x7f5ad78e68e0>, 'from_image': <function from_image at 0x7f5ad73e0f40>, 'floorplan_with_block_letters': <function floorplan_with_block_letters at 0x7f5ad71c7100>, 'bend_circular_heater': <function bend_circular_heater at 0x7f5ad6d702c0>, 'bend_euler_s': <function bend_euler_s at 0x7f5ad6d70900>, 'bezier': <function bezier at 0x7f5ad6d70fe0>, 'bend_s': <function bend_s at 0x7f5ad6d711c0>, 'add_fiber_array_optical_south_electrical_north': <function add_fiber_array_optical_south_electrical_north at 0x7f5ad6d71440>, 'ramp': <function ramp at 0x7f5ad6d71940>, 'taper_strip_to_ridge': <function taper_strip_to_ridge at 0x7f5ad6d71c60>, 'taper_strip_to_ridge_trenches': <function taper_strip_to_ridge_trenches at 0x7f5ad6d71ee0>, 'taper_sc_nc': <function taper_sc_nc at 0x7f5ad6d72020>, 'taper_adiabatic': <function taper_adiabatic at 0x7f5ad6d72340>, 'taper_cross_section': <function taper_cross_section at 0x7f5ad6d72520>, 'taper_from_csv': <function taper_from_csv at 0x7f5ad6d72700>, 'taper_parabolic': <function taper_parabolic at 0x7f5ad6d72840>, 'add_termination': <function add_termination at 0x7f5ad6d723e0>, 'add_trenches': <function add_trenches at 0x7f5ad6d72660>, 'array': <function array at 0x7f5ad6d72a20>, 'copy_layers': <function copy_layers at 0x7f5ad6d72f20>, 'extend_ports_list': <function extend_ports_list at 0x7f5ad6d73060>, 'extend_ports': <function extend_ports at 0x7f5ad6d73380>, 'pack_doe': <function pack_doe at 0x7f5ad6d73ba0>, 'pack_doe_grid': <function pack_doe_grid at 0x7f5ad6d73ce0>, 'splitter_chain': <function splitter_chain at 0x7f5ad6d73e20>, 'mzi': <function mzi at 0x7f5ad71c7f60>, 'mzi_lattice': <function mzi_lattice at 0x7f5ad6da84a0>, 'mzi_lattice_mmi': <function mzi_lattice_mmi at 0x7f5ad6da85e0>, 'mzi_pads_center': <function mzi_pads_center at 0x7f5ad6da8860>, 'mzit': <function mzit at 0x7f5ad6da8a40>, 'mzit_lattice': <function mzit_lattice at 0x7f5ad6da8b80>, 'splitter_tree': <function splitter_tree at 0x7f5ad6d14180>, 'coupler_symmetric': <function coupler_symmetric at 0x7f5ad6da8d60>, 'coupler_straight': <function coupler_straight at 0x7f5ad6da8ea0>, 'coupler': <function coupler at 0x7f5ad6da8fe0>, 'coupler90': <function coupler90 at 0x7f5ad6da91c0>, 'coupler90bend': <function coupler90bend at 0x7f5ad6da9260>, 'coupler_adiabatic': <function coupler_adiabatic at 0x7f5ad6da9580>, 'coupler_asymmetric': <function coupler_asymmetric at 0x7f5ad6da9800>, 'coupler_bent_half': <function coupler_bent_half at 0x7f5ad6da9b20>, 'coupler_bent': <function coupler_bent at 0x7f5ad6da9c60>, 'coupler_broadband': <function coupler_broadband at 0x7f5ad6da9ee0>, 'coupler_full': <function coupler_full at 0x7f5ad6daa0c0>, 'coupler_ring': <function coupler_ring at 0x7f5ad6daa340>, 'coupler_straight_asymmetric': <function coupler_straight_asymmetric at 0x7f5ad6daa5c0>, 'align_wafer': <function align_wafer at 0x7f5ad6daa980>, 'add_frame': <function add_frame at 0x7f5ad6daaa20>, 'die': <function die at 0x7f5ad6daad40>, 'die_with_pads': <function die_with_pads at 0x7f5ad6daaf20>, 'seal_ring': <function seal_ring at 0x7f5ad6dab100>, 'seal_ring_segmented': <function seal_ring_segmented at 0x7f5ad6dab240>, 'wafer': <function wafer at 0x7f5ad6dab420>, 'free_propagation_region': <function free_propagation_region at 0x7f5ad6dab880>, 'awg': <function awg at 0x7f5ad6dab920>, 'dbr_cell': <function dbr_cell at 0x7f5ad6dabc40>, 'dbr': <function dbr at 0x7f5ad6dabd80>, 'dbr_tapered': <function dbr_tapered at 0x7f5ad6dabf60>, 'bbox': <function bbox at 0x7f5ad6dc47c0>, 'C': <function C at 0x7f5ad6dc49a0>, 'circle': <function circle at 0x7f5ad6dc4b80>, 'compass': <function compass at 0x7f5ad6dc4e00>, 'cross': <function cross at 0x7f5ad6dc4fe0>, 'ellipse': <function ellipse at 0x7f5ad6dc51c0>, 'fiducial_squares': <function fiducial_squares at 0x7f5ad6dc5300>, 'L': <function L at 0x7f5ad6dc54e0>, 'nxn': <function nxn at 0x7f5ad6dc56c0>, 'rectangle': <function rectangle at 0x7f5ad6dc58a0>, 'rectangles': <function rectangles at 0x7f5ad6dc59e0>, 'regular_polygon': <function regular_polygon at 0x7f5ad6dc5b20>, 'triangle': <function triangle at 0x7f5ad6dc5d00>, 'triangle2': <function triangle2 at 0x7f5ad6dc5e40>, 'triangle4': <function triangle4 at 0x7f5ad6dc5f80>, 'fiber': <function fiber at 0x7f5ad6dc5940>, 'fiber_array': <function fiber_array at 0x7f5ad6dc6020>, 'crossing_arm': <function crossing_arm at 0x7f5ad6df8a40>, 'crossing': <function crossing at 0x7f5ad6df8b80>, 'crossing_linear_taper': <function crossing_linear_taper at 0x7f5ad6df8cc0>, 'crossing_etched': <function crossing_etched at 0x7f5ad6df8e00>, 'crossing45': <function crossing45 at 0x7f5ad6df8f40>, 'straight_array': <function straight_array at 0x7f5ad6df93a0>, 'wire_straight': <function wire_straight at 0x7f5ad6df94e0>, 'straight_heater_doped_rib': <function straight_heater_doped_rib at 0x7f5ad6df98a0>, 'straight_heater_doped_strip': <function straight_heater_doped_strip at 0x7f5ad6df9a80>, 'straight_heater_meander': <function straight_heater_meander at 0x7f5ad6df9da0>, 'via': <function via at 0x7f5ad6dfa5c0>, 'via_circular': <function via_circular at 0x7f5ad6dfa700>, 'via_chain': <function via_chain at 0x7f5ad6dfaa20>, 'via_corner': <function via_corner at 0x7f5ad6dfac00>, 'via_stack': <function via_stack at 0x7f5ad6dfade0>, 'via_stack_corner45': <function via_stack_corner45 at 0x7f5ad6dfaf20>, 'via_stack_corner45_extended': <function via_stack_corner45_extended at 0x7f5ad6dfb060>, 'via_stack_with_offset': <function via_stack_with_offset at 0x7f5ad6dfb1a0>, 'straight_heater_meander_doped': <function straight_heater_meander_doped at 0x7f5ad6dfa2a0>, 'straight_heater_metal_undercut': <function straight_heater_metal_undercut at 0x7f5ad6dfb100>, 'straight_heater_metal_simple': <function straight_heater_metal_simple at 0x7f5ad6dfb420>, 'straight_piecewise': <function straight_piecewise at 0x7f5ad6dfb560>, 'straight_pin': <function straight_pin at 0x7f5ad6dfb600>, 'straight_pin_slot': <function straight_pin_slot at 0x7f5ad6dfb880>, 'wire_corner': <function wire_corner at 0x7f5ad6dfbb00>, 'wire_corner45': <function wire_corner45 at 0x7f5ad6dfbc40>, 'wire_corner_sections': <function wire_corner_sections at 0x7f5ad6dfbce0>, 'loop_mirror': <function loop_mirror at 0x7f5ad6dc6200>, 'mode_converter': <function mode_converter at 0x7f5ad6c1d760>, 'polarization_splitter_rotator': <function polarization_splitter_rotator at 0x7f5ad6c1da80>, 'terminator': <function terminator at 0x7f5ad6c1e020>, 'grating_coupler_array': <function grating_coupler_array at 0x7f5ad6c1e2a0>, 'grating_coupler_dual_pol': <function grating_coupler_dual_pol at 0x7f5ad6c1e5c0>, 'grating_coupler_elliptical': <function grating_coupler_elliptical at 0x7f5ad6c1ec00>, 'grating_coupler_elliptical_arbitrary': <function grating_coupler_elliptical_arbitrary at 0x7f5ad6c1ee80>, 'grating_coupler_elliptical_uniform': <function grating_coupler_elliptical_uniform at 0x7f5ad6c1f100>, 'grating_coupler_elliptical_lumerical': <function grating_coupler_elliptical_lumerical at 0x7f5ad6c1f240>, 'grating_coupler_elliptical_trenches': <function grating_coupler_elliptical_trenches at 0x7f5ad6c1f2e0>, 'grating_coupler_loss': <function grating_coupler_loss at 0x7f5ad6c1f6a0>, 'grating_coupler_rectangular': <function grating_coupler_rectangular at 0x7f5ad6c1f880>, 'grating_coupler_rectangular_arbitrary': <function grating_coupler_rectangular_arbitrary at 0x7f5ad6c1fb00>, 'grating_coupler_tree': <function grating_coupler_tree at 0x7f5ad6c1fd80>, 'mmi': <function mmi at 0x7f5ad6c480e0>, 'mmi1x2': <function mmi1x2 at 0x7f5ad6c48400>, 'mmi1x2_with_sbend': <function mmi1x2_with_sbend at 0x7f5ad6c485e0>, 'mmi2x2': <function mmi2x2 at 0x7f5ad6c48900>, 'mmi2x2_with_sbend': <function mmi2x2_with_sbend at 0x7f5ad6c48a40>, 'mmi_90degree_hybrid': <function mmi_90degree_hybrid at 0x7f5ad6c48c20>, 'mmi_tapered': <function mmi_tapered at 0x7f5ad6c48f40>, 'pad': <function pad at 0x7f5ad6c491c0>, 'pad_array': <function pad_array at 0x7f5ad6c49440>, 'pad_gsg_short': <function pad_gsg_short at 0x7f5ad6c496c0>, 'pads_shorted': <function pads_shorted at 0x7f5ad6c49940>, 'rectangle_with_slits': <function rectangle_with_slits at 0x7f5ad6c49a80>, 'cavity': <function cavity at 0x7f5ad6c49d00>, 'cdsem_all': <function cdsem_all at 0x7f5ad6c49f80>, 'cdsem_bend180': <function cdsem_bend180 at 0x7f5ad6c4a160>, 'cdsem_coupler': <function cdsem_coupler at 0x7f5ad6c4a2a0>, 'cdsem_straight': <function cdsem_straight at 0x7f5ad6c4a5c0>, 'cdsem_straight_density': <function cdsem_straight_density at 0x7f5ad6c4a700>, 'bendu_double': <function bendu_double at 0x7f5ad6c4a980>, 'straight_double': <function straight_double at 0x7f5ad6c4aac0>, 'cutback_2x2': <function cutback_2x2 at 0x7f5ad6c4ac00>, 'cutback_bend': <function cutback_bend at 0x7f5ad6c4afc0>, 'cutback_bend90': <function cutback_bend90 at 0x7f5ad6c4b100>, 'staircase': <function staircase at 0x7f5ad6c4b240>, 'cutback_bend180': <function cutback_bend180 at 0x7f5ad6c4b380>, 'cutback_component': <function cutback_component at 0x7f5ad6c4b4c0>, 'cutback_splitter': <function cutback_splitter at 0x7f5ad6c4b880>, 'greek_cross': <function greek_cross at 0x7f5ad6c4b9c0>, 'greek_cross_with_pads': <function greek_cross_with_pads at 0x7f5ad6c4bc40>, 'litho_calipers': <function litho_calipers at 0x7f5ad6c4be20>, 'litho_ruler': <function litho_ruler at 0x7f5ad6c88180>, 'litho_steps': <function litho_steps at 0x7f5ad6c88360>, 'resistance_meander': <function resistance_meander at 0x7f5ad6c884a0>, 'resistance_sheet': <function resistance_sheet at 0x7f5ad6c88680>, 'verniers': <function verniers at 0x7f5ad6c88860>, 'text': <function text at 0x7f5ad6c89580>, 'text_lines': <function text_lines at 0x7f5ad6c89760>, 'text_klayout': <function text_klayout at 0x7f5ad6c898a0>, 'text_freetype': <function text_freetype at 0x7f5ad6c89bc0>, 'pixel_array': <function pixel_array at 0x7f5ad6c89e40>, 'text_rectangular': <function text_rectangular at 0x7f5ad6c89f80>, 'text_rectangular_multi_layer': <function text_rectangular_multi_layer at 0x7f5ad6c8a0c0>, 'pixel': <function pixel at 0x7f5ad6c88b80>, 'qrcode': <function qrcode at 0x7f5ad6c89da0>, 'version_stamp': <function version_stamp at 0x7f5ad6c8a160>, 'disk': <function disk at 0x7f5ad6c8a700>, 'disk_heater': <function disk_heater at 0x7f5ad6c8a840>, 'ring': <function ring at 0x7f5ad6c8aac0>, 'ring_crow': <function ring_crow at 0x7f5ad6c8aca0>, 'ring_crow_couplers': <function ring_crow_couplers at 0x7f5ad6c8ade0>, 'ring_double': <function ring_double at 0x7f5ad6c8afc0>, 'ring_double_bend_coupler': <function ring_double_bend_coupler at 0x7f5ad6c8b2e0>, 'ring_double_heater': <function ring_double_heater at 0x7f5ad6c8b420>, 'ring_double_pn': <function ring_double_pn at 0x7f5ad6c8b740>, 'ring_single_pn': <function ring_single_pn at 0x7f5ad6c8b880>, 'ring_single': <function ring_single at 0x7f5ad6c8ba60>, 'ring_single_array': <function ring_single_array at 0x7f5ad6c8bba0>, 'coupler_bend': <function coupler_bend at 0x7f5ad6c8bce0>, 'coupler_ring_bend': <function coupler_ring_bend at 0x7f5ad6c8be20>, 'ring_single_bend_coupler': <function ring_single_bend_coupler at 0x7f5ad6c8bf60>, 'ring_single_dut': <function ring_single_dut at 0x7f5ad6ce4180>, 'delay_snake': <function delay_snake at 0x7f5ad6ce4400>, 'delay_snake2': <function delay_snake2 at 0x7f5ad6ce45e0>, 'delay_snake_sbend': <function delay_snake_sbend at 0x7f5ad6ce4860>, 'spiral': <function spiral at 0x7f5ad6ce4ae0>, 'spiral_double': <function spiral_double at 0x7f5ad6ce4cc0>, 'spiral_racetrack': <function spiral_racetrack at 0x7f5ad6ce4f40>, 'spiral_racetrack_fixed_length': <function spiral_racetrack_fixed_length at 0x7f5ad6ce5080>, 'spiral_racetrack_heater_metal': <function spiral_racetrack_heater_metal at 0x7f5ad6ce5260>, 'spiral_racetrack_heater_doped': <function spiral_racetrack_heater_doped at 0x7f5ad6ce53a0>, 'spiral_inductor': <function spiral_inductor at 0x7f5ad6ce54e0>, 'hline': <function hline at 0x7f5ad6ce5760>, 'optimal_90deg': <function optimal_90deg at 0x7f5ad6ce58a0>, 'optimal_hairpin': <function optimal_hairpin at 0x7f5ad6ce5bc0>, 'optimal_step': <function optimal_step at 0x7f5ad6ce5d00>, 'snspd': <function snspd at 0x7f5ad6ce5ee0>, 'interdigital_capacitor': <function interdigital_capacitor at 0x7f5ad6ce60c0>, 'ge_detector_straight_si_contacts': <function ge_detector_straight_si_contacts at 0x7f5ad6ce6340>, 'edge_coupler_silicon': <function edge_coupler_silicon at 0x7f5ad6ce65c0>, 'edge_coupler_array': <function edge_coupler_array at 0x7f5ad6ce6700>, 'edge_coupler_array_with_loopback': <function edge_coupler_array_with_loopback at 0x7f5ad6ce6840>}, virtual_factories={'virtual_bend_circular': <function virtual_bend_circular_factory.<locals>.virtual_bend_circular at 0x7f5ae14cb420>, 'bend_euler': <function virtual_bend_euler_factory.<locals>.bend_euler at 0x7f5ae14cb6a0>, 'virtual_straight': <function virtual_straight_factory.<locals>.virtual_straight at 0x7f5ae14cb920>, 'bend_circular_all_angle': <function bend_circular_all_angle at 0x7f5ad6d70180>, 'bend_euler_all_angle': <function bend_euler_all_angle at 0x7f5ad6d70cc0>, 'straight_all_angle': <function straight_all_angle at 0x7f5ad6df9260>}, 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 0x7f5aec3507c0>, info=Info(), settings=KCellSettings(version='0.23.1', klayout_version='0.29.11', meta_format='v3'), future_cell_name=None, decorators=<kfactory.decorators.Decorators object at 0x7f5aec745810>) function_name=None basename=None boundary=None insts=<gdsfactory.component.ComponentReferences object at 0x7f5ab812a550> size_info=<kfactory.kcell.SizeInfo object at 0x7f5ab8160810> dsize_info=<kfactory.kcell.DSizeInfo object at 0x7f5ab8175190> 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 0x7f5aec395810>, 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 0x7f5aec3953b0>, factories={'taper': <function taper at 0x7f5ad6d71bc0>, 'bend_s_bezier': <function bend_s_bezier_factory.<locals>.bend_s_bezier at 0x7f5ae14b3f60>, 'bend_circular': <function bend_circular at 0x7f5ad6d17f60>, 'bend_euler': <function bend_euler at 0x7f5ad6d70a40>, 'bend_s_euler': <function bend_s_euler_factory.<locals>.bend_s_euler at 0x7f5ae14ca520>, 'straight': <function straight at 0x7f5ad6df9120>, 'rotate': <function rotate at 0x7f5ad78e68e0>, 'from_image': <function from_image at 0x7f5ad73e0f40>, 'floorplan_with_block_letters': <function floorplan_with_block_letters at 0x7f5ad71c7100>, 'bend_circular_heater': <function bend_circular_heater at 0x7f5ad6d702c0>, 'bend_euler_s': <function bend_euler_s at 0x7f5ad6d70900>, 'bezier': <function bezier at 0x7f5ad6d70fe0>, 'bend_s': <function bend_s at 0x7f5ad6d711c0>, 'add_fiber_array_optical_south_electrical_north': <function add_fiber_array_optical_south_electrical_north at 0x7f5ad6d71440>, 'ramp': <function ramp at 0x7f5ad6d71940>, 'taper_strip_to_ridge': <function taper_strip_to_ridge at 0x7f5ad6d71c60>, 'taper_strip_to_ridge_trenches': <function taper_strip_to_ridge_trenches at 0x7f5ad6d71ee0>, 'taper_sc_nc': <function taper_sc_nc at 0x7f5ad6d72020>, 'taper_adiabatic': <function taper_adiabatic at 0x7f5ad6d72340>, 'taper_cross_section': <function taper_cross_section at 0x7f5ad6d72520>, 'taper_from_csv': <function taper_from_csv at 0x7f5ad6d72700>, 'taper_parabolic': <function taper_parabolic at 0x7f5ad6d72840>, 'add_termination': <function add_termination at 0x7f5ad6d723e0>, 'add_trenches': <function add_trenches at 0x7f5ad6d72660>, 'array': <function array at 0x7f5ad6d72a20>, 'copy_layers': <function copy_layers at 0x7f5ad6d72f20>, 'extend_ports_list': <function extend_ports_list at 0x7f5ad6d73060>, 'extend_ports': <function extend_ports at 0x7f5ad6d73380>, 'pack_doe': <function pack_doe at 0x7f5ad6d73ba0>, 'pack_doe_grid': <function pack_doe_grid at 0x7f5ad6d73ce0>, 'splitter_chain': <function splitter_chain at 0x7f5ad6d73e20>, 'mzi': <function mzi at 0x7f5ad71c7f60>, 'mzi_lattice': <function mzi_lattice at 0x7f5ad6da84a0>, 'mzi_lattice_mmi': <function mzi_lattice_mmi at 0x7f5ad6da85e0>, 'mzi_pads_center': <function mzi_pads_center at 0x7f5ad6da8860>, 'mzit': <function mzit at 0x7f5ad6da8a40>, 'mzit_lattice': <function mzit_lattice at 0x7f5ad6da8b80>, 'splitter_tree': <function splitter_tree at 0x7f5ad6d14180>, 'coupler_symmetric': <function coupler_symmetric at 0x7f5ad6da8d60>, 'coupler_straight': <function coupler_straight at 0x7f5ad6da8ea0>, 'coupler': <function coupler at 0x7f5ad6da8fe0>, 'coupler90': <function coupler90 at 0x7f5ad6da91c0>, 'coupler90bend': <function coupler90bend at 0x7f5ad6da9260>, 'coupler_adiabatic': <function coupler_adiabatic at 0x7f5ad6da9580>, 'coupler_asymmetric': <function coupler_asymmetric at 0x7f5ad6da9800>, 'coupler_bent_half': <function coupler_bent_half at 0x7f5ad6da9b20>, 'coupler_bent': <function coupler_bent at 0x7f5ad6da9c60>, 'coupler_broadband': <function coupler_broadband at 0x7f5ad6da9ee0>, 'coupler_full': <function coupler_full at 0x7f5ad6daa0c0>, 'coupler_ring': <function coupler_ring at 0x7f5ad6daa340>, 'coupler_straight_asymmetric': <function coupler_straight_asymmetric at 0x7f5ad6daa5c0>, 'align_wafer': <function align_wafer at 0x7f5ad6daa980>, 'add_frame': <function add_frame at 0x7f5ad6daaa20>, 'die': <function die at 0x7f5ad6daad40>, 'die_with_pads': <function die_with_pads at 0x7f5ad6daaf20>, 'seal_ring': <function seal_ring at 0x7f5ad6dab100>, 'seal_ring_segmented': <function seal_ring_segmented at 0x7f5ad6dab240>, 'wafer': <function wafer at 0x7f5ad6dab420>, 'free_propagation_region': <function free_propagation_region at 0x7f5ad6dab880>, 'awg': <function awg at 0x7f5ad6dab920>, 'dbr_cell': <function dbr_cell at 0x7f5ad6dabc40>, 'dbr': <function dbr at 0x7f5ad6dabd80>, 'dbr_tapered': <function dbr_tapered at 0x7f5ad6dabf60>, 'bbox': <function bbox at 0x7f5ad6dc47c0>, 'C': <function C at 0x7f5ad6dc49a0>, 'circle': <function circle at 0x7f5ad6dc4b80>, 'compass': <function compass at 0x7f5ad6dc4e00>, 'cross': <function cross at 0x7f5ad6dc4fe0>, 'ellipse': <function ellipse at 0x7f5ad6dc51c0>, 'fiducial_squares': <function fiducial_squares at 0x7f5ad6dc5300>, 'L': <function L at 0x7f5ad6dc54e0>, 'nxn': <function nxn at 0x7f5ad6dc56c0>, 'rectangle': <function rectangle at 0x7f5ad6dc58a0>, 'rectangles': <function rectangles at 0x7f5ad6dc59e0>, 'regular_polygon': <function regular_polygon at 0x7f5ad6dc5b20>, 'triangle': <function triangle at 0x7f5ad6dc5d00>, 'triangle2': <function triangle2 at 0x7f5ad6dc5e40>, 'triangle4': <function triangle4 at 0x7f5ad6dc5f80>, 'fiber': <function fiber at 0x7f5ad6dc5940>, 'fiber_array': <function fiber_array at 0x7f5ad6dc6020>, 'crossing_arm': <function crossing_arm at 0x7f5ad6df8a40>, 'crossing': <function crossing at 0x7f5ad6df8b80>, 'crossing_linear_taper': <function crossing_linear_taper at 0x7f5ad6df8cc0>, 'crossing_etched': <function crossing_etched at 0x7f5ad6df8e00>, 'crossing45': <function crossing45 at 0x7f5ad6df8f40>, 'straight_array': <function straight_array at 0x7f5ad6df93a0>, 'wire_straight': <function wire_straight at 0x7f5ad6df94e0>, 'straight_heater_doped_rib': <function straight_heater_doped_rib at 0x7f5ad6df98a0>, 'straight_heater_doped_strip': <function straight_heater_doped_strip at 0x7f5ad6df9a80>, 'straight_heater_meander': <function straight_heater_meander at 0x7f5ad6df9da0>, 'via': <function via at 0x7f5ad6dfa5c0>, 'via_circular': <function via_circular at 0x7f5ad6dfa700>, 'via_chain': <function via_chain at 0x7f5ad6dfaa20>, 'via_corner': <function via_corner at 0x7f5ad6dfac00>, 'via_stack': <function via_stack at 0x7f5ad6dfade0>, 'via_stack_corner45': <function via_stack_corner45 at 0x7f5ad6dfaf20>, 'via_stack_corner45_extended': <function via_stack_corner45_extended at 0x7f5ad6dfb060>, 'via_stack_with_offset': <function via_stack_with_offset at 0x7f5ad6dfb1a0>, 'straight_heater_meander_doped': <function straight_heater_meander_doped at 0x7f5ad6dfa2a0>, 'straight_heater_metal_undercut': <function straight_heater_metal_undercut at 0x7f5ad6dfb100>, 'straight_heater_metal_simple': <function straight_heater_metal_simple at 0x7f5ad6dfb420>, 'straight_piecewise': <function straight_piecewise at 0x7f5ad6dfb560>, 'straight_pin': <function straight_pin at 0x7f5ad6dfb600>, 'straight_pin_slot': <function straight_pin_slot at 0x7f5ad6dfb880>, 'wire_corner': <function wire_corner at 0x7f5ad6dfbb00>, 'wire_corner45': <function wire_corner45 at 0x7f5ad6dfbc40>, 'wire_corner_sections': <function wire_corner_sections at 0x7f5ad6dfbce0>, 'loop_mirror': <function loop_mirror at 0x7f5ad6dc6200>, 'mode_converter': <function mode_converter at 0x7f5ad6c1d760>, 'polarization_splitter_rotator': <function polarization_splitter_rotator at 0x7f5ad6c1da80>, 'terminator': <function terminator at 0x7f5ad6c1e020>, 'grating_coupler_array': <function grating_coupler_array at 0x7f5ad6c1e2a0>, 'grating_coupler_dual_pol': <function grating_coupler_dual_pol at 0x7f5ad6c1e5c0>, 'grating_coupler_elliptical': <function grating_coupler_elliptical at 0x7f5ad6c1ec00>, 'grating_coupler_elliptical_arbitrary': <function grating_coupler_elliptical_arbitrary at 0x7f5ad6c1ee80>, 'grating_coupler_elliptical_uniform': <function grating_coupler_elliptical_uniform at 0x7f5ad6c1f100>, 'grating_coupler_elliptical_lumerical': <function grating_coupler_elliptical_lumerical at 0x7f5ad6c1f240>, 'grating_coupler_elliptical_trenches': <function grating_coupler_elliptical_trenches at 0x7f5ad6c1f2e0>, 'grating_coupler_loss': <function grating_coupler_loss at 0x7f5ad6c1f6a0>, 'grating_coupler_rectangular': <function grating_coupler_rectangular at 0x7f5ad6c1f880>, 'grating_coupler_rectangular_arbitrary': <function grating_coupler_rectangular_arbitrary at 0x7f5ad6c1fb00>, 'grating_coupler_tree': <function grating_coupler_tree at 0x7f5ad6c1fd80>, 'mmi': <function mmi at 0x7f5ad6c480e0>, 'mmi1x2': <function mmi1x2 at 0x7f5ad6c48400>, 'mmi1x2_with_sbend': <function mmi1x2_with_sbend at 0x7f5ad6c485e0>, 'mmi2x2': <function mmi2x2 at 0x7f5ad6c48900>, 'mmi2x2_with_sbend': <function mmi2x2_with_sbend at 0x7f5ad6c48a40>, 'mmi_90degree_hybrid': <function mmi_90degree_hybrid at 0x7f5ad6c48c20>, 'mmi_tapered': <function mmi_tapered at 0x7f5ad6c48f40>, 'pad': <function pad at 0x7f5ad6c491c0>, 'pad_array': <function pad_array at 0x7f5ad6c49440>, 'pad_gsg_short': <function pad_gsg_short at 0x7f5ad6c496c0>, 'pads_shorted': <function pads_shorted at 0x7f5ad6c49940>, 'rectangle_with_slits': <function rectangle_with_slits at 0x7f5ad6c49a80>, 'cavity': <function cavity at 0x7f5ad6c49d00>, 'cdsem_all': <function cdsem_all at 0x7f5ad6c49f80>, 'cdsem_bend180': <function cdsem_bend180 at 0x7f5ad6c4a160>, 'cdsem_coupler': <function cdsem_coupler at 0x7f5ad6c4a2a0>, 'cdsem_straight': <function cdsem_straight at 0x7f5ad6c4a5c0>, 'cdsem_straight_density': <function cdsem_straight_density at 0x7f5ad6c4a700>, 'bendu_double': <function bendu_double at 0x7f5ad6c4a980>, 'straight_double': <function straight_double at 0x7f5ad6c4aac0>, 'cutback_2x2': <function cutback_2x2 at 0x7f5ad6c4ac00>, 'cutback_bend': <function cutback_bend at 0x7f5ad6c4afc0>, 'cutback_bend90': <function cutback_bend90 at 0x7f5ad6c4b100>, 'staircase': <function staircase at 0x7f5ad6c4b240>, 'cutback_bend180': <function cutback_bend180 at 0x7f5ad6c4b380>, 'cutback_component': <function cutback_component at 0x7f5ad6c4b4c0>, 'cutback_splitter': <function cutback_splitter at 0x7f5ad6c4b880>, 'greek_cross': <function greek_cross at 0x7f5ad6c4b9c0>, 'greek_cross_with_pads': <function greek_cross_with_pads at 0x7f5ad6c4bc40>, 'litho_calipers': <function litho_calipers at 0x7f5ad6c4be20>, 'litho_ruler': <function litho_ruler at 0x7f5ad6c88180>, 'litho_steps': <function litho_steps at 0x7f5ad6c88360>, 'resistance_meander': <function resistance_meander at 0x7f5ad6c884a0>, 'resistance_sheet': <function resistance_sheet at 0x7f5ad6c88680>, 'verniers': <function verniers at 0x7f5ad6c88860>, 'text': <function text at 0x7f5ad6c89580>, 'text_lines': <function text_lines at 0x7f5ad6c89760>, 'text_klayout': <function text_klayout at 0x7f5ad6c898a0>, 'text_freetype': <function text_freetype at 0x7f5ad6c89bc0>, 'pixel_array': <function pixel_array at 0x7f5ad6c89e40>, 'text_rectangular': <function text_rectangular at 0x7f5ad6c89f80>, 'text_rectangular_multi_layer': <function text_rectangular_multi_layer at 0x7f5ad6c8a0c0>, 'pixel': <function pixel at 0x7f5ad6c88b80>, 'qrcode': <function qrcode at 0x7f5ad6c89da0>, 'version_stamp': <function version_stamp at 0x7f5ad6c8a160>, 'disk': <function disk at 0x7f5ad6c8a700>, 'disk_heater': <function disk_heater at 0x7f5ad6c8a840>, 'ring': <function ring at 0x7f5ad6c8aac0>, 'ring_crow': <function ring_crow at 0x7f5ad6c8aca0>, 'ring_crow_couplers': <function ring_crow_couplers at 0x7f5ad6c8ade0>, 'ring_double': <function ring_double at 0x7f5ad6c8afc0>, 'ring_double_bend_coupler': <function ring_double_bend_coupler at 0x7f5ad6c8b2e0>, 'ring_double_heater': <function ring_double_heater at 0x7f5ad6c8b420>, 'ring_double_pn': <function ring_double_pn at 0x7f5ad6c8b740>, 'ring_single_pn': <function ring_single_pn at 0x7f5ad6c8b880>, 'ring_single': <function ring_single at 0x7f5ad6c8ba60>, 'ring_single_array': <function ring_single_array at 0x7f5ad6c8bba0>, 'coupler_bend': <function coupler_bend at 0x7f5ad6c8bce0>, 'coupler_ring_bend': <function coupler_ring_bend at 0x7f5ad6c8be20>, 'ring_single_bend_coupler': <function ring_single_bend_coupler at 0x7f5ad6c8bf60>, 'ring_single_dut': <function ring_single_dut at 0x7f5ad6ce4180>, 'delay_snake': <function delay_snake at 0x7f5ad6ce4400>, 'delay_snake2': <function delay_snake2 at 0x7f5ad6ce45e0>, 'delay_snake_sbend': <function delay_snake_sbend at 0x7f5ad6ce4860>, 'spiral': <function spiral at 0x7f5ad6ce4ae0>, 'spiral_double': <function spiral_double at 0x7f5ad6ce4cc0>, 'spiral_racetrack': <function spiral_racetrack at 0x7f5ad6ce4f40>, 'spiral_racetrack_fixed_length': <function spiral_racetrack_fixed_length at 0x7f5ad6ce5080>, 'spiral_racetrack_heater_metal': <function spiral_racetrack_heater_metal at 0x7f5ad6ce5260>, 'spiral_racetrack_heater_doped': <function spiral_racetrack_heater_doped at 0x7f5ad6ce53a0>, 'spiral_inductor': <function spiral_inductor at 0x7f5ad6ce54e0>, 'hline': <function hline at 0x7f5ad6ce5760>, 'optimal_90deg': <function optimal_90deg at 0x7f5ad6ce58a0>, 'optimal_hairpin': <function optimal_hairpin at 0x7f5ad6ce5bc0>, 'optimal_step': <function optimal_step at 0x7f5ad6ce5d00>, 'snspd': <function snspd at 0x7f5ad6ce5ee0>, 'interdigital_capacitor': <function interdigital_capacitor at 0x7f5ad6ce60c0>, 'ge_detector_straight_si_contacts': <function ge_detector_straight_si_contacts at 0x7f5ad6ce6340>, 'edge_coupler_silicon': <function edge_coupler_silicon at 0x7f5ad6ce65c0>, 'edge_coupler_array': <function edge_coupler_array at 0x7f5ad6ce6700>, 'edge_coupler_array_with_loopback': <function edge_coupler_array_with_loopback at 0x7f5ad6ce6840>}, virtual_factories={'virtual_bend_circular': <function virtual_bend_circular_factory.<locals>.virtual_bend_circular at 0x7f5ae14cb420>, 'bend_euler': <function virtual_bend_euler_factory.<locals>.bend_euler at 0x7f5ae14cb6a0>, 'virtual_straight': <function virtual_straight_factory.<locals>.virtual_straight at 0x7f5ae14cb920>, 'bend_circular_all_angle': <function bend_circular_all_angle at 0x7f5ad6d70180>, 'bend_euler_all_angle': <function bend_euler_all_angle at 0x7f5ad6d70cc0>, 'straight_all_angle': <function straight_all_angle at 0x7f5ad6df9260>}, 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 0x7f5aec3507c0>, info=Info(), settings=KCellSettings(version='0.23.1', klayout_version='0.29.11', meta_format='v3'), future_cell_name=None, decorators=<kfactory.decorators.Decorators object at 0x7f5aec745810>) function_name=None basename=None boundary=None insts=<gdsfactory.component.ComponentReferences object at 0x7f5aacd8f890> size_info=<kfactory.kcell.SizeInfo object at 0x7f5aacd8f650> dsize_info=<kfactory.kcell.DSizeInfo object at 0x7f5aacd8f6d0> 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()