gdsfactory in 5 minutes#

Layout#

gdsfactory easily enables you to layout a Component, a circuit with many Components, or Component top cell for a reticle.

A Component is a canvas where we can add polygons, references to other components or ports.

Lets add two references in a component.

[1]:
import gdsfactory as gf

c = gf.Component()
mzi = c << gf.components.mzi()  # equivalent to mzi = c.add_ref(gf.components.mzi())
bend = (
    c << gf.components.bend_circular()
)  # equivalent to bend = c.add_ref(gf.components.bend_circular())
c
2022-06-28 17:02:53.755 | INFO     | gdsfactory.config:<module>:52 - Load '/home/runner/work/gdsfactory/gdsfactory/gdsfactory' 5.11.4
/home/runner/work/gdsfactory/gdsfactory/gdsfactory/component.py:1054: UserWarning: Component 'Unnamed_61503e00' contains 1 Unnamed cells
  warnings.warn(
../_images/notebooks__4_gdsfactory_in_5minutes_1_1.png
[1]:
Unnamed_61503e00: uid 0, ports [], aliases [], 0 polygons, 2 references

You can connect the bend o1 port to the mzi o2 port.

[2]:
c = gf.Component()
mzi = c << gf.components.mzi()  # equivalent to mzi = c.add_ref(gf.components.mzi())
bend = (
    c << gf.components.bend_circular()
)  # equivalent to bend = c.add_ref(gf.components.bend_circular())
bend.connect("o1", mzi.ports["o2"])
c
/home/runner/work/gdsfactory/gdsfactory/gdsfactory/component.py:1054: UserWarning: Component 'Unnamed_5836eb43' contains 1 Unnamed cells
  warnings.warn(
../_images/notebooks__4_gdsfactory_in_5minutes_3_1.png
[2]:
Unnamed_5836eb43: uid 23, ports [], aliases [], 0 polygons, 2 references

You can also define a cell function that returns a parametric Component depending on the arguments you pass and gets automatic name.

[3]:
@gf.cell
def mzi_with_bend(radius: float = 10):
    c = gf.Component()
    mzi = c << gf.components.mzi()  # equivalent to mzi = c.add_ref(gf.components.mzi())
    bend = c << gf.components.bend_circular(
        radius=radius
    )  # equivalent to bend = c.add_ref(gf.components.bend_circular())
    bend.connect("o1", mzi.ports["o2"])
    return c


c = mzi_with_bend(radius=20)
c
../_images/notebooks__4_gdsfactory_in_5minutes_5_0.png
[3]:
mzi_with_bend_radius20: uid 24, ports [], aliases [], 0 polygons, 2 references

Now to connect your component to other components you need to add ports.

[4]:
c.ports
[4]:
{}
[5]:
@gf.cell
def mzi_with_bend(radius: float = 10):
    c = gf.Component()
    mzi = c << gf.components.mzi()  # equivalent to mzi = c.add_ref(gf.components.mzi())
    bend = c << gf.components.bend_circular(
        radius=radius
    )  # equivalent to bend = c.add_ref(gf.components.bend_circular())
    bend.connect("o1", mzi.ports["o2"])
    c.add_port("o1", port=mzi.ports["o1"])
    c.add_port("o2", port=bend.ports["o2"])
    return c


c = mzi_with_bend(
    radius=20, cache=False
)  # as we changed the code inside the function you need to clear the cache from the cell decorator.
c
../_images/notebooks__4_gdsfactory_in_5minutes_8_0.png
[5]:
mzi_with_bend_radius20: uid 27, ports ['o1', 'o2'], aliases [], 0 polygons, 2 references
[6]:
c.ports
[6]:
{'o1': Port (name o1, midpoint [-10.   0.], width 0.5, orientation 180, layer (1, 0), port_type optical),
 'o2': Port (name o2, midpoint [101.201  20.   ], width 0.5, orientation 90.0, layer (1, 0), port_type optical)}

Once you have ports you can route it to fiber couplers.

[7]:
c_fiber_single = gf.routing.add_fiber_single(c)
c_fiber_single
../_images/notebooks__4_gdsfactory_in_5minutes_11_0.png
[7]:
mzi_with_bend_radius20__d5c09015: uid 31, ports ['vertical_te_00', 'vertical_te_1', 'loopback1', 'loopback2'], aliases [], 0 polygons, 15 references
[8]:
c_fiber_array = gf.routing.add_fiber_array(c, with_loopback=False)
c_fiber_array
../_images/notebooks__4_gdsfactory_in_5minutes_12_0.png
[8]:
mzi_with_bend_radius20__82f34bf0: uid 50, ports ['vertical_te_00', 'vertical_te_01'], aliases [], 0 polygons, 29 references
[9]:
scene = c_fiber_array.to_3d()
scene.show()
[9]: