# QuDA Studio — Plugin SDK User-uploaded blocks let you extend QuDA Studio with your own quantum algorithms (or any other Python code that consumes a circuit + params and produces a result) without forking the repo. Drop a `.zip` into the **Upload** button next to **Add blocks** in the toolbar and your block appears in the catalog immediately, visible only to your browser. ## What's in a plugin Plugins are `.zip` archives containing exactly two top-level files: ``` my_plugin.zip ├── manifest.json ← block metadata (label, family, params, color) └── handler.py ← Python module exposing `run(inputs, params)` ``` Both files must be at the top of the archive (no enclosing folder). ## manifest.json ```jsonc { "kind": "my_block", // unique id, lowercase identifier "label": "My Block", // display name on the tile "family": "algorithm", // source / backend / algorithm / metric / sink "tagline": "noise-aware widget folding", // short caption "description": "...", // optional long form, shown in tile tooltip "color": "#9333ea", // hex, used for the colored badge "author": "Yuchen Yuan", // optional, shown in card footer "params": [ { "key": "threshold", "label": "Threshold", "type": "number", // number / int / select "min": 0, "max": 1, "step": 0.01, "displayPrecision": 2, "hint": "Pruning threshold" }, { "key": "method", "label": "Method", "type": "select", "options": [ {"value": "fast", "label": "Fast"}, {"value": "thorough", "label": "Thorough"} ] } ], "writes": ["my_metric"] // optional docs of ctx keys you write } ``` Constraints (the upload endpoint will reject otherwise): - `kind` — 2–31 chars, `[a-z][a-z0-9_]+`, must not collide with built-ins (`qucad`, `qubound`, etc.) - `family` — one of `source` / `backend` / `algorithm` / `metric` / `sink` - `color` — `#rrggbb` hex - `params` — up to 20 entries; param `key` must be a valid Python identifier; param `type` is `number` / `int` / `select` - Total `.zip` ≤ 1 MB, ≤ 50 files, each file ≤ 512 KB, only `.py` / `.json` / `.txt` / `.md` allowed - Each browser is capped at 5 plugins (delete one to upload another) ## handler.py You must export a single function with this signature: ```python def run(inputs: dict, params: dict) -> dict: """Called by QuDA Studio when the user runs a pipeline that includes this plugin block. `inputs`: "circuit_qpy_bytes": bytes | absent QPY-serialized current circuit (only absent for source plugins). "backend_name": str | None Name of the upstream fake backend (FakeFez/Marrakesh/Torino). "scalars": dict Scalar values already in ctx (e.g. {"fidelity": 0.95}). `params`: The user-set parameter values for this block. Keys match the `key` field of each entry in manifest.params. Return a dict. None of its fields are required. Recognised keys: "summary": dict JSON-serializable values shown in the result card. "circuit_qpy_bytes": bytes Replaces the downstream circuit. Skip if your block doesn't transform the circuit (metrics, sinks). "backend_name": str Selects a fake backend for downstream blocks. Must be one of FakeFez / FakeMarrakesh / FakeTorino. "scalars": dict JSON-friendly scalar values added to ctx. If you write "fidelity" or "qubound_value" they're also reflected in the Output block's summary. "figures": list[dict] Typed rich-output blocks rendered below the summary table in the result card — see "Rich output (figures)" below. "error": str Surface a custom error message instead of finishing OK. """ ... ``` ## Rich output (figures) Beyond the flat `summary` dict, plugins can emit a list of typed figures that render inline in the result card. Each entry is a small JSON object with a `type` field. The backend validates every figure and silently drops any that fail (oversize, malformed, unsafe markup); authors can check the Space's runtime logs for `Plugin figure: …` messages to debug rejections. Five types are supported today: ```python "figures": [ # 1. Markdown narrative. Supports headings, bold/italic/code, # ordered + unordered lists, fenced code blocks. Raw HTML is # rejected (use markdown syntax for everything). { "type": "markdown", "title": "Analysis", # optional, ≤ 120 chars "content": "## Result\n\n**Bell state** has high fidelity.", }, # 2. Table. Headers (≤ 12 cols) + rows (≤ 100 rows). Each cell # must be a primitive (str / int / float / bool / None). { "type": "table", "title": "Per-qubit", # optional "headers": ["qubit", "fidelity"], "rows": [[0, 0.99], [1, 0.97]], }, # 3. Bar chart. Renders as an inline SVG with no JS dependency. # Up to 50 bars; negative values clip to 0. { "type": "bar", "title": "Gates by type", "x_label": "Gate", # optional axis label "y_label": "Count", "data": [ {"label": "h", "value": 5}, {"label": "cx", "value": 3}, ], }, # 4. Raw SVG. ≤ 256 KB; rejected if it contains