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

Schedules & Time-Dependent Evolution

A Schedule tells evolve which time points to integrate over and which named parameters the time-dependent coefficients depend on. It is the bridge between a symbolic Hamiltonian and a concrete numerical trajectory.

The schedule object

Give it the sequence of steps and the parameter names referenced by your coefficients. The integrator advances between consecutive steps and records results at each one.

import qalgora
from qalgora import operators, Schedule
import numpy as np

schedule = Schedule(
    steps=np.linspace(0.0, 10.0, 200),   # 200 sample times
    parameters=["t"],                    # names the coefficients can read
)

Time-dependent coefficients

Wrap any callable of the schedule parameters in operators.scalar. With the documented parameters=["t"] convention the callable receives the single time argument t, evaluated at every step, so a Hamiltonian term can be ramped, pulsed, or chirped.

def envelope(t):                          # a Gaussian control pulse, single argument t
    return np.exp(-((t - 5.0) ** 2) / 2.0)

H = operators.spin.z(0) + operators.scalar(envelope) * operators.spin.x(0)

Choosing what gets saved

store_intermediate_results trades memory for detail. Keep only the final state for long runs, or every expectation value when you need the full trajectory.

psi0 = np.array([1.0, 0.0], dtype=complex)
result = qalgora.evolve(
    H, dimensions={0: 2}, schedule=schedule,
    initial_state=qalgora.State.from_data(psi0),
    observables=[operators.spin.z(0)],
    store_intermediate_results=qalgora.IntermediateResultSave.EXPECTATION_VALUES,
)
# expectation_values() has shape [n_observables, n_steps]
trajectory = result.expectation_values()[0]   # one value per schedule step
SettingKeepsWhen
NONEfinal state onlylong evolutions, lowest memory
EXPECTATION_VALUESobservable trajectoriesplotting dynamics
ALLfull state at every stepdebugging, state tomography

Running asynchronously

Specification — not yet implemented
evolve_async is a specification interface. The public reference build runs evolve synchronously; the future-based API below documents the intended shape.

For long or batched runs, evolve_async returns immediately and hands back a future.

psi0 = np.array([1.0, 0.0], dtype=complex)
future = qalgora.evolve_async(H, dimensions={0: 2}, schedule=schedule,
                              initial_state=qalgora.State.from_data(psi0))
result = future.get()                      # block only when you need the answer
Same schedule, many terms
Every time-dependent coefficient in a Hamiltonian or super-operator reads from the one schedule, so drives stay synchronised across the whole model.

调度与时间依赖演化

Schedule 告诉 evolve 该在哪些时间点上积分,以及时间依赖系数会读取哪些命名参数。它在符号化的哈密顿量和具体的数值轨迹之间架起一座桥。

调度对象

把时间步序列和系数会引用的参数名交给它,积分器就会在相邻步之间推进,并在每一步记录结果。

import qalgora
from qalgora import operators, Schedule
import numpy as np

schedule = Schedule(
    steps=np.linspace(0.0, 10.0, 200),   # 200 个采样时刻
    parameters=["t"],                    # 系数可读取的参数名
)

时间依赖系数

把任意以调度参数为自变量的可调用对象包进 operators.scalar。按照文档中 parameters=["t"] 的约定,该可调用对象接收单个时间参数 t,并在每一步求值,从而让某个哈密顿量项随时间做斜坡、脉冲或啁啾调制。

def envelope(t):                          # 高斯控制脉冲 单一参数 t
    return np.exp(-((t - 5.0) ** 2) / 2.0)

H = operators.spin.z(0) + operators.scalar(envelope) * operators.spin.x(0)

选择保存什么

store_intermediate_results 是在内存占用和细节多少之间做权衡:长程演化只留最终态,需要完整轨迹时再保留每一步的期望值。

psi0 = np.array([1.0, 0.0], dtype=complex)
result = qalgora.evolve(
    H, dimensions={0: 2}, schedule=schedule,
    initial_state=qalgora.State.from_data(psi0),
    observables=[operators.spin.z(0)],
    store_intermediate_results=qalgora.IntermediateResultSave.EXPECTATION_VALUES,
)
# expectation_values() 形状为 [n_observables, n_steps]
trajectory = result.expectation_values()[0]   # 每个调度步一个值
设置保留适用
NONE仅最终态长程演化 内存最省
EXPECTATION_VALUES可观测量轨迹绘制动力学曲线
ALL每一步的完整态调试 态层析

异步运行

规范接口·暂未实现
evolve_async规范接口。公开参考实现以同步方式运行 evolve;下面基于 future 的 API 描述的是预期形态。

对于长程或批量运行,evolve_async 会立即返回一个 future。

psi0 = np.array([1.0, 0.0], dtype=complex)
future = qalgora.evolve_async(H, dimensions={0: 2}, schedule=schedule,
                              initial_state=qalgora.State.from_data(psi0))
result = future.get()                      # 只在需要结果时才阻塞
同一调度 驱动多项
哈密顿量或超算符里的每个时间依赖系数都从同一个调度读取,因此整个模型里的各路驱动始终保持同步。