Skip to content

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.

The following videos go through the same steps. The written guide below contains the most up-to-date instructions.


Create your first cell

  1. In the Visual Studio Code sidebar, select the GF+ tab. This will open a menu with the project components at the top (Project) and the PDK components at the bottom (Base PDK). The Process Design Kit (PDK) includes a set of predefined components provided by the foundry. In this example, we are using the UK-based foundry Cornerstone, which offers an open-source PDK.

    GF+ tab

  2. In the project components section (Project), hover over the word project, then click the button that has a file icon with a + sign on it. Select Create Python Layout, 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.

    Create Python Layout

  3. Replace the starter code imports 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
    
  4. In the right top bar of the tab, click the eye button. Then click Show GDS to open the GDS View.

    Show GDS

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

    Code View and GDS 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=20, 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. 🚀

Bonus: Use the AI Agent

Ask the agent to create an array of texts of different sizes:

Agent text array

Iterate until you're happy with the result:

Iterated result

You can also ask the agent to add ports and test information:

Ports and test info

🎉 Congratulations! You have successfully created your first custom GDSFactory cell!

Continue to Step 2: Design a Photonics Circuit or Design a Quantum-RF Circuit.