跳转至

公式速查

这份速查表把数学记号、代码变量和张量 shape 放在一起,方便调试时对照。

State 与 Token

代码中的 basis state 是 occupation bitstring:

state: Tensor[batch, n_qubits]

默认 qubit 顺序为:

\[ [\alpha_0,\beta_0,\alpha_1,\beta_1,\ldots]. \]

每两个 qubit 合成一个 pair token:

token: Tensor[batch, n_qubits / 2]

编码约定为:

pair token
\(00\) 0
\(10\) 1
\(01\) 2
\(11\) 3

等价地,

\[ \mathrm{token}_i = \alpha_i + 2\beta_i . \]

波函数输出

模型输出:

outputs["log_amp"]: Tensor[batch]
outputs["phase"]:   Tensor[batch]
outputs["psi"]:     complex Tensor[batch]

数学关系:

\[ \log A_\theta(x) = {1 \over 2}\sum_i \log P_\theta(t_i\mid t_{<i}), \]
\[ \psi_\theta(x) = \exp(\log A_\theta(x))\exp(i\phi_\theta(x)). \]

因此采样概率满足:

\[ |\psi_\theta(x)|^2 = \exp(2\log A_\theta(x)). \]

采样权重

采样器返回去重后的 states 与 counts:

unique_states: Tensor[n_unique, n_qubits]
counts:        Tensor[n_unique]

对应权重为:

\[ w(x) = {\mathrm{count}(x) \over \sum_{x'} \mathrm{count}(x')}. \]

训练代码中常见变量:

counts_cpu -> count(x)
weights_np -> w(x)

Local Energy

局域能定义为:

\[ E_{\rm loc}(x) = \sum_{x'} H_{xx'}{\psi_\theta(x') \over \psi_\theta(x)} . \]

代码变量:

local_energies: ndarray[n_unique]

如果 Hamiltonian 写成 Pauli string 之和,

\[ H = \sum_k c_k P_k , \]

那么每个 \(P_k\) 会把 \(x\) 连接到一个 \(x'\),同时给出一个矩阵元因子。

Energy Mean

一轮采样下的能量估计:

\[ E_{\rm mean} = \sum_x w(x) E_{\rm loc}(x). \]

代码变量:

energy_mean: complex

日志中通常记录:

energy_real = energy_mean.real
energy_imag = energy_mean.imag

VMC 梯度代理

令:

\[ \log \psi_\theta(x) = \log A_\theta(x) + i\phi_\theta(x), \qquad \Delta E(x) = E_{\rm loc}(x) - E_{\rm mean}. \]

教学版构造:

\[ L_{\rm proxy} = 2\,\mathrm{Re}\left[ \sum_x w(x)\, \overline{\log \psi_\theta(x)}\, \Delta E(x) \right]. \]

这个量用于产生梯度,数值本身不当作物理能量解释。

若:

\[ \Delta E(x) = a(x) + ib(x), \]

则:

\[ \mathrm{Re}\left[ \overline{\log \psi_\theta(x)}\Delta E(x) \right] = \log A_\theta(x)a(x) + \phi_\theta(x)b(x). \]

所以代码中可以写成实数张量:

loss_proxy = 2.0 * torch.sum(
    weights * (log_amp * corr_real + phase * corr_imag)
)