qalgora-Q Docs Hub量子文档 ✦ Ask AI✦ 问问文档

Visualizing Kernels

◐ Design-level API
This page documents qalgora-Q API design, architecture, or adaptation workflows. Code examples illustrate intended usage and are not guaranteed to run in the current reference implementation.

Today you debug kernels by reading their measured samples and statevectors — both run on the open CPU reference build. Circuit drawing, LaTeX export, result plotting and resource estimation are planned specification interfaces, shown here for the intended API and not yet runnable.

Inspecting the state

get_state runs today on the reference build.

import qalgora
qalgora.set_target("qpp-cpu")

@qalgora.kernel
def ghz(n: int):
    q = qalgora.qvector(n)
    h(q[0])
    for i in range(1, n):
        x.ctrl(q[0], q[i])

state = qalgora.get_state(ghz, 3)
print(state)                      # inspect the statevector

Sampling results

sample returns measured bitstring frequencies — your main current debugging signal.

counts = qalgora.sample(ghz, 3, shots_count=2000)
print(counts)                     # measured bitstring frequencies

Drawing a circuit

# Planned specification API — not in the open reference build yet:
# print(qalgora.draw(ghz, 3))      # ASCII circuit diagram
Specification API — not in the open reference build yet
This example shows a qalgora-Q specification API (or a third-party library) that the open reference build does not bundle today. It documents the intended interface; to run code now, use the reference build’s supported core API.

LaTeX & publication output

Render the same circuit as a Quantikz diagram to drop straight into a paper:

# Planned specification API — not in the open reference build yet:
# print(qalgora.draw(ghz, 3, format="latex"))   # Quantikz / TikZ source
Specification API — not in the open reference build yet
This example shows a qalgora-Q specification API (or a third-party library) that the open reference build does not bundle today. It documents the intended interface; to run code now, use the reference build’s supported core API.

Plotting results

Sample results and statevectors are intended to carry helpers for the common plots — histograms of counts and bar charts of amplitudes/probabilities.

# Planned specification API — not in the open reference build yet:
# qalgora.plot_histogram(counts)        # bitstring frequency bar chart
# qalgora.plot_state(state)             # amplitude / probability plot
Specification API — not in the open reference build yet
This example shows a qalgora-Q specification API (or a third-party library) that the open reference build does not bundle today. It documents the intended interface; to run code now, use the reference build’s supported core API.

Counting resources

Estimate a circuit's cost without running it — useful for hardware planning.

# Planned specification API — not in the open reference build yet:
# res = qalgora.estimate_resources(ghz, 5)
# print(res.gate_count, res.depth, res.num_qubits)
Specification API — not in the open reference build yet
This example shows a qalgora-Q specification API (or a third-party library) that the open reference build does not bundle today. It documents the intended interface; to run code now, use the reference build’s supported core API.
Why visualize
Today, measured samples and statevectors make an algorithm's behavior legible, alongside the browser playground. Circuit diagrams, plots and resource estimates are planned tools that will catch wiring bugs and aid hardware planning.

内核可视化

◐ 设计接口
本页描述的是 qalgora-Q 的接口设计、架构设计或适配工作流。相关代码用于说明预期用法,当前参考实现不保证可以直接运行。

如今你主要通过查看内核的测量采样与态矢量来调试——二者都可在开放的 CPU 参考实现上运行。电路绘制、LaTeX 导出、结果绘图与资源估算属于规划中的规范接口,此处仅展示预期 API,暂不可运行。

检视量子态

get_state 在参考实现上现已可用。

import qalgora
qalgora.set_target("qpp-cpu")

@qalgora.kernel
def ghz(n: int):
    q = qalgora.qvector(n)
    h(q[0])
    for i in range(1, n):
        x.ctrl(q[0], q[i])

state = qalgora.get_state(ghz, 3)
print(state)                      # 查看态矢量

采样结果

sample 返回测得的比特串频率——这是当前主要的调试信号。

counts = qalgora.sample(ghz, 3, shots_count=2000)
print(counts)                     # 测得的比特串频率

绘制电路图

# 规范接口,开放参考实现暂未包含:
# print(qalgora.draw(ghz, 3))      # ASCII 电路图
规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。

LaTeX 与出版级输出

将同一电路渲染为 Quantikz 图,可直接嵌入论文:

# 规范接口,开放参考实现暂未包含:
# print(qalgora.draw(ghz, 3, format="latex"))   # Quantikz / TikZ 源码
规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。

绘制结果图表

采样结果与态矢量按规范将内置常用绘图辅助函数——包括计数直方图和振幅/概率条形图。

# 规范接口,开放参考实现暂未包含:
# qalgora.plot_histogram(counts)        # 比特串频率条形图
# qalgora.plot_state(state)             # 振幅 / 概率图
规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。

估算资源消耗

无需实际运行即可估算电路开销——适用于硬件规划。

# 规范接口,开放参考实现暂未包含:
# res = qalgora.estimate_resources(ghz, 5)
# print(res.gate_count, res.depth, res.num_qubits)
规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。
为何要可视化
如今测量采样与态矢量让算法行为一目了然,并可结合 浏览器 playground 使用。电路图、绘图与资源估算属于规划中的工具,将用于发现连线错误并辅助硬件规划。