qalgora-Q Docs Hub量子文档 ✦ Ask AI✦ 问问文档

Generating the Electronic Hamiltonian

◐ Design-level API
This page documents qalgora-Q API design, architecture, or adaptation workflows. Code examples illustrate intended usage and are not guaranteed to run in the current reference implementation.

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 apaq + ½ Σpqrs hpqrs apaqaras

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.

MappingQubitsPauli-string weight
Jordan–Wignerone per spin-orbitalparity (Z) strings up to O(N) long
Bravyi–Kitaevone per spin-orbitalshorter, ~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())
Specification API — not in the open reference build yet
This example shows a qalgora-Q specification API (or a third-party library) that the open reference build does not bundle today. It documents the intended interface; to run code now, use the reference build’s supported core API.

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.

ReferenceWhen to use
RHFClosed-shell molecules at equilibrium
ROHF / UHFOpen-shell / radical species
Natural / CASSCF orbitalsCompact active spaces for strong correlation
The active-space lever
Treating only the chemically important orbitals quantum-mechanically (an active space) cuts N directly, and because the term count scales as O(N4), even a modest reduction in N pays off dramatically in circuit size and measurement cost.

生成电子哈密顿量

◐ 设计接口
本页描述的是 qalgora-Q 的接口设计、架构设计或适配工作流。相关代码用于说明预期用法,当前参考实现不保证可以直接运行。

将分子转化为量子比特哈密顿量:计算积分、构建二次量子化算符,并将费米子映射到量子比特。

它解决的问题

每一种量子化学算法——VQE、QSCI、SKQD——都需要把分子哈密顿量表示为量子比特算符:一组设备可测量的 Pauli 串的加权和。但你的出发点截然不同:一个分子,以三维空间中处于特定位置的原子核加上一团电子的形式给出。本页讲的就是连通两者的流水线——输入几何结构,输出量子比特算符。

二次量子化

在玻恩–奥本海默近似下,原子核被冻结,我们只求解电子。首先选定一组有限的单粒子轨道作为基组;电子哈密顿量随后用产生与湮灭算符 aa 写成二次量子化形式,这两个算符分别在某个轨道上增添或移除一个电子:

H = Σpq hpq apaq + ½ Σpqrs hpqrs apaqaras

第一项求和是单体部分(电子的动能加上它受到原子核的吸引);第二项是两体部分(电子之间的排斥)。

单电子积分与双电子积分

这些系数并非可自由调节的参数——它们是对所选轨道求出的确定积分,由平均场(例如 Hartree–Fock)与积分程序在经典端计算。单电子积分 hpq 刻画动能与核吸引;双电子积分 hpqrs 刻画电子间的排斥。两者合起来,便为给定的分子与基组在数值上确定了哈密顿量。其中 hpq 为单电子积分,hpqrs 为双电子积分;不同积分记号会导致二体项指标顺序不同,须与所用量子化学后端一致。

将费米子映射到量子比特

电子是费米子:它们的算符反对易,且交换两个电子时波函数必须变号。量子比特没有这条规则,因此需要一种费米子到量子比特的映射。它把每个自旋轨道的占据情况存入一个量子比特,并把每个 aa 改写为 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())
规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。

轨道选择

由于开销随 N 增长得如此陡峭,轨道(平均场参考态)的选择绝非细枝末节——它同时决定了积分的精度,以及你最终能得到多紧凑的哈密顿量。

参考态适用场景
RHF平衡几何结构下的闭壳层分子
ROHF / UHF开壳层分子及自由基体系
Natural / CASSCF orbitals强关联体系的紧凑活性空间
活性空间这一杠杆
仅对化学上重要的轨道做量子力学处理(即活性空间)可直接削减 N,而由于项数按 O(N4) 增长,即便 N 只是适度减少,也会在线路规模与测量开销上带来惊人的回报。