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

Approximate State Preparation using MPS

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

Prepare a target state on hardware by sequentially encoding its matrix-product-state (MPS) representation into a shallow circuit.

The problem it solves

Preparing an arbitrary n-qubit state is exponentially hard. A generic n-qubit state has 2ⁿ complex amplitudes, and exact preparation of such a state generally needs an exponential number of parameters and gates — and the depth, too, grows quickly with system size. For many qubits that is hopeless. But the states we actually care about are rarely generic: the ground states of local, gapped one-dimensional Hamiltonians typically obey an area law — they carry low entanglement and can be efficiently approximated by a small-bond-dimension MPS — and low-entanglement states in general are highly compressible. MPS state preparation is how you cash in that compressibility.

Intuition — entanglement is the real cost

What truly makes state preparation expensive is not the raw count of amplitudes but the entanglement. A state whose entanglement across every left–right cut stays bounded can be written as a matrix product state: a chain of tensors, one per site, linked by bond indices. The dimension χ of those bonds — the bond dimension — measures exactly how much entanglement is carried across each cut. Low entanglement means small χ, and small χ means a compact description.

The idea — bond dimension and sequential encoding

A low-entanglement state has a compact MPS with small bond dimension. Each tensor becomes a few-qubit unitary, so in sequential preparation the number of tensors processed in sequence grows linearly with the system size N — one local unitary per site.

The roles of N and χ are distinct: N sets the number of tensors processed in sequence; χ sets the bond/ancilla dimension (needing roughly ⌈log₂ χ⌉ ancilla qubits). When the isometries / local unitaries are compiled into hardware gates, the local gate count and depth also grow with χ — so χ affects fidelity, ancilla width, and circuit depth together. As long as the target state stays low-entanglement (χ small), the overall cost stays modest — an enormous saving over the exponential cost of generic preparation.

Fidelity versus depth

Truncating the MPS to a finite bond dimension is an approximation: it keeps the χ largest Schmidt coefficients across each cut and discards the rest. The discarded weight at each Schmidt truncation gives the local truncation error of that cut; after many truncations the global fidelity loss must be estimated or bounded cumulatively and is generally not equal to any single discarded weight. A larger χ keeps more of the state — higher overlap with the target — but makes each local unitary wider (and the compilation deeper); a smaller χ gives a shallower circuit at the price of a lower fidelity. The practical recipe is to pick the smallest χ that still meets your overlap target.

What it is — and isn't — good for

  • Low-entanglement states only. The method is efficient precisely when χ is small. Volume-law or highly entangled states need a χ that grows exponentially with system size, which erases the advantage entirely.
  • It is approximate, not exact. Unless the target genuinely has bounded bond dimension, you are preparing a truncated surrogate, not the exact state.
  • It suits chain-like structure. The MPS form mirrors a 1-D arrangement of sites; it is the natural fit for one-dimensional systems and for states with limited long-range entanglement.
  • It is a building block. An approximate MPS state often serves as a high-quality starting point for a subsequent variational or evolution step, rather than an end in itself.

Seeing it in code — sequential encoding

Read the snippet against the theory. qalgora.tensor.to_mps(target_state, max_bond_dim=2) compresses the target into an MPS, capping the bond dimension at χ = 2 — this is the fidelity/depth knob. With χ = 2 each tensor maps to a two-qubit unitary, so the loop walks site by site and each qalgora.apply_unitary(gate, q[i], q[i + 1]) applies one local two-qubit unitary synthesized from one MPS tensor — the one-unitary-per-site sequential preparation described above. This snippet is a simplified illustration: a larger χ needs wider local unitaries (more ancilla/bond qubits per step), so the two-qubit form here corresponds specifically to χ = 2.

Sequential encoding

import qalgora

# compress the target into an MPS, then synthesize gates tensor-by-tensor
# (max_bond_dim=2 is a simplified illustration: chi=2 maps to 2-qubit unitaries)
mps = qalgora.tensor.to_mps(target_state, max_bond_dim=2)

@qalgora.kernel
def prepare(mps_gates: list[list[float]]):
    q = qalgora.qvector(len(mps_gates) + 1)
    for i, gate in enumerate(mps_gates):
        qalgora.apply_unitary(gate, q[i], q[i + 1])   # local 2-qubit unitary
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.
Trade-off
Larger bond dimension means higher fidelity but deeper circuits. Choose the smallest bond dimension that meets your overlap target.
Specification API — not bundled yet
qalgora.tensor.to_mps and the schematic isometry helpers compile_mps_isometries / apply_isometry are documented specification interfaces (规范接口·暂未内置); the open reference build does not ship them yet.

基于 MPS 的近似态制备

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

通过对矩阵乘积态(MPS)表示进行逐张量编码,在硬件上制备目标态,实现浅层电路。

它解决的问题

制备任意 n 量子比特态是指数级困难的。一个一般的 n 量子比特态有 2ⁿ 个复振幅;通用精确态制备通常需要指数级数量的参数和门,深度也随规模快速增长。对许多量子比特而言这毫无希望。但我们真正关心的态很少是一般的:一维局域、有能隙哈密顿量的基态通常满足面积律,纠缠较低,可由较小键维 MPS 高效近似;一般的低纠缠态也是高度可压缩的。MPS 态制备正是把这种可压缩性兑现的方法。

直觉 纠缠才是真正的代价

真正让态制备昂贵的,并非振幅的原始数目,而是纠缠。一个在每一处左右切割上纠缠都保持有界的态,可以写成矩阵乘积态:一条张量链,每个格点一个张量,由指标相连。这些键的维数 χ——即键维数——恰好度量了每一处切割所承载的纠缠量。低纠缠意味着小 χ,而小 χ 意味着紧凑的描述。

基本思路 键维数与逐张量编码

低纠缠态具有键维数小的紧凑 MPS。每个张量对应若干量子比特的幺正算符,因此在顺序制备中,串行处理的张量数随系统规模 N 线性增长——每个格点对应一个局部幺正算符。

N 与 χ 的角色不同:N 决定串行张量数;χ 决定 bond/ancilla 维度(约需 ⌈log₂ χ⌉ 个辅助比特)。将等距映射/局部 unitary 编译成硬件门时,局部门数和深度也随 χ 增大。因此 χ 同时影响保真度、辅助宽度和电路深度。只要目标态保持低纠缠(χ 小),整体开销就保持适中——相较一般态制备的指数级开销,节省巨大。

保真度与深度的权衡

把 MPS 截断到有限键维数是一种近似:它在每一处切割上保留最大的 χ 个 Schmidt 系数,舍弃其余。每次 Schmidt 截断的舍弃权重给出该切割的局部截断误差;多处截断后全局保真度损失需累积估计或界定,一般不等同某一次舍弃权重。χ 越大,保留的态越多——与目标的交叠越高——但每个局部幺正算符也越宽(编译出的电路越深);χ 越小,电路越浅,代价是保真度更低。实用的做法是选取仍能满足交叠目标的最小 χ。

它擅长什么 又不擅长什么

  • 仅限低纠缠态。该方法恰恰在 χ 小时才高效。体积律或高度纠缠的态需要 χ 随系统规模指数增长,这会把优势完全抹去。
  • 它是近似而非精确的。除非目标态确实具有有界的键维数,否则你制备的是一个截断的替身,而非精确态。
  • 它适配链状结构。MPS 形式对应格点的一维排布;它天然契合一维系统以及长程纠缠有限的态。
  • 它是一种构件。近似 MPS 态常常作为后续变分或演化步骤的高质量起点,而非目的本身。

对照代码理解 逐张量编码

请对照原理来读这段代码。qalgora.tensor.to_mps(target_state, max_bond_dim=2) 把目标压缩为 MPS,并把键维数上限设为 χ = 2——这便是保真度/深度的旋钮。χ = 2 时每个张量对应一个双量子比特幺正算符,于是循环逐格点推进,每一句 qalgora.apply_unitary(gate, q[i], q[i + 1]) 都施加由一个 MPS 张量综合出的局部双量子比特幺正算符——即上文所述的每格点一个幺正算符的顺序制备。此代码是简化示意:χ 越大需要越宽的局部幺正算符(每步更多 ancilla/bond 比特),故此处的双量子比特形式专门对应 χ = 2。

import qalgora

# compress the target into an MPS, then synthesize gates tensor-by-tensor
# (max_bond_dim=2 is a simplified illustration: chi=2 maps to 2-qubit unitaries)
mps = qalgora.tensor.to_mps(target_state, max_bond_dim=2)

@qalgora.kernel
def prepare(mps_gates: list[list[float]]):
    q = qalgora.qvector(len(mps_gates) + 1)
    for i, gate in enumerate(mps_gates):
        qalgora.apply_unitary(gate, q[i], q[i + 1])   # local 2-qubit unitary
规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。
权衡
键维数越大,保真度越高,但电路也越深。应选取满足交叠目标的最小键维数。
规范接口·暂未内置
qalgora.tensor.to_mps 以及示意性的等距编译辅助函数 compile_mps_isometriesapply_isometry 均为规范接口·暂未内置;开源参考实现尚未提供。