Visualizing Kernels
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 diagramLaTeX & 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 sourcePlotting 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 plotCounting 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)内核可视化
如今你主要通过查看内核的测量采样与态矢量来调试——二者都可在开放的 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 电路图LaTeX 与出版级输出
将同一电路渲染为 Quantikz 图,可直接嵌入论文:
# 规范接口,开放参考实现暂未包含:
# print(qalgora.draw(ghz, 3, format="latex")) # Quantikz / TikZ 源码绘制结果图表
采样结果与态矢量按规范将内置常用绘图辅助函数——包括计数直方图和振幅/概率条形图。
# 规范接口,开放参考实现暂未包含:
# qalgora.plot_histogram(counts) # 比特串频率条形图
# qalgora.plot_state(state) # 振幅 / 概率图估算资源消耗
无需实际运行即可估算电路开销——适用于硬件规划。
# 规范接口,开放参考实现暂未包含:
# res = qalgora.estimate_resources(ghz, 5)
# print(res.gate_count, res.depth, res.num_qubits)