Files
marqdo/ext/quantum/量子.mq.md
T
cflmyandCursor dfb27d41dc feat(quantum): Q8 circuit SVG themes and view plot chrome
Fix label/wire overlap with gutter + chip labels; default dark tech palette
with light/bw themes; restyle probs/bloch and darken view plot frames.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-28 15:46:02 +08:00

6.0 KiB
Raw Blame History


title: ext/quantum/量子 description: 官方量子电路模拟(中文)。门 + 电路;ABI 插件。 import plugin:lib/plugin.mq.md import sys:lib/sys.mq.md import json:lib/json.mq.md

确保插件

加载 ABI v2 quantum 插件。

p = > plugin.native_path name="quantum"

  1. p

plugin.load path=p

print text=ext/quantum: 未找到原生 quantum 插件(请 build marqdo_plugin_quantum 或 marqdo ext add quantum) sys.exit code=1


张量积

+ `左`
+ `右`

两态或方阵的张量积。

确保插件 > quantum_kron a=左 b=右

施密特分解

+ `态`
+ `分割`=1

确保插件 > quantum_schmidt state=态 cut=分割

保真度

+ `左`
+ `右`

纯态保真度 |⟨a|b⟩|²。

确保插件 > quantum_fidelity a=左 b=右

电路

+ `比特数`=1
+ `步骤`=None

状态向量电路(默认 |0…0⟩)。可选 步骤= 门序列表。方法追加门并返回更新后的句柄。

确保插件 > quantum_circuit_new qubits=比特数 steps=步骤

哈达玛

+ `比特`=0

> quantum_h circuit=self qubit=比特

泡利X

+ `比特`=0

> quantum_x circuit=self qubit=比特

泡利Y

+ `比特`=0

> quantum_y circuit=self qubit=比特

泡利Z

+ `比特`=0

> quantum_z circuit=self qubit=比特

相位S

+ `比特`=0

> quantum_s circuit=self qubit=比特

相位T

+ `比特`=0

> quantum_t circuit=self qubit=比特

单位

+ `比特`=0

> quantum_i circuit=self qubit=比特

绕X

+ `比特`=0
+ `参数`

> quantum_rx circuit=self qubit=比特 theta=参数

绕Y

+ `比特`=0
+ `参数`

> quantum_ry circuit=self qubit=比特 theta=参数

绕Z

+ `比特`=0
+ `参数`

> quantum_rz circuit=self qubit=比特 theta=参数

控非

+ `控制`=0
+ `目标`=1

> quantum_cx circuit=self control=控制 target=目标

控相

+ `控制`=0
+ `目标`=1

> quantum_cz circuit=self control=控制 target=目标

交换

+ `比特甲`=0
+ `比特乙`=1

> quantum_swap circuit=self a=比特甲 b=比特乙

屏障

仅可视化分隔(不改态)。

> quantum_barrier circuit=self

测量

+ `比特`=None

标记计算基读出(空 = 全部比特)。影响 运行 报告哪些位。

> quantum_measure circuit=self qubits=比特

追加

+ `操作`

追加另一电路的 ops,或 {gate,qubits} 操作表。

> quantum_append circuit=self op=操作

施加

+ `门`
+ `比特`=0

将门句柄(具名或 矩阵= 自定义)施加到 比特(整数或列表)。

> quantum_apply circuit=self gate=门 qubits=比特

噪声

+ `种类`
+ `概率`

教学噪声,供 运行 轨迹使用(bitflip / depolarizing / amplitude_damping,或中文:比特翻转 / 退极化 / 振幅阻尼)。模拟 / 概率 忽略。

> quantum_noise circuit=self kind=种类 p=概率

模拟

返回态矢量振幅 {re,im}(理想;无噪声)。

> quantum_simulate circuit=self

态

理想态矢量(与 模拟 相同振幅)。

> quantum_state circuit=self

概率

基矢标签 → 概率(qubit 0 为最右侧比特)。理想;忽略噪声。

> quantum_probabilities circuit=self

运行

+ `次数`=1024
+ `种子`=1

计算基采样(种子= 可复现)。若设置了电路噪声则启用。

> quantum_run circuit=self shots=次数 seed=种子

绘图

+ `路径`=None
+ `种类`=circuit
+ `比特`=0
+ `主题`=dark

电路轨线 / 概率条 / 布洛赫 / 高级态图(种类 circuit、probs、bloch、hinton、city、density、paulivec、qsphere、multibloch)。主题 dark(默认科技感)/ light / bw。经 record_plot 进入 view/CLI plots。

> quantum_draw_circuit circuit=self path=路径 kind=种类 qubit=比特 theme=主题

密度

理想模拟后的纯态密度矩阵 ρ=|ψ⟩⟨ψ|。

> 密度 态=self

期望

+ `可观测量`

Pauli 串(左端=高比特)或矩阵期望值。

> quantum_density_expect density=self obs=可观测量

施密特

+ `分割`=1

二分施密特分解(分割=子系统 A 的比特数,低位)。

> quantum_schmidt state=self cut=分割

门

+ `名`=None
+ `参数`=None
+ `矩阵`=None

具名内置门(名=H)或由 矩阵=(嵌套 list 或公式矩阵围栏)定义的自定义酉门。自定义门可选 名=(默认 U)。

确保插件 > quantum_gate_new name=名 theta=参数 matrix=矩阵

矩阵

> quantum_gate_matrix gate=self

匹配矩阵

+ `矩阵`
+ `容差`=0.000000001

> quantum_gate_matches_matrix gate=self matrix=矩阵 tol=容差

绘图

+ `路径`=None
+ `种类`=gate

门符号或复矩阵热力图(种类=gate|matrix)。经 record_plot 记录。

> quantum_gate_draw gate=self path=路径 kind=种类

密度

+ `态`=None
+ `矩阵`=None

由态/电路(态=)或显式厄米 矩阵= 构造密度矩阵(≤6 比特)。

确保插件

  1. 矩阵 > quantum_density_from_matrix matrix=矩阵

> 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=种类