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

UCCSD Wavefunction Ansatz

◐ 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.

Unitary Coupled Cluster with Singles and Doubles — the chemically-motivated ansatz behind most quantum chemistry VQE workflows. First understand what it is trying to express physically, then see how qalgora-Q assembles it into an optimizable circuit.

The problem it solves — which trial state to use

VQE needs a parameter-controlled trial state |ψ(θ)⟩, but you cannot pick the form of the ansatz arbitrarily: too rigid and it can never reach the true ground state; too unconstrained and the optimizer has nothing to grip onto, with no chemical meaning to boot. UCCSD's answer is to borrow a physically well-grounded ansatz from decades of quantum-chemistry coupled-cluster theory — expressive enough to capture electron correlation, yet carrying interpretable structure of its own.

Intuition — correcting outward from Hartree–Fock

The starting point is the Hartree–Fock reference state: fill electrons one by one into the lowest-energy orbitals to get a single determinant. It already captures most of the energy, but it misses electron correlation — the part of the physics where electrons avoid one another and refuse to crowd together. To recover it, you must let electrons "jump" from occupied orbitals into empty ones, i.e. apply excitations: a single excitation moves one electron to a different orbital, a double excitation moves two at once. UCCSD superposes all of these single and double excitations parametrically, and lets the optimizer decide how much of each to mix in.

The math — the unitary coupled-cluster operator

Sum all single and double excitation operators weighted by their parameters into the cluster operator T = T1 + T2. What UCCSD applies to the reference state is not T itself but its unitary form

|ψ(θ)⟩ = exp(T − T) |HF⟩.

Here T − T is anti-Hermitian, so exp(T − T) is guaranteed unitary and maps directly onto reversible evolution in a quantum circuit — exactly why it suits a quantum machine better than classical coupled cluster (classical CCSD uses the non-unitary exp(T)). Each excitation contributes one parameter θ, and the whole thing is a family of trial states continuously controlled by θ.

The mechanism — Trotterizing into a circuit

The individual excitation operators inside the exponential generally do not commute, so you cannot cleanly split exp(T − T) into a product of independent single-excitation exponentials. The practical recipe is Trotter decomposition: approximate the big exponential as a sequence of single-excitation exponentials multiplied in turn, and compile each excitation exponential into circuit blocks. After a Jordan–Wigner or Bravyi–Kitaev mapping, each fermionic single/double excitation generally becomes the exponential of several Pauli strings; each Pauli rotation in turn compiles into a basis change, a CNOT ladder, and a parameterized Rz(θ) — so one excitation corresponds to a group of gate blocks rather than a single CNOT plus one Rz. The Trotter error shrinks as the number of steps grows; most VQE workflows take a single first-order step, because the subsequent parameter optimization can partly absorb the residual error itself. Note that the gate ordering, the number of Trotter steps, and the ordering of the excitation operators all affect the ansatz's expressivity and how easy it is to optimize.

How the parameter count grows with size

The number of parameters equals the number of excitations. The count of single excitations is roughly the number of occupied orbitals times the number of virtual orbitals; the count of doubles is the number of ways to choose two occupied orbitals and two virtual orbitals, which grows far faster with system size. Roughly speaking the parameter count scales as O(Nocc2 · Nvirt2), with the doubles as the dominant term. This is the source of UCCSD's expressive power and also the reason it becomes expensive on large molecules — both the circuit depth and the number of parameters to optimize swell along with it. The exact count depends on whether you use a spin-orbital or a spin-adapted form, on symmetry tapering, and on the implementation, so uccsd_num_parameters may differ across frameworks.

Honest limitations

  • "Singles + doubles" is a deliberate truncation. Omitting triple and higher excitations may not be accurate enough for strongly correlated, multireference systems, which can require triples (UCCSDT) or adaptive methods such as ADAPT-VQE; it is a trade-off between expressiveness and cost.
  • Trotterization introduces approximation error. Too few steps and the error is large; too many and the circuit becomes too deep — a balance is required.
  • Circuit depth rises with size. The rapid growth in the number of doubles quickly outruns the coherence time of near-term hardware, which is what motivated adaptive methods like ADAPT-VQE that select only the operators they truly need.
  • It is still bound by the variational principle and the optimization landscape. UCCSD gives a principled ansatz, not a guarantee of reaching the exact ground state.

Seeing it in code

Read this circuit against the discussion above. The opening for i in range(n_electrons): x(q[i]) uses x gates to fill electrons one by one into the lowest orbitals, preparing exactly the Hartree–Fock reference state; this assumes a qubit ordering in which the first n_electrons qubits correspond to the lowest occupied spin-orbitals. Then qalgora.kernels.uccsd(...) expands all single and double excitations, each a parameterized rotation controlled by θ — that is, the Trotterized circuit of exp(T − T). uccsd_num_parameters(...) simply counts the total number of excitations described above, which is the number of parameters to optimize.

Implementation

import qalgora

@qalgora.kernel
def uccsd(thetas: list[float], n_qubits: int, n_electrons: int):
    q = qalgora.qvector(n_qubits)
    for i in range(n_electrons):     # Hartree-Fock reference
        x(q[i])
    # single + double excitations, each a parameterized rotation
    qalgora.kernels.uccsd(q, thetas, n_electrons, n_qubits)

# count parameters for the excitation pool
n_params = qalgora.kernels.uccsd_num_parameters(n_electrons=2, n_qubits=4)
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.

Running VQE

With the ansatz in hand, hand it to VQE: the optimizer tunes thetas to drive the energy down toward the ground state. The number of parameters is given by the total excitation count we counted above.

optimizer = qalgora.optimizers.LBFGS()
energy, params = qalgora.vqe(uccsd, hamiltonian, optimizer,
                             parameter_count=n_params)
print("UCCSD ground-state energy:", energy)
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.
What comes next
When the doubles stretch the circuit too deep, ADAPT-VQE picks out only the genuinely necessary excitations from the same UCCSD operator pool, trading them for a more compact circuit better tailored to the specific molecule.

UCCSD 波函数线路拟设

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

幺正耦合簇单双激发——大多数量子化学 VQE 工作流背后基于化学原理的线路拟设。先弄清它在物理上想表达什么,再看 qalgora-Q 如何把它组装成一条可优化的线路。

它解决的问题 该用什么试探态

VQE 要求一个由参数控制的试探态 |ψ(θ)⟩,但拟设的形式不能乱选:选得太死板就够不到真实基态,选得太随意又会让优化无从下手、还不带任何化学含义。UCCSD 给出的答案,是从量子化学几十年积累的耦合簇理论里借来一个有充分物理依据的拟设——既足够表达电子关联,又自带可解释的结构。

直觉 从 Hartree–Fock 出发去修正

起点是 Hartree–Fock 参考态:把电子依次填入能量最低的若干轨道,得到一个单一的行列式态。它已经抓住了大部分能量,但漏掉了电子关联——电子之间相互回避、不愿挤在一起的那部分效应。要补上它,就得允许电子从已占据轨道"跳"到空轨道上去,也就是施加激发:单激发让一个电子换一个轨道,双激发让两个电子同时换。UCCSD 把所有这些单、双激发都参数化地叠加进来,让优化器去决定每一种激发该掺入多少。

数学 幺正耦合簇算符

把全体单、双激发算符按参数加权求和,记作簇算符 T = T1 + T2。UCCSD 作用在参考态上的不是 T 本身,而是幺正形式

|ψ(θ)⟩ = exp(T − T) |HF⟩

这里 T − T 是反厄米的,所以 exp(T − T) 必为幺正,能直接对应到量子线路上的可逆演化——这正是它比经典耦合簇更适合量子机的原因(经典 CCSD 用的是非幺正的 exp(T))。每一个激发对应一个参数 θ,整体就是一族由 θ 连续控制的试探态。

机制 Trotter 化为线路

指数里的各个激发算符彼此一般不对易,没法把 exp(T − T) 干净地拆成各激发独立指数的乘积。实际做法是Trotter 分解:把这个大指数近似为一串单个激发指数依次相乘,再把每个激发指数编译为线路块。每个费米子单/双激发经 Jordan–Wigner 或 Bravyi–Kitaev 映射后通常变成若干 Pauli 字符串的指数演化;每个 Pauli rotation 再编译为基变换、CNOT 链和参数化 Rz(θ),因此一般对应一组门块,而非单个 CNOT 加一个 Rz。Trotter 误差会随分解步数减小;多数 VQE 工作流取一阶单步,因为后续的参数优化本身就能部分吸收这点误差。需注意,门的排列顺序、Trotter 步数以及激发算符的排序,都会影响拟设的表达力和优化的难易。

参数数量如何随规模增长

参数个数等于激发的个数。单激发数约为占据轨道数乘以空轨道数;双激发数则是从占据轨道选两个、再从空轨道选两个的组合数,因此随体系大小增长得快得多。粗略地说,参数量大致按 O(Nocc2 · Nvirt2) 标度,其中双激发是主导项。这正是 UCCSD 表达力的来源,也是它在大分子上变得昂贵的原因——线路深度和待优化的参数数都随之膨胀。具体参数数取决于采用自旋轨道还是自旋适配(spin-adapted)形式、是否做对称性 tapering 以及具体实现,因此 uccsd_num_parameters 在不同框架间可能不一致。

诚实的边界

  • "单 + 双"是有意的截断。不引入三激发及更高阶,对强关联、多参考体系可能不够准,这类体系可能需要三激发(UCCSDT)或 ADAPT-VQE 这类自适应方法;这是表达力与代价之间的权衡。
  • Trotter 化引入近似误差。步数太少误差偏大,步数太多线路又太深——需要折中。
  • 线路深度随规模上升。双激发数量的快速增长会很快超出近期硬件的相干时间,这也催生了 ADAPT-VQE 这类只挑必要算符的自适应方法。
  • 它仍受变分原理与优化地形的约束。UCCSD 给的是一个有原则的拟设,而非通往精确基态的保证。

对照代码理解

请对照上文来读这段线路。开头的 for i in range(n_electrons): x(q[i])x 门把电子逐个填入最低的几条轨道,制备的正是 Hartree–Fock 参考态;这里假定了一种比特排序,即前 n_electrons 个比特对应能量最低的已占自旋轨道。随后 qalgora.kernels.uccsd(...) 展开全部单、双激发,每个激发都是一个由 θ 控制的参数化旋转——也就是 exp(T − T) 经 Trotter 化后的线路。uccsd_num_parameters(...) 数出的就是上面所说的激发总数,即待优化的参数个数。

实现方法

import qalgora

@qalgora.kernel
def uccsd(thetas: list[float], n_qubits: int, n_electrons: int):
    q = qalgora.qvector(n_qubits)
    for i in range(n_electrons):     # Hartree-Fock reference
        x(q[i])
    # single + double excitations, each a parameterized rotation
    qalgora.kernels.uccsd(q, thetas, n_electrons, n_qubits)

# count parameters for the excitation pool
n_params = qalgora.kernels.uccsd_num_parameters(n_electrons=2, n_qubits=4)
规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。

运行 VQE

有了拟设,就把它交给 VQE:优化器调节 thetas 把能量往下压,逼近基态。参数个数由上面数出的激发总数给定。

optimizer = qalgora.optimizers.LBFGS()
energy, params = qalgora.vqe(uccsd, hamiltonian, optimizer,
                             parameter_count=n_params)
print("UCCSD ground-state energy:", energy)
规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。
下一步
当双激发把线路撑得太深时,ADAPT-VQE 会从同一个 UCCSD 算符池中只挑出真正必要的那几个激发,换来一条更紧凑、更贴合具体分子的线路。