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
| Setting | Keeps | When |
|---|---|---|
NONE | final state only | long evolutions, lowest memory |
EXPECTATION_VALUES | observable trajectories | plotting dynamics |
ALL | full state at every step | debugging, state tomography |
Running asynchronously
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
调度与时间依赖演化
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() # 只在需要结果时才阻塞