Skip to content

Add lih vqe example#158

Open
Hugh-888 wants to merge 1 commit into
TuringQ:mainfrom
Hugh-888:dev_example/vqe_lih
Open

Add lih vqe example#158
Hugh-888 wants to merge 1 commit into
TuringQ:mainfrom
Hugh-888:dev_example/vqe_lih

Conversation

@Hugh-888
Copy link
Copy Markdown
Collaborator

No description provided.

@Hugh-888 Hugh-888 requested review from Jooyuza and sansiro77 April 22, 2026 07:12
@Hugh-888 Hugh-888 added the documentation Improvements or additions to documentation label Apr 22, 2026
Copy link
Copy Markdown
Contributor

@sansiro77 sansiro77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

内容 review:主要是理论表述与代码行为一致性问题。

# 接着把它切分成两个 3 比特算符 $O_a$ 与 $O_b$,使得 $O_k=O_a\otimes O_b$。
# 然后分别用 $U\psi_3^n$ 与 $V\psi_3^n$ 计算对应子系统上的算符期望值。
#
# $$<O> = <O_a><O_b> = \sum_{nm} \lambda_n \lambda_m <\psi_3^n|U^+O_a U|\psi_3^n><\psi_3^n|V^+O_b V|\psi_3^n> = \vec{\lambda}^T M \vec{\lambda}$$
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的整体期望值不应写成 <O_a><O_b> 的简单乘积;forged 态下应直接写成 <O_a \otimes O_b> 的双重求和形式。并且当前求和是 n,m,但矩阵元仍写成同一个 n,和后面的 M_{ij} 定义也不一致。建议把这一式改成与矩阵定义一致的表达。

# 3. 把所有算符的期望值按分解系数求和,可得到
# $M_{sum}=\sum_k w_k M_k$。
# 于是哈密顿量的期望值可以写成二次型:$\langle H\rangle = \vec{\lambda}^T M_{sum} \vec{\lambda}$。
# 在约束 $||\vec{\lambda}||=1$ 下,这个二次型的最小值等于矩阵 $M_{sum}$ 的最小特征值;对应的 $\vec{\lambda}$ 就是该特征值的特征向量。因此,最小特征值也对应于哈密顿量的基态能量。
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里“最小特征值也对应于基态能量”的说法少了常数项说明。代码实际优化的是 test[0] + constant,因此若 M_sum 只收集 Pauli 非常数项,理论文字应明确总能量还需要再加哈密顿量分解中的 constant

# 1 & 1\\
# 1 & -1
# \end{pmatrix},
# S = \frac{\sqrt{2}}{2}\begin{pmatrix}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里给出的 S 矩阵和代码里的 s_mat = diag(1, i) 不一致。当前公式写成了带 1/sqrt(2) 的非标准矩阵,会误导后面的叠加态制备推导;建议改成标准相位门 diag(1, i)

loss_all = []
pauli_coef_ts = torch.tensor(pauli_coef)
data = nn.Parameter(torch.rand(64) * 2 * torch.pi)
lambdas = nn.Parameter(torch.rand(1, 3, dtype=torch.complex128))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lambdas 被加入 optimizer,但后续 loss 计算没有使用它;当前实现已经通过 torch.linalg.eigh() 直接取最小特征值,因此这个参数不会参与训练。建议删除它,或改成显式使用/展示 eigensolver 返回的 Schmidt 系数,避免和前文叙述冲突。

Copy link
Copy Markdown
Contributor

补充一个文档导航问题:新增了 docs/source/demos/difficult/vqe_lih/tutorial_LiH_molecule_vqe.ipynb,但 docs/source/index.md 的 Demos toctree 里还没有加入该路径。这样文档站点不会在导航中展示这个新 demo,建议补上 demos/difficult/vqe_lih/tutorial_LiH_molecule_vqe.ipynb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants