Examples
Short, focused snippets that demonstrate one concept at a time.
Two kinds of examples
This chapter mixes examples that run directly on the open reference implementation with ones that
document specification / planned workflows. Each page flags its current runnable status inline.
Quantum Operations →
Standard gates and how to apply them.
Measuring & Sampling →
Collect bitstring statistics from circuits.
Applications →
Full variational algorithms.
Build & sample in one shot
import qalgora
@qalgora.kernel
def circuit():
q = qalgora.qvector(2)
h(q[0])
x.ctrl(q[0], q[1])
mz(q)
counts = qalgora.sample(circuit, shots_count=1000)
print(counts)
for bits, n in counts.items():
print(bits, n)
示例
简短的代码片段,每段只讲透一个核心概念。
两类示例
本章含两类示例:可在开放参考实现直接运行的,与说明规范接口/规划工作流的;每页就近标注当前可运行状态。
一步完成构建与采样
import qalgora
@qalgora.kernel
def circuit():
q = qalgora.qvector(2)
h(q[0])
x.ctrl(q[0], q[1])
mz(q)
counts = qalgora.sample(circuit, shots_count=1000)
print(counts)
for bits, n in counts.items():
print(bits, n)