Step 1: Create a Parametric Cell

Let's create and customize a cell with Python code, and see its changes in the graphical GDS viewer. We'll start with a hard-coded cell, and then add parameters to make it a parametric cell.

Create your first cell

In the VSCode sidebar, select the GF+ tab. This will open a menu with the project components. The PDK includes a set of pre-defined components provided by the foundry.

In this example, we use the UK-based foundry Cornerstone, which offers an open-source PDK.

You can filter the available components through tags.

screenshot

At the top of the list of components, click on + New. Select the Python icon, then type hello for the name and press enter. This will create a Python file named hello, and open its Code View in a new tab.

code view

Replace the starter code that is provided in the file with the following code:

import gdsfactory as gf

@gf.cell
def sample_pcell() -> gf.Component:
    c = gf.Component()
    ref1 = c.add_ref(gf.components.rectangle(size=(10, 10), layer=(1, 0)))
    ref2 = c.add_ref(gf.components.text("Hello", size=10, layer=(2, 0)))
    ref3 = c.add_ref(gf.components.text("world", size=10, layer=(2, 0)))
    ref1.xmax = ref2.xmin - 5
    ref3.xmin = ref2.xmax + 2
    ref3.rotate(90)
    return c

In the right top bar of the tab, click the eye button. Then click Show GDS to open the GDS View.

GDS View

You should see something like the following image, where the Code View of the Python cell is in a window on the left, and the GDS View (CAD file view) is in a window to the right.

CAD file view

In the Code View, replace World with your name to personalize your Python cell, and observe the changes in the GDS View.

Make it parametric

The previous example used a fixed cell (with no input parameters). Now, let's define a parametric cell where you can modify input parameters dynamically. For instance, we can customize the text name and size by modifying the code as shown below:

@gf.cell
def sample_pcell(size=1, name="world") -> gf.Component:
    c = gf.Component()
    ref1 = c.add_ref(gf.components.rectangle(size=(10, 10), layer=(1, 0)))
    ref2 = c.add_ref(gf.components.text("Hello", size=size, layer=(2, 0)))
    ref3 = c.add_ref(gf.components.text(name, size=size, layer=(2, 0)))
    ref1.xmax = ref2.xmin - 5
    ref3.xmin = ref2.xmax + 2
    ref3.rotate(90)
    return c

Experiment by changing the name and size parameters to see how they affect the output. πŸš€

πŸŽ‰ Congratulations! You have successfully created your first custom GDSFactory cell!

Continue to Step 2: Design your first circuit.

On This Page