Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

Implementation Plan for apply_within_conjugate

  • Explore codebase and understand current apply_within implementation
  • Add apply_within_conjugate declaration in _hamiltonian.cpp
  • Implement hamiltonian_apply_conjugate_kernel in _hamiltonian_cpu.cpp
  • Implement apply_within_conjugate_kernel in _hamiltonian_cpu.cpp
  • Implement apply_within_conjugate_interface in _hamiltonian_cpu.cpp
  • Implement hamiltonian_apply_conjugate_kernel in _hamiltonian_cuda.cu
  • Implement apply_within_conjugate_kernel in _hamiltonian_cuda.cu
  • Implement apply_within_conjugate_interface in _hamiltonian_cuda.cu
  • Add apply_within_conjugate method to Hamiltonian class in hamiltonian.py
  • Fix code review issues (device variable and typo)
  • Run security checks (0 vulnerabilities found)
  • Fix iteration order per feedback: now sorts configs and iterates over result_configs

Summary

Updated implementation based on feedback from @hzhangxyz. The key change is the iteration strategy:

Previous (incorrect): Iterate over configs (larger), search in result_configs (smaller)
Now (correct): Sort configs (larger), iterate over result_configs (smaller), search in sorted configs

This is more efficient when result_configs is smaller than configs, which is the primary use case for the conjugate operation.

Original prompt

This section details on the original issue you should resolve

<issue_title>实现apply_within_conjugate功能</issue_title>
<issue_description>目前存在一个函数 apply_within, 在 _hamiltonian.cpp 中申明, 在 _hamiltonian_cpu.cpp 和 _hamiltonian_cuda.cu 中实现的, 并且接口通过 hamiltonian.py 封装出来了.

这个实际上是作用hamiltonian在某个子空间向量中, 现在, 需要实现他的共额版本, 之所以需要实现其共轭版本是因为, 投影的时候 apply within 的 输入比输出小很多, 所以搜索的时候用src * term 然后判断是否在dst中 .

在一些场景下, 需要乘上H的conj,这时dst比src小, 所以搜索够行方式也应个变化.应该是 term * dst看看是否在src中.

需要注意的是, 由于hamiltonian是共轭转置的, 所以依然可以用大部分公用的函数.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Implement apply_within_conjugate function for Hamiltonian Implement apply_within_conjugate for Hermitian adjoint Hamiltonian application Dec 18, 2025
Copilot AI requested a review from hzhangxyz December 18, 2025 20:26
Copy link
Member

@hzhangxyz hzhangxyz left a comment

Choose a reason for hiding this comment

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

不是这么写的, 应该是将 configs 排序, 然后遍历 result config, result config和每个term交叉算一下, 得到的current config 看看是否能在sorted configs 中找到, 如果能找到, 算一下psi.这样才是效率高的方法, 因为这里results configs比configs少.

Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

不是这么写的, 应该是将 configs 排序, 然后遍历 result config, result config和每个term交叉算一下, 得到的current config 看看是否能在sorted configs 中找到, 如果能找...

Fixed in commit 31ecae3. Changed implementation to:

  • Sort configs (the larger input space)
  • Iterate over result_configs (the smaller destination space)
  • For each result_config, apply conjugate operation and search in sorted configs

This is more efficient when result_configs is smaller, as you noted.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

实现apply_within_conjugate功能

2 participants