Add formula-matrix custom gates and fix Variables modal in view.
Parse $$ pmatrix/[[…]] into executable matrices for quantum.gate matrix=, and make the vars panel open a rich modal without breaking the page script. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
505d478724
commit
d269ccb7e7
15 files changed
+1622
-162
No files matched your search
@@ -0,0 +1,49 @@
|
||||
# `ext/quantum` — 自定义酉门(公式矩阵 → 可施加)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | **Accepted · 已落地** |
|
||||
| 日期 | 2026-08-12 |
|
||||
| 父设计 | [ext-quantum.md](ext-quantum.md) |
|
||||
|
||||
---
|
||||
|
||||
## 1. 目标
|
||||
|
||||
作者用 `$$…$$`(或嵌套 list)写出酉矩阵 → `quantum.gate matrix=…` 得到可复用门句柄 → `` `qc`.apply gate=… qubits=… `` 施加到电路。
|
||||
|
||||
---
|
||||
|
||||
## 2. 公式矩阵
|
||||
|
||||
`$$` 围栏若含 `[[…]]` 或 `\begin{pmatrix}` / `\begin{bmatrix}`,在**解析期**求值为嵌套数值 list(非整棵 `Formula` 标量树)。
|
||||
|
||||
支持:
|
||||
|
||||
- ASCII:`[[1,0],[0,-1]]`、`(1/sqrt(2))*[[1,1],[1,-1]]`
|
||||
- LaTeX 子集:`\frac{…}{…}`、`\sqrt{…}`、`pmatrix` / `bmatrix`(`&` / `\\`)
|
||||
|
||||
复数:list 路径仍可用 `{re,im}` 或 `[re,im]`;公式路径本切片以实矩阵为主。
|
||||
|
||||
---
|
||||
|
||||
## 3. API
|
||||
|
||||
```markdown
|
||||
*`U` = > quantum.gate matrix=`H_matrix` name=U *
|
||||
# 或构造参数 matrix=;name 可选(默认 U)
|
||||
|
||||
*`qc` = > `qc`.apply gate=`U` qubits=0 *
|
||||
# qubits= 标量或 list;矩阵维数须为 2^k
|
||||
```
|
||||
|
||||
中文:`量子.门 矩阵=` / `` `qc`.施加 门= 比特= ``。
|
||||
|
||||
具名门仍可用 `name=H`;`matrix` / `matches_matrix` / `draw` 对自定义门同样有效。
|
||||
|
||||
---
|
||||
|
||||
## 4. 验收
|
||||
|
||||
- 公式(或 list)定义的 H 与内置 `H` 概率一致
|
||||
- EN/ZH 金样
|
||||
@@ -131,7 +131,7 @@ marqdo ext add quantum
|
||||
|
||||
### 4.3 公式面(对齐 math 精神,不抢 math 实现)
|
||||
|
||||
允许用 `` `G` = `` + `$$…$$` 书写门矩阵或态(**展示 + 教学核对**):
|
||||
允许用 `` `G` = `` + `$$…$$` 书写门矩阵(**可执行**,见 [ext-quantum-custom-gate.md](ext-quantum-custom-gate.md)):
|
||||
|
||||
````markdown
|
||||
`H_matrix` =
|
||||
@@ -139,16 +139,14 @@ $$
|
||||
\frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\1&-1\end{pmatrix}
|
||||
$$
|
||||
|
||||
*`H` = > quantum.gate name=H *
|
||||
*`U` = > quantum.gate matrix=`H_matrix` *
|
||||
*`qc` = > `qc`.apply gate=`U` qubits=0 *
|
||||
*`ok` = > `H`.matches_matrix matrix=`H_matrix` *
|
||||
````
|
||||
|
||||
- v1:**具名门**以插件内置酉矩阵为准;`matches_matrix` 为可选数值核对(容差)。
|
||||
- 叙述区无名 `$$` 仍只是注释(同 [stdlib-math.md](stdlib-math.md) §2.4)。
|
||||
- **不**要求核心 `Value::Formula` 理解量子;矩阵核对可走「公式 ASCII/LaTeX → 插件解析子集」或作者显式 `matrix=` 表。
|
||||
|
||||
**v1 优先路径:** 电路用**表 + 方法**;`$$` 作文档展示;矩阵核对可放 **Q3**。
|
||||
|
||||
- v1:**具名门**以插件内置酉矩阵为准;`matrix=` 可从嵌套 list / `$$` 矩阵围栏构造自定义门。
|
||||
- `$$` 含 `[[…]]` 或 `\begin{pmatrix}` 时解析期求值为数值 list;标量公式仍为 `Formula`。
|
||||
- `matches_matrix` 仍可用于核对。
|
||||
---
|
||||
|
||||
## 5. 作者面 API(锁定草图)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | **Q0–Q5 最小 + Q5.5 振幅阻尼已落地**(更大 n / 完整开放系统另文) |
|
||||
| 状态 | **Q0–Q6 已落地**(含公式自定义门;更大 n / 完整开放系统另文) |
|
||||
| 日期 | 2026-08-12 |
|
||||
| **锁定设计** | [design/ext-quantum.md](../design/ext-quantum.md) |
|
||||
| 相关 | [ext-cli.md](../design/ext-cli.md) · [ext-abi.md](../design/ext-abi.md) · [stdlib-math.md](../design/stdlib-math.md) · [view.md](../design/view.md) |
|
||||
@@ -29,8 +29,9 @@
|
||||
| **Q4** | 概率条 / 布洛赫;`matches_matrix`;examples + 用户文档 | **done** |
|
||||
| **Q5** | 教学噪声 + barrier/measure/append/state — [ext-quantum-q5.md](../design/ext-quantum-q5.md) | **done(最小)** |
|
||||
| **Q5.5** | `amplitude_damping` 轨迹 — [ext-quantum-q5.5.md](../design/ext-quantum-q5.5.md) | **done** |
|
||||
| **Q6** | 公式/`matrix=` 自定义门 + `apply` — [ext-quantum-custom-gate.md](../design/ext-quantum-custom-gate.md) | **done** |
|
||||
|
||||
验收金样:`tests/ext/quantum-bell-smoke.mq.md`、`quantum-draw-smoke.mq.md`、`quantum-gate-matrix-smoke.mq.md`、`quantum-gate-heatmap-smoke.mq.md`、`quantum-author-api-smoke.mq.md`、`quantum-noise-smoke.mq.md`、`quantum-amp-damp-smoke.mq.md`、中文对称样例(`quantum-author-api-zh-smoke` / `quantum-noise-zh-smoke` / `quantum-amp-damp-zh-smoke`)。
|
||||
验收金样:`tests/ext/quantum-bell-smoke.mq.md`、`quantum-draw-smoke.mq.md`、`quantum-gate-matrix-smoke.mq.md`、`quantum-gate-heatmap-smoke.mq.md`、`quantum-author-api-smoke.mq.md`、`quantum-noise-smoke.mq.md`、`quantum-amp-damp-smoke.mq.md`、`quantum-custom-gate-smoke.mq.md`、中文对称样例。
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in new issue
Block a user