Skip to content

Instantly share code, notes, and snippets.

@kumanna
Created March 7, 2024 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumanna/0320c1ab60a535b30df7be8debc1502e to your computer and use it in GitHub Desktop.
Save kumanna/0320c1ab60a535b30df7be8debc1502e to your computer and use it in GitHub Desktop.
import numpy as np
import numpy.linalg as LA
def flag_distance(mat1, mat2):
n_columns = mat1.shape[1]
running_metric = 0.0
for i in range(n_columns):
running_metric = LA.norm(np.outer(mat1[:,i], mat1[:,i].conj()) - np.outer(mat2[:,i], mat2[:,i].conj()), 'fro')**2
return np.sqrt(running_metric)
def gen_2by2_unitary_matrix(a):
ma = np.abs(a)
theta = np.angle(a)
cos = np.cos
sin = np.sin
return np.array([[cos(ma), np.exp(1j * theta) * np.sin(ma)],
[-np.exp(-1j * theta) * np.sin(ma), cos(ma)]])
a1 = np.random.rand() * np.pi / 2 * np.exp(1j * np.random.rand() * np.pi * 2)
a2 = np.random.rand() * np.pi / 2 * np.exp(1j * np.random.rand() * np.pi * 2)
A1 = gen_2by2_unitary_matrix(a1)
A2 = gen_2by2_unitary_matrix(a2)
print(flag_distance(A1, A2))
A11 = gen_2by2_unitary_matrix(np.abs(a1))
A21 = gen_2by2_unitary_matrix(np.abs(a2))
print(flag_distance(A11, A21))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment