iqm-finland / KQCircuits

KLayout Python library for integrated quantum circuit design.
GNU General Public License v3.0
144 stars 73 forks source link

Display ports in simulation export Klayout dialog #52

Open qpavsmi opened 1 year ago

qpavsmi commented 1 year ago

Prerequisites

KQCircuits, GUI and standalone installations

Issue description

When exporting files to be used by an external FEM simulation software, KQCircuits will usually show a preview of the geometry files that will be used for simulations in KLayout to review that the correct geometry is placed in correct layers. We also export some coordinates within geometry as "ports" in separate json files to be used by the simulation software. These ports do not show up in KLayout, and it's inconvenient to look them up from a separate file to see how the coordinates match with the design geometry. During the preview it would be good to have the port coordinates be outlined as text objects in KLayout.

How to get started

Go to root of the KQCircuits source code folder and run: python klayout_package/python/scripts/simulations/xs1_full_chip_sim.py

This will cause a KLayout window to pop up, showing geometry of an example chip for which a simulation can be run (remove some clutter double-clicking the refpoints layer to hide it). The python script will also generate the tmp subfolder if not present already, with a folder tmp/xs1_full_chip_sim_output inside. Inside that folder there is simulation.oas design file, which is exactly what the pop up window shows.

Review the contents of the tmp/xs1_full_chip_sim_output/Simulation.json file. Look through the "ports" list. You will see that ports numbered 1-8 are of type EdgePort, and the rest of the ports are of type InternalPort. These are the two classes of ports that are used in KQCircuits. EdgePorts are placed at the edge of the simulation region and InternalPorts are placed inside the region. Every port is defined by signal_location 2D coordinate, InternalPorts may additionally have a ground_location 2D coordinate.

You can compare the port locations as exported to tmp/xs1_full_chip_sim_output/Simulation.json with how we define the ports in single_xmons_full_chip_sim.py. There are two calls of self.ports.append, EdgePorts are placed for the launchers and InternalPorts are added for the SQUID parts of qubits, signal locations located at the edge of qubits' inner metal part and ground locations located outside of qubits. See below charts.

image

internalports

These would be good to illustrate by placing text objects similar to what we currently do in the refpoints layer. We already place some visualisation elements during simulation preview using the function visualise_region. Currently we do that with taking XSections and defining PartitionRegions.

Using visualise_region you can set the name of the layer drawing shapes for visualisation purposes, let's call it simulation_ports. You can also specify the label of the text object. The label should specify the port index and type, for example edge_port_1, internal_port_signal_2, internal_port_ground_3. So a way to place a single text object as a point could be:

# port is some EdgePort
self.visualise_region(pya.Region(), "edge_port_1", "simulation_ports", port.signal_location)

Since EdgePorts are always placed at edges of the simulation box, you can infer the direction of the port based on which edge of the box the port is placed in. It would be nice if the port would be visualised as a line segment that starts from port location and extends for some length outside of the box, as presented in first illustration. See the first argument pya.Region() in the example call of visualise_region. This constructs an "empty" region, which means that only the text object is placed, and no polygons. You might consider visualising the ports as 2D shapes in the case of EdgePorts

Suppose we want to place a vertical line of width w from 2D point (x,y1) to (x,y2). We can just draw it using a box: pya.Region(pya.DBox(x-w, y1, x+w, y2).to_itype(self.layout.dbu)). Here pya.DBox is defined in domain specific units (in this case microns), but pya.Region only accepts KLayout's internal integer measurements. Therefore we need to convert the pya.DBox to integer units using .to_itype(self.layout.dbu). You could also set w=0 if you'd prefer infinitely thin lines, these still get rendered in the KLayout window.

For InternalPorts you might also draw a line from signal_location to ground_location. Notice that the line might have some angled direction, in which case using a pya.DBox might not look correct, so you could instead use a pya.DPolygon with four points. Notice also that ground_location is an optional property, so if it is not defined, just placing a text point is enough.

The port visualisation code should run as last call in Simulation.__init__ function. You should have access to all ports from Simulation.ports attribute, which gets populated after build call.

Definition of done

AbdullahKazi500 commented 4 months ago

Hi @qpavsmi Since Unitary fund hackathon is over I would like to take on this issue as an open source contribution can I know some details on the issue

qpavsmi commented 4 months ago

Hi @qpavsmi Since Unitary fund hackathon is over I would like to take on this issue as an open source contribution can I know some details on the issue

Hi, thanks for the interest! What detail would you like to know that is not provided in the issue description, or is the problem that the description is not easy to follow (apologies if that is the case).

AbdullahKazi500 commented 4 months ago

Hi @qpavsmi Since Unitary fund hackathon is over I would like to take on this issue as an open source contribution can I know some details on the issue

Hi, thanks for the interest! What detail would you like to know that is not provided in the issue description, or is the problem that the description is not easy to follow (apologies if that is the case).

yeah thanks Pavel so I would like to know the changes should be made in which directory and which file

qpavsmi commented 4 months ago

Probably the change only needs to be made in klayout_package/python/kqcircuits/simulations/simulation.py. Probably need to add a new function there and then call that function as a last step in __init__

AbdullahKazi500 commented 4 months ago

Probably the change only needs to be made in klayout_package/python/kqcircuits/simulations/simulation.py. Probably need to add a new function there and then call that function as a last step in __init__

I will have a look