# Demo 2:态层析 > 第 7 章 量子信息 · [本章演示](index.md) · [代码演示总索引](../index.md) **可视化**:3D 球+3 子图 —— 3 态 3 基重建 Bloch 矢量 **对应教程**:[第 7 章 量子信息 中相关小节](https://tutorial.chenzhaoyun.com/quantum-tutorial/ch07-quantum-info/) · 依赖安装:`pip install "unified-quantum[visualization,simulation]"` ## 实现要点 核心:对 3 个单 qubit 态做三轴 (X, Y, Z) 投影测量,重建 Bloch 矢量 并与理论值比较。 - |+> = H|0> (target Bloch: (1, 0, 0)) - |+i> = S·H|0> (target Bloch: (0, 1, 0)) - |psi_tt> = RY(pi/3) P(pi/4) |0> (general mixed-axis state) 测量约定: - Z 基: 直接 measure(0) - X 基: H(0) 后 measure,⟨X⟩ = 2·P(0) - 1 - Y 基: S†(0) H(0) 后 measure,⟨Y⟩ = 2·P(0) - 1 ## 完整源码 ```{literalinclude} 02_state_tomography.py :language: python :linenos: :caption: demos/ch07-quantum-info/02_state_tomography.py ``` ## 运行结果 ![Demo 2:态层析](02_state_tomography.png) ## 运行方式 ```bash # 仓库根目录执行;输出 PNG 到 demos/ch07-quantum-info/02_state_tomography.png,关键统计到 stdout .venv/bin/python3 demos/ch07-quantum-info/02_state_tomography.py ``` --- [← 本章演示](index.md) · [↑ 代码演示总索引](../index.md) · [⌂ 教程门户](https://tutorial.chenzhaoyun.com/)