Skip to Content

哈密顿量模拟

hamiltonian_simulation() 近似计算时间演化算符 。统一入口可在七类算法之间切换,并返回相同结构的结果对象。

最小示例

import numpy as np from unitarylab.library import hamiltonian_simulation H = np.array([[0, 1], [1, 0]], dtype=float) result = hamiltonian_simulation( H, t=0.5, method="trotter", target_error=1e-3, steps=20, order=1, backend="torch", device="cpu", ) print(result.circuit) print(result.total_error) print(result.evolution_result)

入口签名

hamiltonian_simulation( H, t, method="trotter", target_error=1e-6, backend="torch", device="cpu", dtype=np.complex128, **kwargs )

H 必须是有限数值组成的方阵且满足厄米性,t 必须有限,target_error 必须大于零。若维度不是 ,矩阵会补零到下一个二次幂,并发出提示;结果矩阵仍可按原始维度读取。

方法与专属参数

method用途专属参数与默认值
trotter确定性乘积公式order=1、steps=1000
qdrift随机 Pauli 项采样steps=5000
taylorTaylor/Chebyshev 近似degree=5
qsp / qsvt块编码后的信号变换degree=15、beta=0.7、block_encoding_method="nagy"
bessel-lcuBessel 展开与 LCU无专属参数
cartan-lax实对称矩阵的 Cartan Lax 流evol_time、lr、max_steps、reps
cartan-optimization实对称矩阵的 Cartan 数值优化evol_time、lr、max_steps、optimizer

只传递当前方法支持的关键字参数;未知方法或不受支持的参数会触发 ValueError。Cartan 方法要求输入为实对称矩阵。

结果对象

HamiltonianSimulationResult 提供以下惰性属性:

属性说明
.circuit构造并缓存模拟线路
.evolution_result线路对应的近似演化矩阵
.total_error精确 与近似矩阵之间的算符误差

第一次访问惰性属性时才会完成相应构造或矩阵计算。.total_error 是实际近似误差;target_error 是请求的目标精度,两者含义不同,不应假设所有方法都能以同一种方式严格保证目标值。

规模建议

  • 先使用 或 矩阵检查方法与参数。
  • steps、degree 和输入维度都会增加线路长度;状态向量和矩阵计算随量子比特数指数增长。
  • 固定随机实验时,为包含随机过程的方法在其支持的参数中设置种子。
  • 仅需线路时,不要提前访问 .evolution_result 或 .total_error。

相关页面

最后更新于