qcc_kplugin.tools ================= .. py:module:: qcc_kplugin.tools .. autoapi-nested-parse:: Interactive KLayout tools (toolbar modes) for editing a qcc design in place. Structure follows KQC's ``kqcircuits/util/edit_node_plugin.py`` (GPL-3.0): a ``pya.PluginFactory`` registers each mode and creates one ``pya.Plugin`` per view; overlays are ``pya.Marker`` objects sized in screen pixels. Unlike KQC's node editor these tools never change the layout: every action edits ``design.json`` through :mod:`qcc_kplugin.design_io` and the session rebuilds it. * **qcc Connect** — pen tool: start on a port or on empty canvas (a free end), click nodes, finish on a port, on a line (a hanger coupler) or on the last node again (a free end) → route dialog (cpw / meander + length, bend radius, free-end termination). Clicks snap to KLayout's editor grid; without a modifier each click adds a square corner (Manhattan), Shift makes the segment 0° / 45° / 90° or along the start port's own angle when it faces an angle, Ctrl places the node as clicked: any angle, one oblique straight. The rubber band shows the route with its corners bent to the radius as you move (and the oblique straight the router draws between ports that face an angle). * **qcc Route handles** — every route shows its nodes (filled squares: click to select and pick up, click to drop; right-click deletes) and an insert handle on each free straight segment (hollow square). Nodes move to any angle on the grid; Shift snaps to 0° / 45° / 90° or an angled port's axis. A route the last build left out (failed) is drawn in red with the same handles. A selected corner shows a curvature handle that sets that corner's own bend radius. Double-click a node for its properties, a route for its options (type, length, radius, meander segment). * **qcc Move/Snap** — drag an instance; a port that comes within the capture radius of a compatible port (same CPW, facing) snaps, and the placement is stored as ``place.snap``. Otherwise the new ``place.at`` is grid-rounded. ``[`` / ``]`` rotate by 90° while dragging; a port near a compatible one also turns the component to face it (any angle: StarQubit pins, ConcentricTransmon couplers), unless Ctrl is held. A pending component (double-click in the panel, Duplicate) follows the mouse and snaps the same way; the next click drops it. Attributes ---------- .. autoapisummary:: qcc_kplugin.tools.ACTIVE qcc_kplugin.tools.CATEGORY qcc_kplugin.tools.CTRL qcc_kplugin.tools.C_UM_PER_NS qcc_kplugin.tools.FACING_GAP_TEXT qcc_kplugin.tools.FACTORIES qcc_kplugin.tools.FAILED qcc_kplugin.tools.HANGER_TITLE qcc_kplugin.tools.ICONS qcc_kplugin.tools.INSTANCES qcc_kplugin.tools.JOIN qcc_kplugin.tools.JUNCTION_TITLE qcc_kplugin.tools.LEFT qcc_kplugin.tools.LINE_GAP_TEXT qcc_kplugin.tools.MEANDER_SIDES qcc_kplugin.tools.MERGE_TEXT qcc_kplugin.tools.PENDING_PLACE qcc_kplugin.tools.RIGHT qcc_kplugin.tools.ROTATE_HINT qcc_kplugin.tools.ROTATE_KEYS qcc_kplugin.tools.SEGMENT_TEXT qcc_kplugin.tools.SHIFT Classes ------- .. autoapisummary:: qcc_kplugin.tools.ConnectFactory qcc_kplugin.tools.ConnectTool qcc_kplugin.tools.JunctionRows qcc_kplugin.tools.RouteEditFactory qcc_kplugin.tools.RouteEditTool qcc_kplugin.tools.SnapFactory qcc_kplugin.tools.SnapTool qcc_kplugin.tools.TargetsEditor Functions --------- .. autoapisummary:: qcc_kplugin.tools.apply_instance_edit qcc_kplugin.tools.arm_place qcc_kplugin.tools.delete_node qcc_kplugin.tools.delete_route qcc_kplugin.tools.delete_selected_node qcc_kplugin.tools.draw_failed qcc_kplugin.tools.drawn_junction_value qcc_kplugin.tools.edit_instance_dialog qcc_kplugin.tools.edit_route_options qcc_kplugin.tools.fill_table qcc_kplugin.tools.fix_placed_junction qcc_kplugin.tools.ghost qcc_kplugin.tools.ghost_async qcc_kplugin.tools.ghost_cached qcc_kplugin.tools.hanger_dialog qcc_kplugin.tools.icon qcc_kplugin.tools.junction_info qcc_kplugin.tools.length_hint qcc_kplugin.tools.lom_section qcc_kplugin.tools.may_have_junction qcc_kplugin.tools.meander_here qcc_kplugin.tools.node_dialog qcc_kplugin.tools.node_properties qcc_kplugin.tools.refresh_failed_overlay qcc_kplugin.tools.register_tools qcc_kplugin.tools.rotate qcc_kplugin.tools.rounded_path qcc_kplugin.tools.route_dialog qcc_kplugin.tools.schema qcc_kplugin.tools.schema_async qcc_kplugin.tools.size_note qcc_kplugin.tools.snap_text qcc_kplugin.tools.squid_l_eff qcc_kplugin.tools.substrate_eps qcc_kplugin.tools.table_values qcc_kplugin.tools.toggle_join Module Contents --------------- .. py:class:: ConnectFactory(ident, title, priority, tip='') Bases: :py:obj:`_Factory` .. py:attribute:: tool_cls .. py:class:: ConnectTool(manager, view) Bases: :py:obj:`_Tool` Pen-tool routing. Start on a port, or on empty canvas (a free end); every canvas click adds a node; finish on a port, on a line (a hanger coupler on it), or by clicking the last node again (a free end there). Clicks snap to the grid. Without Shift a segment turns once with a square corner (the preview shows it and the click commits it, so the built route is what was previewed); with Shift it goes straight at 0° / 45° / 90° / …. Right-click removes the last click (or cancels). .. py:method:: anchor() The previous point of the route (what Shift aligns the next segment with): the last node, the free start, or the end of the start port's stub. .. py:method:: anchor_before(end) .. py:method:: anchor_dir() Direction of the segment arriving at the anchor: the next square corner leaves along it. .. py:method:: finish(end) .. py:method:: finish_free() The last node clicked again: the route ends there in a free end pointing back along the last segment. .. py:method:: finish_hanger(host, here) End the route on route ``host[0]`` at the clicked point: as a hanger coupler beside it (a λ/4 readout on a feedline: meander from a claw or from a free open end, short end on the line), or merged into it with a T (the join mode, Ctrl+Shift+J; the dialog's checkbox decides). .. py:method:: finish_merge(design, rname, poly, here, opts) Split line ``rname`` at ``here`` with a T (KQC ``WaveguideCoplanarSplitter``) whose stem faces the dialog's side and end the route on the stem: a capacitor or a resonator galvanically on the line, not beside it. .. py:method:: keep_state() The route in progress, to carry it over a layout reload (a rebuild that lands while the user is drawing switches the tool off and on again, which would otherwise drop the clicks made so far). .. py:method:: key_event(key, buttons) .. py:method:: mouse_click_event(p, buttons, prio) .. py:method:: mouse_moved_event(p, buttons, prio) .. py:method:: node_point(p) A canvas click / hover at ``p`` → the node it places (grid; Shift: 0° / 45° / 90° or the start port's angle; Ctrl: the grid point, any angle). .. py:method:: pdk_ab_if_wide() The PDK CPW (a, b) when the start port is no CPW end (a reference plane much wider than the PDK line, e.g. a Gatemon ``readout`` island edge, a = 150 µm): a route would otherwise take that width. (None, None) else. .. py:method:: port_corner(end_port: str) Square corner into the stub of ``end_port`` after the user's nodes (none without nodes: the router turns by itself then, as before; none with Shift or Ctrl: straight into the stub). .. py:method:: rays() -> list The axis of the start port when it faces an angle (a StarQubit pin, a ConcentricTransmon coupler): offered by Shift next to 0° / 45° / 90°, so a node can sit exactly on the port's own direction. .. py:method:: redraw() .. py:method:: reset() .. py:method:: restore_state(state) -> None Take back a :meth:`keep_state` after the reload; dropped when its start port is gone. .. py:method:: route_near(p) (route, segment) under ``p`` (capture radius), not a route starting at the start port. .. py:method:: route_r(value) The route's ``r`` for design.json: None when the dialog still holds the PDK turn radius it was preset with, so the route keeps following the PDK (a changed value is written). .. py:method:: segment_to(q) Nodes a click at ``q`` (already on the grid / Shift-snapped) adds: the square corner the preview shows, then ``q``; with Shift just ``q`` (a straight 0° / 45° / 90° / port-angle segment), with Ctrl just ``q`` at the clicked point (any angle). .. py:method:: start_point() (position, outward direction or None) of the route start. .. py:method:: stub() -> float .. py:method:: target(p) What a click at ``p`` does: ("start-port", name) / ("start-free", pt) before the start; then ("port", name) / ("finish-free", pt) / ("line", (route, seg)) / ("node", pt). A port near the click always wins, so port → port routing behaves as before. .. py:method:: undo_click() Remove the nodes the last click added (a square corner goes with its node). .. py:property:: started :type: bool .. py:class:: JunctionRows(dialog, form, junction: dict | None, info: dict | None = None, drawn: dict | None = None) The junction section of the component dialog: L_J, I_c, R_n and C_J (L_J = Φ0/2πI_c, I_c·R_n = πΔ/2e with the PDK's Δ: typing any one fills the other two), for a SQUID the flux Φ/Φ0 and the asymmetry d, then read-only: the L at this bias (L_J0 / √(cos² πΦ + d² sin² πΦ), live), where the value comes from, and the junction the cell draws (PDK rule). These are simulation and LOM values, fixed per component: the drawn junction is for fab only. ``junction``: design.json's ``junction``. ``info``: the sidecar's entry (kind, source, ``error``). ``drawn``: the drawn trilayer junction's values. With no design value but a drawn junction, its values are the fields' placeholders ("PDK, drawn junction") and nothing is written unless the user types. .. py:method:: lj0() L_J0 in use: the typed / stored value, else the drawn junction's PDK value, else None. .. py:method:: refresh() Recompute the read-only rows from the fields. .. py:method:: source_text() -> str .. py:method:: values() ``(Lj_nH or None, Cj_fF or None, flux_phi0, asym)`` (flux and asym ``design_ops.KEEP`` for a component that is not a SQUID), or None for a multi-junction qubit (left as it is). .. py:attribute:: drawn :value: None .. py:attribute:: e .. py:attribute:: e_asym .. py:attribute:: e_cj .. py:attribute:: e_flux .. py:attribute:: gap .. py:attribute:: l_drawn :value: None .. py:attribute:: l_eff .. py:attribute:: l_err .. py:attribute:: l_src .. py:attribute:: l_title .. py:attribute:: multi .. py:attribute:: pdk :value: None .. py:attribute:: squid .. py:class:: RouteEditFactory(ident, title, priority, tip='') Bases: :py:obj:`_Factory` .. py:attribute:: tool_cls .. py:class:: RouteEditTool(manager, view) Bases: :py:obj:`_Tool` Pen-tool node editing. Click a node (filled square) to select it and pick it up, move, click to drop it (grid, any angle; Shift aligns it with its neighbours at 0° / 45° / 90° or on an angled port's axis, Ctrl = no alignment). A route the last build left out is drawn in red with its handles: edit its nodes, double-click it for its options, or press Delete on its line to delete the route. A selected corner shows its curvature handle (green, on the arc): pick it, move, drop to set that corner's bend radius. Hollow squares insert a node. Right-click a node deletes it. .. py:method:: corner(rname, i) (prev, pos, next, radius, polyline index) of node ``i`` of ``rname``, or None. .. py:method:: drag_point(p) .. py:method:: drag_radius(p) -> float | None .. py:method:: drop(here) .. py:method:: handle_near(p) .. py:method:: handles() .. py:method:: key_event(key, buttons) .. py:method:: mouse_click_event(p, buttons, prio) Click a handle to pick it up, move, click again to drop it there. Right-click a node deletes it; right-click while moving cancels. .. py:method:: mouse_double_click_event(p, buttons, prio) Double-click a node: its properties (x, y, corner radius, airbridge); elsewhere on a route: the route's options (type, length, radius, meander segment). .. py:method:: mouse_moved_event(p, buttons, prio) .. py:method:: neighbours(route: dict, kind: str, index: int) .. py:method:: port_rays(route: dict) -> list :staticmethod: Axes of the end stubs that face an angle (a StarQubit pin, a ConcentricTransmon coupler): Shift offers them next to 0° / 45° / 90°. Failed routes have no stubs. .. py:method:: preview(route: dict, kind: str, index: int, pos) (points, radii) of ``route`` with the dragged handle at ``pos`` (a radius for kind "radius"). .. py:method:: radii(route: dict) -> list Bend radius of each polyline point (the route's, or a waypoint's own). .. py:method:: radius_handle() .. py:method:: redraw() .. py:method:: reset() .. py:method:: route(rname) -> dict .. py:method:: routes() -> dict The sidecar routes with every corner as a node: the router's own corners (a route drawn without clicks, corners the router added) are listed next to the user's nodes, so each gets a handle; the first edit of such a corner writes them all to design.json (:func:`design_io.materialize_nodes`). .. py:attribute:: selected :value: None .. py:class:: SnapFactory(ident, title, priority, tip='') Bases: :py:obj:`_Factory` .. py:attribute:: tool_cls .. py:class:: SnapTool(manager, view) Bases: :py:obj:`_Tool` .. py:method:: drop_instance() .. py:method:: instance_at(p) .. py:method:: key_event(key, buttons) .. py:method:: load_outline(inst) The held instance's etched outline for the preview (background query, cached; the bbox shows until it arrives, and when the instance's parameters cannot be read). .. py:method:: mouse_click_event(p, buttons, prio) .. py:method:: mouse_double_click_event(p, buttons, prio) Double-click a placed component: edit its parameters and rotation (written to design.json, rebuilt). .. py:method:: mouse_moved_event(p, buttons, prio) .. py:method:: other_ports(inst) -> dict .. py:method:: own_ports(inst) -> dict .. py:method:: pending_snap(c) ``(own port, target port, corrected position, extra turn)`` for the component being placed with its origin at ``c`` (it follows the mouse like a held instance: a port near a compatible one snaps, turning to face it; Ctrl: only ports that already face each other), or None. .. py:method:: place(at) .. py:method:: redraw() .. py:method:: reset() .. py:class:: TargetsEditor(dialog, layout, keys: dict, current: dict) The optional "Targets" rows of an edit dialog: one line edit per key (empty = no target). The values go to ``design.json`` ``targets[element]`` (see :func:`design_io.set_targets`). .. py:method:: values() -> dict .. py:attribute:: edits .. py:function:: apply_instance_edit(design: dict, name: str, out) -> str Write the result of :func:`edit_instance_dialog` into ``design`` and describe it. .. py:function:: arm_place(cell: str, params: dict, rot: float = 0.0, mirror: bool = False, extra: dict | None = None) -> None Next click in *Move/Snap* drops ``cell``; its outline follows the mouse; [ and ] rotate it by 90°. ``rot``/``mirror``/``extra`` (entry keys such as ``junction``) come from a duplicated component. .. py:function:: delete_node(rname: str, index: int) -> None Delete node ``index`` of ``rname`` as Route handles shows it (the router's own corners count as nodes: they are written to design.json first, then the one is removed). .. py:function:: delete_route(rname: str) -> None Delete route ``rname`` (and the routes hanging on it) from design.json: a failed route has no cell, so KLayout's own Delete cannot reach it. .. py:function:: delete_selected_node() -> None Quantcore menu: delete the node selected in *Route handles*. .. py:function:: draw_failed(o, name: str, f: dict) -> None One failed route in red: its last good path (the route as it last built, wide) when there is one, and the path the design asks for now (its ends and nodes, dashed), with the name and the reason. .. py:function:: drawn_junction_value(entry: dict, info: dict | None) -> dict | None What the cell's drawn trilayer junction gives (``{"Lj_nH", "Cj_fF", "source"}``, PDK rule), or None. The sidecar has it when the design holds no value of its own (``source`` "drawn ..."); with a design value, and a cell whose ``junction_type`` is a trilayer junction, the library is asked (``qcc design placement-junction``). .. py:function:: edit_instance_dialog(name: str, entry: dict, targets: dict | None = None) Dialog: the placed instance's parameters (its values over the cell defaults), rotation and, for components that can have them (qubits), targets. ``targets`` is the element's current ``design.json`` targets (None: no targets section). Returns ``(changed params, rotation or None, targets or None, position or None, junction or None)`` (None targets: section not shown; None position: unchanged or snapped; junction ``(Lj_nH, Cj_fF, flux, asym)`` for a qubit) or None when cancelled. .. py:function:: edit_route_options(rname: str, segment: int | None = None) -> None The route dialog for an existing route (type, length, radius, meander segment). .. py:function:: fill_table(table, rows: list[dict], values: dict, cell: str | None = None) -> None Two-column parameter table (name, value); ``values`` override the defaults; hover shows the description (and, with ``cell``, the PDK junction an unset KQC ``junction_type`` default is drawn as). .. py:function:: fix_placed_junction(design: dict, name: str) -> str | None Placing a qubit fixes its junction at design time: ``junction = {Lj_nH, Cj_fF}`` goes into design.json (a drawn trilayer junction's PDK value, else the PDK nominal SQUID, both from the library), unless the instance already has one (a duplicate keeps its source's). Returns the status-bar note, or None. .. py:function:: ghost(cell: str, params: dict) -> dict | None The component's outline, bbox and ports in its own frame (cached; one `qcc` call, ~1.5 s, per cell+params). .. py:function:: ghost_async(cell: str, params: dict, done=None) -> None Load the outline in the background (``done(outline or None)`` afterwards; at once when it is cached). .. py:function:: ghost_cached(cell: str, params: dict) -> bool .. py:function:: hanger_dialog(name, host, side, r, free_start=False, merge=False, a=None, b=None, wide_port=None) Options of a route ending on line ``host`` → dict ``{name, kind, length, r, coupler, side, end, gap, merge}`` (+ ``free``/``free_gap`` for a free start) or None. ``merge`` presets the checkbox that merges the route into the line with a T instead of hanging it beside the line (the coupler fields are then unused); ``a`` / ``b`` preset the line's own width / gap (``wide_port``: the start port that is no CPW end, named in a note). .. py:function:: icon(name: str) -> str | None .. py:function:: junction_info(name: str) -> dict | None The build sidecar's ``instances..junction`` (kind, Lj0_nH, Cj_fF, flux_phi0, asym, Lj_eff_nH, source, maybe error), None for a component without a junction or before the first build. .. py:function:: length_hint(text: str, eps_r: float | None = None) -> str Bare λ/4 frequency of a CPW of this length on the design's substrate: f = c / (4 L √ε_eff), ε_eff = (εr + 1) / 2 (a thick substrate; a claw or a hanger coupler loads it a few % to ~10 % lower: Q1 + R1, 4200 µm: 7.5 GHz bare, 6.65 GHz in its LOM). The thickness does not matter at these widths; the loss tangent sets Q, not f. .. py:function:: lom_section(dialog, layout, element: str) -> None Read-only rows: the element's circuit as the last build's LOM sees it (C to ground and couplings, L_J / C_J, the resonator line, the hanger κ); Run LOM uses these, a simulation replaces the C values. .. py:function:: may_have_junction(cell: str, params: dict | None = None) -> bool Whether a placed ``cell`` can carry a junction (a qubit, or a cell with a ``junction_type`` parameter): then the placement asks the library for its simulation value (:func:`fix_placed_junction`). .. py:function:: meander_here() -> None Quantcore menu: put the meander of the route under the cursor on the segment under the cursor (Route handles). .. py:function:: node_dialog(route: str, index: int, props: dict, route_r: float) Node ``index`` of ``route``: x, y, bend radius of its corner (empty = the route's), airbridge, and the line width / gap from this node on (a taper; empty = as before the node) → dict or None. .. py:function:: node_properties() -> None Quantcore menu: x, y, corner radius and airbridge of the node selected in *Route handles*. .. py:function:: refresh_failed_overlay() -> None Red markers for the routes the last build left out, on the design's view (a listener of the session: it runs after every sidecar change, so the marks follow each build and vanish when the route builds again). .. py:function:: register_tools() .. py:function:: rotate(step: float) -> None Rotate the component being placed (or the instance being dragged) by ``step`` degrees: the Quantcore menu's [ / ] actions, so the keys work wherever the keyboard focus is (e.g. still in the panel after a double-click). .. py:function:: rounded_path(points, width: float, r: float) -> pya.DPath Sharp polyline → path with every corner bent to radius ``r`` (what KQC does when it builds the route). .. py:function:: route_dialog(name, kind, length, r, title='qcc route', free_ends=(), segment=None, segments=None, targets=None, a=None, b=None, join=None, hanger=None, meander=None, lom_of=None, error=None, last_good=None) Route options → dict ``{name, kind, length, r, a, b}`` (+ ``free_``/``free_gap`` for each free end, ``segment`` for the meander segment, ``merge`` when ``join`` is given) or None. ``length`` is only used for meanders; ``a`` / ``b`` (CPW width and gap, empty = taken from the ports) are written only when set. ``join`` = ``(line, merged)`` for a route that ends on a line: the checkbox merges it into the line with a T (checked) or hangs it beside the line (unchecked). ``hanger`` (the route's hanger end) adds its coupler rows → ``out["hanger"]`` with the edited ``length``, ``side``, ``end``, ``ground_gap``, ``open_gap``, ``direction``. ``meander`` (``{"meanders", "meander_direction"}`` of an existing route) adds the meander's turn count and first-turn side → ``out["meanders"]`` (-1 = automatic) and ``out["meander_direction"]`` (1 / -1). ``error`` (a route the last build left out) shows why at the top, with ``last_good`` (its last good length) and a "Delete this route" box → ``out["delete"]``. .. py:function:: schema(cell: str) -> list[dict] The cell's editable parameters and defaults (`qcc components CELL --schema`, cached). .. py:function:: schema_async(cell: str, done) -> None ``done(rows)`` with the cell's parameters, loaded in the background (at once when cached). .. py:function:: size_note(cell: str, g: dict | None) -> str "" when the outline fits on the chip, else a status-bar sentence: a wafer-level or frame cell (WaferMap75, BoundaryBox, AlignmentMarkers) is not a component to drop on a chip, and the user should know before it builds. .. py:function:: snap_text(hit, rot: float) -> str The label of a port snap while dragging: which ports, and the turn the snap added. .. py:function:: squid_l_eff(lj0_nh: float, flux_phi0: float = 0.0, asym: float = 0.0) -> float L of a DC SQUID at flux Φ/Φ0 with asymmetry d: L_J0 / √(cos² πΦ + d² sin² πΦ) (the library's ``lom.fragment.squid_l_eff``; raises at Φ = ½ with d = 0). .. py:function:: substrate_eps() -> float εr of the open design's substrate (Chip settings; the PDK's by default), from the sidecar. .. py:function:: table_values(table, rows: list[dict]) -> dict .. py:function:: toggle_join() -> None Quantcore menu (Ctrl+Shift+J): a route that ends on a line hangs beside it (a hanger coupler) or merges into it (a T-junction); the dialog can still change it per route. .. py:data:: ACTIVE :type: list :value: [] .. py:data:: CATEGORY :type: dict .. py:data:: CTRL .. py:data:: C_UM_PER_NS :value: 299792.458 .. py:data:: FACING_GAP_TEXT :value: "Coupler: this route's gap facing the line µm (empty = its b)" .. py:data:: FACTORIES :value: [] .. py:data:: FAILED .. py:data:: HANGER_TITLE :value: 'Hanger coupler beside {host}' .. py:data:: ICONS .. py:data:: INSTANCES :value: [] .. py:data:: JOIN .. py:data:: JUNCTION_TITLE :value: 'Junction (simulation and LOM only, not drawn, not in the fab mask)' .. py:data:: LEFT .. py:data:: LINE_GAP_TEXT :value: "Coupler: {host}'s gap facing this route µm (empty = {host}'s b)" .. py:data:: MEANDER_SIDES :value: ('left of the travel (+1)', 'right of the travel (-1)') .. py:data:: MERGE_TEXT :value: 'Merge into {host} (T-junction) instead of hanging beside it' .. py:data:: PENDING_PLACE :type: dict .. py:data:: RIGHT .. py:data:: ROTATE_HINT :value: '[ ] rotate 90°' .. py:data:: ROTATE_KEYS .. py:data:: SEGMENT_TEXT :value: 'Meander on straight' .. py:data:: SHIFT