diff --git a/adv0/__init__.py b/adv0/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/adv0/attacks.py b/adv0/attacks.py new file mode 100644 index 00000000..fb4bfef2 --- /dev/null +++ b/adv0/attacks.py @@ -0,0 +1,205 @@ +"""ADV-0 classical attack suite. Each attack tries to recover the hidden string s of a peaked circuit. + + pauli_propagation Heisenberg-picture Pauli propagation of every Z_i with coefficient and term-count + truncation; bit i is recovered when the sign of is right and || >= 0.5. + light_cone exact statevector of each qubit's backward light cone (when the cone fits in memory). + mps matrix-product-state sampling with a bond-dimension cap; wins if the modal sample is s. + +An attack "wins" a circuit when it recovers all n bits. All attacks are generic: none looks for the mirror +structure. A structure-aware attack is listed as an open item in the report. +""" + +from __future__ import annotations + +import time +from typing import Dict, List, Sequence, Tuple + +import numpy as np + +from adv0.peaked import Gate, Peaked + +_P = [np.eye(2), np.array([[0, 1], [1, 0]]), np.array([[0, -1j], [1j, 0]]), np.diag([1.0, -1.0])] +_SX = 0.5 * np.array([[1 + 1j, 1 - 1j], [1 - 1j, 1 + 1j]]) +_X = np.array([[0, 1], [1, 0]], dtype=complex) +_CZ = np.diag([1, 1, 1, -1]).astype(complex) + + +def _table1(g: np.ndarray) -> np.ndarray: + """A[l, k] with g^dagger P_l g = sum_k A[l, k] P_k (real for Hermitian P_l).""" + a = np.zeros((4, 4)) + for l in range(4): + m = g.conj().T @ _P[l] @ g + for k in range(4): + a[l, k] = np.real(np.trace(_P[k] @ m)) / 2 + return a + + +def _table2(g: np.ndarray) -> Tuple[np.ndarray, np.ndarray]: + """Clifford 2-qubit gate: permutation and sign over the 16 Pauli pairs (index 4*la + lb).""" + perm, sign = np.zeros(16, dtype=np.int8), np.zeros(16) + for la in range(4): + for lb in range(4): + m = g.conj().T @ np.kron(_P[la], _P[lb]) @ g + for ka in range(4): + for kb in range(4): + c = np.real(np.trace(np.kron(_P[ka], _P[kb]) @ m)) / 4 + if abs(c) > 1e-9: + perm[4 * la + lb], sign[4 * la + lb] = 4 * ka + kb, c + return perm, sign + + +def _clifford1(a: np.ndarray): + perm = np.argmax(np.abs(a), axis=1).astype(np.int8) + return perm, a[np.arange(4), perm] + + +SX_T = _clifford1(_table1(_SX)) +X_T = _clifford1(_table1(_X)) +CZ_T = _table2(_CZ) + + +class _Ops: + """Propagated observable: rows of Pauli letters (0=I,1=X,2=Y,3=Z) with real coefficients.""" + + def __init__(self, n: int, q: int): + self.L = np.zeros((1, n), dtype=np.int8) + self.L[0, q] = 3 + self.c = np.ones(1) + self.dropped = 0.0 # sum of squared coefficients removed by truncation + + def cliff1(self, q: int, t): + perm, sign = t + old = self.L[:, q].copy() + self.L[:, q] = perm[old] + self.c *= sign[old] + + def cz(self, a: int, b: int): + perm, sign = CZ_T + idx = 4 * self.L[:, a] + self.L[:, b] + new = perm[idx] + self.L[:, a], self.L[:, b] = new // 4, new % 4 + self.c *= sign[idx] + + def rz(self, q: int, theta: float): + # rz^dag X rz = cos X - sin Y ; rz^dag Y rz = cos Y + sin X (checked against _table1 in tests) + co, si = np.cos(theta), np.sin(theta) + col = self.L[:, q] + m = (col == 1) | (col == 2) + if not m.any(): + return + if abs(si) < 1e-12: + self.c[m] *= co + return + sub = self.L[m].copy() + cs = self.c[m].copy() + sgn = np.where(sub[:, q] == 1, -si, si) + sub[:, q] = 3 - sub[:, q] # 1 <-> 2 + if abs(co) < 1e-12: + self.L[m] = sub + self.c[m] = cs * sgn + return + self.c[m] *= co + self.L = np.concatenate([self.L, sub]) + self.c = np.concatenate([self.c, cs * sgn]) + + def merge(self, eps: float, max_terms: int): + L = np.ascontiguousarray(self.L) + v = L.view(np.dtype((np.void, L.shape[1]))).ravel() + _, first, inv = np.unique(v, return_index=True, return_inverse=True) + c = np.bincount(inv.ravel(), weights=self.c, minlength=len(first)) + L = L[first] + keep = np.abs(c) > eps + if keep.sum() > max_terms: + thr = np.partition(np.abs(c), -max_terms)[-max_terms] + keep &= np.abs(c) >= thr + self.dropped += float(np.sum(c[~keep] ** 2)) + self.L, self.c = L[keep], c[keep] + + def expect_zero(self) -> float: + diag = np.all((self.L == 0) | (self.L == 3), axis=1) + return float(self.c[diag].sum()) + + +def pp_expect_z(gates: Sequence[Gate], n: int, q: int, eps: float = 1e-5, max_terms: int = 2 ** 15, + merge_every: int = 2 ** 14) -> Dict: + """<0| C^dag Z_q C |0> by backward Heisenberg propagation (O <- G^dag O G, last gate first).""" + o = _Ops(n, q) + peak = 1 + for name, qs, th in reversed(gates): + if name == "rz": + o.rz(qs[0], th) + if len(o.c) > merge_every: + o.merge(eps, max_terms) + elif name == "sx": + o.cliff1(qs[0], SX_T) + elif name == "x": + o.cliff1(qs[0], X_T) + elif name == "cz": + o.cz(*qs) + peak = max(peak, len(o.c)) + o.merge(eps, max_terms) + return {"z": o.expect_zero(), "dropped": o.dropped, "max_terms_seen": peak} + + +def pauli_propagation(p: Peaked, eps: float = 1e-5, max_terms: int = 2 ** 15, order_seed: int = 0) -> Dict: + """Stops at the first qubit it fails to recover (an attack must recover every bit).""" + t0 = time.time() + order = np.random.default_rng(order_seed).permutation(p.n) + got, worst = 0, 1.0 + for q in order: + r = pp_expect_z(p.gates, p.n, int(q), eps, max_terms) + want = 1.0 if p.secret[q] == "0" else -1.0 + worst = min(worst, r["z"] * want) + if r["z"] * want < 0.5: + return {"win": False, "bits_recovered_before_fail": got, "failed_z_signed": r["z"] * want, + "dropped_weight": r["dropped"], "seconds": time.time() - t0} + got += 1 + return {"win": True, "bits_recovered_before_fail": got, "min_z_signed": worst, "seconds": time.time() - t0} + + +def light_cone(gates: Sequence[Gate], q: int) -> Tuple[List[int], List[Gate]]: + cone, keep = {q}, [] + for g in reversed(gates): + if set(g[1]) & cone: + cone.update(g[1]) + keep.append(g) + return sorted(cone), list(reversed(keep)) + + +def light_cone_attack(p: Peaked, limit: int = 26) -> Dict: + from qiskit import QuantumCircuit + from qiskit.quantum_info import Pauli + from qiskit_aer import AerSimulator + t0 = time.time() + sim = AerSimulator(method="statevector") + sizes = [] + for q in range(p.n): + cone, gs = light_cone(p.gates, q) + sizes.append(len(cone)) + if len(cone) > limit: + return {"win": False, "max_cone": max(sizes), "cone_limit": limit, "qubit": q, + "seconds": time.time() - t0} + pos = {v: i for i, v in enumerate(cone)} + qc = QuantumCircuit(len(cone)) + for name, qs, th in gs: + m = [pos[x] for x in qs] + getattr(qc, name)(*([th] if name == "rz" else []), *m) + qc.save_expectation_value(Pauli("Z"), [pos[q]]) + z = float(np.real(sim.run(qc).result().data()["expectation_value"])) + want = 1.0 if p.secret[q] == "0" else -1.0 + if z * want < 0.5: + return {"win": False, "max_cone": max(sizes), "qubit": q, "z_signed": z * want, + "seconds": time.time() - t0} + return {"win": True, "max_cone": max(sizes), "seconds": time.time() - t0} + + +def mps_attack(p: Peaked, chi: int = 64, shots: int = 200, seed: int = 7) -> Dict: + from qiskit_aer import AerSimulator + t0 = time.time() + sim = AerSimulator(method="matrix_product_state", matrix_product_state_max_bond_dimension=chi, + matrix_product_state_truncation_threshold=1e-10, seed_simulator=seed) + counts = sim.run(p.qiskit(), shots=shots).result().get_counts() + target = p.secret[::-1] # qiskit strings are little-endian + modal = max(counts, key=counts.get) + return {"win": modal == target, "p_peak_est": counts.get(target, 0) / shots, "chi": chi, + "seconds": time.time() - t0} diff --git a/adv0/peaked.py b/adv0/peaked.py new file mode 100644 index 00000000..bb4dd87d --- /dev/null +++ b/adv0/peaked.py @@ -0,0 +1,253 @@ +"""ADV-0: peaked circuits on a heavy-hex region, and their hardware cost. + +Construction (twirled mirror). Pick a connected n-qubit region of the device's coupling graph, grown greedily +from the lowest-error edge. Split its edges into matchings (CZ layers). Build R = d layers of (random SU(2) on +every qubit, then CZ on one matching), plus a final SU(2) layer. The circuit is + + C = X^s . R^dagger . R + +so C|0...0> = |s> exactly: one hidden bitstring s carries probability 1. + +To keep the two halves from reading as gate-by-gate inverses, every CZ gets an identity gauge: random RZ(phi) +on both qubits before it and RZ(-phi) after (RZ commutes with CZ), plus a random Pauli twirl before it with the +CZ-conjugated Pauli after. All single-qubit runs are then merged into the native basis {rz, sx, x}, and X^s is +merged into the last layer. The result has native gates only and no literal palindrome. + +Scope, stated plainly: a mirror-type construction can be undone by an attacker who re-synthesises the circuit and +spots the R^dagger R structure. It is a family for measuring (a) where GENERIC classical simulators stop +recovering s and (b) whether hardware still produces the peak there. It is not, by itself, an advantage candidate; +see docs/adv0/ADV0_REPORT.md. +""" + +from __future__ import annotations + +from dataclasses import dataclass, field +from typing import Dict, List, Sequence, Tuple + +import numpy as np + +Gate = Tuple[str, Tuple[int, ...], float] # (name, virtual qubits, parameter or 0.0) +SHOT_SECONDS = 63.0 / 216_000 # measured on XTOP-005 (ibm_marrakesh, 216 circuits x 1000 shots, 63 QPU s) + + +def backend(): + from qiskit_ibm_runtime.fake_provider import FakeMarrakesh + return FakeMarrakesh() + + +def _err(target, op: str, qargs: Tuple[int, ...]) -> float: + try: + p = target[op][qargs] + except KeyError: + p = target[op].get(tuple(reversed(qargs))) if len(qargs) == 2 else None + return float(p.error) if p is not None and p.error is not None else 0.0 + + +def device_graph(be) -> Tuple[Dict[int, set], Dict[Tuple[int, int], float]]: + t = be.target + adj: Dict[int, set] = {} + cz: Dict[Tuple[int, int], float] = {} + for a, b in t["cz"].keys(): + e = (min(a, b), max(a, b)) + if e in cz: + continue + cz[e] = _err(t, "cz", (a, b)) + adj.setdefault(a, set()).add(b) + adj.setdefault(b, set()).add(a) + return adj, cz + + +def choose_region(be, n: int) -> List[int]: + """Grow a connected region from the lowest-error CZ edge, adding the frontier qubit whose best connecting + edge plus readout error is smallest. Qubits with a CZ edge error >= 5% or readout error >= 5% are excluded.""" + t = be.target + adj, cz = device_graph(be) + ro = {q: _err(t, "measure", (q,)) for q in adj} + bad = {q for q in adj if ro[q] >= 0.05} + good = {e: v for e, v in cz.items() if v < 0.05 and not (set(e) & bad)} + start = min(good, key=good.get) + region = list(start) + while len(region) < n: + best, score = None, None + for q in region: + for nb in adj[q]: + if nb in region or nb in bad: + continue + e = (min(q, nb), max(q, nb)) + if e not in good: + continue + s = good[e] + ro[nb] + if score is None or s < score: + best, score = nb, s + if best is None: + raise RuntimeError(f"region cannot grow past {len(region)} qubits") + region.append(best) + return region + + +def region_edges(be, region: Sequence[int]) -> List[Tuple[int, int]]: + """Edges of the induced subgraph, as VIRTUAL index pairs (i < j).""" + adj, _ = device_graph(be) + pos = {p: i for i, p in enumerate(region)} + out = set() + for p in region: + for nb in adj[p]: + if nb in pos: + out.add((min(pos[p], pos[nb]), max(pos[p], pos[nb]))) + return sorted(out) + + +def matchings(edges: Sequence[Tuple[int, int]]) -> List[List[Tuple[int, int]]]: + """Greedy proper edge colouring (heavy-hex has max degree 3, so this gives 3 or 4 colours).""" + colours: List[List[Tuple[int, int]]] = [] + used: List[set] = [] + for e in edges: + for k, u in enumerate(used): + if e[0] not in u and e[1] not in u: + colours[k].append(e) + u.update(e) + break + else: + colours.append([e]) + used.append(set(e)) + return colours + + +@dataclass +class Peaked: + n: int + depth: int + seed: int + region: List[int] + secret: str # s, character k = virtual qubit k + gates: List[Gate] = field(default_factory=list) + + @property + def n_cz(self) -> int: + return sum(1 for g in self.gates if g[0] == "cz") + + def qiskit(self, measure: bool = True): + from qiskit import QuantumCircuit + qc = QuantumCircuit(self.n, self.n if measure else 0, name=f"adv0_n{self.n}_d{self.depth}_s{self.seed}") + for name, qs, p in self.gates: + if name == "rz": + qc.rz(p, qs[0]) + elif name == "sx": + qc.sx(qs[0]) + elif name == "x": + qc.x(qs[0]) + elif name == "cz": + qc.cz(*qs) + else: + raise ValueError(name) + if measure: + qc.measure(range(self.n), range(self.n)) + return qc + + +_PAULI = {"I": np.eye(2), "X": np.array([[0, 1], [1, 0]]), "Y": np.array([[0, -1j], [1j, 0]]), + "Z": np.diag([1, -1])} + + +def _haar_su2(rng) -> np.ndarray: + z = (rng.normal(size=(2, 2)) + 1j * rng.normal(size=(2, 2))) / np.sqrt(2) + q, r = np.linalg.qr(z) + q = q @ np.diag(np.diag(r) / np.abs(np.diag(r))) + return q / np.sqrt(np.linalg.det(q)) + + +def _rz(t: float) -> np.ndarray: + return np.diag([np.exp(-0.5j * t), np.exp(0.5j * t)]) + + +def _decompose_zsx(u: np.ndarray, q: int) -> List[Gate]: + """u (2x2 unitary) as native rz/sx gates on virtual qubit q, via qiskit's ZSX Euler decomposer.""" + from qiskit.synthesis import OneQubitEulerDecomposer + qc = OneQubitEulerDecomposer("ZSX")(u, simplify=True, atol=1e-12) + out: List[Gate] = [] + for inst in qc.data: + nm = inst.operation.name + if nm == "rz": + out.append(("rz", (q,), float(inst.operation.params[0]) % (2 * np.pi))) + elif nm in ("sx", "x"): + out.append((nm, (q,), 0.0)) + else: + raise ValueError(nm) + return out + + +def _cz_conj(pa: str, pb: str) -> Tuple[str, str]: + """CZ (pa x pb) CZ = (pa' x pb') up to sign: X/Y on one side picks up a Z on the other.""" + def mul(p: str, flip: bool) -> str: + if not flip: + return p + return {"I": "Z", "Z": "I", "X": "Y", "Y": "X"}[p] + return mul(pa, pb in "XY"), mul(pb, pa in "XY") + + +def build(n: int, depth: int, seed: int, be=None, region: Sequence[int] | None = None) -> Peaked: + be = be or backend() + region = list(region) if region is not None else choose_region(be, n) + cols = matchings(region_edges(be, region)) + rng = np.random.default_rng(seed) + secret = "".join(rng.choice(["0", "1"], size=n)) + + # Logical layers: list of ("u", {q: 2x2}) and ("cz", [edges]). + R: List[Tuple[str, object]] = [] + for k in range(depth): + R.append(("u", {q: _haar_su2(rng) for q in range(n)})) + R.append(("cz", cols[k % len(cols)])) + R.append(("u", {q: _haar_su2(rng) for q in range(n)})) + Rdg: List[Tuple[str, object]] = [] + for kind, val in reversed(R): + Rdg.append((kind, {q: m.conj().T for q, m in val.items()} if kind == "u" else val)) + layers = R + Rdg + layers.append(("u", {q: (_PAULI["X"] if secret[q] == "1" else _PAULI["I"]).astype(complex) for q in range(n)})) + + # Pending single-qubit unitary per qubit; flush into native gates before each CZ that touches the qubit. + pend = {q: np.eye(2, dtype=complex) for q in range(n)} + gates: List[Gate] = [] + + def flush(q: int): + gates.extend(_decompose_zsx(pend[q], q)) + pend[q] = np.eye(2, dtype=complex) + + for kind, val in layers: + if kind == "u": + for q, m in val.items(): + pend[q] = m @ pend[q] + continue + for a, b in val: + pa, pb = rng.choice(list("IXYZ")), rng.choice(list("IXYZ")) + fa, fb = rng.uniform(0, 2 * np.pi, size=2) + pend[a] = _PAULI[pa] @ _rz(fa) @ pend[a] + pend[b] = _PAULI[pb] @ _rz(fb) @ pend[b] + flush(a) + flush(b) + gates.append(("cz", (a, b), 0.0)) + qa, qb = _cz_conj(pa, pb) + pend[a] = _rz(-fa) @ _PAULI[qa] + pend[b] = _rz(-fb) @ _PAULI[qb] + for q in range(n): + flush(q) + return Peaked(n=n, depth=depth, seed=seed, region=region, secret=secret, gates=gates) + + +def hardware_estimate(p: Peaked, be=None, detect_counts: int = 20) -> Dict[str, float]: + """Predicted peak probability on the device = product of (1 - error) over every native gate and readout, + from the backend's reported calibration. This ignores idle decoherence and crosstalk (both made XTOP-005 + worse than its simulator), so it is an optimistic first-order number; validate with noisy simulation.""" + be = be or backend() + t = be.target + logf = 0.0 + for name, qs, _ in p.gates: + if name == "rz": + continue + phys = tuple(p.region[q] for q in qs) + logf += np.log1p(-_err(t, name, phys)) + for q in range(p.n): + logf += np.log1p(-_err(t, "measure", (p.region[q],))) + ps = float(np.exp(logf)) + shots = int(max(1000, np.ceil(detect_counts / max(ps, 1e-12)))) + return {"p_peak_pred": ps, "shots_needed": shots, "qpu_seconds_pred": shots * SHOT_SECONDS, + "uniform_baseline": 2.0 ** -p.n} diff --git a/adv0/scan.py b/adv0/scan.py new file mode 100644 index 00000000..e6857e2a --- /dev/null +++ b/adv0/scan.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +"""ADV-0 scan: for each (n, depth), build a peaked circuit, run the classical attacks, and predict hardware. + +Outputs (docs/adv0/): + scan.jsonl one line per (n, depth): attack results, CZ count, predicted peak probability, QPU seconds + noisy_check.jsonl predicted vs simulated peak probability under FakeMarrakesh's full noise model (small n) +""" + +from __future__ import annotations + +import argparse +import json +import os +import time +from pathlib import Path + +from adv0 import attacks as A +from adv0 import peaked as P + +OUT = Path(os.environ.get("ADV0_OUT", Path(__file__).resolve().parents[1] / "docs" / "adv0")) + + +def scan(ns, depths, seed=20261121, pp_terms=2 ** 15, lc_limit=26, chis=(64, 256)): + OUT.mkdir(parents=True, exist_ok=True) + be = P.backend() + f = open(OUT / "scan.jsonl", "a") + for n in ns: + reg = P.choose_region(be, n) + for d in depths: + p = P.build(n, d, seed + 1000 * n + d, be, reg) + row = {"n": n, "depth": d, "seed": p.seed, "region": p.region, "n_cz": p.n_cz, + "n_1q": sum(1 for g in p.gates if g[0] in ("sx", "x")), **P.hardware_estimate(p, be)} + row["pauli_prop"] = A.pauli_propagation(p, eps=1e-5, max_terms=pp_terms) + row["light_cone"] = A.light_cone_attack(p, limit=lc_limit) + row["mps"] = [A.mps_attack(p, chi=c, shots=200) for c in chis] + row["classical_win"] = (row["pauli_prop"]["win"] or row["light_cone"]["win"] + or any(m["win"] for m in row["mps"])) + f.write(json.dumps(row) + "\n") + f.flush() + print(n, d, "cz", p.n_cz, "p_hw %.3g" % row["p_peak_pred"], "PP", row["pauli_prop"]["win"], + "LC", row["light_cone"]["win"], "MPS", [m["win"] for m in row["mps"]], + "t", round(sum([row["pauli_prop"]["seconds"], row["light_cone"]["seconds"]] + + [m["seconds"] for m in row["mps"]]), 1), flush=True) + + +def noisy_check(n=12, depths=(2, 4, 6, 8, 12), shots=4000, seed=20261121): + from qiskit import transpile + from qiskit_aer import AerSimulator + OUT.mkdir(parents=True, exist_ok=True) + be = P.backend() + sim = AerSimulator.from_backend(be) + reg = P.choose_region(be, n) + with open(OUT / "noisy_check.jsonl", "a") as f: + for d in depths: + p = P.build(n, d, seed + 1000 * n + d, be, reg) + isa = transpile(p.qiskit(), be, initial_layout=reg, optimization_level=0) + assert isa.count_ops().get("cz", 0) == p.n_cz, "routing added gates" + c = sim.run(isa, shots=shots, seed_simulator=seed).result().get_counts() + row = {"n": n, "depth": d, "n_cz": p.n_cz, "pred": P.hardware_estimate(p, be)["p_peak_pred"], + "sim": c.get(p.secret[::-1], 0) / shots, "modal_is_secret": max(c, key=c.get) == p.secret[::-1], + "duration_us": isa.estimate_duration(be.target, unit="u") if hasattr(isa, "estimate_duration") else None} + f.write(json.dumps(row) + "\n") + print(row, flush=True) + + +if __name__ == "__main__": + ap = argparse.ArgumentParser() + ap.add_argument("--ns", default="12,20,28,40,56") + ap.add_argument("--depths", default="2,4,6,8,12,16") + ap.add_argument("--noisy", action="store_true") + a = ap.parse_args() + t0 = time.time() + if a.noisy: + noisy_check() + else: + scan([int(x) for x in a.ns.split(",")], [int(x) for x in a.depths.split(",")]) + print("done in %.0f s" % (time.time() - t0)) diff --git a/docs/adv0/ADV0_REPORT.md b/docs/adv0/ADV0_REPORT.md new file mode 100644 index 00000000..9bbfc27a --- /dev/null +++ b/docs/adv0/ADV0_REPORT.md @@ -0,0 +1,62 @@ +# ADV-0: Where generic classical simulators stop recovering a peaked circuit on heavy-hex + +**Status:** offline study. No QPU time was used. Nothing here is a claim of quantum advantage. + +## Question + +For peaked circuits the size of an IBM Heron r2 region, does any generic classical attack still recover the hidden string? If so, how does its success compare with what the hardware is predicted to deliver? + +## Setup + +**Circuits.** `adv0/peaked.py` builds twirled-mirror circuits: C = X^s · R† · R on a connected n-qubit heavy-hex region of FakeMarrakesh, so ideally C|0⟩ = |s⟩. + +- **R:** d layers, each of Haar-random SU(2) on every qubit followed by CZ on one edge matching, then one final SU(2) layer. +- **Obfuscation:** every CZ gets a random RZ gauge and a random Pauli twirl, and all single-qubit runs are merged into native rz/sx/x gates. +- **Region:** grown greedily from the lowest-error CZ edge; qubits with 5% or worse readout or CZ error are excluded. + +**Attacks** (`adv0/attacks.py`). All are generic, none looks for mirror structure, and each must recover every bit: + +- **Pauli propagation:** Heisenberg picture, coefficient cut-off 1e-5, at most 32,768 terms. +- **Exact light-cone statevector:** limited to cones of 26 qubits or fewer. +- **MPS sampling:** bond dimension 64 or 256, 200 shots. It wins if the most frequent sample is s. + +**Hardware prediction.** The product of (1 − error) over every native gate and readout, from the backend's calibration. It ignores idle decoherence and crosstalk. Against a full FakeMarrakesh noisy simulation at n = 12 (`noisy_check.jsonl`), it was optimistic by 1–7% (relative): predicted 0.883 against 0.874 simulated at depth 2, and 0.746 against 0.694 at depth 12. + +**Tests.** 9 in `tests/test_adv0.py`, all passing. They check that every circuit peaks with probability 1, that there is no literal palindrome, that Pauli propagation matches the statevector exactly when not truncated, and that the cost model falls with depth. + +## Results (`scan.jsonl`, 30 cells) + +| n | depth | CZ | hw peak (pred.) | Pauli prop. | light cone | MPS χ=64 | MPS χ=256 | +|---|---|---|---|---|---|---|---| +| 12 | 16 | 120 | 0.691 | fail | win | win (1.00, <1 s) | win | +| 20 | 16 | 206 | 0.492 | fail | win | win (0.73, 2 s) | win (1.00, 59 s) | +| 28 | 8 | 158 | 0.471 | fail | fail | win (0.86, 4 s) | win (1.00, 132 s) | +| 28 | 16 | 304 | 0.288 | fail | fail | win (0.17, 8 s) | win (0.58, 683 s) | +| 40 | 12 | 328 | 0.217 | fail | fail | win (0.18, 10 s) | win (0.66, 617 s) | +| 40 | 16 | 446 | 0.146 | fail | fail | win (0.015, 14 s) | win (0.14, 4,884 s) | +| 56 | 8 | 320 | 0.149 | fail | fail | win (0.52, 7 s) | win (0.97, 1,604 s) | +| 56 | 12 | 456 | 0.080 | fail | fail | win (0.13, 11 s) | win (0.57, 12,547 s) | +| 56 | 16 | 618 | 0.041 | fail | fail | **fail** (0.005, 18 s) | win (0.165, 1,274 s) | + +The hw and MPS columns give the peak probability; the MPS columns also give run time. Cells at depths 2–6 are in the JSONL: every attack except light-cone wins there. + +The Aer MPS run times vary between runs, so treat them as rough. One example: (56, 16) took less time than (56, 12). + +## Findings + +1. **In every one of the 30 cells, at least one laptop-scale attack recovers s.** On this family and this hardware, the classical side wins across the whole range. +2. **MPS is the attack that matters.** Pauli propagation fails from depth 8–12, and the light-cone attack fails at 28 qubits or more from depth 6. MPS at bond dimension 64 only fails at the largest cell (n = 56, d = 16), and bond dimension 256 still wins there with a peak of 0.165, against 0.041 predicted for hardware. +3. **Peak detection is forgiving for both sides.** A simulator does not need high fidelity, only that s stays the most frequent sample. Whatever makes the hardware's job easy makes the classical job easy too. +4. **Hardware fidelity falls faster than MPS fidelity as the circuit grows:** the predicted peak is 0.041 at 618 CZ. The region grown for low error is long and thin, and MPS handles low-entanglement, nearly 1D geometries well. +5. **QPU cost is not the constraint.** Each cell needs about 0.3 s of QPU time at 1,000 shots. + +## What this rules out, and what comes next + +Twirled-mirror peaked circuits on a low-error heavy-hex region are **not** an advantage candidate on Heron r2. Even ignoring the structure attack, which removes the mirror outright, generic MPS recovers s at every size where the hardware still has a usable peak. + +Any next candidate has to close two gaps at once: + +- **Entanglement geometry.** Use regions with heavy-hex loops (12-qubit rings) and brickwork that crosses them, so that MPS cuts run through many bonds. Cost: a lower hardware peak, from worse qubits and more CZ. +- **No mirror.** Use a peaked construction in which no half-circuit inverts the other, for example a random circuit followed by a peaking block optimised to concentrate on s (Aaronson–Zhang style), or a published challenge circuit. Any such construction also has to be run against a structure-aware attack, which needs to be added to the harness. + +**Gate for any hardware run:** a cell qualifies only if MPS at bond dimension 1024 or more, Pauli propagation and light-cone all fail, and the hardware peak predicted from calibration is at least 10× the uniform baseline with 1,000 shots in budget. ADV-0 found no cell that passes. diff --git a/docs/adv0/noisy_check.jsonl b/docs/adv0/noisy_check.jsonl new file mode 100644 index 00000000..37fedd19 --- /dev/null +++ b/docs/adv0/noisy_check.jsonl @@ -0,0 +1,5 @@ +{"n": 12, "depth": 2, "n_cz": 20, "pred": 0.883151341140941, "sim": 0.8735, "modal_is_secret": true, "duration_us": 3.2640000000000002} +{"n": 12, "depth": 4, "n_cz": 32, "pred": 0.8581244852576082, "sim": 0.8505, "modal_is_secret": true, "duration_us": 3.7760000000000002} +{"n": 12, "depth": 6, "n_cz": 44, "pred": 0.8305993991837733, "sim": 0.809, "modal_is_secret": true, "duration_us": 4.335999999999999} +{"n": 12, "depth": 8, "n_cz": 64, "pred": 0.7935111558298049, "sim": 0.774, "modal_is_secret": true, "duration_us": 4.920000000000001} +{"n": 12, "depth": 12, "n_cz": 88, "pred": 0.7459378173459188, "sim": 0.694, "modal_is_secret": true, "duration_us": 6.016000000000004} diff --git a/docs/adv0/scan.jsonl b/docs/adv0/scan.jsonl new file mode 100644 index 00000000..7405c69e --- /dev/null +++ b/docs/adv0/scan.jsonl @@ -0,0 +1,30 @@ +{"n": 12, "depth": 2, "seed": 20273123, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39], "n_cz": 20, "n_1q": 94, "p_peak_pred": 0.883151341140941, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 0.000244140625, "pauli_prop": {"win": true, "bits_recovered_before_fail": 12, "min_z_signed": 0.9999999999999984, "seconds": 0.03104257583618164}, "light_cone": {"win": true, "max_cone": 6, "seconds": 0.019628047943115234}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.0257260799407959}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.007517814636230469}], "classical_win": true} +{"n": 12, "depth": 4, "seed": 20273125, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39], "n_cz": 32, "n_1q": 138, "p_peak_pred": 0.8581244852576082, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 0.000244140625, "pauli_prop": {"win": true, "bits_recovered_before_fail": 12, "min_z_signed": 0.9999999998716159, "seconds": 0.11369943618774414}, "light_cone": {"win": true, "max_cone": 10, "seconds": 0.02857065200805664}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.00950765609741211}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.007623195648193359}], "classical_win": true} +{"n": 12, "depth": 6, "seed": 20273127, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39], "n_cz": 44, "n_1q": 192, "p_peak_pred": 0.8305993991837733, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 0.000244140625, "pauli_prop": {"win": true, "bits_recovered_before_fail": 12, "min_z_signed": 0.9999999866118638, "seconds": 0.2473616600036621}, "light_cone": {"win": true, "max_cone": 12, "seconds": 0.05602240562438965}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.009922981262207031}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.011706829071044922}], "classical_win": true} +{"n": 12, "depth": 8, "seed": 20273129, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39], "n_cz": 64, "n_1q": 268, "p_peak_pred": 0.7935111558298049, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 0.000244140625, "pauli_prop": {"win": true, "bits_recovered_before_fail": 12, "min_z_signed": 0.9393096174111251, "seconds": 6.673253297805786}, "light_cone": {"win": true, "max_cone": 12, "seconds": 0.10679507255554199}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.022962093353271484}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.01453852653503418}], "classical_win": true} +{"n": 12, "depth": 12, "seed": 20273133, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39], "n_cz": 88, "n_1q": 366, "p_peak_pred": 0.7459378173459188, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 0.000244140625, "pauli_prop": {"win": false, "bits_recovered_before_fail": 2, "failed_z_signed": 0.3698494813337841, "dropped_weight": 0.6945745747484113, "seconds": 4.389252185821533}, "light_cone": {"win": true, "max_cone": 12, "seconds": 0.16357421875}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.028549671173095703}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.028546810150146484}], "classical_win": true} +{"n": 12, "depth": 16, "seed": 20273137, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39], "n_cz": 120, "n_1q": 498, "p_peak_pred": 0.6907350369866846, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 0.000244140625, "pauli_prop": {"win": false, "bits_recovered_before_fail": 1, "failed_z_signed": 0.37959737666428045, "dropped_weight": 0.6349987457186428, "seconds": 4.53576922416687}, "light_cone": {"win": true, "max_cone": 12, "seconds": 0.24642562866210938}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.06433415412902832}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.06158876419067383}], "classical_win": true} +{"n": 20, "depth": 2, "seed": 20281123, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32], "n_cz": 32, "n_1q": 146, "p_peak_pred": 0.801127399314748, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 9.5367431640625e-07, "pauli_prop": {"win": true, "bits_recovered_before_fail": 20, "min_z_signed": 0.999999999999999, "seconds": 0.06663751602172852}, "light_cone": {"win": true, "max_cone": 6, "seconds": 0.026314496994018555}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.028224945068359375}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.011915206909179688}], "classical_win": true} +{"n": 20, "depth": 4, "seed": 20281125, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32], "n_cz": 54, "n_1q": 234, "p_peak_pred": 0.7546529240137957, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 9.5367431640625e-07, "pauli_prop": {"win": true, "bits_recovered_before_fail": 20, "min_z_signed": 0.9999999995608484, "seconds": 0.24081802368164062}, "light_cone": {"win": true, "max_cone": 12, "seconds": 0.059511661529541016}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.014377355575561523}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.00995182991027832}], "classical_win": true} +{"n": 20, "depth": 6, "seed": 20281127, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32], "n_cz": 76, "n_1q": 330, "p_peak_pred": 0.7039000026227193, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 9.5367431640625e-07, "pauli_prop": {"win": true, "bits_recovered_before_fail": 20, "min_z_signed": 0.9999996077447427, "seconds": 0.7782511711120605}, "light_cone": {"win": true, "max_cone": 16, "seconds": 0.1331787109375}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.021355867385864258}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.02236795425415039}], "classical_win": true} +{"n": 20, "depth": 8, "seed": 20281129, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32], "n_cz": 108, "n_1q": 452, "p_peak_pred": 0.6475551308752024, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 9.5367431640625e-07, "pauli_prop": {"win": true, "bits_recovered_before_fail": 20, "min_z_signed": 0.7468378882837698, "seconds": 17.92786717414856}, "light_cone": {"win": true, "max_cone": 20, "seconds": 0.6965186595916748}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.4302661418914795}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.21017122268676758}], "classical_win": true} +{"n": 20, "depth": 12, "seed": 20281133, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32], "n_cz": 152, "n_1q": 624, "p_peak_pred": 0.5701182166610617, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 9.5367431640625e-07, "pauli_prop": {"win": false, "bits_recovered_before_fail": 0, "failed_z_signed": 0.1763333380350275, "dropped_weight": 0.8740244694817164, "seconds": 1.8205478191375732}, "light_cone": {"win": true, "max_cone": 20, "seconds": 1.9652416706085205}, "mps": [{"win": true, "p_peak_est": 0.97, "chi": 64, "seconds": 1.345081090927124}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 3.1149749755859375}], "classical_win": true} +{"n": 20, "depth": 16, "seed": 20281137, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32], "n_cz": 206, "n_1q": 850, "p_peak_pred": 0.49196125940602875, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 9.5367431640625e-07, "pauli_prop": {"win": false, "bits_recovered_before_fail": 0, "failed_z_signed": 0.05104132007810089, "dropped_weight": 0.9747113987518373, "seconds": 2.7293829917907715}, "light_cone": {"win": true, "max_cone": 20, "seconds": 4.119465112686157}, "mps": [{"win": true, "p_peak_est": 0.725, "chi": 64, "seconds": 2.115469455718994}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 59.07734298706055}], "classical_win": true} +{"n": 28, "depth": 2, "seed": 20289123, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3], "n_cz": 46, "n_1q": 208, "p_peak_pred": 0.6832129119614627, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 3.725290298461914e-09, "pauli_prop": {"win": true, "bits_recovered_before_fail": 28, "min_z_signed": 0.9999999999999993, "seconds": 0.10239267349243164}, "light_cone": {"win": true, "max_cone": 6, "seconds": 0.040834903717041016}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.009704828262329102}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.013642311096191406}], "classical_win": true} +{"n": 28, "depth": 4, "seed": 20289125, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3], "n_cz": 80, "n_1q": 352, "p_peak_pred": 0.6079575845040328, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 3.725290298461914e-09, "pauli_prop": {"win": true, "bits_recovered_before_fail": 28, "min_z_signed": 0.999999997800693, "seconds": 0.39566469192504883}, "light_cone": {"win": true, "max_cone": 19, "seconds": 0.17139339447021484}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.34862399101257324}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.16545939445495605}], "classical_win": true} +{"n": 28, "depth": 6, "seed": 20289127, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3], "n_cz": 112, "n_1q": 478, "p_peak_pred": 0.5434880654561276, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 3.725290298461914e-09, "pauli_prop": {"win": true, "bits_recovered_before_fail": 28, "min_z_signed": 0.9913230599787606, "seconds": 7.145482301712036}, "light_cone": {"win": false, "max_cone": 28, "cone_limit": 26, "qubit": 4, "seconds": 3.6831352710723877}, "mps": [{"win": true, "p_peak_est": 0.97, "chi": 64, "seconds": 1.891577959060669}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 5.635940313339233}], "classical_win": true} +{"n": 28, "depth": 8, "seed": 20289129, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3], "n_cz": 158, "n_1q": 654, "p_peak_pred": 0.4709398269496359, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 3.725290298461914e-09, "pauli_prop": {"win": false, "bits_recovered_before_fail": 10, "failed_z_signed": 0.3995838042306239, "dropped_weight": 0.6418575963995196, "seconds": 12.889595031738281}, "light_cone": {"win": false, "max_cone": 28, "cone_limit": 26, "qubit": 0, "seconds": 0.0004837512969970703}, "mps": [{"win": true, "p_peak_est": 0.855, "chi": 64, "seconds": 3.7765796184539795}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 132.40933895111084}], "classical_win": true} +{"n": 28, "depth": 12, "seed": 20289133, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3], "n_cz": 224, "n_1q": 920, "p_peak_pred": 0.37494272129386885, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 3.725290298461914e-09, "pauli_prop": {"win": false, "bits_recovered_before_fail": 0, "failed_z_signed": 0.43944865557255314, "dropped_weight": 0.7525981043548639, "seconds": 2.7565815448760986}, "light_cone": {"win": false, "max_cone": 28, "cone_limit": 26, "qubit": 0, "seconds": 0.0006635189056396484}, "mps": [{"win": true, "p_peak_est": 0.44, "chi": 64, "seconds": 5.626415491104126}, {"win": true, "p_peak_est": 0.87, "chi": 256, "seconds": 304.6426010131836}], "classical_win": true} +{"n": 28, "depth": 16, "seed": 20289137, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3], "n_cz": 304, "n_1q": 1252, "p_peak_pred": 0.2882065455886689, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 3.725290298461914e-09, "pauli_prop": {"win": false, "bits_recovered_before_fail": 0, "failed_z_signed": 0.02258714338237986, "dropped_weight": 0.9974346234208284, "seconds": 3.849540948867798}, "light_cone": {"win": false, "max_cone": 28, "cone_limit": 26, "qubit": 0, "seconds": 0.000530242919921875}, "mps": [{"win": true, "p_peak_est": 0.165, "chi": 64, "seconds": 8.404659032821655}, {"win": true, "p_peak_est": 0.58, "chi": 256, "seconds": 683.047929763794}], "classical_win": true} +{"n": 40, "depth": 2, "seed": 20301123, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3, 2, 1, 0, 16, 27, 54, 55, 59, 75, 74, 49, 23], "n_cz": 68, "n_1q": 316, "p_peak_pred": 0.5315270635732114, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 9.094947017729282e-13, "pauli_prop": {"win": true, "bits_recovered_before_fail": 40, "min_z_signed": 0.9999999999999996, "seconds": 0.17969179153442383}, "light_cone": {"win": true, "max_cone": 6, "seconds": 0.07084774971008301}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.03309226036071777}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.03081202507019043}], "classical_win": true} +{"n": 40, "depth": 4, "seed": 20301125, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3, 2, 1, 0, 16, 27, 54, 55, 59, 75, 74, 49, 23], "n_cz": 118, "n_1q": 518, "p_peak_pred": 0.4459851978485729, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 9.094947017729282e-13, "pauli_prop": {"win": true, "bits_recovered_before_fail": 40, "min_z_signed": 0.999999998135861, "seconds": 0.7168514728546143}, "light_cone": {"win": true, "max_cone": 22, "seconds": 1.9031012058258057}, "mps": [{"win": true, "p_peak_est": 0.995, "chi": 64, "seconds": 0.6600742340087891}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.32268500328063965}], "classical_win": true} +{"n": 40, "depth": 6, "seed": 20301127, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3, 2, 1, 0, 16, 27, 54, 55, 59, 75, 74, 49, 23], "n_cz": 164, "n_1q": 692, "p_peak_pred": 0.38080570027063243, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 9.094947017729282e-13, "pauli_prop": {"win": true, "bits_recovered_before_fail": 40, "min_z_signed": 0.9853773712206765, "seconds": 20.34957981109619}, "light_cone": {"win": false, "max_cone": 28, "cone_limit": 26, "qubit": 2, "seconds": 0.04307746887207031}, "mps": [{"win": true, "p_peak_est": 0.94, "chi": 64, "seconds": 3.004074811935425}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 69.4401216506958}], "classical_win": true} +{"n": 40, "depth": 8, "seed": 20301129, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3, 2, 1, 0, 16, 27, 54, 55, 59, 75, 74, 49, 23], "n_cz": 232, "n_1q": 954, "p_peak_pred": 0.3051295043908139, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 9.094947017729282e-13, "pauli_prop": {"win": false, "bits_recovered_before_fail": 6, "failed_z_signed": 0.2124276890913135, "dropped_weight": 0.8656732336063073, "seconds": 14.983591079711914}, "light_cone": {"win": false, "max_cone": 32, "cone_limit": 26, "qubit": 0, "seconds": 0.00043392181396484375}, "mps": [{"win": true, "p_peak_est": 0.605, "chi": 64, "seconds": 5.862485885620117}, {"win": true, "p_peak_est": 0.995, "chi": 256, "seconds": 311.4932973384857}], "classical_win": true} +{"n": 40, "depth": 12, "seed": 20301133, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3, 2, 1, 0, 16, 27, 54, 55, 59, 75, 74, 49, 23], "n_cz": 328, "n_1q": 1356, "p_peak_pred": 0.21735851556354788, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 9.094947017729282e-13, "pauli_prop": {"win": false, "bits_recovered_before_fail": 0, "failed_z_signed": 0.078708787034489, "dropped_weight": 0.943377548306732, "seconds": 4.002247095108032}, "light_cone": {"win": false, "max_cone": 40, "cone_limit": 26, "qubit": 0, "seconds": 0.000583648681640625}, "mps": [{"win": true, "p_peak_est": 0.18, "chi": 64, "seconds": 9.546310901641846}, {"win": true, "p_peak_est": 0.655, "chi": 256, "seconds": 616.8075313568115}], "classical_win": true} +{"n": 40, "depth": 16, "seed": 20301137, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3, 2, 1, 0, 16, 27, 54, 55, 59, 75, 74, 49, 23], "n_cz": 446, "n_1q": 1828, "p_peak_pred": 0.1459926839134708, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 9.094947017729282e-13, "pauli_prop": {"win": false, "bits_recovered_before_fail": 0, "failed_z_signed": 0.013276615836612679, "dropped_weight": 0.9873434113983485, "seconds": 5.657838582992554}, "light_cone": {"win": false, "max_cone": 40, "cone_limit": 26, "qubit": 0, "seconds": 0.0008494853973388672}, "mps": [{"win": true, "p_peak_est": 0.015, "chi": 64, "seconds": 14.436453580856323}, {"win": true, "p_peak_est": 0.14, "chi": 256, "seconds": 4883.992116212845}], "classical_win": true} +{"n": 56, "depth": 2, "seed": 20317123, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3, 2, 1, 0, 16, 27, 54, 55, 59, 75, 74, 49, 23, 22, 21, 20, 36, 41, 42, 40, 43, 44, 45, 46, 47, 56, 63, 62, 64], "n_cz": 92, "n_1q": 448, "p_peak_pred": 0.39481008003136375, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 1.3877787807814457e-17, "pauli_prop": {"win": true, "bits_recovered_before_fail": 56, "min_z_signed": 0.999999999999999, "seconds": 0.31717419624328613}, "light_cone": {"win": true, "max_cone": 6, "seconds": 0.09867000579833984}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.01620650291442871}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.015217065811157227}], "classical_win": true} +{"n": 56, "depth": 4, "seed": 20317125, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3, 2, 1, 0, 16, 27, 54, 55, 59, 75, 74, 49, 23, 22, 21, 20, 36, 41, 42, 40, 43, 44, 45, 46, 47, 56, 63, 62, 64], "n_cz": 162, "n_1q": 696, "p_peak_pred": 0.288539930232383, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 1.3877787807814457e-17, "pauli_prop": {"win": true, "bits_recovered_before_fail": 56, "min_z_signed": 0.9999999988127022, "seconds": 1.121124505996704}, "light_cone": {"win": true, "max_cone": 22, "seconds": 0.5444707870483398}, "mps": [{"win": true, "p_peak_est": 1.0, "chi": 64, "seconds": 0.6257963180541992}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 0.29999828338623047}], "classical_win": true} +{"n": 56, "depth": 6, "seed": 20317127, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3, 2, 1, 0, 16, 27, 54, 55, 59, 75, 74, 49, 23, 22, 21, 20, 36, 41, 42, 40, 43, 44, 45, 46, 47, 56, 63, 62, 64], "n_cz": 228, "n_1q": 964, "p_peak_pred": 0.21519409292918049, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 1.3877787807814457e-17, "pauli_prop": {"win": true, "bits_recovered_before_fail": 56, "min_z_signed": 0.9455564324871385, "seconds": 27.17247462272644}, "light_cone": {"win": false, "max_cone": 28, "cone_limit": 26, "qubit": 2, "seconds": 0.05083870887756348}, "mps": [{"win": true, "p_peak_est": 0.93, "chi": 64, "seconds": 3.3077781200408936}, {"win": true, "p_peak_est": 1.0, "chi": 256, "seconds": 73.65977430343628}], "classical_win": true} +{"n": 56, "depth": 8, "seed": 20317129, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3, 2, 1, 0, 16, 27, 54, 55, 59, 75, 74, 49, 23, 22, 21, 20, 36, 41, 42, 40, 43, 44, 45, 46, 47, 56, 63, 62, 64], "n_cz": 320, "n_1q": 1330, "p_peak_pred": 0.14871123550598922, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 1.3877787807814457e-17, "pauli_prop": {"win": false, "bits_recovered_before_fail": 13, "failed_z_signed": 0.439999074144423, "dropped_weight": 0.5669331248219966, "seconds": 33.116042613983154}, "light_cone": {"win": false, "max_cone": 32, "cone_limit": 26, "qubit": 0, "seconds": 0.0016105175018310547}, "mps": [{"win": true, "p_peak_est": 0.52, "chi": 64, "seconds": 6.67586874961853}, {"win": true, "p_peak_est": 0.97, "chi": 256, "seconds": 1603.5095851421356}], "classical_win": true} +{"n": 56, "depth": 12, "seed": 20317133, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3, 2, 1, 0, 16, 27, 54, 55, 59, 75, 74, 49, 23, 22, 21, 20, 36, 41, 42, 40, 43, 44, 45, 46, 47, 56, 63, 62, 64], "n_cz": 456, "n_1q": 1888, "p_peak_pred": 0.08006054893876784, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 1.3877787807814457e-17, "pauli_prop": {"win": false, "bits_recovered_before_fail": 1, "failed_z_signed": 0.18635439943721815, "dropped_weight": 0.8394678179733935, "seconds": 10.006701707839966}, "light_cone": {"win": false, "max_cone": 42, "cone_limit": 26, "qubit": 0, "seconds": 0.0007932186126708984}, "mps": [{"win": true, "p_peak_est": 0.13, "chi": 64, "seconds": 10.611077308654785}, {"win": true, "p_peak_est": 0.565, "chi": 256, "seconds": 12547.392963409424}], "classical_win": true} +{"n": 56, "depth": 16, "seed": 20317137, "region": [13, 14, 12, 11, 10, 18, 15, 19, 35, 34, 33, 39, 53, 9, 8, 7, 6, 5, 17, 32, 31, 30, 29, 38, 52, 28, 4, 3, 2, 1, 0, 16, 27, 54, 55, 59, 75, 74, 49, 23, 22, 21, 20, 36, 41, 42, 40, 43, 44, 45, 46, 47, 56, 63, 62, 64], "n_cz": 618, "n_1q": 2518, "p_peak_pred": 0.04050199531638111, "shots_needed": 1000, "qpu_seconds_pred": 0.2916666666666667, "uniform_baseline": 1.3877787807814457e-17, "pauli_prop": {"win": false, "bits_recovered_before_fail": 1, "failed_z_signed": 0.0470873836181673, "dropped_weight": 0.9737306191211602, "seconds": 17.726224660873413}, "light_cone": {"win": false, "max_cone": 52, "cone_limit": 26, "qubit": 0, "seconds": 0.001199960708618164}, "mps": [{"win": false, "p_peak_est": 0.005, "chi": 64, "seconds": 18.210887908935547}, {"win": true, "p_peak_est": 0.165, "chi": 256, "seconds": 1274.121815919876}], "classical_win": true} diff --git a/tests/test_adv0.py b/tests/test_adv0.py new file mode 100644 index 00000000..723df629 --- /dev/null +++ b/tests/test_adv0.py @@ -0,0 +1,105 @@ +import numpy as np +import pytest + +# ADV-0 needs the IBM stack (FakeMarrakesh calibration, Aer MPS); CI installs neither, so skip there. +pytest.importorskip("qiskit") +pytest.importorskip("qiskit_aer") +pytest.importorskip("qiskit_ibm_runtime") + +from adv0 import attacks as A +from adv0 import peaked as P + + +@pytest.fixture(scope="module") +def be(): + return P.backend() + + +def _statevector(p): + from qiskit.quantum_info import Statevector + return Statevector(p.qiskit(measure=False)) + + +def test_region_connected_and_native(be): + reg = P.choose_region(be, 20) + assert len(set(reg)) == 20 + edges = P.region_edges(be, reg) + seen, stack, adj = {0}, [0], {} + for a, b in edges: + adj.setdefault(a, []).append(b) + adj.setdefault(b, []).append(a) + while stack: + for nb in adj.get(stack.pop(), []): + if nb not in seen: + seen.add(nb) + stack.append(nb) + assert len(seen) == 20 + for col in P.matchings(edges): + qs = [q for e in col for q in e] + assert len(qs) == len(set(qs)) + + +@pytest.mark.parametrize("n,d,seed", [(6, 2, 1), (8, 4, 2), (10, 6, 3)]) +def test_circuit_is_peaked_on_secret(be, n, d, seed): + p = P.build(n, d, seed, be) + assert {g[0] for g in p.gates} <= {"rz", "sx", "x", "cz"} + probs = _statevector(p).probabilities_dict() + assert probs.get(p.secret[::-1], 0) == pytest.approx(1.0, abs=1e-9) + assert p.n_cz == 2 * sum(len(P.matchings(P.region_edges(be, p.region))[k % len(P.matchings(P.region_edges(be, p.region)))]) for k in range(d)) + + +def test_no_literal_palindrome(be): + p = P.build(8, 4, 5, be) + oneq = [g for g in p.gates if g[0] == "rz"] + k = len(oneq) // 2 + first = sorted(round(g[2], 6) for g in oneq[:k]) + second = sorted(round((-g[2]) % (2 * np.pi), 6) for g in oneq[k:]) + assert first != second + + +def test_rz_table_matches_closed_form(): + for th in (0.3, 1.1, -2.0): + a = A._table1(np.diag([np.exp(-0.5j * th), np.exp(0.5j * th)])) + assert a[1, 1] == pytest.approx(np.cos(th)) and a[1, 2] == pytest.approx(-np.sin(th)) + assert a[2, 2] == pytest.approx(np.cos(th)) and a[2, 1] == pytest.approx(np.sin(th)) + + +def test_pauli_propagation_exact_on_random_circuit(): + from qiskit.quantum_info import SparsePauliOp, Statevector + rng = np.random.default_rng(0) + n, gates = 5, [] + for _ in range(60): + r = rng.integers(4) + q = int(rng.integers(n)) + if r == 0: + gates.append(("rz", (q,), float(rng.uniform(0, 6.28)))) + elif r == 1: + gates.append(("sx", (q,), 0.0)) + elif r == 2: + gates.append(("x", (q,), 0.0)) + else: + a, b = rng.choice(n, 2, replace=False) + gates.append(("cz", (int(a), int(b)), 0.0)) + p = P.Peaked(n=n, depth=0, seed=0, region=list(range(n)), secret="0" * n, gates=gates) + sv = Statevector(p.qiskit(measure=False)) + for q in range(n): + lab = ["I"] * n + lab[n - 1 - q] = "Z" + want = float(np.real(sv.expectation_value(SparsePauliOp("".join(lab))))) + got = A.pp_expect_z(gates, n, q, eps=0.0, max_terms=10 ** 9)["z"] + assert got == pytest.approx(want, abs=1e-9) + + +def test_attacks_win_small_and_pp_fails_when_starved(be): + p = P.build(8, 4, 11, be) + assert A.pauli_propagation(p, eps=0.0, max_terms=10 ** 9)["win"] + assert A.light_cone_attack(p)["win"] + assert A.mps_attack(p, chi=16, shots=64)["win"] + big = P.build(16, 10, 12, be) + assert not A.pauli_propagation(big, eps=1e-2, max_terms=8)["win"] + + +def test_hardware_estimate_monotone_in_depth(be): + reg = P.choose_region(be, 12) + e = [P.hardware_estimate(P.build(12, d, 3, be, reg), be)["p_peak_pred"] for d in (2, 6, 10)] + assert 1 > e[0] > e[1] > e[2] > 0