Skip to content

Commit 26f1887

Browse files
Suxecaclaude
andcommitted
【创新应用】新增 SU(2) detector-response toy simulation demo
新增一个自包含的 SU(2) 对称量子模拟教程示例,包含数值参考观测量、OpenQASM 线路原型和 pyQPanda CPUQVM 示例。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 5f973ef commit 26f1887

23 files changed

Lines changed: 1514 additions & 0 deletions

SU2DetectorResponseToy/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
__pycache__/
2+
.pytest_cache/
3+
.venv/
4+
*.pyc
5+
*.pyo
6+
outputs*/
7+
Tutorials/SU2DetectorResponseToy/outputs*/

SU2DetectorResponseToy/README.md

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
# SU(2) Detector Response Toy Simulation
2+
3+
## 项目简介
4+
5+
本项目是一个面向量子算法创新应用的 SU(2) 对称量子多体模拟示例。项目使用小规模 color-chain toy Hamiltonian,展示 SU(2) singlet 态制备、singlet/triplet sector 能谱分析、局域 color-singlet quench 以及左右探测点的 connected color correlation。
6+
7+
该示例默认使用 4 到 8 个 qubit,可在本地完成精确对角化扫描、图表生成和基础线路导出;同时提供 pyQPanda CPUQVM 示例,便于学习和迁移到 pyQPanda 生态。
8+
9+
本项目定位为一个自包含教程型贡献:NumPy 精确对角化部分提供可复现实验参考量,pyQPanda CPUQVM 脚本展示对应的 singlet 态制备与局域 probe 线路构造方式。
10+
11+
## 任务类型
12+
13+
```text
14+
【创新应用】SU(2) detector-response toy simulation demo
15+
```
16+
17+
## 主要功能
18+
19+
- 构造 SU(2)-scalar color interaction:$S_i \cdot S_j$。
20+
- 扫描 dimerization 参数下的低能谱结构。
21+
- 计算 total spin sector,用于区分 singlet 与 triplet 能级。
22+
- 对中心 bond 施加 color-singlet local quench。
23+
- 计算 quench energy injection 与 low-level spectral weights。
24+
- 计算左右 detector sites 的 connected color correlation。
25+
- 导出 singlet-pair state preparation 与 color-quench probe 的 OpenQASM 原型。
26+
- 提供 pyQPanda CPUQVM 示例脚本。
27+
28+
## 目录结构
29+
30+
```text
31+
SU2DetectorResponseToy/
32+
├── README.md
33+
├── SUBMISSION_CHECKLIST.md
34+
├── contest_pitch.txt
35+
├── requirements.txt
36+
├── run_demo.py
37+
├── make_plots.py
38+
├── pyqpanda_demo.py
39+
├── src/eec_toy/
40+
├── tests/test_eec_toy.py
41+
└── Tutorials/SU2DetectorResponseToy/
42+
├── README.md
43+
├── DERIVATION.md
44+
├── CONTRIBUTION_NOTE.md
45+
├── PR_DESCRIPTION.md
46+
├── run_tutorial.py
47+
├── make_tutorial_plots.py
48+
└── pyqpanda_cpuqvm_example.py
49+
```
50+
51+
## 安装依赖
52+
53+
```bash
54+
pip install -r requirements.txt
55+
```
56+
57+
依赖包括:
58+
59+
```text
60+
numpy
61+
matplotlib
62+
pyqpanda
63+
```
64+
65+
其中 `pyqpanda` 用于 CPUQVM 示例;如果只运行数值扫描和画图,`numpy``matplotlib` 即可。
66+
67+
## 赛事指定工具使用说明
68+
69+
本项目使用 pyQPanda CPUQVM 构造并运行 singlet-pair preparation 与 central color-quench probe 线路。NumPy 精确对角化部分用于生成参考观测量,帮助解释和验证量子线路示例的物理含义;pyQPanda CPUQVM 部分用于展示可执行的量子编程入口;OpenQASM 导出用于连接线路原型与后续模拟器或硬件迁移。
70+
71+
因此,本项目的设计关系为:
72+
73+
```text
74+
NumPy exact diagonalization -> reference observables
75+
OpenQASM export -> portable circuit prototype
76+
pyQPanda CPUQVM -> executable circuit realization
77+
```
78+
79+
## 运行示例
80+
81+
### 1. 运行 SU(2) 扫描
82+
83+
```bash
84+
python run_demo.py --num-qubits 6 --points 17 --out outputs_su2_n6
85+
```
86+
87+
示例终端输出如下:
88+
89+
```text
90+
SU(2) detector-response toy simulation 完成
91+
输出目录:outputs_su2_n6
92+
singlet-triplet gap 最小窗口:delta = -0.750000
93+
detector slope 诊断窗口:delta = -0.562500
94+
fidelity dip 诊断窗口:delta = -0.187500
95+
detector color correlation = -0.073882
96+
```
97+
98+
### 2. 生成图表
99+
100+
```bash
101+
python make_plots.py --input outputs_su2_n6/summary.json --out outputs_su2_n6/figures
102+
```
103+
104+
### 3. 运行 tutorial 入口
105+
106+
```bash
107+
python Tutorials/SU2DetectorResponseToy/run_tutorial.py --num-qubits 6 --points 17
108+
python Tutorials/SU2DetectorResponseToy/make_tutorial_plots.py
109+
```
110+
111+
### 4. 运行 pyQPanda CPUQVM 示例
112+
113+
```bash
114+
python pyqpanda_demo.py --num-qubits 6 --shots 1000
115+
```
116+
117+
或:
118+
119+
```bash
120+
python Tutorials/SU2DetectorResponseToy/pyqpanda_cpuqvm_example.py --num-qubits 6 --shots 1000
121+
```
122+
123+
运行后会输出 bitstring counts,并保存为 JSON 文件。示例终端输出如下:
124+
125+
```text
126+
pyQPanda CPUQVM SU(2) singlet-pair demo 完成
127+
输出文件:outputs_pyqpanda/counts.json
128+
非零 bitstring 数:...
129+
```
130+
131+
## 输出文件
132+
133+
运行扫描后会生成:
134+
135+
```text
136+
su2_spectrum_scan.csv
137+
summary.json
138+
singlet_triplet_gap_chart.txt
139+
detector_slope_chart.txt
140+
fidelity_loss_chart.txt
141+
state_prep_singlet_pairs.qasm
142+
color_quench_probe.qasm
143+
```
144+
145+
运行画图脚本后会生成:
146+
147+
```text
148+
singlet_triplet_gap.png
149+
detector_color_correlation.png
150+
fidelity_loss.png
151+
quench_delta_energy.png
152+
summary_panels.png
153+
```
154+
155+
图表含义:
156+
157+
- `singlet_triplet_gap.png`:展示最低 singlet 与 triplet sector 的能量差随参数变化的趋势。
158+
- `detector_color_correlation.png`:展示左右 detector sites 的 connected color correlation。
159+
- `fidelity_loss.png`:展示相邻参数点之间 ground-state overlap 的变化。
160+
- `quench_delta_energy.png`:展示 central color-singlet quench 后的能量注入。
161+
- `summary_panels.png`:汇总主要诊断量,便于快速检查教程输出。
162+
163+
## 数值诊断量与线路对应关系
164+
165+
数值扫描用于生成参考观测量,pyQPanda / OpenQASM 部分用于展示可迁移的线路构造入口。
166+
167+
| 数值或线路对象 | 物理含义 | 主要输出文件 | pyQPanda / OpenQASM 对应关系 |
168+
|---|---|---|---|
169+
| singlet-pair state preparation | SU(2) singlet 初态构造 | `state_prep_singlet_pairs.qasm` | pyQPanda 示例中的 pair preparation 线路 |
170+
| singlet/triplet sector energies | sector-resolved spectroscopy | `su2_spectrum_scan.csv`, `singlet_triplet_gap_chart.txt` | 作为后续 VQE 或谱测量线路的 reference observable |
171+
| central color-singlet quench response | 中心 bond 上的 SU(2)-scalar 局域扰动响应 | `summary.json`, `quench_delta_energy.png` | `color_quench_probe.qasm` 与 CPUQVM local probe circuit |
172+
| detector connected color correlation | 左右 detector sites 的 connected color response | `detector_slope_chart.txt`, `detector_color_correlation.png` | 给出后续 measurement circuit 的目标观测量 |
173+
| ground-state fidelity loss | 参数扫描中基态结构变化的参考诊断 | `fidelity_loss_chart.txt`, `fidelity_loss.png` | 可用于验证参数化线路扫描的一致性 |
174+
175+
## 数学模型概述
176+
177+
每个 qubit 表示一个 fundamental SU(2) color spin。两体相互作用取 SU(2)-scalar 形式:
178+
179+
$$
180+
S_i \cdot S_j = \frac{X_i X_j + Y_i Y_j + Z_i Z_j}{4}
181+
$$
182+
183+
模型 Hamiltonian 为:
184+
185+
$$
186+
\begin{aligned}
187+
H(\delta)
188+
&= \sum_i J\left[1 + \delta(-1)^i\right] S_i \cdot S_{i+1} \\
189+
&\quad + \kappa \sum_{i<j} e^{-|i-j|/\xi} S_i \cdot S_j .
190+
\end{aligned}
191+
$$
192+
193+
其中 $\delta$ 控制 dimerization,$\kappa$ 和 $\xi$ 控制长程 color interaction 的强度与衰减。
194+
195+
## 项目亮点
196+
197+
- 物理结构保留 SU(2) 对称性。
198+
- 输出 singlet/triplet sector resolved spectroscopy。
199+
- 以 connected color correlation 作为 detector-response 诊断量。
200+
- 示例规模小,便于教学、复现实验和算法展示。
201+
- 同时包含数值模拟、图表生成、OpenQASM 导出和 pyQPanda CPUQVM 示例。
202+
203+
## 验证方式
204+
205+
```bash
206+
python -m py_compile run_demo.py make_plots.py pyqpanda_demo.py
207+
python Tutorials/SU2DetectorResponseToy/run_tutorial.py --num-qubits 6 --points 17
208+
python Tutorials/SU2DetectorResponseToy/make_tutorial_plots.py
209+
python -c "import sys; sys.path.insert(0, 'tests'); import test_eec_toy as t; [getattr(t, n)() for n in dir(t) if n.startswith('test_')]; print('tests ok')"
210+
```
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# 提交检查清单
2+
3+
## PR 标题
4+
5+
```text
6+
【创新应用】SU(2) detector-response toy simulation demo
7+
```
8+
9+
## 文件清单
10+
11+
- [x] `README.md`:项目总说明
12+
- [x] `contest_pitch.txt`:项目简介与应用场景
13+
- [x] `requirements.txt`:依赖列表
14+
- [x] `run_demo.py`:主扫描入口
15+
- [x] `make_plots.py`:图表生成入口
16+
- [x] `pyqpanda_demo.py`:pyQPanda CPUQVM 示例入口
17+
- [x] `src/eec_toy/`:SU(2) toy simulation 模块
18+
- [x] `tests/test_eec_toy.py`:基础测试
19+
- [x] `Tutorials/SU2DetectorResponseToy/README.md`:教程说明
20+
- [x] `Tutorials/SU2DetectorResponseToy/DERIVATION.md`:模型原理说明
21+
- [x] `Tutorials/SU2DetectorResponseToy/CONTRIBUTION_NOTE.md`:贡献说明
22+
- [x] `Tutorials/SU2DetectorResponseToy/PR_DESCRIPTION.md`:PR 正文草稿
23+
- [x] `Tutorials/SU2DetectorResponseToy/run_tutorial.py`:教程运行入口
24+
- [x] `Tutorials/SU2DetectorResponseToy/make_tutorial_plots.py`:教程画图入口
25+
- [x] `Tutorials/SU2DetectorResponseToy/pyqpanda_cpuqvm_example.py`:教程版 pyQPanda 示例
26+
27+
## 本地验证命令
28+
29+
```bash
30+
python -m py_compile run_demo.py make_plots.py pyqpanda_demo.py
31+
python -m py_compile Tutorials/SU2DetectorResponseToy/run_tutorial.py Tutorials/SU2DetectorResponseToy/make_tutorial_plots.py Tutorials/SU2DetectorResponseToy/pyqpanda_cpuqvm_example.py
32+
python Tutorials/SU2DetectorResponseToy/run_tutorial.py --num-qubits 6 --points 17
33+
python Tutorials/SU2DetectorResponseToy/make_tutorial_plots.py
34+
python -c "import sys; sys.path.insert(0, 'tests'); import test_eec_toy as t; [getattr(t, n)() for n in dir(t) if n.startswith('test_')]; print('tests ok')"
35+
```
36+
37+
## 输出文件检查
38+
39+
运行后生成的 `outputs/``outputs_su2_n6/``__pycache__/``*.pyc` 请排除在提交内容之外。
40+
41+
## 提交前检查
42+
43+
- [ ] README 可以独立说明项目目的与运行方式。
44+
- [ ] tutorial 文档可以独立运行。
45+
- [ ] `DERIVATION.md` 只说明模型原理与算法设计。
46+
- [ ] PR 正文使用中文为主,描述清楚教程定位、创新点、运行方式和测试方式。
47+
- [ ] README 已说明 `pyqpanda` 只用于 CPUQVM 示例,数值教程可用 NumPy 与 Matplotlib 运行。
48+
- [ ] README 已说明 NumPy reference、OpenQASM prototype 与 pyQPanda CPUQVM execution 的关系。
49+
- [ ] pyQPanda CPUQVM 示例说明了 bitstring counts 输出位置。
50+
- [ ] 提交内容不包含本地输出、缓存文件或个人配置。
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
outputs*/
2+
__pycache__/
3+
*.pyc
4+
*.pyo
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Contribution Note: SU(2) Detector Response Toy Simulation
2+
3+
## PR 标题
4+
5+
```text
6+
【创新应用】SU(2) detector-response toy simulation demo
7+
```
8+
9+
## 提交类型
10+
11+
```text
12+
创新应用 / quantum simulation example
13+
```
14+
15+
## 项目概述
16+
17+
本贡献提供一个小规模 SU(2)-对称量子多体模拟示例。项目使用 color-chain toy Hamiltonian 展示 SU(2)-scalar interaction、singlet/triplet sector spectroscopy、局域 color-singlet quench 和 detector connected color correlation。
18+
19+
该示例面向教学、算法展示和 pyQPanda 线路迁移,默认规模为 4 到 8 个 qubit,可在本地快速运行。
20+
21+
贡献定位为教程型创新应用:数值扫描部分提供参考观测量,pyQPanda CPUQVM 示例提供对应线路构造入口。
22+
23+
## 主要内容
24+
25+
1. `Tutorials/SU2DetectorResponseToy/README.md`
26+
- 教程入口与运行方式。
27+
28+
2. `Tutorials/SU2DetectorResponseToy/DERIVATION.md`
29+
- SU(2) 模型原理、sector 诊断和 detector correlation 说明。
30+
31+
3. `Tutorials/SU2DetectorResponseToy/run_tutorial.py`
32+
- 运行 SU(2) spectrum / detector correlation 扫描。
33+
34+
4. `Tutorials/SU2DetectorResponseToy/make_tutorial_plots.py`
35+
- 根据扫描结果生成图表。
36+
37+
5. `Tutorials/SU2DetectorResponseToy/pyqpanda_cpuqvm_example.py`
38+
- pyQPanda CPUQVM 线路示例。
39+
40+
6. `src/eec_toy/`
41+
- 可复用 SU(2) toy simulation 模块。
42+
43+
## 模型形式
44+
45+
Hamiltonian 由 SU(2)-scalar interaction 构成:
46+
47+
$$
48+
S_i \cdot S_j = \frac{X_i X_j + Y_i Y_j + Z_i Z_j}{4}
49+
$$
50+
51+
扫描参数 $\delta$:
52+
53+
$$
54+
\begin{aligned}
55+
H(\delta)
56+
&= \sum_i J\left[1 + \delta(-1)^i\right] S_i \cdot S_{i+1} \\
57+
&\quad + \kappa \sum_{i<j} e^{-|i-j|/\xi} S_i \cdot S_j .
58+
\end{aligned}
59+
$$
60+
61+
核心输出包括:
62+
63+
- singlet/triplet sector energies。
64+
- singlet-triplet gap。
65+
- ground-state fidelity loss。
66+
- central color-singlet quench response。
67+
- left-right detector connected color correlation。
68+
69+
## 创新点
70+
71+
- 使用 SU(2)-对称 toy model 展示 color-sector 诊断。
72+
- 将谱结构、局域 quench 和 detector correlation 放在同一个小规模示例中。
73+
- 同时提供数值扫描、图表、OpenQASM 线路和 pyQPanda CPUQVM 示例。
74+
- 示例规模小,便于复现和教学。
75+
76+
## 本地验证
77+
78+
```bash
79+
python Tutorials/SU2DetectorResponseToy/run_tutorial.py --num-qubits 6 --points 17
80+
python Tutorials/SU2DetectorResponseToy/make_tutorial_plots.py
81+
python -c "import sys; sys.path.insert(0, 'tests'); import test_eec_toy as t; [getattr(t, n)() for n in dir(t) if n.startswith('test_')]; print('tests ok')"
82+
```

0 commit comments

Comments
 (0)