# Demo 1:K3 量子行走 > 第 12 章 量子图算法 · [本章演示](index.md) · [代码演示总索引](../index.md) **可视化**:双图(轨迹+经典对照) —— 4 步位置概率演化 **对应教程**:[第 12 章 量子图算法 中相关小节](https://tutorial.chenzhaoyun.com/quantum-tutorial/ch12-quantum-graphs/) · 依赖安装:`pip install "unified-quantum[visualization,simulation]"` ## 实现要点 核心:K3 (3-node complete graph) 也是 C3 (3-cycle)。一个 qubit 硬币 (q3) 加三个 一元编码位置 q2 q1 q0,节点 k 的"1"在 q[k]。每一步 = H(q3) 然后受控移位: coin=0 → INC (|001⟩→|010⟩→|100⟩→|001⟩),coin=1 → DEC (逆序)。INC 与 DEC 都分解成两个 SWAP(q0,q1) 和 SWAP(q0,q2),在 uniqc 中再用 CSWAP(q3,…) 做受控选择。和经典随机游走对比:量子游走呈现单向漂移(来自单向硬币的干涉), 而经典游走在三节点环上保持振荡。 ## 完整源码 ```{literalinclude} 01_graph_walk.py :language: python :linenos: :caption: demos/ch12-quantum-graphs/01_graph_walk.py ``` ## 运行结果 ![Demo 1:K3 量子行走](01_graph_walk.png) ## 运行方式 ```bash # 仓库根目录执行;输出 PNG 到 demos/ch12-quantum-graphs/01_graph_walk.png,关键统计到 stdout .venv/bin/python3 demos/ch12-quantum-graphs/01_graph_walk.py ``` --- [← 本章演示](index.md) · [↑ 代码演示总索引](../index.md) · [⌂ 教程门户](https://tutorial.chenzhaoyun.com/)