Closed jkotilahti closed 11 months ago
Open KLayout (in edit mode) and drag-and-drop, lets say, a Swissmon qubit into the layout. You will find the Swissmon qubit entry from bottom left Libraries
panel by choosing the Qubit library - Library for qubits.
from the dropdown. With the swissmon qubit placed somewhere in the layout, without closing the KLayout window, edit the swissmon.py code, for example, by decreasing iterations to the for loop that calls self._produce_coupler
to have range(2)
. Then in KLayout window, from the top toolbar choose KQCircuits > Reload Libraries
.
Seemingly, there is no difference on the Swissmon already placed in the layout. However, by double-clicking the Swissmon you will notice that the PCell parameters can no longer be changed. Now drag-and-drop another instance of Swissmon. Now you will see that the Swissmon placed after pressing Reload Libraries
has a right-hand coupler missing, which is caused by our edit in swissmon.py code. You can also verify that editing PCell parameters for the newer Swissmon is possible.
This should be changed so that after pressing Reload Libraries
the old instance of the Swissmon qubit would get updated according to the current state of the code. The PCell parameters should also be available for editing. This would involve removing PCells and memorizing their coordinates, classes and PCell parameters, then reloading the library and then placing the PCells back to their coordinates with PCell parameters intact (just as outlined in above comment).
When Reload Libraries
is pressed, it runs a macro 0reload.lym. Notice that macros are a python script wrapped in some xml structure. It could be more convenient to edit macros from KLayout's own macro editor (from top toolbar: Macros > Macro Development (F5)
).
Right now 0reload.lym only calls load_libraries
from library_helper.py which does the library reloading. This macro should be extended to include the extra features.
Following are some of the methods from KLayout and KQCircuits API to help you implement this feature. We do not guarantee that the feature gets implemented using only these methods.
You will need to reconstruct every PCell placed on every open layout of a KLayout window where the Reload Libraries
was pressed.
To iterate over each LayoutView use pya.Application.instance().main_window()
to access the view method that returns a LayoutView by integer index. The number of available views is returned by the views method. Notice that pya
is a built-in module in the KLayout macro environment. Then for each LayoutView object use the active_cellview to get a CellView object and then cell to access the current top cell of that view[*]
. Then iterate over every instance under the top cell with each_inst.
To retrieve the location of an instance use trans method to get a Trans object. This object contains the full transformation of the instance, including position, rotation, scale and mirroring. The instance can be converted into a PCellDeclaration object using the pcell_declaration method. If the method returns None
, then the instance was not a PCell and can be skipped. Use the python built-in method __class__
to access the implementing class of the PCellDeclaration
, which would be Swissmon in our example use case. Then cast the PCellDeclaration
object into Element and use pcell_params_by_name
to retrieve PCell parameters of the instance.
After reloading the library, iterate over each LayoutView again and retrieve their "Top Cell", suppose it's under the variable top_cell
. Then using insert_cell_into(top_cell, cell_class, cell_trans, **cell_parameters)
insert a new instance of class cell_class
with PCell parameters cell_parameters
and under transformation cell_trans
. Please refer to API docs of insert_cell_into in case additional information is required to re-add the PCells.
[*]
Technically there could be other cells in a layout that are parallel to the "Top Cell" in cell hierarchy. This is usually not the case in actual KQCircuits workflow. In order to streamline implementing this issue it is fine to assume that each layout has a "Top Cell" cell which is always active for that layout.
Reload Libraries
should reload all PCells in all open layouts of the KLayout window so that the PCells are rendered according to most up-to-date code, without the need of creating another PCell after the factAs outlined in above comment, it would be nice to have a mechanism that notices the change in the source files which would prompt KLayout to automatically perform library reload. We will leave this as a future task. You are welcome to submit an additional PR if you are interested in implementing this.
It is a bit undefined what should happen if a default parameter value also changes in the code. We could either use the instance's parameter value or the new default value. In this case it is probably better to stick with the instance's value. Unless the instance was using the default parameter value then after reload it could use the new default value.
If I edit a PCell source code and want to see the changes within KLayout application, I need to:
Would be nice if there was one less manual step and I would not need to make a new PCell. Instead:
Maybe after this issue we should have the follow up features: