feat(quantum): Q7 density linear algebra and advanced SVG viz

Add density-matrix ops (partial trace, Hermitian eig, Schmidt, Pauli
expect, purity/fidelity, kron) and hinton/city/qsphere/paulivec/multibloch
draw kinds via plugins/quantum ABI, with EN/ZH L1 and gold smokes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-28 14:23:24 +08:00
1 parent 4956460773
commit 88fe076216
13 files changed
+1871 -8

No files matched your search

+96 -1
View File
@@ -18,6 +18,33 @@ Load the ABI v2 `quantum` plugin once.
> sys.exit code=1
****
## kron
+ `a`
+ `b`
Tensor product of two states or square matrices.
> ensure_plugin
**> quantum_kron a=`a` b=`b`**
## schmidt
+ `state`
+ `cut`=1
Schmidt decomposition of a pure state / circuit across `cut` (subsystem A = low qubits).
> ensure_plugin
**> quantum_schmidt state=`state` cut=`cut`**
## fidelity
+ `a`
+ `b`
Pure-state fidelity |⟨a|b⟩|².
> ensure_plugin
**> quantum_fidelity a=`a` b=`b`**
# circuit
+ `qubits`=1
+ `steps`=None
@@ -165,10 +192,30 @@ Sample computational-basis shots (deterministic with `seed=`). Applies circuit `
+ `kind`=circuit
+ `qubit`=0
Circuit rail / probability bars / Bloch sphere SVG (`kind=circuit|probs|bloch`). Records into view/CLI plots via host `record_plot`.
Circuit rail / probability bars / Bloch / advanced state plots (`kind=circuit|probs|bloch|hinton|city|density|paulivec|qsphere|multibloch`). Records into view/CLI plots via host `record_plot`.
**> quantum_draw_circuit circuit=`self` path=`path` kind=`kind` qubit=`qubit`**
## density
Pure-state density matrix ρ=|ψ⟩⟨ψ| after ideal simulate.
**> density state=`self`**
## expect
+ `obs`
Pauli string (left = high bit) or matrix expectation on the ideal state.
**> quantum_density_expect density=`self` obs=`obs`**
## schmidt
+ `cut`=1
Schmidt / singular values across a bipartition (`cut` = qubits in subsystem A, low bits).
**> quantum_schmidt state=`self` cut=`cut`**
# gate
+ `name`=None
+ `theta`=None
@@ -196,3 +243,51 @@ Named built-in gate (`name=H`) or custom unitary from `matrix=` (nested list or
Gate glyph or complex-matrix heatmap (`kind=gate|matrix`). Records via host `record_plot`.
**> quantum_gate_draw gate=`self` path=`path` kind=`kind`**
# density
+ `state`=None
+ `matrix`=None
Density matrix from a state/circuit (`state=`) or an explicit Hermitian `matrix=` (≤6 qubits).
> ensure_plugin
1. `matrix`
**> quantum_density_from_matrix matrix=`matrix`**
2. *
**> quantum_density_from_state state=`state`**
## matrix
**> quantum_density_matrix density=`self`**
## purity
Tr(ρ²).
**> quantum_density_purity density=`self`**
## partial_trace
+ `keep`
Keep listed qubits (LSB=0); trace out the rest.
**> quantum_density_partial_trace density=`self` keep=`keep`**
## eig
Hermitian spectrum → `{eigenvalues, eigenvectors}`.
**> quantum_density_eig density=`self`**
## expect
+ `obs`
**> quantum_density_expect density=`self` obs=`obs`**
## draw
+ `path`=None
+ `kind`=hinton
Hinton / city / density-cells / Pauli vector SVG (`kind=hinton` or city or density or paulivec).
**> quantum_density_draw density=`self` path=`path` kind=`kind`**
+94 -1
View File
@@ -18,6 +18,31 @@ import json:lib/json.mq.md
> sys.exit code=1
****
## 张量积
+ `左`
+ `右`
两态或方阵的张量积。
> 确保插件
**> quantum_kron a=`左` b=`右`**
## 施密特分解
+ `态`
+ `分割`=1
> 确保插件
**> quantum_schmidt state=`态` cut=`分割`**
## 保真度
+ `左`
+ `右`
纯态保真度 |⟨a|b⟩|²。
> 确保插件
**> quantum_fidelity a=`左` b=`右`**
# 电路
+ `比特数`=1
+ `步骤`=None
@@ -165,10 +190,30 @@ import json:lib/json.mq.md
+ `种类`=circuit
+ `比特`=0
电路轨线 / 概率条 / 布洛赫球(种类 circuit、probs 或 bloch)。经 record_plot 进入 view/CLI plots。
电路轨线 / 概率条 / 布洛赫 / 高级态图(种类 circuit、probs、bloch、hinton、city、density、paulivec、qsphere、multibloch)。经 record_plot 进入 view/CLI plots。
**> quantum_draw_circuit circuit=`self` path=`路径` kind=`种类` qubit=`比特`**
## 密度
理想模拟后的纯态密度矩阵 ρ=|ψ⟩⟨ψ|。
**> 密度 态=`self`**
## 期望
+ `可观测量`
Pauli 串(左端=高比特)或矩阵期望值。
**> quantum_density_expect density=`self` obs=`可观测量`**
## 施密特
+ `分割`=1
二分施密特分解(`分割`=子系统 A 的比特数,低位)。
**> quantum_schmidt state=`self` cut=`分割`**
# 门
+ `名`=None
+ `参数`=None
@@ -196,3 +241,51 @@ import json:lib/json.mq.md
门符号或复矩阵热力图(`种类=gate|matrix`)。经 `record_plot` 记录。
**> quantum_gate_draw gate=`self` path=`路径` kind=`种类`**
# 密度
+ `态`=None
+ `矩阵`=None
由态/电路(`态=`)或显式厄米 `矩阵=` 构造密度矩阵(≤6 比特)。
> 确保插件
1. `矩阵`
**> quantum_density_from_matrix matrix=`矩阵`**
2. *
**> quantum_density_from_state state=`态`**
## 矩阵
**> quantum_density_matrix density=`self`**
## 纯度
Tr(ρ²)。
**> quantum_density_purity density=`self`**
## 部分迹
+ `保留`
保留所列比特(LSB=0),对其余求迹。
**> quantum_density_partial_trace density=`self` keep=`保留`**
## 本征
厄米谱 → `{eigenvalues, eigenvectors}`。
**> quantum_density_eig density=`self`**
## 期望
+ `可观测量`
**> quantum_density_expect density=`self` obs=`可观测量`**
## 绘图
+ `路径`=None
+ `种类`=hinton
Hinton / 城市 / 密度格 / 泡利向量 SVG(`种类=hinton` 或 city / density / paulivec)。
**> quantum_density_draw density=`self` path=`路径` kind=`种类`**