Dynamics Simulation
Simulate the time evolution of open and closed quantum systems by integrating the Schrödinger or Lindblad master equation.
Defining a Hamiltonian
Build the generator from spin, boson, or fermion operators. A coefficient can be a constant or a callable of time for a time-dependent drive.
import qalgora
from qalgora import operators, Schedule
import numpy as np
omega = 2.0 * np.pi
H0 = 0.5 * omega * operators.spin.z(0) # static term
def drive(t): # time-dependent coefficient
return np.cos(omega * t)
H = H0 + operators.spin.x(0) * operators.scalar(drive)
Evolving the state
evolve integrates the Schrödinger (closed) or Lindblad master (open) equation over
a Schedule of time steps. dimensions declares each degree of freedom's
level count (2 for a qubit, more for a cavity).
The snippets below are illustrative; construct the initial state and parameters for your own model. A closed/pure system takes a state vector, an open/Lindblad system takes a density matrix.
psi0 = np.array([1.0, 0.0], dtype=complex) # |0>, a pure initial state
schedule = Schedule(steps=np.linspace(0, 1, 100), parameters=["t"])
result = qalgora.evolve(
H, dimensions={0: 2}, schedule=schedule,
initial_state=qalgora.State.from_data(psi0),
observables=[operators.spin.z(0), operators.spin.x(0)],
)
# expectation_values() returns an array of shape [n_observables, n_steps]
print(result.expectation_values()) # one row per observable
print(result.final_state)
Open systems
Add collapse operators to model dissipation — the evolution then follows the Lindblad master
equation instead of the Schrödinger equation. An open system evolves a density matrix,
so pass rho0 through State.from_data.
gamma = 0.1
psi0 = np.array([1.0, 0.0], dtype=complex)
rho0 = np.outer(psi0, psi0.conj()) # density matrix initial state
result = qalgora.evolve(H, dimensions={0: 2}, schedule=schedule,
initial_state=qalgora.State.from_data(rho0),
collapse_operators=[np.sqrt(gamma) * operators.spin.minus(0)])
Going further
- Operators & Hamiltonians — spin, boson, fermion, mixed.
- Numerical integrators — Runge–Kutta, stiff, differentiable.
- Batch simulation — many initial states / parameters at once.
dynamics target integrates the full many-body state on the GPU,
enabling time evolution of systems that are intractable on CPU.
动力学模拟
通过对薛定谔方程或林德布拉德主方程进行数值积分,模拟开放和封闭量子系统的时间演化。
定义哈密顿量
从自旋、玻色子或费米子算符构建生成元。系数可以是常数,也可以是关于时间的可调用对象,用于表示含时驱动。
import qalgora
from qalgora import operators, Schedule
import numpy as np
omega = 2.0 * np.pi
H0 = 0.5 * omega * operators.spin.z(0) # static term
def drive(t): # time-dependent coefficient
return np.cos(omega * t)
H = H0 + operators.spin.x(0) * operators.scalar(drive)
演化量子态
evolve 在 Schedule 指定的时间步上对薛定谔方程(封闭系统)或林德布拉德主方程(开放系统)进行积分。dimensions 声明每个自由度的能级数(量子比特为 2,腔模态可更大)。
以下为片段示例,初态/参数需按模型自行构造:封闭/纯态传态矢量,开放/林德布拉德系统传密度矩阵。
psi0 = np.array([1.0, 0.0], dtype=complex) # |0> 纯初态
schedule = Schedule(steps=np.linspace(0, 1, 100), parameters=["t"])
result = qalgora.evolve(
H, dimensions={0: 2}, schedule=schedule,
initial_state=qalgora.State.from_data(psi0),
observables=[operators.spin.z(0), operators.spin.x(0)],
)
# expectation_values() 返回形状为 [n_observables, n_steps] 的数组
print(result.expectation_values()) # 每个可观测量一行
print(result.final_state)
开放系统
添加坍缩算符以建模耗散——演化将转而遵循林德布拉德主方程而非薛定谔方程。开放系统演化的是密度矩阵,因此通过 State.from_data 传入 rho0。
gamma = 0.1
psi0 = np.array([1.0, 0.0], dtype=complex)
rho0 = np.outer(psi0, psi0.conj()) # 密度矩阵初态
result = qalgora.evolve(H, dimensions={0: 2}, schedule=schedule,
initial_state=qalgora.State.from_data(rho0),
collapse_operators=[np.sqrt(gamma) * operators.spin.minus(0)])
深入了解
dynamics 目标后端在 GPU 上对完整的多体态矢量进行积分,支持 CPU 上难以处理的系统的时间演化。