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

+48
View File
@@ -0,0 +1,48 @@
---
title: quantum linalg smoke
description: Q7a density / partial_trace / expect / schmidt / purity
import quantum:ext/quantum/quantum.mq.md
import math:lib/math.mq.md
---
# main
*qc = > quantum.circuit qubits=2*
*qc = > `qc`.h qubit=0*
*qc = > `qc`.cx control=0 target=1*
*rho = > `qc`.density*
*pur = > `rho`.purity*
*lo = > math.div a=9 b=10*
1. `pur` > `lo`
> print text=purity-ok
2. *
> print text=purity-fail
*red = > `rho`.partial_trace keep=0*
*rpur = > `red`.purity*
*half_lo = > math.div a=4 b=10*
*half_hi = > math.div a=6 b=10*
1. `rpur` > `half_lo`
1. `rpur` < `half_hi`
> print text=reduce-ok
2. *
> print text=reduce-fail
2. *
> print text=reduce-fail
*zz = "ZZ"*
*ezz = > `qc`.expect obs=`zz`*
*zzi = > math.div a=9 b=10*
1. `ezz` > `zzi`
> print text=expect-ok
2. *
> print text=expect-fail
*sch = > `qc`.schmidt cut=1*
*ent = sch[^entropy]*
*elo = > math.div a=1 b=2*
1. `ent` > `elo`
> print text=schmidt-ok
2. *
> print text=schmidt-fail
@@ -0,0 +1,20 @@
---
title: quantum viz advanced smoke
description: Q7b hinton / qsphere / multibloch SVG markers
import quantum:ext/quantum/quantum.mq.md
---
# main
*qc = > quantum.circuit qubits=2*
*qc = > `qc`.h qubit=0*
*qc = > `qc`.cx control=0 target=1*
*h = > `qc`.draw kind="hinton" path="quantum-viz-hinton.svg"*
*q = > `qc`.draw kind="qsphere" path="quantum-viz-qsphere.svg"*
*m = > `qc`.draw kind="multibloch" path="quantum-viz-multibloch.svg"*
*rho = > `qc`.density*
*c = > `rho`.draw kind="city" path="quantum-viz-city.svg"*
> print text=viz-ok
+39
View File
@@ -2595,6 +2595,45 @@ fn ext_quantum_custom_gate_zh_smoke() {
assert_out("tests/ext/quantum-custom-gate-zh-smoke.mq.md", "custom-ok");
}
#[test]
fn ext_quantum_linalg_smoke() {
let status = Command::new("cargo")
.args(["build", "-p", "marqdo_plugin_quantum"])
.current_dir(env!("CARGO_MANIFEST_DIR"))
.status()
.expect("build quantum plugin");
assert!(status.success(), "failed to build marqdo_plugin_quantum");
assert_out(
"tests/ext/quantum-linalg-smoke.mq.md",
"purity-ok\nreduce-ok\nexpect-ok\nschmidt-ok",
);
}
#[test]
fn ext_quantum_viz_advanced_smoke() {
let status = Command::new("cargo")
.args(["build", "-p", "marqdo_plugin_quantum"])
.current_dir(env!("CARGO_MANIFEST_DIR"))
.status()
.expect("build quantum plugin");
assert!(status.success(), "failed to build marqdo_plugin_quantum");
assert_out("tests/ext/quantum-viz-advanced-smoke.mq.md", "viz-ok");
for (p, marker) in [
("tests/ext/quantum-viz-hinton.svg", "data-hinton"),
("tests/ext/quantum-viz-qsphere.svg", "data-qsphere"),
("tests/ext/quantum-viz-multibloch.svg", "data-multibloch"),
("tests/ext/quantum-viz-city.svg", "data-city"),
] {
let svg = std::fs::read_to_string(p).unwrap_or_default();
assert!(
svg.contains("<svg") && svg.contains(marker),
"expected {marker} in {p}, got {} bytes",
svg.len()
);
let _ = std::fs::remove_file(p);
}
}
#[test]
fn ext_agent_framework_smoke() {
let status = Command::new("cargo")