Skip to content

Add fermionic-to-bosonic Hamiltonian mapper#159

Open
Hugh-888 wants to merge 7 commits into
TuringQ:mainfrom
Hugh-888:dev_fermion_map_boson
Open

Add fermionic-to-bosonic Hamiltonian mapper#159
Hugh-888 wants to merge 7 commits into
TuringQ:mainfrom
Hugh-888:dev_fermion_map_boson

Conversation

@Hugh-888
Copy link
Copy Markdown
Collaborator

Add class FermionMapBoson for mapping the fermionic Hamiltonian to the bosonic Hamiltonian in Fock basis.
Example:

h_z = 3
geometry = [("H", (0, 0, 0)), ("H", (0, 0, h_z))]
basis = "sto-3g"
multiplicity = 1
charge = 0
occupied_indices = []
active_indices = [0,1]
config = {'geometry': geometry, 'basis':basis, 'multiplicity':multiplicity, 'charge':charge, 'n_ele':2, 'n_orbit':4,
          'occupied_indices':occupied_indices, 'active_indices': active_indices}

fermion_map = dqp.ansatz.FermionMapBoson(config)
h_f = fermion_map.construct_h_fermion()
energy2 = np.linalg.eigvals(h_f)
constant = fermion_map.constant
print(fermion_map.fci_energy(),  np.min(energy2) + constant)

h_fock = fermion_map.mapping()
h_fock
image

@Hugh-888 Hugh-888 requested a review from sansiro77 April 24, 2026 08:13
@Hugh-888 Hugh-888 added the enhancement New feature or request label Apr 24, 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.

按讨论整理了几个接口和边界问题。

Comment thread src/deepquantum/photonic/ansatz.py Outdated
return sort_samples


class FermionMapBoson:
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.

这个类的职责是量子化学/费米到玻色映射,不是 photonic ansatz;放在 photonic/ansatz.py 会让模块边界混乱。

Comment thread src/deepquantum/photonic/ansatz.py Outdated
self.m = 2 * len(self.active_indices)

def construct_h_fermion(self):
from openfermion import get_fermion_operator
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.

这里依赖 OpenFermion/PySCF,但 PR 没有新增对应的 optional dependency,用户无法通过安装 extras 获得完整功能。

Comment thread src/deepquantum/photonic/ansatz.py Outdated
return sort_samples


class FermionMapBoson:
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.

FermionMapBoson 这个命名不够清晰,建议改成更符合语义的 FermionToBosonMapper

Comment thread src/deepquantum/photonic/ansatz.py Outdated
These form the primary Hilbert space for VQE.
"""

def __init__(self, config: dict = None) -> None:
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.

这个类作为用户主接口,当前用裸 dict 初始化且缺少参数校验,接口稳定性和可读性都不够。

Comment thread src/deepquantum/photonic/ansatz.py Outdated
def fci_energy(self):
return self.molecule.fci_energy

@staticmethod
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.

这些 staticmethod 不依赖类状态,更像底层 helper;放在主接口类里会扩大公开 API,建议重新组织到类外或内部私有实现中。

Comment thread src/deepquantum/photonic/ansatz.py Outdated
else:
return 0.0

@staticmethod
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.

当前实现隐含了重要边界:常数项不在矩阵里、复系数会被丢弃、输入默认是 normal-ordered 分子哈密顿量;这些限制需要在接口说明中明确。

@sansiro77 sansiro77 changed the title Map fermionic hamiltonian to bosonic hamiltonian in Fock basis Add fermionic-to-bosonic Hamiltonian mapper May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants