Generating the Electronic Hamiltonian
Turn a molecule into a qubit Hamiltonian: compute integrals, build the second-quantized operator, and map fermions to qubits.
The problem it solves
Every quantum-chemistry algorithm — VQE, QSCI, SKQD — needs the molecular Hamiltonian as a qubit operator: a weighted sum of Pauli strings the device can measure. But you start from something very different: a molecule, given as nuclei at positions in 3-D space with a cloud of electrons. This page is about the pipeline that bridges the two — geometry in, qubit operator out.
Second quantization
Within the Born–Oppenheimer approximation the nuclei are frozen and we solve for the electrons. First
pick a finite basis set of single-particle orbitals; the electronic
Hamiltonian is then written in second quantization using creation and annihilation
operators a† and a, which add or remove an electron in an
orbital:
H = Σpq hpq a†paq
+ ½ Σpqrs hpqrs a†pa†qaras
The first sum is the one-body part (an electron's kinetic energy plus its attraction to the nuclei); the second is the two-body part (electron–electron repulsion).
One- and two-electron integrals
The coefficients are not free parameters — they are definite integrals over the chosen orbitals,
computed classically by a mean-field (e.g. Hartree–Fock) and integral code. The
one-electron integrals hpq capture kinetic energy and
nuclear attraction; the two-electron integrals hpqrs capture
the repulsion between electrons. Together they pin down the Hamiltonian numerically for a given molecule
and basis. Be careful with conventions: hpq are the one-electron integrals and
hpqrs the two-electron integrals, but different integral notations order the
two-body indices differently, so the convention must match the quantum-chemistry backend you use.
Mapping fermions to qubits
Electrons are fermions: their operators anticommute and the wavefunction must change sign
when two are swapped. Qubits have no such rule, so a fermion-to-qubit mapping is needed.
It stores the occupation of each spin-orbital in one qubit and rewrites every a†,
a as Pauli strings, with extra Z operators threaded through to enforce the
antisymmetric sign.
| Mapping | Qubits | Pauli-string weight |
|---|---|---|
| Jordan–Wigner | one per spin-orbital | parity (Z) strings up to O(N) long |
| Bravyi–Kitaev | one per spin-orbital | shorter, ~O(log N) — trades locality for weight |
"One qubit per spin-orbital" refers to the common mapping without symmetry tapering; exploiting Z2 symmetries (particle number, parity, spin, point group, …) can remove qubits. Bravyi–Kitaev, by encoding both occupation and parity information at once, compresses the parity strings that can reach O(N) in Jordan–Wigner down to about O(log N), at the price of a more intricate mapping structure.
Why the term count scales as O(N⁴)
In the naive construction the two-electron integrals hpqrs carry four
orbital indices, so the number of non-zero two-body terms — and therefore the number of Pauli strings
after mapping — grows as O(N4) in the worst case in the number of
spin-orbitals N. This is the dominant cost driver of quantum chemistry: it sets how large the Hamiltonian
object is and how many terms VQE must measure. In practice the term count is reduced by integral
symmetries, threshold truncation, an active space, localized orbitals, and low-rank / double
factorization. Shrinking N through a good orbital choice or an active space is the main lever against
it.
From geometry to qubit operator
Read the snippet as the pipeline above, step by step. geometry is the molecule;
create_molecule(...) calls a classical quantum-chemistry backend that computes the AO integrals
from the geometry and basis and typically runs a mean-field step (e.g. RHF) to obtain the molecular
orbitals and reference state; molecular_hamiltonian(...) assembles the second-quantized operator and applies
the Jordan–Wigner mapping to emit the qubit operator; and get_qubit_count() reports the
number of spin-orbitals that drives the O(N4) scaling.
import qalgora
# 1. define the molecule
geometry = [("H", (0., 0., 0.)), ("H", (0., 0., 0.735))]
# 2. run a mean-field calculation (RHF) and get integrals
molecule = qalgora.chemistry.create_molecule(geometry, basis="sto-3g")
# 3. build the second-quantized Hamiltonian, Jordan-Wigner mapped
hamiltonian = qalgora.chemistry.molecular_hamiltonian(molecule)
print("qubits:", hamiltonian.get_qubit_count())Orbital choices
Because cost scales so steeply with N, the choice of orbitals (the mean-field reference) is not a detail — it decides both the accuracy of the integrals and how compact a Hamiltonian you can get away with.
| Reference | When to use |
|---|---|
| RHF | Closed-shell molecules at equilibrium |
| ROHF / UHF | Open-shell / radical species |
| Natural / CASSCF orbitals | Compact active spaces for strong correlation |
生成电子哈密顿量
将分子转化为量子比特哈密顿量:计算积分、构建二次量子化算符,并将费米子映射到量子比特。
它解决的问题
每一种量子化学算法——VQE、QSCI、SKQD——都需要把分子哈密顿量表示为量子比特算符:一组设备可测量的 Pauli 串的加权和。但你的出发点截然不同:一个分子,以三维空间中处于特定位置的原子核加上一团电子的形式给出。本页讲的就是连通两者的流水线——输入几何结构,输出量子比特算符。
二次量子化
在玻恩–奥本海默近似下,原子核被冻结,我们只求解电子。首先选定一组有限的单粒子轨道作为基组;电子哈密顿量随后用产生与湮灭算符 a† 与 a 写成二次量子化形式,这两个算符分别在某个轨道上增添或移除一个电子:
H = Σpq hpq a†paq
+ ½ Σpqrs hpqrs a†pa†qaras
第一项求和是单体部分(电子的动能加上它受到原子核的吸引);第二项是两体部分(电子之间的排斥)。
单电子积分与双电子积分
这些系数并非可自由调节的参数——它们是对所选轨道求出的确定积分,由平均场(例如 Hartree–Fock)与积分程序在经典端计算。单电子积分 hpq 刻画动能与核吸引;双电子积分 hpqrs 刻画电子间的排斥。两者合起来,便为给定的分子与基组在数值上确定了哈密顿量。其中 hpq 为单电子积分,hpqrs 为双电子积分;不同积分记号会导致二体项指标顺序不同,须与所用量子化学后端一致。
将费米子映射到量子比特
电子是费米子:它们的算符反对易,且交换两个电子时波函数必须变号。量子比特没有这条规则,因此需要一种费米子到量子比特的映射。它把每个自旋轨道的占据情况存入一个量子比特,并把每个 a†、a 改写为 Pauli 串,其中穿插额外的 Z 算符以强制实现反对称符号。
| 映射 | 量子比特 | Pauli 串权重 |
|---|---|---|
| Jordan–Wigner | 每个自旋轨道一个 | 宇称(Z)串长可达 O(N) |
| Bravyi–Kitaev | 每个自旋轨道一个 | 更短,约 O(log N)——以局域性换取权重 |
"每个自旋轨道一个量子比特"(指未经对称性 tapering 的常见映射;利用粒子数/宇称/自旋/点群等 Z₂ 对称性可减少量子比特)。Bravyi–Kitaev 通过同时编码占据与宇称信息,将 JW 中最长可达 O(N) 的宇称串压缩到约 O(log N),但映射结构更复杂。
为何项数按 O(N⁴) 增长
朴素构造中二电子积分 hpqrs 有四个轨道指标,非零二体项最坏按 O(N4) 增长(这也是映射后 Pauli 串数目随自旋轨道数 N 的增长方式)。这是量子化学最主要的开销来源:它决定了哈密顿量对象有多大,以及 VQE 必须测量多少项。实际项数因积分对称性、阈值截断、活性空间、局域轨道、低秩/双因子化而减少。通过良好的轨道选择或活性空间缩小 N,是对抗这一增长的主要手段。
从几何结构到量子比特算符
请把这段代码逐步当作上文的流水线来读。geometry 即分子;create_molecule(...) 调用经典量子化学后端,按几何与基组计算 AO 积分,并通常运行 RHF 等平均场步骤得到分子轨道与参考态;molecular_hamiltonian(...) 装配出二次量子化算符并施加 Jordan–Wigner 映射,给出量子比特算符;而 get_qubit_count() 报告驱动 O(N4) 增长的自旋轨道数。
import qalgora
# 1. define the molecule
geometry = [("H", (0., 0., 0.)), ("H", (0., 0., 0.735))]
# 2. run a mean-field calculation (RHF) and get integrals
molecule = qalgora.chemistry.create_molecule(geometry, basis="sto-3g")
# 3. build the second-quantized Hamiltonian, Jordan-Wigner mapped
hamiltonian = qalgora.chemistry.molecular_hamiltonian(molecule)
print("qubits:", hamiltonian.get_qubit_count())轨道选择
由于开销随 N 增长得如此陡峭,轨道(平均场参考态)的选择绝非细枝末节——它同时决定了积分的精度,以及你最终能得到多紧凑的哈密顿量。
| 参考态 | 适用场景 |
|---|---|
| RHF | 平衡几何结构下的闭壳层分子 |
| ROHF / UHF | 开壳层分子及自由基体系 |
| Natural / CASSCF orbitals | 强关联体系的紧凑活性空间 |