Manuscript En02-D@4 · En02-D-v4.tex · section · e19ec871
Computational supplement
Computational supplement · lines 1392–1500
Copy the following listing to 02_d_v4.py.
Dependencies are Python, NumPy, CVXPY, and a supported SDP solver.
The default command requests SCS; installed versions are recorded.
Complex Hermitian variables and solver invocation follow the
official implementation documentation CVXPY.
python en02_d_v4.py –mode audit python en02_d_v4.py –mode pilot –tex En02-D-v4.tex –compile # Run the larger extension only after inspecting pilot cost: python en02_d_v4.py –mode extend –tex En02-D-v4.tex –compile
Each invocation creates a new archive directory. It initially has status RUNNING. Exceptions preserve arrays, residuals, and a traceback with FAILED status. A numerical passing status is issued only after the requested checks finish. Compilation is separately recorded and is required for the combined numerical-and-compilation status.
The archive is a finite floating-point regression, not a formal certificate. The code below has not been executed here.
"""En02-D-v4: unexecuted coherent audit and pilot implementation.""" import argparse import datetime import hashlib import itertools as it import json import math from pathlib import Path import shutil import subprocess import sys import traceback from fractions import Fraction as F import numpy as np
I = np.eye(2, dtype=complex) X = np.array([[0,1],[1,0]],complex) Y = np.array([[0,-1j],[1j,0]],complex) Z = np.diag([1,-1]).astype(complex) H = np.array([[1,1],[1,-1]],complex)/np.sqrt(2) SD = np.diag([1,-1j]).astype(complex) CZ = np.diag([1,1,1,-1]).astype(complex) CX = np.array([[1,0,0,0],[0,1,0,0], [0,0,0,1],[0,0,1,0]],complex) SW = np.array([[1,0,0,0],[0,0,1,0], [0,1,0,0],[0,0,0,1]],complex) TOL, STOL = 1e-10, 3e-4 DATA = {"checks":{}, "records":[], "solvers":[], "occupancy":[]} ROOT = None SOLVER = "SCS"
def need(ok, msg): if not ok: raise AssertionError(msg)
def herm(A): return (A+A.conj().T)/2
def mineig(A): return float(np.linalg.eigvalsh(herm(A)).min())
def check(name,A,B,tol=TOL): need(name not in DATA["checks"], "duplicate check "+name) A,B = np.asarray(A),np.asarray(B) need(A.shape==B.shape,"shape "+name) e = float(np.max(np.abs(A-B))) DATA["checks"][name] = e need(e<=tol, name+" residual "+str(e))
def save(name, **arrays): np.savez_compressed(ROOT/(name+".npz"), **arrays)
def dump(): (ROOT/"records.json").write_text(json.dumps(DATA,indent=2))
def kron(*ops): A = np.array([[1]],complex) for B in ops: A = np.kron(A,B) return A
def bits(i,n): return tuple((i>>(n-1-j))&1 for j in range(n))
def integer(b): out = 0 for z in b: out = 2*out+int(z) return out
def embed(G,pos,n): pos = tuple(pos) A = np.zeros((2**n,2**n),complex) for col in range(2**n): b = list(bits(col,n)) for row in range(2**len(pos)): a = b.copy() for p,z in zip(pos,bits(row,len(pos))): a[p] = z A[integer(a),col] += G[row,integer([b[p] for p in pos])] return A