qcc_kplugin.pcells

Live PCells (opt-in, Settings): the Quantcore PDK cells as a KLayout library, so KLayout’s own Instance tool and its PCell parameter dialog place and edit them, while design.json stays the source of truth.

The plugin still does not import quantcore_circuits or KQCircuits inside KLayout (KLayout’s Python is a MinGW build without pydantic, and the KQC Salt package it may load is another KQC version than the one qcc builds with). Each PCell here is a light declaration: its parameters come from one qcc components --source quantcore --schemas call, and its geometry is copied from what ``qcc`` built:

  • after every rebuild, each placed component’s built cell is cached under (cell, parameters) and the static instance is swapped for a library PCell instance with the same parameters (same transform, same id property), so the geometry in the view is exactly the build’s;

  • a parameter set not built yet (a new value in the Instance tool or the PCell dialog) is drawn from the nearest cached geometry of that cell at once, and a background qcc components CELL --oas fetches the real one (--design gives it the chip’s inherited parameters); the library is refreshed when it lands.

Edits flow back like every other edit: a library PCell instance without id (placed with the Instance tool) becomes a design instance, a changed parameter becomes the instance’s params, both through SESSION.commit (Undo works), and the rebuild replaces the preview with the built geometry.

Attributes

Classes

GeometryCache

Flat copies of built component cells, by params_key(), in a private layout.

Live

The opt-in state: schemas loading in the background, the registered library, the provider.

Provider

Geometry for the declarations: the cache, plus background qcc fetches of parameter sets not built yet.

Functions

base_cell(ref) → str

The library name of a design.json cell (Xmon or quantcore_circuits.layouts....Xmon).

coerce(value, row)

value as KLayout's dialog hands it back (list items are strings) → the type of the schema row.

context_key(design[, path]) → str

Geometry depends on the chip (inherited a/b, PDK): a new context empties the geometry cache.

declaration(cell, info, provider)

A PCell declaration for Quantcore cell (schema rows of qcc components --schemas).

draw(src, layout, cell) → None

Copy the (flat) cached src into a PCell's cell of layout, layer by layer (same layer infos as the

draw_marker(layout, cell[, size]) → None

Nothing of this cell is cached yet: a small open square until its geometry arrives.

full_params(schema, own) → dict

Every PCell parameter: the defaults with own on top (what add_pcell_variant takes).

library_cell_name(inst, layout) → str | None

The PCell name of an instance (in layout) of the Quantcore library (None for anything else).

liveable(entry, schemas) → str | None

The library cell for a design instance, or None when it cannot be a live PCell: not a Quantcore PDK cell, or

liven(chip, design, lib, provider) → list[str]

After a rebuild: cache each component's built cell, then swap the static instance for a library PCell

make_library(schemas, provider)

The Quantcore library with one PCell per schema entry (not registered yet).

norm(value)

A canonical JSON value: tuples as lists, integral floats as ints (10.0 and 10 are the same parameter).

own_params(schema, values) → dict

The design.json params for PCell values: coerced, and only those that differ from the defaults.

params_key(cell, own) → str

safe_refresh(lib) → None

lib.refresh() (re-produce every variant, so new geometry replaces a preview), with KLayout's Instance tool

startup() → None

Called by the autorun macro: register the library when Settings has live PCells on.

sync(design, chip, schemas) → tuple[dict, list[str]]

Quantcore library PCells in chip → design: an instance without id (placed with KLayout's Instance

Module Contents

class qcc_kplugin.pcells.GeometryCache

Flat copies of built component cells, by params_key(), in a private layout.

clear() → None
get(key: str)
load(key: str, path) → bool

Cache the geometry qcc components CELL --oas wrote (top cell qcc_component).

nearest(cell: str)
put(key: str, src) → None

Cache src (a cell of any layout, in its local frame) under key, flattened.

cells: dict[str, int]
context = ''
latest: dict[str, str]
layout
class qcc_kplugin.pcells.Live

The opt-in state: schemas loading in the background, the registered library, the provider.

active() → bool
after_build(session, chip) → None

The view shows a fresh build: its components become live PCells (geometry = the build’s).

enabled() → bool
start(wait: bool = False) → None

Load the schemas (one qcc call, ~1 s, in the background) and register the library.

stop() → None
sync(session, chip) → None

Instance tool placements and PCell dialog edits → design.json (one commit).

tick() → None
error = ''
lib = None
loading: tuple[subprocess.Popen, pathlib.Path] | None = None
provider: Provider | None = None
property ready: bool
timer = None
class qcc_kplugin.pcells.Provider(qcc: str = 'qcc', design=None, env=None, outdir=None)

Geometry for the declarations: the cache, plus background qcc fetches of parameter sets not built yet.

busy() → bool
poll() → bool

Advance the background fetch; True when new geometry was cached (refresh the library).

produce(cell: str, values: dict, layout, target) → None
request(cell: str, own: dict) → None
stop() → None
cache
declarations: list = []
design = None
env = None
failed: dict[str, str]
fallback: set[str]
outdir
produced = 0
qcc = 'qcc'
queue: dict[str, tuple[str, dict]]
running: tuple[str, subprocess.Popen, pathlib.Path] | None = None
schemas: dict
qcc_kplugin.pcells.base_cell(ref: str) → str

The library name of a design.json cell (Xmon or quantcore_circuits.layouts....Xmon).

qcc_kplugin.pcells.coerce(value, row: dict)

value as KLayout’s dialog hands it back (list items are strings) → the type of the schema row.

qcc_kplugin.pcells.context_key(design: dict, path=None) → str

Geometry depends on the chip (inherited a/b, PDK): a new context empties the geometry cache.

qcc_kplugin.pcells.declaration(cell: str, info: dict, provider: Provider)

A PCell declaration for Quantcore cell (schema rows of qcc components --schemas).

qcc_kplugin.pcells.draw(src, layout, cell) → None

Copy the (flat) cached src into a PCell’s cell of layout, layer by layer (same layer infos as the built OAS, so the view gets no new layers).

qcc_kplugin.pcells.draw_marker(layout, cell, size: float = 100.0) → None

Nothing of this cell is cached yet: a small open square until its geometry arrives.

qcc_kplugin.pcells.full_params(schema: list[dict], own: dict) → dict

Every PCell parameter: the defaults with own on top (what add_pcell_variant takes).

qcc_kplugin.pcells.library_cell_name(inst, layout) → str | None

The PCell name of an instance (in layout) of the Quantcore library (None for anything else).

qcc_kplugin.pcells.liveable(entry: dict, schemas: dict) → str | None

The library cell for a design instance, or None when it cannot be a live PCell: not a Quantcore PDK cell, or params outside its editable schema (shapes, layers), which the PCell could not carry.

qcc_kplugin.pcells.liven(chip, design: dict, lib, provider: Provider) → list[str]

After a rebuild: cache each component’s built cell, then swap the static instance for a library PCell instance with the same parameters (transform and properties such as id stay). Returns the instance names.

qcc_kplugin.pcells.make_library(schemas: dict, provider: Provider)

The Quantcore library with one PCell per schema entry (not registered yet).

qcc_kplugin.pcells.norm(value)

A canonical JSON value: tuples as lists, integral floats as ints (10.0 and 10 are the same parameter).

qcc_kplugin.pcells.own_params(schema: list[dict], values: dict) → dict

The design.json params for PCell values: coerced, and only those that differ from the defaults.

qcc_kplugin.pcells.params_key(cell: str, own: dict) → str
qcc_kplugin.pcells.safe_refresh(lib) → None

lib.refresh() (re-produce every variant, so new geometry replaces a preview), with KLayout’s Instance tool switched off meanwhile: KLayout 0.30.3 crashes when a library is refreshed while that tool shows a preview of one of its PCells (tested). The tool is switched on again, so the user stays in it.

qcc_kplugin.pcells.startup() → None

Called by the autorun macro: register the library when Settings has live PCells on.

qcc_kplugin.pcells.sync(design: dict, chip, schemas: dict) → tuple[dict, list[str]]

Quantcore library PCells in chip → design: an instance without id (placed with KLayout’s Instance tool) becomes a new design instance (and gets its id); a changed parameter becomes the instance’s params (keys outside the PCell schema are kept). Moves, rotations and deletes are synced by the session as before.

qcc_kplugin.pcells.CFG_LIVE = 'qcc-kplugin-live-pcells'
qcc_kplugin.pcells.LIB_NAME = 'Quantcore'
qcc_kplugin.pcells.LIVE