谱线路的算子级合成优化¶
oracq.algorithms.common.spectral_synthesis
Operator-level circuit synthesis optimizations (arXiv:2509.08807 appendix D).
This implements the paper's three logical-resource optimizations while preserving the unitary semantics exactly:
Uniformly controlled rotations, UCR: rewrite the multi-controlled rotation tree of a state preparation into plain rotations plus a CNOT ladder, eliminating multi-controlled Toffoli gates;
Similar-group merging, match by signal / similar group: merge terms of a linear combination that differ only by a global sign or a scalar factor into one term, absorbing the coefficient into the preparation amplitudes;
Fan-out phase grid: rewrite the controlled-phase layer of an FBBE into single-qubit rotations plus fan-out CNOTs, eliminating controlled rotations, see Figure 9(a2) of the paper.
Each construction is compared elementwise against the naive construction in tests/core/test_spectral_synthesis.py, and estimate_resources verifies the resource reduction.
- oracq.algorithms.common.spectral_synthesis.uniformly_controlled_prep(amplitudes, *, name=None)[源代码]¶
UCR state preparation: unitarily equivalent to gate_state_prep, without multi-controlled rotations.
Each layer's 2^d controlled Ry rotations are rewritten into 2^d single-qubit Ry rotations and 2^d CNOTs; the complex phases are still written by controlled gphase.
- 参数:
amplitudes -- Complex amplitude sequence of the target state, with power-of-two length, not all zero.
name -- Name of the generated preparation module; generated automatically when omitted.
- 返回:
State preparation handle containing only single-qubit rotations and CNOTs.
- 返回类型:
- oracq.algorithms.common.spectral_synthesis.merge_similar(terms)[源代码]¶
Merge linear-combination terms by block-encoding identity, match by signal / similar group.
Terms with identical operations, including the case differing only by the global sign −1, merge into one term with summed coefficients; terms whose coefficient vanishes are dropped. This is an exact algebraic rewrite: the LCU α and the angle block are unchanged, while the SELECT branch count, the preparation amplitude tree and the controlled call count all decrease.
- 参数:
terms -- Linear-combination term sequence of, coefficient and block encoding, pairs; zero-coefficient terms are dropped directly.
- 返回:
Term list merged by block-encoding identity with summed coefficients.
- 返回类型:
list[tuple[complex, BlockEncoding]]
- oracq.algorithms.common.spectral_synthesis.fanout_spectral_diagonal(spectrum, width)[源代码]¶
Fan-out form of an FBBE: the controlled-phase grid is rewritten as rotations plus fan-out CNOTs.
Figure 9(a2) of the paper: each spectral-bit-controlled phase layer becomes one half-angle rotation per target bit, a fan-out CNOT, a negated half-angle rotation and another fan-out CNOT; CNOTs sharing the same control bit form a multi-target fan-out X, a native operation of surface code lattice surgery. In the RIR the fan-out appears as a same-source xor sequence. Elementwise equivalent to the sequential variant of spectral_diagonal.
- 参数:
spectrum -- Mapping from spectral frequencies to complex coefficients; the frequencies are interpreted as integers mod 2^width.
width -- Target register bit width, determining the phase angle denominator 2^width.
- 返回:
Spectral diagonal block encoding in fan-out form, with scale equal to the sum of absolute coefficient values.
- 返回类型: