# Demo 1:QAOA K4 MaxCut > 第 14 章 优化与数值量子算法 · [本章演示](index.md) · [代码演示总索引](../index.md) **可视化**:双图(热图+top cuts) —— 11×11 网格 + 爬山 **对应教程**:[第 14 章 优化与数值量子算法 中相关小节](https://tutorial.chenzhaoyun.com/quantum-tutorial/ch14-optimization-numerics/) · 依赖安装:`pip install "unified-quantum[visualization,simulation]"` ## 实现要点 核心:K4 = 4-node complete graph, 6 edges. We scan the (γ, β) landscape for p=1 QAOA, plot ⟨H_C⟩ as a contour/heatmap, overlay a classical hill-climb trajectory that pushes past the grid optimum, then histogram the dominant bitstrings at the final (γ*, β*). For K4 the optimal cut = 4 and QAOA p=1 typically attains ≈ 0.92 approximation ratio (Farhi et al. 2014). ## 完整源码 ```{literalinclude} 01_qaoa_maxcut_4node.py :language: python :linenos: :caption: demos/ch14-optimization-numerics/01_qaoa_maxcut_4node.py ``` ## 运行结果 ![Demo 1:QAOA K4 MaxCut](01_qaoa_maxcut_4node.png) ## 运行方式 ```bash # 仓库根目录执行;输出 PNG 到 demos/ch14-optimization-numerics/01_qaoa_maxcut_4node.png,关键统计到 stdout .venv/bin/python3 demos/ch14-optimization-numerics/01_qaoa_maxcut_4node.py ``` --- [← 本章演示](index.md) · [↑ 代码演示总索引](../index.md) · [⌂ 教程门户](https://tutorial.chenzhaoyun.com/)