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
| Primitive | qalgora-Q call | Returns |
|---|---|---|
| Sampler | qalgora.sample(kernel) | Bitstring distribution (counts) |
| Estimator | qalgora.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
| Option | Effect |
|---|---|
shots_count | Number of samples per circuit |
resilience_level | How much error mitigation to apply (0–3) |
target | Which 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 里
它们分别对应 sample 和 observe 两个调用。
两种原语
| 原语 | qalgora-Q 调用 | 返回值 |
|---|---|---|
| Sampler | qalgora.sample(kernel) | 比特串分布(计数) |
| Estimator | qalgora.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 | 执行该原语的目标后端 |
spin 的两种含义
qalgora.spin 是 Pauli 可观测量别名(用于构造测量可观测量,如 spin.z(0)),而 qalgora.operators.spin 是用于时间演化的动力学算子构造器。