Constructing Operators
Spin operators are weighted sums of Pauli strings. They define the Hamiltonians and observables you measure.
Building spin operators
Start from the Pauli primitives spin.x(i), spin.y(i),
spin.z(i), and the identity spin.i(i); combine them with +,
-, * and scalar coefficients (real or complex). This runs on the reference
build today.
from qalgora import spin
op = spin.z(0) + 0.5 * spin.x(1) - spin.y(0) * spin.y(1)
print(op) # human-readable Pauli sum
op.get_term_count(), op.get_qubit_count()) and
iterating individual Pauli terms (for term in op, term.to_string()) are
documented specification interfaces; the open reference build does not implement them yet. The
lines below are illustrative.
# Spec interface — not yet in the reference build:
# print("terms:", op.get_term_count())
# print("qubits:", op.get_qubit_count())
# for term in op: # iterate the individual Pauli terms
# print(term.get_coefficient(), str(term))
Pauli words & exponentiation
A pauli_word like "XYZ" names a Pauli string. exp_pauli
applies exp(-iθP) directly — the elementary step of Trotterized time evolution.
exp_pauli and the pauli_word type are documented specification
interfaces; the open reference build does not bundle them yet. The kernel below shows the intended
usage.
import qalgora
@qalgora.kernel
def trotter_step(q: qalgora.qview, words: list[qalgora.pauli_word],
coeffs: list[float], dt: float):
for i in range(len(words)):
exp_pauli(coeffs[i] * dt, q, words[i]) # exp(-i c dt P) (spec interface)Decomposing a Hamiltonian
Extract coefficients and Pauli words from any spin operator to drive a Trotter loop or hand to hardware:
term.to_string(),
term.get_coefficient()) is a documented specification interface; the open reference
build does not implement it yet.
# Spec interface — not yet in the reference build:
# words = [str(term) for term in hamiltonian] # e.g. "XYZ"
# coeffs = [term.get_coefficient() for term in hamiltonian]
Common Hamiltonians
- Ising:
-J Σ Z_i Z_{i+1} - h Σ X_i - Heisenberg:
Σ (X_iX_j + Y_iY_j + Z_iZ_j) - Molecular: a Jordan–Wigner-mapped fermionic Hamiltonian (see OpenFermion interop)
构造算符
自旋算符是 Pauli 串的加权求和,用来描述要测量的哈密顿量和可观测量。
构建自旋算符
从 Pauli 原语 spin.x(i)、spin.y(i)、
spin.z(i) 和单位算符 spin.i(i) 出发,用 +、
-、* 配上实数或复数系数组合起来即可。这部分现在即可在参考实现上运行。
from qalgora import spin
op = spin.z(0) + 0.5 * spin.x(1) - spin.y(0) * spin.y(1)
print(op) # 人类可读的 Pauli 求和
op.get_term_count()、op.get_qubit_count())以及遍历各个 Pauli 项(for term in op、term.to_string())属于规范中的接口,开放参考实现目前尚未实现。下面几行仅用于说明。
# 规范接口——参考实现暂未内置:
# print("terms:", op.get_term_count())
# print("qubits:", op.get_qubit_count())
# for term in op: # 遍历各个 Pauli 项
# print(term.get_coefficient(), str(term))
Pauli 词与指数化
pauli_word(如 "XYZ")用来表示一个 Pauli 串。exp_pauli
直接施加 exp(-iθP)——它是 Trotter 时间演化的基本步骤。
exp_pauli 与 pauli_word 类型属于规范中的接口,开放参考实现目前尚未内置;下面的内核仅用于说明预期用法。
import qalgora
@qalgora.kernel
def trotter_step(q: qalgora.qview, words: list[qalgora.pauli_word],
coeffs: list[float], dt: float):
for i in range(len(words)):
exp_pauli(coeffs[i] * dt, q, words[i]) # exp(-i c dt P)(规范接口)分解哈密顿量
从任意自旋算符里取出系数和 Pauli 词,用来驱动 Trotter 循环或喂给硬件:
term.to_string()、term.get_coefficient())属于规范中的接口,开放参考实现目前尚未实现。
# 规范接口——参考实现暂未内置:
# words = [str(term) for term in hamiltonian] # 例如 "XYZ"
# coeffs = [term.get_coefficient() for term in hamiltonian]
常见哈密顿量
- Ising:
-J Σ Z_i Z_{i+1} - h Σ X_i - Heisenberg:
Σ (X_iX_j + Y_iY_j + Z_iZ_j) - 分子哈密顿量: 经 Jordan–Wigner 映射的费米子哈密顿量(参见 OpenFermion 互操作)