# Demo 1:Shor N=15 > 第 4 章 经典量子算法 · [本章演示](index.md) · [代码演示总索引](../index.md) **可视化**:3 子图(U_7 矩阵、周期轨道、QPE 相位) —— 因子分解 15=3×5 全流程 + 周期读取 **对应教程**:[第 4 章 经典量子算法 中相关小节](https://tutorial.chenzhaoyun.com/quantum-tutorial/ch04-classic-algorithms/) · 依赖安装:`pip install "unified-quantum[visualization,simulation]"` ## 实现要点 经典部分: 用 numpy 构造 U_7 排列矩阵 (4-qubit)、演示本征态 |1> -> |7> -> |4> -> |13> -> |1> 的周期 r=4, 并计算 QPE 输出相位直方图(峰值应出现在 0, 1/4, 1/2, 3/4)。 量子部分: 用 uniqc 跑 4-qubit Hadamard 均匀叠加电路以及 |1> 本征态的制备和测量, 作为真机的 sanity check。 ## 完整源码 ```{literalinclude} 01_shor_N15.py :language: python :linenos: :caption: demos/ch04-classic-algorithms/01_shor_N15.py ``` ## 运行结果 ![Demo 1:Shor N=15](01_shor_N15.png) ## 运行方式 ```bash # 仓库根目录执行;输出 PNG 到 demos/ch04-classic-algorithms/01_shor_N15.png,关键统计到 stdout .venv/bin/python3 demos/ch04-classic-algorithms/01_shor_N15.py ``` --- [← 本章演示](index.md) · [↑ 代码演示总索引](../index.md) · [⌂ 教程门户](https://tutorial.chenzhaoyun.com/)