Source code for kqcircuits.layer_config.stack_info

# This code is part of KQCircuits
# Copyright (C) 2026 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/iqm-open-source-trademark-policy). IQM welcomes contributions to the code.
# Please see our contribution agreements for individuals (meetiqm.com/iqm-individual-contributor-license-agreement)
# and organizations (meetiqm.com/iqm-organization-contributor-license-agreement).

import re

from kqcircuits.pya_resolver import pya


[docs] class FaceInfo: """FaceInfo class contains parameters specific to a particular face""" def __init__(self, face_id, face_id_across_vacuum, face_id_across_substrate, **face_info_params): self.face_id = face_id self.face_id_across_vacuum = face_id_across_vacuum self.face_id_across_substrate = face_id_across_substrate for k, v in face_info_params.items(): if k not in ["a", "b"]: setattr(self, k, v) def __repr__(self) -> str: return ( f"FaceInfo({repr(self.face_id)}, {repr(self.face_id_across_vacuum)}, {repr(self.face_id_across_substrate)})" )
[docs] class FrameInfo: """FrameInfo class contains parameters specific to frames""" def __init__( self, frame_enabled=True, frame_box=pya.DBox(0, 0, 10000, 10000), dice_width=200, text_margin=100, marker_dist=1200, mirrored=False, marker_types=("",) * 4, dice_grid_margin=100, **frame_info_params, ): self.frame_enabled = frame_enabled self.frame_box = frame_box self.text_margin = text_margin self.dice_grid_margin = dice_grid_margin self.dice_width = dice_width self.marker_dist = marker_dist self.mirrored = mirrored self.marker_types = marker_types for k, v in frame_info_params.items(): setattr(self, k, v)
[docs] class StackInfo: def __init__(self, face_infos, physical_order_face_ids, ml_stack=None): self.face_infos = face_infos self.face_infos_dict = {fi.face_id: fi for fi in face_infos} self.physical_order_face_ids = physical_order_face_ids # pylint: disable=R1718 if set(physical_order_face_ids) != set([fi.face_id for fi in face_infos]): raise ValueError( "elements of physical_order_face_ids should match the face_id attributes in the set" " of FaceInfo objects" ) self.ml_stack = ml_stack def __repr__(self) -> str: """Returns the string representation of the stack info.""" stack = [] for face_id in self.physical_order_face_ids: stack.append(face_id) face_info = self.face_infos_dict[face_id] across_vac = face_info.face_id_across_vacuum across_sub = face_info.face_id_across_substrate if across_sub and across_sub not in stack: stack.append("sub") elif across_vac and across_vac not in stack: stack.append("vac") return ( f"Layers: {' - '.join(stack)}\n" f"StackInfo(\n" f" physical_order_face_ids: {repr(self.physical_order_face_ids)},\n" f" face_infos_dict: {repr(self.face_infos_dict)},\n" f" ml_stack: {repr(self.ml_stack)}\n" f")" )
[docs] def get_face_info(self, face_name): return self.face_infos_dict[face_name]
[docs] def get_highest_face_id_on_tier(self, tier): return [x.face_id for x in self.face_infos if x.face_id[0] == str(tier)][-1]
[docs] def get_lowest_face_id_on_tier(self, tier): return [x.face_id for x in self.face_infos if x.face_id[0] == str(tier)][0]
[docs] def get_tiers(self): tiers = [] seen = set() for face_id in self.physical_order_face_ids: if face_id[0] not in seen: tiers.append(face_id[0]) seen.add(face_id[0]) return tiers
[docs] def get_opposing_face_ids(self): opposing_face_ids = [] tiers = self.get_tiers() for tier in tiers[:-1]: t_face = self.get_highest_face_id_on_tier(tier) b_face = self.physical_order_face_ids[self.physical_order_face_ids.index(t_face) + 1] opposing_face_ids.append((t_face, b_face)) return opposing_face_ids
[docs] def get_tier(self, face_id): return re.split("t|b", face_id)[0]