The script src/22-quantum/emulation.py of the validation package of the paper 22-qm, rendered with an anchor per line. ▶ run the predicates on Google Colab.
1## T9: qudit emulation of the FRC worked examples on quantum hardware.2## The forced-basis measurement of the formalism compiles to a shallow circuit:3## index the object cycle C_12 of the 157/53/13 example by (alpha, ell) with4## u = g_O^(alpha + 3*ell); the measurement vectors v_{r,alpha} are then5## delta_{alpha} x (quarter-turn characters i^{r ell}), so measuring in the6## forced basis is: apply (I_3 x F_4^dagger), read (alpha, r). F_4 is the7## 2-qubit QFT; the alpha register is a qutrit (or 2 qubits, 12 of 16 levels).8## The 641 configuration compiles identically with F_8 (3-qubit QFT) and a9## C_2 outcome register. What a hardware run certifies: the forced-basis10## statistics, the selection rules, the uniform-outcome law for winding states,11## and the three-outcome Malus law at the carrier's phase granularity.12## Claims verified:13## (M1) U = I_3 x F_4 is unitary and its columns are exactly the normalised14## forced-basis vectors (Gaussian-rational arithmetic);15## (M2) winding states u^s: channel r = s mod 4 deterministic, outcome alpha16## uniform (P = 1/3), all 12 windings, to 1e-12 (selection rule already17## exact in validate.py);18## (M3) doublet states u^s + lam*u^{s+4}: the three-outcome Malus law19## P(alpha) = |1 + lam*omega^alpha|^2 / 6, omega = zeta_3, swept over20## 12 phases lam = zeta_12^j;21## (M4) gate decomposition: the 2-qubit circuit H-CS-H-SWAP reproduces F_422## exactly (entry-by-entry);23## (M5) the 641 compilation: I_2 x F_8 statistics reproduce the sigma_x24## doublet law w_+- = |1 +- lam|^2/4 of composite.py (C3), swept over25## the pi/40 setting granularity.26import numpy as np2728def report(label, ok):29 print(('PASS ' if ok else 'FAIL ') + label)30 assert ok, label3132# ---------------- M1: the measurement unitary, 157/53/13 ----------------33# basis order: |alpha, ell>, alpha in 0..2, ell in 0..3 (12 levels)34F4 = np.array([[1j**(r*l) for l in range(4)] for r in range(4)])/2.035U = np.kron(np.eye(3), F4) # maps forced basis -> comp basis36report('M1: I_3 x F_4 unitary (12-level)', np.allclose(U @ U.conj().T, np.eye(12)))37# forced-basis vectors: v_{r,alpha}(alpha', ell) = delta * i^{r ell} / 238ok1 = True39for r in range(4):40 for al in range(3):41 v = np.zeros(12, complex)42 for l in range(4):43 v[al*4 + l] = 1j**(r*l)/2.044 e = np.zeros(12); e[al*4 + r] = 145 if not np.allclose(U.conj().T @ v, e): ok1 = False46report('M1: columns of U are exactly the normalised forced-basis vectors', ok1)4748# ---------------- M2: winding states -> deterministic channel, uniform outcome ----49z12 = np.exp(2j*np.pi/12)50ok2 = True51for s in range(12):52 psi = np.array([z12**(s*(al + 3*l)) for al in range(3) for l in range(4)])/np.sqrt(12)53 probs = np.abs(U.conj().T @ psi)**254 for al in range(3):55 for r in range(4):56 tgt = (1/3) if (r - s) % 4 == 0 else 0.057 if abs(probs[al*4 + r] - tgt) > 1e-12: ok2 = False58report('M2: winding u^s -> channel r = s mod 4 deterministic, outcome uniform '59 '1/3, all 12 windings', ok2)6061# ---------------- M3: three-outcome Malus law ----------------62ok3 = True63om = np.exp(2j*np.pi/3)64for s in (0, 1, 5):65 for j in range(12):66 lam = z12**j67 psi = np.array([z12**(s*(al + 3*l)) + lam*z12**((s+4)*(al + 3*l))68 for al in range(3) for l in range(4)])69 psi /= np.linalg.norm(psi)70 probs = np.abs(U.conj().T @ psi)**271 r = s % 472 for al in range(3):73 tgt = abs(1 + lam*om**al)**2/674 if abs(probs[al*4 + r] - tgt) > 1e-12: ok3 = False75report('M3: doublet Malus law P(alpha) = |1 + lam omega^alpha|^2/6, '76 'swept over 12 phases and 3 windings', ok3)7778# ---------------- M4: gate decomposition of F_4 ----------------79H = np.array([[1, 1], [1, -1]])/np.sqrt(2)80S = np.diag([1, 1j])81CS = np.diag([1, 1, 1, 1j]) # controlled-S82SWAP = np.array([[1,0,0,0],[0,0,1,0],[0,1,0,0],[0,0,0,1]])83QFT4 = SWAP @ np.kron(np.eye(2), H) @ CS @ np.kron(H, np.eye(2))84# standard QFT with kernel exp(2 pi i jk/4)/2 = i^{jk}/285report('M4: H-CS-H-SWAP two-qubit circuit reproduces F_4 exactly',86 np.allclose(QFT4, F4))8788# ---------------- M5: the 641 compilation (C_16, core C_8, C_2 outcome) ----------89F8 = np.array([[np.exp(2j*np.pi*r*l/8) for l in range(8)] for r in range(8)])/np.sqrt(8)90U16 = np.kron(np.eye(2), F8)91report('M5: I_2 x F_8 unitary (16-level)', np.allclose(U16 @ U16.conj().T, np.eye(16)))92z16 = np.exp(2j*np.pi/16)93ok5 = True94for s in (0, 3, 9):95 for j in range(80):96 lam = np.exp(2j*np.pi*8*j/640) # pi/40 granularity97 # basis |alpha, ell>, u = g_O^(alpha + 2*ell), alpha in {0,1}, ell in 0..798 psi = np.array([z16**(s*(al + 2*l)) + lam*z16**((s+8)*(al + 2*l))99 for al in range(2) for l in range(8)])100 psi /= np.linalg.norm(psi)101 probs = np.abs(U16.conj().T @ psi)**2102 r = s % 8103 wplus = abs(1 + lam)**2/4104 wminus = abs(1 - lam)**2/4105 # alpha = 0 fibre carries (1+lam*(-1)^alpha) pattern: check both outcomes106 got = (probs[0*8 + r], probs[1*8 + r])107 if abs(got[0] - wplus) > 1e-12 or abs(got[1] - wminus) > 1e-12: ok5 = False108report('M5: 641 compilation reproduces the sigma_x doublet law w_+- = '109 '|1 +- lam|^2/4 over the pi/40 sweep', ok5)110111print('INFO experiment card (157/53/13): prepare 12-level winding or doublet '112 'states; apply I_3 x QFT_4^dagger; read (alpha, r). Targets: trapped-ion '113 'qudits (d = 12 native) or 4-qubit embedding (12 of 16 levels).')114print('INFO experiment card (641/41/17): 16-level, I_2 x QFT_8^dagger; '115 'certifies Malus at pi/40 and the Tsirelson configuration statistics.')116print('emulation: all checks passed')117