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

Dynamics Simulation

Simulate the time evolution of open and closed quantum systems by integrating the Schrödinger or Lindblad master equation.

Reference implementation scope
The current public reference implementation runs dynamics on small systems with NumPy/SciPy on the CPU. GPU integration, TorchDiffEq differentiable integrators, GPU batching, and multi-node backends are specification interfaces / planned, not yet shipping.

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

GPU-accelerated
In the specification, the dynamics target integrates the full many-body state on the GPU, enabling time evolution of systems that are intractable on CPU.
Specification — not in the open reference build
GPU integration is part of the specification. The open reference build integrates the many-body state on the CPU with NumPy/SciPy, so it is limited to small systems — the GPU path documents the intended interface, not shipping software.

动力学模拟

通过对薛定谔方程或林德布拉德主方程进行数值积分,模拟开放和封闭量子系统的时间演化。

参考实现范围
当前公开参考实现用 CPU 上的 NumPy/SciPy 对小规模系统做动力学;GPU 积分、TorchDiffEq 可微积分器、GPU 批处理、多节点后端属规范接口/规划中。

定义哈密顿量

从自旋、玻色子或费米子算符构建生成元。系数可以是常数,也可以是关于时间的可调用对象,用于表示含时驱动。

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)

演化量子态

evolveSchedule 指定的时间步上对薛定谔方程(封闭系统)或林德布拉德主方程(开放系统)进行积分。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)])

深入了解

GPU 加速
在规范中,dynamics 目标后端在 GPU 上对完整的多体态矢量进行积分,支持 CPU 上难以处理的系统的时间演化。
规范——开源参考实现暂未包含
GPU 积分属于规范。开源参考实现是在 CPU 上用 NumPy/SciPy 对多体态进行积分,因此仅限于小规模系统——GPU 路径描述的是预期接口,而非已发布的软件。