Created
March 7, 2024 10:11
-
-
Save kumanna/0320c1ab60a535b30df7be8debc1502e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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