Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload Libraries macro issues: doesn't restore PCells on error, and fails for non-KQC PCells #89

Closed
qpavsmi opened this issue May 2, 2024 · 3 comments
Assignees
Labels
bug Something isn't working GUI unitaryhack-bounty

Comments

@qpavsmi
Copy link
Contributor

qpavsmi commented May 2, 2024

What happened? What you expected to happen?

I place a KQC element, for example the Double Pads from the Qubit Library. Then I open klayout_package/python/kqcircuits/qubits/double_pads.py and make _build_island2 return empty pya.Region(). I go back to the same KLayout session and select KQCircuits > Reload Libraries. I get what I expected, which is that the bottom island on the qubit is not present anymore and there are no errors in File > Log Viewer.

Now I open Basic from the library panel, and place a Circle. For better demonstration I double click the Circle cell, choose PCell Parameters and change Radius to 100 microns and layer to 1t1 base metal wo grid 130/1. Now do some change in double pads code (e.g. revert change made above) and try KQCircuits > Reload Libraries. Now it gives error AttributeError: type object 'PCellDeclaration_Native' has no attribute 'get_schema'. Also the double pads qubit will disappear.

Prerequisites

KQCircuits GUI installation required

Where to start?

The Reload Libraries command is a macro at klayout_package/python/scripts/macros/0system/0reload.lym.
It is an XML file with python code embedded in the <text> field. The macro code is simple:

views = extract_pcell_data_from_views()  # Collect all cells currently placed in the KLayout session, removing them in the process
load_libraries(flush=True)               # Make KLayout reload the KQC plugin code
restore_pcells_to_views(views)           # Reconstruct all cells that were collected before KQC reload

It seems that the extract_pcell_data_from_views function does not filter the cells based on whether they are introduced by the KQC library or if they are native KLayout objects or cells defined from some other library. Every cell that comes from the KQC library is a subclass of kqcircuits.elements.element.Element class, so it should be easy to filter using the isinstance python function.

The described bug happens because: the macro collects the pcells, deleting some of them in the process, then it encounters a cell that it cannot work with, throws an error, and then leaves it at that - without restoring the deleted cells.
This bug should be fixed by performing the macro actions only on KQC cells, and writing a good try except block where the restore_pcells_to_views is called in case of exception.

Definition of done

  • Bug cannot be replicated: cells that are placed on the layout should stay there after running Reload Libraries
  • Tests not needed for this issue

Versions

Version independent issue

Issue Severity

Low: it is annoying

@qpavsmi qpavsmi added the bug Something isn't working label May 2, 2024
@qpavsmi qpavsmi added the GUI label May 17, 2024
@PietroCampana
Copy link
Contributor

Hi, I would like to work on this issue as part of unitaryhack 2024

@qpavsmi
Copy link
Contributor Author

qpavsmi commented Jun 4, 2024

Hi, I would like to work on this issue as part of unitaryhack 2024

Sounds great! I encourage to make a pull request early even if the solution is not completely finalized to get early feedback.

@qpavsmi
Copy link
Contributor Author

qpavsmi commented Jun 10, 2024

Completed by #95 thanks @PietroCampana

@qpavsmi qpavsmi closed this as completed Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working GUI unitaryhack-bounty
Projects
None yet
Development

No branches or pull requests

2 participants