quantcore_circuits.design.pyscript ================================== .. py:module:: quantcore_circuits.design.pyscript .. autoapi-nested-parse:: design.json → a readable Python script that rebuilds the same design with the :class:`Designer` API. ``qcc design to-python DESIGN -o design.py`` (the KLayout plugin's *Design ▸ Save as Python script*) writes the script; running it writes the design.json again (``python design.py`` or ``%run design.py``) and leaves the live :class:`~quantcore_circuits.designer.Designer` as ``d`` so the chip can be continued as code. The script is checked before it is returned: it is executed here and the design it builds must have the same ``design_hash`` as the source. What the Designer calls cannot say (a static cell's ports, explicit ``nets``, another chip cell, a coupling's ``fem`` flag, a waypoint's corner radius, …) is written for that one entry as a plain ``d.data[...] = {...}`` assignment with a comment, so the round trip never silently drops anything. Exceptions ---------- .. autoapisummary:: quantcore_circuits.design.pyscript.RoundTripError Functions --------- .. autoapisummary:: quantcore_circuits.design.pyscript.design_to_python quantcore_circuits.design.pyscript.lit quantcore_circuits.design.pyscript.write_python Module Contents --------------- .. py:exception:: RoundTripError Bases: :py:obj:`RuntimeError` The generated script did not rebuild the same design. .. py:function:: design_to_python(source, check: bool = True) -> str The script text for ``source`` (a design file, dict or :class:`Design`). With ``check`` (default) the script is executed and must rebuild a design with the same ``design_hash`` (else :class:`RoundTripError`); an entry the Designer rejects or rebuilds differently is written as plain data. .. py:function:: lit(value, indent: int = 0, width: int = _WIDTH) -> str A Python literal for JSON-like ``value``: one line when it fits, else one entry per line. .. py:function:: write_python(source, out: str | pathlib.Path, check: bool = True) -> pathlib.Path