interferometer 1.1__tar.gz → 1.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: interferometer
3
- Version: 1.1
3
+ Version: 1.1.1
4
4
  Summary: Algorithms for universal interferometers
5
5
  Author-email: "William R. Clements" <mail@william-clements.com>
6
6
  Project-URL: Homepage, https://github.com/clementsw/interferometer
@@ -13,6 +13,8 @@ Classifier: Topic :: Scientific/Engineering :: Physics
13
13
  Requires-Python: >=3.7
14
14
  Description-Content-Type: text/markdown
15
15
  License-File: LICENSE
16
+ Requires-Dist: numpy
17
+ Requires-Dist: matplotlib
16
18
 
17
19
  # Interferometer package
18
20
 
@@ -185,8 +185,8 @@ def triangle_decomposition(U):
185
185
  for ii in range(N-1):
186
186
  for jj in range(N-1-ii):
187
187
  modes = [N - jj - 1, N - jj]
188
- theta = np.arctan(abs(U[ii, N - 1 - jj] / U[ii, N - 2 - jj]))
189
- phi = -np.angle(-U[ii, N - 1 - jj] / U[ii, N - 2 - jj])
188
+ theta = custom_arctan(U[ii, N - 1 - jj], U[ii, N - 2 - jj])
189
+ phi = -custom_angle(-U[ii, N - 1 - jj], U[ii, N - 2 - jj])
190
190
  invT = np.eye(N, dtype=np.complex_)
191
191
  invT[modes[0]-1, modes[0]-1] = np.exp(-1j * phi) * np.cos(theta)
192
192
  invT[modes[0]-1, modes[1]-1] = np.exp(-1j * phi) * np.sin(theta)
@@ -216,8 +216,8 @@ def square_decomposition(U):
216
216
  if np.mod(ii, 2) == 0:
217
217
  for jj in range(ii+1):
218
218
  modes = [ii - jj + 1, ii + 2 - jj]
219
- theta = np.arctan(abs(U[N-1-jj, ii-jj] / U[N-1-jj, ii-jj+1]))
220
- phi = np.angle(U[N-1-jj, ii-jj] / U[N-1-jj, ii-jj+1])
219
+ theta = custom_arctan(U[N-1-jj, ii-jj], U[N-1-jj, ii-jj+1])
220
+ phi = custom_angle(U[N-1-jj, ii-jj], U[N-1-jj, ii-jj+1])
221
221
  invT = np.eye(N, dtype=np.complex_)
222
222
  invT[modes[0]-1, modes[0]-1] = np.exp(-1j * phi) * np.cos(theta)
223
223
  invT[modes[0]-1, modes[1]-1] = np.exp(-1j * phi) * np.sin(theta)
@@ -228,8 +228,8 @@ def square_decomposition(U):
228
228
  else:
229
229
  for jj in range(ii+1):
230
230
  modes = [N+jj-ii-1, N+jj-ii]
231
- theta = np.arctan(abs(U[N+jj-ii-1, jj] / U[N+jj-ii-2, jj]))
232
- phi = np.angle(-U[N+jj-ii-1, jj] / U[N+jj-ii-2, jj])
231
+ theta = custom_arctan(U[N+jj-ii-1, jj], U[N+jj-ii-2, jj])
232
+ phi = custom_angle(-U[N+jj-ii-1, jj], U[N+jj-ii-2, jj])
233
233
  T = np.eye(N, dtype=np.complex_)
234
234
  T[modes[0]-1, modes[0]-1] = np.exp(1j * phi) * np.cos(theta)
235
235
  T[modes[0]-1, modes[1]-1] = -np.sin(theta)
@@ -246,8 +246,8 @@ def square_decomposition(U):
246
246
  invT[modes[1]-1, modes[0]-1] = -np.sin(BS.theta)
247
247
  invT[modes[1]-1, modes[1]-1] = np.cos(BS.theta)
248
248
  U = np.matmul(invT, U)
249
- theta = np.arctan(abs(U[modes[1]-1, modes[0]-1]/U[modes[1]-1, modes[1]-1]))
250
- phi = np.angle(U[modes[1]-1, modes[0]-1] / U[modes[1]-1, modes[1]-1])
249
+ theta = custom_arctan(U[modes[1]-1, modes[0]-1], U[modes[1]-1, modes[1]-1])
250
+ phi = custom_angle(U[modes[1]-1, modes[0]-1], U[modes[1]-1, modes[1]-1])
251
251
  invT[modes[0]-1, modes[0]-1] = np.exp(-1j * phi) * np.cos(theta)
252
252
  invT[modes[0]-1, modes[1]-1] = np.exp(-1j * phi) * np.sin(theta)
253
253
  invT[modes[1]-1, modes[0]-1] = -np.sin(theta)
@@ -281,3 +281,15 @@ def random_unitary(N):
281
281
  U = np.matmul(q, r)
282
282
 
283
283
  return U
284
+
285
+ def custom_arctan(x1, x2):
286
+ if x2 != 0:
287
+ return np.arctan(abs(x1/x2))
288
+ else:
289
+ return np.pi/2
290
+
291
+ def custom_angle(x1, x2):
292
+ if x2 != 0:
293
+ return np.angle(x1/x2)
294
+ else:
295
+ return 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: interferometer
3
- Version: 1.1
3
+ Version: 1.1.1
4
4
  Summary: Algorithms for universal interferometers
5
5
  Author-email: "William R. Clements" <mail@william-clements.com>
6
6
  Project-URL: Homepage, https://github.com/clementsw/interferometer
@@ -13,6 +13,8 @@ Classifier: Topic :: Scientific/Engineering :: Physics
13
13
  Requires-Python: >=3.7
14
14
  Description-Content-Type: text/markdown
15
15
  License-File: LICENSE
16
+ Requires-Dist: numpy
17
+ Requires-Dist: matplotlib
16
18
 
17
19
  # Interferometer package
18
20
 
@@ -7,4 +7,5 @@ interferometer.egg-info/PKG-INFO
7
7
  interferometer.egg-info/SOURCES.txt
8
8
  interferometer.egg-info/dependency_links.txt
9
9
  interferometer.egg-info/requires.txt
10
- interferometer.egg-info/top_level.txt
10
+ interferometer.egg-info/top_level.txt
11
+ tests/test_interferometer.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "interferometer"
7
- version = "1.1"
7
+ version = "1.1.1"
8
8
  authors = [
9
9
  { name="William R. Clements", email="mail@william-clements.com" },
10
10
  ]
@@ -0,0 +1,17 @@
1
+ import numpy as np
2
+ from unittest import TestCase
3
+
4
+ from interferometer import random_unitary, triangle_decomposition, square_decomposition
5
+
6
+ class TestInterferometer(TestCase):
7
+
8
+ def test_triangle_interferometer(self):
9
+ U = random_unitary(5)
10
+ I = triangle_decomposition(U)
11
+ self.assertTrue(abs(np.max(I.calculate_transformation() - U)) < 1e-14)
12
+
13
+ def test_square_interferometer(self):
14
+ U = random_unitary(5)
15
+ I = square_decomposition(U)
16
+ self.assertTrue(abs(np.max(I.calculate_transformation() - U)) < 1e-14)
17
+
File without changes
File without changes
File without changes