Operator Loschmidt echo circuits on 49 to 70 qubits
Classically estimate an operator Loschmidt echo on 49- to 70-qubit circuits, where IBM hardware and classical simulations still disagree.
| 1 | #!/usr/bin/env python3 |
| 2 | """Judge a route's classical estimate of the operator Loschmidt echo. |
| 3 | |
| 4 | Usage: estimate.py <route_dir> |
| 5 | |
| 6 | The route folder may hold estimate.json, the report of one estimate: |
| 7 | |
| 8 | {"instance": "49x1296", # tracker id, with or without the operator_loschmidt_echo_ prefix |
| 9 | "value": 0.66, # the reported estimate of f_delta(O) |
| 10 | "lower": 0.655, "upper": 0.665, # the defensible error bar; the metric is upper - lower |
| 11 | "method": "BP-TN, bond dimension 512", |
| 12 | "convergence": [{"bond": 128, "estimate": 0.6599}, ...], # >= 2 entries, numeric "estimate" |
| 13 | "reproduce": "python3 bp_tn.py --bond 512 > estimate.json", |
| 14 | "runtime_s": 7260, "hardware": "...", "notes": "..." } # optional |
| 15 | |
| 16 | The check is exact about the contract and agnostic about the physics: it cannot recompute |
| 17 | f_delta(O) for 49-70 qubit circuits in a 10-minute, 4-CPU, no-network job, so it enforces |
| 18 | what makes an interval comparable within an instance and reports the width as the score. |
| 19 | O is a product of Pauli Z operators, O^2 = I, so f_delta(O) lies in [-1, 1]. |
| 20 | |
| 21 | Exits 0 when the report holds (or when there is no report to judge), 1 when it does not, |
| 22 | 2 when the folder cannot be read. metrics.json {"score": width} is written into the route |
| 23 | folder when a score is judged; everything the check prints is also on stdout. |
| 24 | """ |
| 25 | import json |
| 26 | import math |
| 27 | import os |
| 28 | import re |
| 29 | import sys |
| 30 | |
| 31 | INSTANCE_RE = re.compile(r"^(operator_loschmidt_echo_)?([1-9][0-9]{0,2})x([1-9][0-9]{0,4})$") |
| 32 | KNOWN = {"49x648", "49x1296", "70x1872", "56x1488"} # baseline + active candidates as of 2026-10-20 |
| 33 | CODE_SUFFIXES = (".py", ".ipynb", ".sh", ".jl", ".c", ".cc", ".cpp", ".rs", ".nb") |
| 34 | |
| 35 | |
| 36 | def fail(reason): |
| 37 | print(f"estimate: reject: {reason}") |
| 38 | sys.exit(1) |
| 39 | |
| 40 | |
| 41 | def number(report, key): |
| 42 | value = report.get(key) |
| 43 | if isinstance(value, bool) or not isinstance(value, (int, float)): |
| 44 | fail(f"{key} must be a number") |
| 45 | value = float(value) |
| 46 | if not math.isfinite(value): |
| 47 | fail(f"{key} must be finite (got {value})") |
| 48 | return value |
| 49 | |
| 50 | |
| 51 | def judge(route_dir): |
| 52 | path = os.path.join(route_dir, "estimate.json") |
| 53 | if not os.path.isdir(route_dir): |
| 54 | print(f"estimate: cannot judge: no folder {route_dir}") |
| 55 | sys.exit(2) |
| 56 | if not os.path.isfile(path): |
| 57 | print(f"Nothing to judge yet: {route_dir} holds no estimate.json") |
| 58 | sys.exit(0) |
| 59 | |
| 60 | try: |
| 61 | with open(path, encoding="utf-8") as handle: |
| 62 | report = json.load(handle) |
| 63 | except (OSError, UnicodeDecodeError) as err: |
| 64 | fail(f"estimate.json cannot be read: {err}") |
| 65 | except json.JSONDecodeError as err: |
| 66 | fail(f"estimate.json is not valid JSON: line {err.lineno}: {err.msg}") |
| 67 | if not isinstance(report, dict): |
| 68 | fail("estimate.json must hold a JSON object") |
| 69 | |
| 70 | instance = report.get("instance") |
| 71 | if not isinstance(instance, str) or not INSTANCE_RE.match(instance): |
| 72 | fail("instance must be a tracker id like 49x1296 or operator_loschmidt_echo_56x1488") |
| 73 | short = INSTANCE_RE.match(instance).group(2) + "x" + INSTANCE_RE.match(instance).group(3) |
| 74 | qubits = int(INSTANCE_RE.match(instance).group(2)) |
| 75 | if qubits > 156: |
| 76 | fail(f"instance names {qubits} qubits; the circuit files' register has 156") |
| 77 | if short not in KNOWN: |
| 78 | print(f"estimate: note: instance {short} is not one of the known ids " |
| 79 | f"{sorted(KNOWN)}; judged on form only") |
| 80 | |
| 81 | lower = number(report, "lower") |
| 82 | upper = number(report, "upper") |
| 83 | value = number(report, "value") |
| 84 | if not -1.0 <= lower: |
| 85 | fail(f"lower {lower} is below -1: O is a Z string with O^2 = I, so f_delta(O) in [-1, 1]") |
| 86 | if not upper <= 1.0: |
| 87 | fail(f"upper {upper} is above 1: O is a Z string with O^2 = I, so f_delta(O) in [-1, 1]") |
| 88 | if not lower <= value <= upper: |
| 89 | fail(f"value {value} is not inside [lower, upper] = [{lower}, {upper}]") |
| 90 | width = upper - lower |
| 91 | if width <= 0.0: |
| 92 | fail("the interval must have positive width: width 0 claims exactness") |
| 93 | |
| 94 | method = report.get("method") |
| 95 | if not isinstance(method, str) or not method.strip(): |
| 96 | fail("method must be a non-empty string (what computed the estimate)") |
| 97 | |
| 98 | convergence = report.get("convergence") |
| 99 | if not isinstance(convergence, list) or len(convergence) < 2: |
| 100 | fail("convergence must be a list of at least 2 entries: the README asks for evidence of convergence") |
| 101 | for i, entry in enumerate(convergence): |
| 102 | if not isinstance(entry, dict) or isinstance(entry.get("estimate"), bool) \ |
| 103 | or not isinstance(entry.get("estimate"), (int, float)) \ |
| 104 | or not math.isfinite(float(entry["estimate"])): |
| 105 | fail(f"convergence entry {i} must be an object with a finite numeric \"estimate\"") |
| 106 | estimate = float(entry["estimate"]) |
| 107 | if not -1.0 <= estimate <= 1.0: |
| 108 | fail(f"convergence entry {i} estimate {estimate} is outside [-1, 1]") |
| 109 | |
| 110 | reproduce = report.get("reproduce") |
| 111 | if not isinstance(reproduce, str) or not reproduce.strip(): |
| 112 | fail("reproduce must be a non-empty command: anyone should be able to rerun the code on the QASM file") |
| 113 | code = [name for name in os.listdir(route_dir) |
| 114 | if name.endswith(CODE_SUFFIXES) and os.path.isfile(os.path.join(route_dir, name))] |
| 115 | if not code: |
| 116 | fail(f"no code in the route folder ({', '.join(CODE_SUFFIXES)}): push what produced the estimate") |
| 117 | |
| 118 | runtime = report.get("runtime_s") |
| 119 | if runtime is not None and (isinstance(runtime, bool) or not isinstance(runtime, (int, float)) |
| 120 | or not math.isfinite(float(runtime)) or runtime < 0): |
| 121 | fail("runtime_s, when given, must be a finite number >= 0") |
| 122 | hardware = report.get("hardware") |
| 123 | if hardware is not None and not isinstance(hardware, str): |
| 124 | fail("hardware, when given, must be a string") |
| 125 | |
| 126 | score = round(width, 12) or width # trim float dust, never round a positive width to 0 |
| 127 | metrics = {"score": score} |
| 128 | metrics_path = os.path.join(route_dir, "metrics.json") |
| 129 | try: |
| 130 | with open(metrics_path, "w", encoding="utf-8") as handle: |
| 131 | json.dump(metrics, handle) |
| 132 | handle.write("\n") |
| 133 | print(f"estimate: wrote {metrics_path}: {json.dumps(metrics)}") |
| 134 | except OSError as err: |
| 135 | print(f"estimate: could not write {metrics_path}: {err}; score on stdout only: " |
| 136 | f"{json.dumps(metrics)}") |
| 137 | print(f"instance {short}: value {value} in [{lower}, {upper}], width {width} " |
| 138 | f"({len(convergence)} convergence entries, code: {', '.join(sorted(code))})") |
| 139 | sys.exit(0) |
| 140 | |
| 141 | |
| 142 | if __name__ == "__main__": |
| 143 | if len(sys.argv) != 2: |
| 144 | print(__doc__) |
| 145 | sys.exit(2) |
| 146 | judge(sys.argv[1]) |