Python intro#

gdsfactory is written in python and requires some basic knowledge of python.

If you are new to python you can find many resources online

This notebook is for you to experiment with some common python patterns in gdsfactory

Classes#

Gdsfactory has already some pre-defined classes for you. The only class you may need to define is a Layermap. Which can be easily defined as a dataclass

All the other classes (Component, ComponentReference, Port …) are already available in gf.types

Classes are good for keeping state, which means that they store some information inside them (polygons, ports, references …)

[1]:
import gdsfactory as gf

gf.CONF.plotter = "holoviews"

c = gf.Component(name="my_fist_class")
c.add_polygon([(-8, 6, 7, 9), (-6, 8, 17, 5)], layer=(1, 0))
c
2022-06-28 17:02:21.964 | INFO     | gdsfactory.config:<module>:52 - Load '/home/runner/work/gdsfactory/gdsfactory/gdsfactory' 5.11.4
../_images/notebooks__0_python_1_1.png
[1]:
my_fist_class: uid 0, ports [], aliases [], 1 polygons, 0 references
[2]:
c.ploth()