qcc_kplugin.pcells ================== .. py:module:: qcc_kplugin.pcells .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: qcc_kplugin.pcells.CFG_LIVE qcc_kplugin.pcells.LIB_NAME qcc_kplugin.pcells.LIVE Classes ------- .. autoapisummary:: qcc_kplugin.pcells.GeometryCache qcc_kplugin.pcells.Live qcc_kplugin.pcells.Provider Functions --------- .. autoapisummary:: qcc_kplugin.pcells.base_cell qcc_kplugin.pcells.coerce qcc_kplugin.pcells.context_key qcc_kplugin.pcells.declaration qcc_kplugin.pcells.draw qcc_kplugin.pcells.draw_marker qcc_kplugin.pcells.full_params qcc_kplugin.pcells.library_cell_name qcc_kplugin.pcells.liveable qcc_kplugin.pcells.liven qcc_kplugin.pcells.make_library qcc_kplugin.pcells.norm qcc_kplugin.pcells.own_params qcc_kplugin.pcells.params_key qcc_kplugin.pcells.safe_refresh qcc_kplugin.pcells.startup qcc_kplugin.pcells.sync Module Contents --------------- .. py:class:: GeometryCache Flat copies of built component cells, by :func:`params_key`, in a private layout. .. py:method:: clear() -> None .. py:method:: get(key: str) .. py:method:: load(key: str, path) -> bool Cache the geometry ``qcc components CELL --oas`` wrote (top cell ``qcc_component``). .. py:method:: nearest(cell: str) .. py:method:: put(key: str, src) -> None Cache ``src`` (a cell of any layout, in its local frame) under ``key``, flattened. .. py:attribute:: cells :type: dict[str, int] .. py:attribute:: context :value: '' .. py:attribute:: latest :type: dict[str, str] .. py:attribute:: layout .. py:class:: Live The opt-in state: schemas loading in the background, the registered library, the provider. .. py:method:: active() -> bool .. py:method:: after_build(session, chip) -> None The view shows a fresh build: its components become live PCells (geometry = the build's). .. py:method:: enabled() -> bool .. py:method:: start(wait: bool = False) -> None Load the schemas (one ``qcc`` call, ~1 s, in the background) and register the library. .. py:method:: stop() -> None .. py:method:: sync(session, chip) -> None Instance tool placements and PCell dialog edits → design.json (one commit). .. py:method:: tick() -> None .. py:attribute:: error :value: '' .. py:attribute:: lib :value: None .. py:attribute:: loading :type: tuple[subprocess.Popen, pathlib.Path] | None :value: None .. py:attribute:: provider :type: Provider | None :value: None .. py:property:: ready :type: bool .. py:attribute:: timer :value: None .. py:class:: 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. .. py:method:: busy() -> bool .. py:method:: poll() -> bool Advance the background fetch; True when new geometry was cached (refresh the library). .. py:method:: produce(cell: str, values: dict, layout, target) -> None .. py:method:: request(cell: str, own: dict) -> None .. py:method:: stop() -> None .. py:attribute:: cache .. py:attribute:: declarations :type: list :value: [] .. py:attribute:: design :value: None .. py:attribute:: env :value: None .. py:attribute:: failed :type: dict[str, str] .. py:attribute:: fallback :type: set[str] .. py:attribute:: outdir .. py:attribute:: produced :value: 0 .. py:attribute:: qcc :value: 'qcc' .. py:attribute:: queue :type: dict[str, tuple[str, dict]] .. py:attribute:: running :type: tuple[str, subprocess.Popen, pathlib.Path] | None :value: None .. py:attribute:: schemas :type: dict .. py:function:: base_cell(ref: str) -> str The library name of a design.json ``cell`` (``Xmon`` or ``quantcore_circuits.layouts....Xmon``). .. py:function:: coerce(value, row: dict) ``value`` as KLayout's dialog hands it back (list items are strings) → the type of the schema ``row``. .. py:function:: context_key(design: dict, path=None) -> str Geometry depends on the chip (inherited ``a``/``b``, PDK): a new context empties the geometry cache. .. py:function:: declaration(cell: str, info: dict, provider: Provider) A PCell declaration for Quantcore ``cell`` (schema rows of ``qcc components --schemas``). .. py:function:: 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). .. py:function:: draw_marker(layout, cell, size: float = 100.0) -> None Nothing of this cell is cached yet: a small open square until its geometry arrives. .. py:function:: full_params(schema: list[dict], own: dict) -> dict Every PCell parameter: the defaults with ``own`` on top (what ``add_pcell_variant`` takes). .. py:function:: library_cell_name(inst, layout) -> str | None The PCell name of an instance (in ``layout``) of the Quantcore library (None for anything else). .. py:function:: 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. .. py:function:: 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. .. py:function:: make_library(schemas: dict, provider: Provider) The ``Quantcore`` library with one PCell per schema entry (not registered yet). .. py:function:: norm(value) A canonical JSON value: tuples as lists, integral floats as ints (10.0 and 10 are the same parameter). .. py:function:: own_params(schema: list[dict], values: dict) -> dict The design.json ``params`` for PCell ``values``: coerced, and only those that differ from the defaults. .. py:function:: params_key(cell: str, own: dict) -> str .. py:function:: 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. .. py:function:: startup() -> None Called by the autorun macro: register the library when Settings has live PCells on. .. py:function:: 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. .. py:data:: CFG_LIVE :value: 'qcc-kplugin-live-pcells' .. py:data:: LIB_NAME :value: 'Quantcore' .. py:data:: LIVE