Operators & Hamiltonians (Dynamics)
Time evolution is driven by operators. The dynamics module provides spin, boson, and fermion operators plus time-dependent coefficients.
Building a Hamiltonian
import qalgora
from qalgora import operators
import numpy as np
# static term
H0 = 2.0 * np.pi * 0.1 * operators.spin.z(0)
# time-dependent drive: coefficient is a callable of t
def drive(t):
return np.cos(2.0 * np.pi * t)
H = H0 + operators.spin.x(0) * operators.scalar(drive)
Conventions
operators.spin.x/y/zare the Pauli matrices σ, not S = σ/2.operators.scalar(callable)wraps a coefficient that theSchedule(parameters=["t"])binds at each step: the callable receives the single time argumentt. Multi-parameter binding behaviour is unspecified in the current reference implementation.
Built-in operator library
Each degree of freedom has its own algebra. Spin operators act on qubits; boson operators act on truncated harmonic modes (cavities, resonators); fermion operators carry the correct anticommutation.
| Family | Builders | Models |
|---|---|---|
operators.spin | x y z i, plus, minus | qubits, two-level atoms |
operators.boson | annihilate create number, position momentum, displace squeeze | cavities, oscillators, photonics |
operators.fermion | annihilate create number | electrons, molecular orbitals |
Boson operators & a cavity mode
a = operators.boson.annihilate(0) # lowering operator
adag = operators.boson.create(0)
n = operators.boson.number(0) # == adag * a
x = operators.boson.position(0) # (a + adag)/sqrt(2)
p = operators.boson.momentum(0) # i(adag - a)/sqrt(2)
H_kerr = adag * adag * a * a # Kerr nonlinearity
# displace/squeeze return parametrised operators: pass the parameter explicitly
alpha, zeta = 0.5 + 0.2j, 0.3
D = operators.boson.displace(0, alpha) # displacement, parameter alpha
S = operators.boson.squeeze(0, zeta) # squeezing, parameter zeta
Parametrised boson operators
operators.boson.displace(0) and squeeze(0) return parametrised
operators. Supply the parameter directly — displace(0, alpha) /
squeeze(0, zeta) — or leave it to be bound at schedule/instantiation time.
Fermion operators
c0 = operators.fermion.annihilate(0)
c1 = operators.fermion.annihilate(1)
# hopping term with correct anticommutation
H_hop = operators.fermion.create(0) * c1 + operators.fermion.create(1) * c0
Fermion ordering
Fermion operators use a fixed mode ordering; the required minus signs come from
the Jordan–Wigner anticommutation, so products like the hopping term above carry the correct
fermionic signs automatically.
Custom operators
Define an operator once from its matrix elements, then instantiate it on any degree of freedom. Coefficients may be callables of the schedule parameters, so a custom operator can be time-dependent too.
import numpy as np
# register a custom 3-level operator by its matrix
operators.define("clock", [3],
lambda dim: np.diag([1.0, np.exp(2j*np.pi/3), np.exp(4j*np.pi/3)]))
H_qutrit = operators.instantiate("clock", [0]) # apply it to degree of freedom 0
Mixed systems
Operators on different degrees of freedom (qubit + cavity, electron + phonon) compose with
* and +, so cavity-QED, spin-boson and Hubbard-type models are built
directly. Declare every mode's level count in dimensions when you call
evolve.
算符与哈密顿量
时间演化由算符驱动。动力学模块提供自旋、玻色和费米算符,以及含时系数。
构建哈密顿量
import qalgora
from qalgora import operators
import numpy as np
# 静态项
H0 = 2.0 * np.pi * 0.1 * operators.spin.z(0)
# 时间依赖驱动 系数是关于 t 的可调用对象
def drive(t):
return np.cos(2.0 * np.pi * t)
H = H0 + operators.spin.x(0) * operators.scalar(drive)
约定
operators.spin.x/y/z表示 Pauli 矩阵 σ,而非 S = σ/2。operators.scalar(callable)包裹一个系数,由Schedule(parameters=["t"])在每一步绑定:该可调用对象接收单个时间参数t。当前参考实现未规定多参数绑定行为。
内置算符库
每种自由度都有各自的代数:自旋算符作用于量子比特,玻色算符作用于截断的谐振模(腔、谐振器),费米算符则带有正确的反对易关系。
| 族 | 构造器 | 建模对象 |
|---|---|---|
operators.spin | x y z i plus minus | 量子比特、二能级原子 |
operators.boson | annihilate create number position momentum displace squeeze | 腔、振子、光子学 |
operators.fermion | annihilate create number | 电子、分子轨道 |
玻色算符与腔模
a = operators.boson.annihilate(0) # 下降算符
adag = operators.boson.create(0)
n = operators.boson.number(0) # == adag * a
x = operators.boson.position(0) # (a + adag)/sqrt(2)
p = operators.boson.momentum(0) # i(adag - a)/sqrt(2)
H_kerr = adag * adag * a * a # 克尔非线性
# displace/squeeze 返回参数化算符 显式传入参数
alpha, zeta = 0.5 + 0.2j, 0.3
D = operators.boson.displace(0, alpha) # 位移 参数 alpha
S = operators.boson.squeeze(0, zeta) # 压缩 参数 zeta
参数化玻色算符
operators.boson.displace(0) 与 squeeze(0) 返回参数化算符。可直接传入参数——displace(0, alpha) / squeeze(0, zeta)——或留待在调度/实例化时绑定。
费米算符
c0 = operators.fermion.annihilate(0)
c1 = operators.fermion.annihilate(1)
# 带正确反对易关系的跃迁项
H_hop = operators.fermion.create(0) * c1 + operators.fermion.create(1) * c0
费米子排序
费米算符采用固定的模式排序;所需的负号来自 Jordan–Wigner 反对易关系,因此上面这样的跃迁项乘积会自动带上正确的费米子符号。
自定义算符
用矩阵元把算符定义一次,就能实例化到任意自由度上。系数同样可以是调度参数的可调用对象,因此自定义算符也能含时变化。
import numpy as np
# 用矩阵注册一个自定义三能级算符
operators.define("clock", [3],
lambda dim: np.diag([1.0, np.exp(2j*np.pi/3), np.exp(4j*np.pi/3)]))
H_qutrit = operators.instantiate("clock", [0]) # 作用到自由度 0
混合系统
不同自由度上的算符(量子比特 + 腔、电子 + 声子)用 * 和 + 自由组合,因此腔 QED、自旋玻色、哈伯德型模型都能直接搭建。调用 evolve 时,在 dimensions 里声明每个模式的能级数即可。