-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmethods.py
153 lines (109 loc) · 4.55 KB
/
methods.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import numpy as np
import math
from typing import Dict, Union
from scipy.linalg import block_diag
def wigner_d(j: int, beta: float) -> np.ndarray:
dim = int(2 * j + 1)
mat = np.zeros((dim, dim))
m_prime_list = np.linspace(-j, j, dim)
m_list = np.linspace(-j, j, dim)
for row, m_prime in enumerate(m_prime_list):
for col, m in enumerate(m_list):
mat[row, col] += wigner_d_component(j, m_prime, m, beta)
return mat
def wigner_d_block_diag(jmax: int, beta: float) -> np.ndarray:
n = int(jmax * 2)
block = block_diag(*[wigner_d(i / 2, beta) for i in range(n)])
return block
def wigner_D(j: int, alpha: float, beta: float, gamma: float) -> np.ndarray:
dim = int(2 * j + 1)
mat = np.zeros((dim, dim), dtype="complex_")
m_prime_list = np.linspace(-j, j, dim)
m_list = np.linspace(-j, j, dim)
for row, m_prime in enumerate(m_prime_list):
for col, m in enumerate(m_list):
mat[row, col] += wigner_D_component(j, m_prime, m, alpha, beta, gamma)
return mat
def wigner_D_block_diag(jmax: int, beta: float) -> np.ndarray:
n = int(jmax * 2)
block = block_diag(*[wigner_d(i / 2, beta) for i in range(n)])
return block
def wigner_D_from_d(wigner_d: np.ndarray, alpha: float, gamma: float) -> np.ndarray:
"""Get the Wigner D matrix from the Wigner little d matrix"""
dim = wigner_d.shape[0]
mat = np.zeros((dim, dim), dtype="complex_")
m_range = np.linspace(-int((dim - 1) / 2), int((dim - 1) / 2), dim)
for row, m_prime in enumerate(m_range):
for col, m in enumerate(m_range):
mat[row, col] = (
np.exp(-1j * (m_prime * alpha + m * gamma)) * wigner_d[row, col]
)
return mat
def wigner_d_from_D(wigner_D: np.ndarray, alpha: float, gamma: float) -> np.ndarray:
"""Get the Wigner little d matrix from the Wigner D matrix"""
dim = wigner_D.shape[0]
mat = np.zeros((dim, dim), dtype="complex_")
m_range = np.linspace(-int((dim - 1) / 2), int((dim - 1) / 2), dim)
for row, m_prime in enumerate(m_range):
for col, m in enumerate(m_range):
mat[row, col] = (
np.exp(1j * (m_prime * alpha + m * gamma)) * wigner_D[row, col]
)
return mat
def wigner_d_dict(jmax: int, beta: float, jmin: int = 0) -> Dict[float, np.ndarray]:
res = dict()
jmin = max(jmin, 0)
for j in range(int(2 * jmin), int(2 * jmax + 1)):
res[j / 2] = wigner_d(j / 2, beta)
return res
def wigner_D_dict(
jmax: int, alpha: float, beta: float, gamma: float, jmin: int = 0
) -> Dict[float, np.ndarray]:
res = dict()
jmin = max(jmin, 0)
for j in range(int(2 * jmin), int(2 * jmax + 1)):
res[j / 2] = wigner_D(j / 2, alpha, beta, gamma)
return res
def wigner_D_dict_from_d_dict(
wigner_d_dict: Dict[float, np.ndarray], alpha: float, gamma: float
) -> Dict[float, np.ndarray]:
"""Get a dictionary of wigner D matrices from a dictionary of wigner d matrices"""
res = dict()
for j in wigner_d_dict.keys():
res[j] = wigner_D_from_d(wigner_d_dict[j], alpha, gamma)
return res
def wigner_d_dict_from_D_dict(
wigner_D_dict: Dict[float, np.ndarray], alpha: float, gamma: float
) -> Dict[float, np.ndarray]:
"""Get a dictionary of wigner D matrices from a dictionary of wigner d matrices"""
res = dict()
for j in wigner_D_dict.keys():
res[j] = wigner_d_from_D(wigner_D_dict[j], alpha, gamma)
return res
def wigner_d_component(j: int, m_prime: int, m: int, beta: int) -> float:
coefficient = math.sqrt(
math.factorial(j + m_prime)
* math.factorial(j - m_prime)
* math.factorial(j + m)
* math.factorial(j - m)
)
smin = max(0, m - m_prime)
smax = min(j + m, j - m_prime)
matrix_element = 0
s_list = np.linspace(smin, smax, int(smax - smin + 1))
for s in s_list:
numerator = (-1) ** (m_prime - m + s)
numerator *= np.cos(beta / 2) ** (2 * j + m - m_prime - 2 * s)
numerator *= np.sin(beta / 2) ** (m_prime - m + 2 * s)
denominator = math.factorial(j + m - s)
denominator *= math.factorial(s)
denominator *= math.factorial(m_prime - m + s)
denominator *= math.factorial(j - m_prime - s)
matrix_element += numerator / denominator
return coefficient * matrix_element
def wigner_D_component(
j: int, m_prime: int, m: int, alpha: float, beta: float, gamma: float
) -> Union[float, complex]:
return np.exp(-1j * (m_prime * alpha + m * gamma)) * wigner_d_component(
j, m_prime, m, beta
)