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

Quantum-Selected Configuration Interaction (QSCI)

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

Use a quantum computer only to select the most important electronic configurations, then diagonalize that small subspace classically — a hybrid scheme that asks the quantum device for the one thing it is good at and leaves the rest to proven classical linear algebra.

The problem it solves

The exact ground state of a molecule is a superposition over electronic configurations — Slater determinants, each a way of placing the electrons in the available orbitals. Full configuration interaction (full CI) keeps every determinant and diagonalizes the Hamiltonian in that complete space; it is exact, but the number of determinants grows combinatorially with the number of orbitals and electrons, so full CI hits an exponential wall after only a handful of atoms.

The saving grace is that for weakly to moderately correlated systems the ground state is often near-sparse in this basis: a small minority of configurations carry almost all of the weight, and the rest contribute next to nothing (for strongly correlated, multireference systems this sparsity is much weaker). If you could name just those dominant determinants, you could diagonalize the Hamiltonian in a tiny subspace and recover most of the correlation energy. Classical "selected CI" methods spend their effort hunting for that important set with iterative heuristics. QSCI replaces this classical heuristic hunt with a repeated sampling procedure: it gathers the high-frequency bitstrings over many shots, then filters them by physical sector — electron number, spin, symmetry — keeping only valid Slater determinants as candidate basis states for the CI subspace.

Intuition — let the quantum state vote

Prepare an approximate quantum state — a shallow ansatz, or the output of a (possibly under-converged) VQE — that already concentrates its amplitude on the chemically relevant configurations. Now measure it in the computational basis. Each measured bitstring is a configuration (which orbitals are occupied), and the configurations you see most often are exactly those with the largest amplitude. The sampler is doing importance sampling over an astronomically large configuration space for free: you never enumerate the determinants, you just let the state tell you which ones matter.

The mechanism — diagonalize in the selected subspace

Collect the most frequent bitstrings as a basis of configurations {|D1⟩, …, |Dk⟩}. Project the molecular Hamiltonian onto that span by computing the matrix elements Hij = ⟨Di|H|Dj, giving a small k×k matrix, and diagonalize it on a classical computer for its lowest eigenvalue. If the Hij are constructed exactly in one finite orbital basis and within a valid physical sector, the lowest eigenvalue of the subspace obeys the variational principle and is an upper bound on the exact ground-state energy within that finite space — a bound that can only improve as you enlarge the selected subspace.

  1. Prepare an approximate quantum state (e.g. a shallow ansatz).
  2. Sample it — the most frequent bitstrings name the dominant configurations.
  3. Build the Hamiltonian in that selected subspace.
  4. Diagonalize classically for the ground-state energy.

Seeing it in code

Read the snippet against the steps above. qalgora.sample(...) draws the bitstrings from the ansatz; is_valid_sector(...) keeps only bitstrings in the right physical sector (electron number, spin, symmetry); sorting by count and slicing the top 64 performs the selection step; build_subspace_hamiltonian(configs) assembles the k×k projected matrix; and classical_diagonalize(H_sub) is the classical eigensolve that returns the variational energy.

import qalgora
from collections import Counter

counts = qalgora.sample(ansatz, theta, shots_count=20000)
# keep only bitstrings in a valid physical sector (electron number, spin, symmetry)
valid = {b: c for b, c in counts.items() if is_valid_sector(b)}
# keep the top-k most probable configurations
top = sorted(valid.items(), key=lambda kv: -kv[1])[:64]
configs = [bits for bits, _ in top]

H_sub = build_subspace_hamiltonian(configs)   # classical
energy = classical_diagonalize(H_sub)
print("QSCI ground-state energy:", energy)

What it is — and isn't — good for

  • Relatively noise-tolerant, not immune. QSCI only needs the sampler to surface the right configurations, not to reproduce their amplitudes precisely, because the energy ultimately comes from a classical diagonalization. Noise that reshuffles probabilities but still leaves the important determinants in the top-k is largely harmless — which is why QSCI runs on hardware that would derail an energy-estimating VQE. But if noise changes the ranking enough that an important configuration drops out of the selection, or it is missed altogether, accuracy still degrades.
  • You can only diagonalize what you sample. If an important configuration never appears in the samples, it is absent from the subspace and its correlation energy is simply lost. The method is only as good as the state you prepare and the number of shots you can afford.
  • Rare-but-important configurations are expensive. Resolving a determinant that carries small-but-nonzero weight requires many shots, so the sampling cost grows as you chase the last fractions of the correlation energy.
  • The classical step must stay tractable. The selected subspace is small by construction, but computing the matrix elements and diagonalizing still bounds how large k can be.
Why this is robust
Because the final energy comes from a classical diagonalization of the exact Hamiltonian in the selected subspace, the quantum device never has to estimate an energy — it only has to point at the right configurations. That division of labour is what makes QSCI one of the more noise-resilient near-term chemistry methods.

量子选态组态相互作用(QSCI)

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

仅借助量子计算机筛选最重要的电子组态,再在经典端对该小型子空间进行对角化——这是一种混合方案,只向量子设备索取它真正擅长的那件事,其余全部交给久经检验的经典线性代数。

它解决的问题

分子的精确基态是众多电子组态的叠加——每个组态都是一个 Slater 行列式,即把电子安置到可用轨道上的一种方式。完全组态相互作用(full CI)保留全部行列式,并在这个完整空间中对哈密顿量做对角化;它是精确的,但行列式的数目随轨道数与电子数呈组合式增长,因此只要几个原子之后,full CI 便撞上指数墙。

幸运之处在于:对弱到中等关联的体系,基态在该基底下往往近似稀疏——极少数组态承载了几乎全部权重,其余几乎毫无贡献(对强关联、多参考的体系,这种稀疏性会弱得多)。如果能只点出那些主导行列式,就可以在一个极小的子空间里对角化哈密顿量,从而回收绝大部分关联能。经典的"选态 CI"方法把功夫花在用迭代启发式去搜寻这组重要行列式上,而 QSCI 则用多次采样流程取代经典启发式搜寻:通过许多 shots 统计高频 bitstring,再按电子数、自旋、对称性等物理扇区筛选合法 Slater 行列式作为 CI 子空间候选基底。

直觉 让量子态来投票

制备一个近似量子态——浅层拟设,或一次(可能尚未收敛的)VQE 的输出——它已把振幅集中到化学上相关的组态上。现在在计算基下测量它。每个测得的比特串就是一个组态(哪些轨道被占据),而你最常看到的组态恰是振幅最大的那些。采样器免费地在一个天文级大的组态空间里做了重要性采样:你从不枚举行列式,只让量子态告诉你哪些才要紧。

机制 在所选子空间中对角化

把出现频率最高的比特串收集为一组组态基底 {|D1⟩, …, |Dk⟩}。通过计算矩阵元 Hij = ⟨Di|H|Dj 把分子哈密顿量投影到该张成空间上,得到一个小的 k×k 矩阵,再在经典计算机上对角化求其最低本征值。若 Hij 在同一有限轨道基、合法物理扇区中精确构造,则子空间最低本征值满足变分原理,是该有限空间的上界——且随着所选子空间的扩大只会变得更好。

  1. 制备近似量子态(例如浅层线路拟设)。
  2. 对其采样——出现频率最高的比特串即对应主导组态。
  3. 在所选子空间中构建哈密顿量。
  4. 经典对角化求解基态能量。

对照代码理解

请对照上述步骤来读这段代码。qalgora.sample(...) 从拟设中抽取比特串;is_valid_sector(...) 只保留落在正确物理扇区(电子数、自旋、对称性)的比特串;按计数排序并取出前 top 64 个完成了筛选步骤;build_subspace_hamiltonian(configs) 装配出 k×k 的投影矩阵;而 classical_diagonalize(H_sub) 即返回变分能量的经典本征求解。

import qalgora
from collections import Counter

counts = qalgora.sample(ansatz, theta, shots_count=20000)
# keep only bitstrings in a valid physical sector (electron number, spin, symmetry)
valid = {b: c for b, c in counts.items() if is_valid_sector(b)}
# keep the top-k most probable configurations
top = sorted(valid.items(), key=lambda kv: -kv[1])[:64]
configs = [bits for bits, _ in top]

H_sub = build_subspace_hamiltonian(configs)   # classical
energy = classical_diagonalize(H_sub)
print("QSCI ground-state energy:", energy)

它擅长什么 又不擅长什么

  • 相对抗噪,但并非免疫。QSCI 只需采样器把正确的组态浮现出来,并不要求精确复现它们的振幅,因为能量最终来自经典对角化。那些只是打乱概率、却仍把重要行列式留在前 k 名里的噪声,基本无害——这正是 QSCI 能在会让能量估算型 VQE 失效的硬件上运行的原因。但若噪声把排序改变到让某个重要组态跌出筛选,或干脆漏采,精度仍会下降。
  • 采不到的就对角化不了。若某个重要组态从未在采样中出现,它便缺席于子空间,其关联能也就直接丢失。该方法的好坏取决于你所制备的态以及负担得起的采样次数。
  • 稀有却重要的组态代价高昂。要分辨出一个权重虽小却非零的行列式需要大量采样,因此在追逐关联能最后那点零头时,采样开销会随之上升。
  • 经典步骤须保持可处理。所选子空间在构造上很小,但计算矩阵元与对角化仍然限定了 k 能取多大。
为何稳健
由于最终能量来自对所选子空间中精确哈密顿量的经典对角化,量子设备从不需要估算能量——它只需指出正确的组态。正是这种分工,使 QSCI 成为近期最具抗噪能力的化学方法之一。