Setting up the editor environment (PyCharm)

Downloading PyCharm

If you haven’t installed PyCharm yet, please download a copy from https://www.jetbrains.com/pycharm/download/. The Community Edition is well suited for IPKISS use and is free of charge.

Launching PyCharm

IPKISS comes with preconfigured PyCharm IDE settings. To use these settings, you need to start PyCharm through the Luceda Control Center.

Launch PyCharm from the Luceda Control Center.

Fig. 11 Launch PyCharm from the Luceda Control Center.

The following settings are preconfigured:

  • Default location of new projects (under <USER_HOME>/luceda/projects)
  • Setting up of the Python interpreter. The name of the interpreter contains the IPKISS version that you’ll use (for example, ‘ipkiss 3.1.3, python 2.7.15’)
  • The interpreter can be selected when starting a new design project
  • The samples project is set up to open from the correct location, using the installed Python interpreter. To open the samples, just click the ‘Samples in PyCharm’ button.

Note

Although we recommend to start PyCharm via the Luceda Control Center, PyCharm can be of course also be started in the classical way (from the start menu or desktop shortcut on Windows, or from the terminal on Linux). In this case, a bit more setup is needed to choose the proper Python executable, configure the samples project, etc.

Creating a PyCharm project

Like many IDE’s, PyCharm has a built-in project manager that we can use to structure our work into different projects. In order to create a new project, start PyCharm and select Create File ‣ New Project (note: if this is your first time running, you’ll see this window anyway):

Create new project in PyCharm.

Fig. 12 Create new project in PyCharm.

Specify the project Location, for example, C:\Users\username\luceda\projects\my_design_project. Note that the correct Python interpreter is already chosen (with IPKISS 3.1.3 preinstalled):

Specify project location.

Fig. 13 Specify project location.

Then click Create. Once the project has been created, you can start creating python packages and modules.

The created new project in PyCharm.

Fig. 14 The created new project in PyCharm.

Configuring Python interpreter after project creation

We have configured the Python interpreter when we created a project in the previous step. But if that’s not done for some reason (for example, in case you directly open a folder in PyCharm), we can also configure that from the project settings in PyCharm. In PyCharm menu bar, select File ‣ Settings… Then in the Settings dialog, select Project: <Your project name> ‣ Project Interpreter tab. Then, select the gear next to the interpreter list; and then click Add Local….

Specify project interpreter.

Fig. 15 Specify project interpreter.

In Add Local Python Interpreter dialog, under Conda Environment section, select Existing environment, modify the Interpreter path to: <path_to_IPKISS_installation>\python\envs\ipkiss3\python.exe.

You may enable Make available to all projects. Then click OK.

This is how you create a fresh new IPKISS design project in PyCharm. In the following, we provide a design project example, so you may have a first try from directly opening an IPKISS project and run a first IPKISS design.

Setting up an IPKISS design project

Before we do our first design, we need to set up the design project structure properly so the design project can be easier extended and maintained.

Typically, a photonics design consists of custom PCells, subcircuits, input-output cells, top-level circuits, and utility functions for automating parts of the design flow. All those files are organized in different Python files and are part of the IPKISS design project. A design project also typically links to a PDK (Process Design Kit) which contains the technology information and a series of predefined building blocks.

We strongly recommend structuring your files, and, if possible, use version control to manage and share your code in an efficient way.

To illustrate this, let’s take the example project that is bundled with the IPKISS installation. First, open this project in PyCharm by File–>`Open…`, and open <path_to_IPKISS_installation>\samples\demo\projects. After loading, you will see the following project structure in the PyCharm project navigator:

The sample IPKISS design project.

Fig. 16 The sample IPKISS design project.

You may refer to Library Organization in the documentation to find out more explanations on the library structure and its content.

Let’s now add the PDK and a custom design library that we’d like to reference in our current design project. Go to File ‣ Setting, then under the Project: <Your project name> then Project Structure section, you may add the PDK to the project structure here: In Project Structure, click on + Add Content Root. Then select the PDK folder: <path_to_IPKISS_installation>\samples\demo\libraries\demolib.

Add PDK as source root from the project structure settings.

Now add an additional content root: add <path_to_IPKISS_installation>\samples\demo\built_libraries\my_library to the project. Now your project looks like shown below. It contains the reference to the PDK demolib, a user-made library my_library, and a series of designs that create GDSII files:

Add PDK as source root from the project structure settings.

Fig. 17 Add PDK as source root from the project structure settings.

Now, the project has all the packages needed (PDKs and other custom design floders).

Note

If you have an IPKISS version of the PDK (e.g., IMEC, IME, IHP, IMECAS, Cornerstone, ASP, SiEPIC, LigenTec, Smartphotonics, Tyndall), you will use it as an imported module in your IPKISS design project in PyCharm. Similar to how we added demolib in the previous step, you can also add the PDKs mentioned above to your project.

In order to be able to use those packages in your IPKISS design, next, we will tell PyCharm to properly reference them.

Adding PDKs (or other modules) to your PYTHONPATH

Before we run a first sample design, we need to configure PYTHONPATH (this is where Python searches for packages & modules).

In this sample project, we will add the demolib PDK and the custom design library my_library to PYTHONPATH. This can be done by right-clicking on the folders in the project navigator, then select Mark director as ‣ Source Root.

Mark PDK as source root.

Fig. 18 Mark PDK as source root.

You may see the marked directory is highlighted in blue color now:

PDK is marked as source root.

Fig. 19 PDK is marked as source root.

Now you can start designing. For example, you may test your settings by running a first IPKISS design:

Run a first IPKISS design.

Fig. 20 Run a first IPKISS design.

After running, a 4-channel ring DEMUX will be visualized, and written to GDS.

e have created a first layout design in IPKISS.

Fig. 21 We have created a first layout design in IPKISS.

Some useful PyCharm features

Below you find a short, incomplete list of a few useful features:

Autocompletion

While typing, PyCharm will try to autocomplete your code. This happens automatically as you type your class, function or method. To invoke the auto-completion manually, press the Ctrl+Space key.

If PyCharm can deduce what you’re trying to type it will complete your code. If multiple choices are available, it will present those choices to you.

Autocompletion function in PyCharm.

Fig. 22 Autocompletion function in PyCharm.

Jump-to-definition

To efficiently jump to the definition of an object, just hover your cursor over the class, function or module to which you want to navigate and press Ctrl+[left-click]. PyCharm will then jump to the correct location. When you just press Ctrl, PyCharm will present a link if it knows where to jump to, and also the documentation of the class.

Jump-to-definition function in PyCharm.

Fig. 23 Jump-to-definition function in PyCharm.

Debugging

To place a breakpoint, left click next to the line number. Now a red dot appears. When you now debug your program (by Ctrl+[right-click] somewhere in your code window and selecting ‘Debug [filename]’), it will stop right before executing this dot:

Debugging in PyCharm.

Fig. 24 Debugging in PyCharm.

If you are familiar with Wing IDE and want to set up IPKISS for Wing, you can follow the guide to set up Wing IDE.

Manually setting the project interpreter

If you are not starting PyCharm from the Luceda Control Center, you will want to manually set the project interpreter.

Continuing from the ‘Create Project’ menu, in the same dialog window, expand the Project Interpreter label and select Existing Interpreter. Then select Add local….

Specify project interpreter.

Fig. 25 Specify project interpreter.

You are prompted with Add Local Python Interpreter dialog. Under Conda Environment section, modify the Interpreter path to: <path_to_IPKISS_installation>/python/envs/ipkiss3/python.exe. You may enable Make available to all projects. Then click OK.

Add Python interpreter.

Fig. 26 Add Python interpreter.