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

Batch Simulation (Dynamics)

◐ 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.

Evolve many initial states or parameter sets at once, sharing the integrator and (on a planned GPU target) the same kernels for near-linear speedups.

Placeholder symbols
The snippets below are illustrative fragments. Supply your own hamiltonian / make_hamiltonian, initial states (psi0, psi_a, …) and schedule — see Schedules for building a schedule.

Batching initial states

import qalgora
import numpy as np

states = [psi_a, psi_b, psi_c]          # a batch of initial states
results = qalgora.evolve(
    hamiltonian, dimensions={0: 2},
    schedule=qalgora.Schedule(steps=np.linspace(0, 1, 100), parameters=["t"]),
    initial_state=states,               # list -> batched evolution
)
for r in results:
    print(r.expectation_values()[0][-1])   # first observable, final time

Sweeping a control parameter

amplitudes = np.linspace(0.0, 2.0, 16)  # 16 drive strengths
batched = qalgora.evolve(make_hamiltonian(amplitudes), dimensions={0: 2},
                         schedule=schedule, initial_state=psi0)

Batching the Hamiltonian itself

Beyond batching states, you can batch a list of different Hamiltonians — for example a parameter scan where each member has distinct couplings. The solver evolves the whole stack in one launch instead of looping in Python.

amplitudes = np.linspace(0.5, 2.0, 64)              # 64 coupling values
hams = [make_hamiltonian(A) for A in amplitudes]    # one Hamiltonian per value
results = qalgora.evolve(hams, dimensions={0: 2, 1: 2},
                         schedule=schedule, initial_state=psi0)   # 64 trajectories, one launch
Sparse format selection
Many-body generators are mostly zeros. The solver automatically switches to a multidiagonal sparse representation when the operator is banded, so batched evolution scales to large Hilbert spaces — tune the switch-over thresholds with the QALGORA_DYNAMICS_MIN_MULTIDIAGONAL_DIMENSION and QALGORA_DYNAMICS_MAX_DIAGONAL_COUNT environment variables.
GPU batching (planned)
GPU execution of dynamics is a planned / specification interface. On the planned GPU target the whole batch would run as one set of tensor operations, so a 64-member batch costs far less than 64 separate runs — large batches on a high-memory GPU approach an order-of-magnitude speedup over sequential evolution.

批量仿真(动力学)

◐ 设计接口
本页描述的是 qalgora-Q 的接口设计、架构设计或适配工作流。相关代码用于说明预期用法,当前参考实现不保证可以直接运行。

同时演化多个初态或参数组合,共享积分器(GPU 目标为规划中接口),实现近线性加速。

占位符号
下文代码均为示例片段。其中 hamiltonian/make_hamiltonian、初态(psi0psi_a 等)与 schedule 需自行构造(构造 schedule 见时序表页)。

批量初态演化

import qalgora
import numpy as np

states = [psi_a, psi_b, psi_c]          # a batch of initial states
results = qalgora.evolve(
    hamiltonian, dimensions={0: 2},
    schedule=qalgora.Schedule(steps=np.linspace(0, 1, 100), parameters=["t"]),
    initial_state=states,               # list -> batched evolution
)
for r in results:
    print(r.expectation_values()[0][-1])   # 第一个观测量 终态时刻

控制参数扫描

amplitudes = np.linspace(0.0, 2.0, 16)  # 16 drive strengths
batched = qalgora.evolve(make_hamiltonian(amplitudes), dimensions={0: 2},
                         schedule=schedule, initial_state=psi0)

批处理哈密顿量本身

除了批处理初态,你还能批处理一组不同的哈密顿量——比如让每个成员对应一次不同的耦合扫描。求解器一次启动就把整组算符全部演化完,不必在 Python 里挨个循环。

amplitudes = np.linspace(0.5, 2.0, 64)              # 64 个耦合值
hams = [make_hamiltonian(A) for A in amplitudes]    # 每个值一个哈密顿量
results = qalgora.evolve(hams, dimensions={0: 2, 1: 2},
                         schedule=schedule, initial_state=psi0)   # 64 条轨迹 一次启动
稀疏格式选择
多体生成元大多是零。一旦算符呈带状结构,求解器就自动切换到多对角稀疏表示,让批处理演化能扩展到很大的希尔伯特空间。切换阈值可用环境变量 QALGORA_DYNAMICS_MIN_MULTIDIAGONAL_DIMENSIONQALGORA_DYNAMICS_MAX_DIAGONAL_COUNT 调节。
GPU 批处理(规划中)
动力学的 GPU 执行为规范接口 / 规划中能力。在规划中的 GPU 目标上,整批任务将作为一组张量运算一起跑,所以一个 64 成员的批次远比跑 64 次独立任务划算;在大显存 GPU 上,大批次有望比串行演化快近一个数量级。