Skip to content

Commit

Permalink
Added functions to aid junction tuning within cells
Browse files Browse the repository at this point in the history
Junction data can be extracted from a given cell hierarchy,
both if the cell contains or doesn't contain PCell data.

This junction data can later be added into another cell
retaining junction position and orientation, with possibility
to tune junction parameters and junction type using external files.
  • Loading branch information
qpavsmi committed Feb 9, 2024
1 parent 68c1f4a commit 8245c8b
Show file tree
Hide file tree
Showing 7 changed files with 1,235 additions and 186 deletions.
13 changes: 13 additions & 0 deletions klayout_package/python/kqcircuits/masks/mask_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from kqcircuits.util.geometry_json_encoder import GeometryJsonEncoder
from kqcircuits.util.netlist_extraction import export_cell_netlist
from kqcircuits.util.export_helper import export_drc_report
from kqcircuits.util.replace_junctions import extract_junctions, get_tuned_junction_json


def export_mask_set(mask_set, skip_extras=False):
Expand Down Expand Up @@ -67,6 +68,8 @@ def export_chip(chip_cell, chip_name, chip_dir, layout, export_drc, alt_netlists
dummy_cell = layout.create_cell(chip_name)
dummy_cell.insert(pya.DCellInstArray(chip_cell.cell_index(), pya.DTrans()))
_export_cell(chip_dir / f"{chip_name}_with_pcells.oas", dummy_cell, "all")
if not skip_extras:
export_junction_parameters(dummy_cell, chip_dir / f"{chip_name}_junction_parameters.json")
dummy_cell.delete()
static_cell = layout.cell(layout.convert_cell_to_static(chip_cell.cell_index()))

Expand Down Expand Up @@ -383,3 +386,13 @@ def _get_directory(directory):

def get_mask_layout_full_name(mask_set, mask_layout):
return f"{mask_set.name}_v{mask_set.version}-{mask_layout.face_id}{mask_layout.extra_id}"


def export_junction_parameters(cell, path):
"""Exports a json file containing all parameter values for each junction in the given chip (as cell)"""
junctions = extract_junctions(cell, {})
if len(junctions) > 0:
params_json = json.dumps(get_tuned_junction_json(junctions), indent=2)
with open(path, 'w') as file:
file.write(params_json)
logging.info(f"Exported tunable junction parameters to {path}")
455 changes: 455 additions & 0 deletions klayout_package/python/kqcircuits/util/replace_junctions.py

Large diffs are not rendered by default.

185 changes: 0 additions & 185 deletions klayout_package/python/kqcircuits/util/replace_squids.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<klayout-macro>
<description>Exports junctions parameters</description>
<version/>
<category>pymacros</category>
<prolog/>
<epilog/>
<doc/>
<autorun>false</autorun>
<autorun-early>false</autorun-early>
<priority>0</priority>
<shortcut/>
<show-in-menu>false</show-in-menu>
<group-name/>
<menu-path/>
<interpreter>python</interpreter>
<dsl-interpreter-name/>
<text># This code is part of KQCircuits
# Copyright (C) 2024 IQM Finland Oy
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# https://www.gnu.org/licenses/gpl-3.0.html.
#
# The software distribution should follow IQM trademark policy for open-source software
# (meetiqm.com/developers/osstmpolicy). IQM welcomes contributions to the code. Please see our contribution agreements
# for individuals (meetiqm.com/developers/clas/individual) and organizations (meetiqm.com/developers/clas/organization).


"""Exports all current junnction parameter values for each junction in the PCell.
Assumes that a single chip exists in the top cell, and it is a PCell.
Results of this macro can be used to tune junctions for cells without PCell data.
"""

import json
from kqcircuits.klayout_view import KLayoutView
from kqcircuits.util.replace_junctions import extract_junctions, get_tuned_junction_json

top_cell = KLayoutView(current=True).active_cell

### Set file location, or leave empty to get tuned junction JSON in the output
FILE_LOCATION = ""

try:
junctions = extract_junctions(top_cell, {})
if len(junctions) &gt; 0:
json_str = json.dumps(get_tuned_junction_json(junctions), indent=2)

if FILE_LOCATION:
with open(FILE_LOCATION, 'w') as file:
file.write(json_str)
print(f"Wrote junction parameters to {FILE_LOCATION}")
else:
print(json_str)
else:
print("No junctions detected")
except ValueError:
raise ValueError("For this macro to work, the active layout must contain a chip PCell, for which PCell parameters are present")
</text>
</klayout-macro>
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ from kqcircuits.util.export_helper import generate_probepoints_json

top_cell = KLayoutView(current=True).active_cell

### Set file location, or leave empty to get probepoint JSON empty
### Set file location, or leave empty to get probepoint JSON in the output
FILE_LOCATION = ""
### Action
# See API docs on how to best call generate_probepoints_json for your purposes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<klayout-macro>
<description>Exports junctions in given chip with tuned parameters</description>
<version/>
<category>pymacros</category>
<prolog/>
<epilog/>
<doc/>
<autorun>false</autorun>
<autorun-early>false</autorun-early>
<priority>0</priority>
<shortcut/>
<show-in-menu>false</show-in-menu>
<group-name/>
<menu-path/>
<interpreter>python</interpreter>
<dsl-interpreter-name/>
<text># This code is part of KQCircuits
# Copyright (C) 2024 IQM Finland Oy
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# https://www.gnu.org/licenses/gpl-3.0.html.
#
# The software distribution should follow IQM trademark policy for open-source software
# (meetiqm.com/developers/osstmpolicy). IQM welcomes contributions to the code. Please see our contribution agreements
# for individuals (meetiqm.com/developers/clas/individual) and organizations (meetiqm.com/developers/clas/organization).


"""Exports junctions of a chip to a separate file. Parameters of individual junctions may be tuned.
Assumes that a single chip exists in the top cell.
Will export a new .oas file in TMP path containing junctions of original cell,
with possibly tuned junction parameters, and a "base_metal_gap" layer for reference.
This new layout will also be opened in current KLayout session in new layout.
Macro can be used on cells with or without PCell data.
In the latter case the `tuned_junction_parameters` must include a value for every
junction parameter of every junction in the cell.
You can use "export_junction_parameters" macro on a PCell to get full listing of parameters,
to later reuse on cells without PCell data.
See kqcircuits.util.replace_junctions API docs for more technical details.
"""

import json
from kqcircuits.defaults import TMP_PATH
from kqcircuits.klayout_view import KLayoutView
from kqcircuits.pya_resolver import pya
from kqcircuits.util.replace_junctions import extract_junctions, place_junctions, copy_one_layer_of_cell

top_cell = KLayoutView(current=True).active_cell

# If there are too many parameters to tune (for example tuning junctions for file without PCells),
# these can be written in a separate .json file and read from the macro
EXTERNAL_TUNE_FILE = ""

if EXTERNAL_TUNE_FILE:
with open(EXTERNAL_TUNE_FILE) as f:
tuned_junction_parameters = json.load(f)
else:
# Or tuned parameters can be typed up here by hand
tuned_junction_parameters = {}
# Example: exaggerate junction width for qubit "qb_1" for "Single Xmons" PCell
# tuned_junction_parameters = {"qb_1": {"squid": {"junction_width": 2.0}}}

junctions = extract_junctions(top_cell, tuned_junction_parameters)
clean_cell_name = top_cell.basic_name().replace(" ", "").replace("*", "").split("$")[0]
exported_file = str(TMP_PATH / f'tuned_junctions_{clean_cell_name}.oas')
copy_one_layer_of_cell(exported_file, top_cell, junctions, "base_metal_gap")

print(f"Extracted and tuned {len(junctions)} junctions")
new_view = KLayoutView()
new_view.layout.clear()
new_view.layout.read(exported_file)
top_cell = new_view.layout.top_cells()[-1]
top_cell.flatten(True)
place_junctions(top_cell, junctions)
new_view.focus(top_cell)

print(f"Saving tuned junctions to {exported_file}")
svopt = pya.SaveLayoutOptions()
svopt.set_format_from_filename(exported_file)
new_view.layout.write(exported_file, svopt)
</text>
</klayout-macro>
Loading

0 comments on commit 8245c8b

Please sign in to comment.