feat: add U(1) example script for nuclear norm calculations and corrections
This commit is contained in:
parent
991af99562
commit
8e4263f632
2 changed files with 173 additions and 1 deletions
36
scripts/symmetric_states/9_check_u1_example.py
Normal file
36
scripts/symmetric_states/9_check_u1_example.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import numpy as np
|
||||
|
||||
X=np.array([[0,1],[1,0]],dtype=complex); Y=np.array([[0,-1j],[1j,0]],dtype=complex); Z=np.array([[1,0],[0,-1]],dtype=complex)
|
||||
I=np.eye(2,dtype=complex)
|
||||
paulis={'I':I,'X':X,'Y':Y,'Z':Z}
|
||||
|
||||
def state(phi):
|
||||
psi = np.zeros(16, dtype=complex)
|
||||
psi[0b0011] = np.cos(phi)
|
||||
psi[0b1100] = np.sin(phi)
|
||||
return psi
|
||||
|
||||
def kron4(a,b,c,d):
|
||||
return np.kron(np.kron(np.kron(a,b),c),d)
|
||||
|
||||
def corr(rho, labels):
|
||||
O = kron4(*[paulis[l] for l in labels])
|
||||
return np.trace(rho@O).real
|
||||
|
||||
for phi_deg in [10, 40, -10, -40, 100, 130, 200]:
|
||||
phi = np.deg2rad(phi_deg)
|
||||
psi = state(phi)
|
||||
rho = np.outer(psi, psi.conj())
|
||||
# build the 9x9 raw M_AB block (source AB active, target CD active) and get its true nuclear norm
|
||||
axes = [X,Y,Z]
|
||||
M = np.zeros((9,9))
|
||||
for ia in range(3):
|
||||
for ib in range(3):
|
||||
for ic in range(3):
|
||||
for id_ in range(3):
|
||||
O = kron4(axes[ia],axes[ib],axes[ic],axes[id_])
|
||||
M[3*ia+ib, 3*ic+id_] = np.trace(rho@O).real
|
||||
nn_true = np.linalg.svd(M, compute_uv=False).sum() / 3.0 # normalize by sqrt(3*3)=3
|
||||
pred_with_abs = 1/3 + 4/3*abs(np.sin(2*phi))
|
||||
pred_no_abs = 1/3 + 4/3*np.sin(2*phi)
|
||||
print(f"phi={phi_deg:+4d} deg: true ||M||_*={nn_true:.6f} pred_with_abs={pred_with_abs:.6f} pred_no_abs={pred_no_abs:.6f}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue