WebUI 与持久化

UnifiedQuantum 自带一个 FastAPI 网关 + 前端 SPA,可以用浏览器查看 backend 列表、 芯片可视化、本地任务历史、提交并跟踪任务。

启动方式

# 前端构建在 frontend/dist 下,CLI 会自动 mount 它
uniqc gateway --host 127.0.0.1 --port 8000
# 然后在浏览器打开 http://127.0.0.1:8000/

开发前端:

cd frontend
npm install
npm run dev   # vite dev server,会代理到 uniqc gateway 后端

后端的 ASGI app 由 uniqc.gateway.server.create_app() 构造;可以直接用 uvicorn / gunicorn / 第三方 reverse-proxy 部署。

编程访问

01 — Gateway / WebUI: programmatic launch and persistence

Source: examples/5_webui/01_gateway_demo.py
Status: pass

uniqc gateway 启动一个 FastAPI 服务(uniqc.gateway.server:app),既给前端 SPA 当后端,又对外提供 REST + WebSocket。本例不真的把进程留住,只演示如何在 Python 里 拿到 ASGI app、读出网关配置(host/port)以及触发一次任务,让后台任务库里有数据 可看。

实际开发中请用 uniqc gateway --host 127.0.0.1 --port 8000 启动;前端在 frontend/ 下,cd frontend && npm install && npm run dev

Source code

"""01 — Gateway / WebUI: programmatic launch and persistence

[doc-require: ]
[doc-output-include: stdout, source]

``uniqc gateway`` 启动一个 FastAPI 服务(``uniqc.gateway.server:app``),既给前端 SPA
当后端,又对外提供 REST + WebSocket。本例不真的把进程留住,只演示如何在 Python 里
拿到 ASGI app、读出网关配置(host/port)以及触发一次任务,让后台任务库里有数据
可看。

实际开发中请用 ``uniqc gateway --host 127.0.0.1 --port 8000`` 启动;前端在
``frontend/`` 下,``cd frontend && npm install && npm run dev``。
"""

from __future__ import annotations

from uniqc import Circuit, submit_task
from uniqc.gateway.config import load_gateway_config
from uniqc.gateway.server import create_app


def main() -> None:
    app = create_app()
    print("== Gateway ASGI app ==")
    print(type(app).__name__, "with", len(list(app.router.routes)), "routes")

    print()
    print("== Configured host/port ==")
    cfg = load_gateway_config()
    print("host:", cfg["host"])
    print("port:", cfg["port"])

    print()
    print("== Triggering one dummy task so the UI has something to show ==")
    c = Circuit()
    c.h(0)
    c.measure(0)
    task_id = submit_task(c, backend="dummy:local:simulator", shots=64)
    print("task_id:", task_id)

    print()
    print("Launch the UI with:")
    print(f"    uniqc gateway --host {cfg['host']} --port {cfg['port']}")
    print(f"    # then open http://{cfg['host']}:{cfg['port']}/")


if __name__ == "__main__":
    main()

Stdout

== Gateway ASGI app ==
FastAPI with 26 routes

== Configured host/port ==
host: 127.0.0.1
port: 18765

== Triggering one dummy task so the UI has something to show ==
task_id: uqt_cb17f887e0b34d0691425ff41333d6d4

Launch the UI with:
    uniqc gateway --host 127.0.0.1 --port 18765
    # then open http://127.0.0.1:18765/

持久化层

路径

内容

~/.uniqc/config.yaml

平台 token、proxy、profile、gateway host/port

~/.uniqc/tasks.db

本地任务历史(SQLite,由 TaskStore 管理)

~/.uniqc/backend-cache/

后端发现 / chip characterization 缓存

~/.uniqc/calibration_cache/

XEB / readout 校准结果(带 ISO-8601 时间戳)

~/.uniqc/logs/

gateway / cli 运行日志(如果启用)

任务库是 TaskStore 抽象(uniqc.backend_adapter.task.store)的默认 SQLite 实现, schema 由 uniqc.backend_adapter.database_migration 管理,可以平滑升级到新版本。 迁移在每次 submit_task / query_task 第一次调用时自动触发。