# Demo 3:Childs-Goldstone 空间搜索 > 第 12 章 量子图算法 · [本章演示](index.md) · [代码演示总索引](../index.md) **可视化**:3 子图 —— C4 + γ=1/√2 + Rabi 振荡 **对应教程**:[第 12 章 量子图算法 中相关小节](https://tutorial.chenzhaoyun.com/quantum-tutorial/ch12-quantum-graphs/) · 依赖安装:`pip install "unified-quantum[visualization,simulation]"` ## 实现要点 核心:4-环 C4 上做 Childs-Goldstone 连续时间空间搜索。Hamiltonian H = -γ A - |w⟩⟨w| 取 γ ≈ 1/√N = 1/2 (对 C_N 的渐近最优 γ 是 1/(2 sin(π/N)),对 N=4 ≈ 0.707), 初态 |s⟩ = (1/2) Σ_i |i⟩ 是 A 的本征态(本征值 2)。H 把 |s⟩ 局限在 span{|s⟩, |w⟩} 的 2 维子空间里做 Rabi 振荡;振幅在 t ≈ π√N/2 时刻翻转到 |w⟩,P(target) 接近 1。相比之下,经典随机游走 P_t = T^t|s⟩ 需要 O(N)=4 步 才能把概率抬到 1/4 量级。这里画 P(target) vs t 的连续时间量子振荡曲线, 并叠加经典随机游走的概率作为参考;同时画 4 个节点振幅 |⟨i|ψ(t)⟩|² 的时间演化。 ## 完整源码 ```{literalinclude} 03_spatial_search.py :language: python :linenos: :caption: demos/ch12-quantum-graphs/03_spatial_search.py ``` ## 运行结果 ![Demo 3:Childs-Goldstone 空间搜索](03_spatial_search.png) ## 运行方式 ```bash # 仓库根目录执行;输出 PNG 到 demos/ch12-quantum-graphs/03_spatial_search.png,关键统计到 stdout .venv/bin/python3 demos/ch12-quantum-graphs/03_spatial_search.py ``` --- [← 本章演示](index.md) · [↑ 代码演示总索引](../index.md) · [⌂ 教程门户](https://tutorial.chenzhaoyun.com/)