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

Primitives: Sampler & Estimator

◐ 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.

Two execution primitives cover almost every workload: a Sampler returns measurement distributions, an Estimator returns expectation values. In qalgora-Q they are sample and observe.

The two primitives

Primitiveqalgora-Q callReturns
Samplerqalgora.sample(kernel)Bitstring distribution (counts)
Estimatorqalgora.observe(kernel, op)Expectation value ⟨op⟩

Inputs & outputs

A primitive call takes a kernel, optional parameters, and (for the Estimator) one or more observables. You can batch many parameter sets in a single call.

import qalgora
from qalgora import spin
import numpy as np

# Estimator: one observable, swept over many angles
angles = np.linspace(0, 2*np.pi, 50)
# `angles` is a batched binding for the kernel parameter "theta"
results = qalgora.observe(ansatz, observables=[spin.z(0)],
                          parameter_values={"theta": angles})   # 50 expectation values

# Sampler: measurement counts
counts = qalgora.sample(bell, shots_count=4000)

Options

OptionEffect
shots_countNumber of samples per circuit
resilience_levelHow much error mitigation to apply (0–3)
targetWhich backend executes the primitive
From Qiskit
qalgora-Q's sample/observe correspond conceptually to Qiskit's Sampler/Estimator; for migration specifics see Qiskit Interop.
spin: two distinct things
qalgora.spin is the Pauli observable alias (used to build measurement observables, e.g. spin.z(0)), whereas qalgora.operators.spin is the dynamics operator builder used for time evolution.

原语:Sampler 与 Estimator

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

两种执行原语几乎能覆盖所有工作负载:Sampler 返回 测量分布,Estimator 返回期望值。在 qalgora-Q 里 它们分别对应 sampleobserve 两个调用。

两种原语

原语qalgora-Q 调用返回值
Samplerqalgora.sample(kernel)比特串分布(计数)
Estimatorqalgora.observe(kernel, op)期望值 ⟨op⟩

输入与输出

原语调用接受一个 kernel、可选的参数,以及(对 Estimator 而言)一个或多个 可观测量。多组参数可以在一次调用里批量传入。

import qalgora
from qalgora import spin
import numpy as np

# Estimator: one observable, swept over many angles
angles = np.linspace(0, 2*np.pi, 50)
# `angles` is a batched binding for the kernel parameter "theta"
results = qalgora.observe(ansatz, observables=[spin.z(0)],
                          parameter_values={"theta": angles})   # 50 expectation values

# Sampler: measurement counts
counts = qalgora.sample(bell, shots_count=4000)

选项

选项说明
shots_count每个线路的采样次数
resilience_level误差缓解的强度档位(0–3)
target执行该原语的目标后端
来自 Qiskit
qalgora-Q 的 sample/observe 与 Qiskit 的 Sampler/Estimator 在概念上对应;具体迁移见 Qiskit 互操作页。
spin 的两种含义
qalgora.spin 是 Pauli 可观测量别名(用于构造测量可观测量,如 spin.z(0)),而 qalgora.operators.spin 是用于时间演化的动力学算子构造器。