Fix 3 audit findings: export signatures, cache safety, accessibility
Browse files1. CRITICAL — exportPython.ts CompressVQC template had 3 wrong
function calls:
- quadraticProgram_luttoqp(lut) → (qc, lut)
- admmOptimizedCompVQC(qp, lut) → (qp)
- resultsCompressVQC(qc, result, lut) → (result, qc)
All verified against backend/qlib/compvqc.py actual signatures.
Users who exported and ran pipeline.py would have hit TypeError.
2. MEDIUM — Step cache _cache_put now deep-copies QuantumCircuit
objects via qc.copy() instead of storing references. Prevents a
future handler that mutates circuit in-place from silently
corrupting cached snapshots. Current handlers all reassign, so
this is defensive, but the cost (one .copy() per step) is cheap.
3. MEDIUM — BlockPicker button now has aria-haspopup, aria-expanded,
aria-label. Dropdown div has role="menu" and aria-label. Screen
reader users can now navigate the block catalog.
|
@@ -73,7 +73,16 @@ def _prefix_hash(circuit_qpy: bytes, nodes_so_far: list[FlowNode]) -> str:
|
|
| 73 |
|
| 74 |
|
| 75 |
def _cache_put(key: str, result: StepResult, ctx: dict) -> None:
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
_step_cache.move_to_end(key)
|
| 78 |
while len(_step_cache) > _STEP_CACHE_MAX:
|
| 79 |
_step_cache.popitem(last=False)
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
def _cache_put(key: str, result: StepResult, ctx: dict) -> None:
|
| 76 |
+
# Deep-copy QuantumCircuit objects to prevent a future handler that
|
| 77 |
+
# mutates in-place from silently corrupting the cached snapshot.
|
| 78 |
+
# Other ctx values (backend, floats) are either immutable or cheap.
|
| 79 |
+
snapshot = {}
|
| 80 |
+
for k, v in ctx.items():
|
| 81 |
+
if isinstance(v, QuantumCircuit):
|
| 82 |
+
snapshot[k] = v.copy()
|
| 83 |
+
else:
|
| 84 |
+
snapshot[k] = v
|
| 85 |
+
_step_cache[key] = (result, snapshot)
|
| 86 |
_step_cache.move_to_end(key)
|
| 87 |
while len(_step_cache) > _STEP_CACHE_MAX:
|
| 88 |
_step_cache.popitem(last=False)
|
|
@@ -106,13 +106,20 @@ export function BlockPicker({
|
|
| 106 |
type="button"
|
| 107 |
onClick={() => setOpen((v) => !v)}
|
| 108 |
className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] font-medium border border-accent/50 text-accent hover:bg-accent/10 transition-colors whitespace-nowrap"
|
|
|
|
|
|
|
|
|
|
| 109 |
>
|
| 110 |
<Plus className="w-3 h-3" />
|
| 111 |
Add blocks
|
| 112 |
</button>
|
| 113 |
|
| 114 |
{open && (
|
| 115 |
-
<div
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
{/* Search */}
|
| 117 |
<div className="p-2 border-b border-edge">
|
| 118 |
<div className="relative">
|
|
|
|
| 106 |
type="button"
|
| 107 |
onClick={() => setOpen((v) => !v)}
|
| 108 |
className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-[11px] font-medium border border-accent/50 text-accent hover:bg-accent/10 transition-colors whitespace-nowrap"
|
| 109 |
+
aria-haspopup="menu"
|
| 110 |
+
aria-expanded={open}
|
| 111 |
+
aria-label="Add blocks to canvas"
|
| 112 |
>
|
| 113 |
<Plus className="w-3 h-3" />
|
| 114 |
Add blocks
|
| 115 |
</button>
|
| 116 |
|
| 117 |
{open && (
|
| 118 |
+
<div
|
| 119 |
+
role="menu"
|
| 120 |
+
aria-label="Block catalog"
|
| 121 |
+
className="fixed left-3 top-14 sm:absolute sm:left-0 sm:top-full sm:mt-1 z-40 w-[min(320px,calc(100vw-1.5rem))] max-h-[70vh] rounded-lg border border-edge bg-surface shadow-xl flex flex-col"
|
| 122 |
+
>
|
| 123 |
{/* Search */}
|
| 124 |
<div className="p-2 border-b border-edge">
|
| 125 |
<div className="relative">
|
|
@@ -206,9 +206,9 @@ export function generatePythonScript(
|
|
| 206 |
lines.push(` comp_backend = FakeFezV2()`);
|
| 207 |
lines.push(` lut = get_LUT(qc, comp_backend)`);
|
| 208 |
lines.push(` if lut:`);
|
| 209 |
-
lines.push(` qp = quadraticProgram_luttoqp(lut)`);
|
| 210 |
-
lines.push(` result = admmOptimizedCompVQC(qp
|
| 211 |
-
lines.push(` qc = resultsCompressVQC(
|
| 212 |
lines.push(` print(f"CompressVQC: compressed circuit depth {qc.depth()}")`);
|
| 213 |
lines.push(` else:`);
|
| 214 |
lines.push(` print("CompressVQC: no compressible pairs found")`);
|
|
|
|
| 206 |
lines.push(` comp_backend = FakeFezV2()`);
|
| 207 |
lines.push(` lut = get_LUT(qc, comp_backend)`);
|
| 208 |
lines.push(` if lut:`);
|
| 209 |
+
lines.push(` qp = quadraticProgram_luttoqp(qc, lut)`);
|
| 210 |
+
lines.push(` result = admmOptimizedCompVQC(qp)`);
|
| 211 |
+
lines.push(` qc = resultsCompressVQC(result, qc)`);
|
| 212 |
lines.push(` print(f"CompressVQC: compressed circuit depth {qc.depth()}")`);
|
| 213 |
lines.push(` else:`);
|
| 214 |
lines.push(` print("CompressVQC: no compressible pairs found")`);
|