summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2019-11-30 10:11:40 +0100
committerDennis Kobert <dennis@kobert.dev>2019-11-30 10:11:40 +0100
commitf0662ea546cbbfde2a4bf369bd1d856ef39f5319 (patch)
tree6ca1445c83de09c117d6933d18bbd25ab483f989
Add single_dequantify.py
-rw-r--r--single_dequantify.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/single_dequantify.py b/single_dequantify.py
new file mode 100644
index 0000000..2a5e2bc
--- /dev/null
+++ b/single_dequantify.py
@@ -0,0 +1,45 @@
+
+import math as mth
+import cmath as cmt
+import numpy as npy
+import scipy.linalg as sla
+#import matplotlib.pyplot as plt
+
+alpha = 1 / npy.sqrt(2)
+beta = 1 / npy.sqrt(2)
+state = npy.array([alpha, beta])
+
+dt = 0.2
+iterations = 200
+
+H = npy.array([[2,-2j],[2j,3]])
+
+
+def time_evolution(state, dt = dt):
+ return npy.dot(state, sla.expm(-1j * dt * H))
+
+def bloch_map(state):
+ temp = npy.conj(state[0] / state[1])
+ phi = 2 * npy.arctan(1 / abs(temp))
+ theta = npy.arctan(temp.imag / temp.real)
+ return npy.array([phi, theta])
+
+def sphere2cart(phi, theta):
+ return [
+ mth.sin(theta) * mth.cos(phi),
+ mth.sin(theta) * mth.sin(phi),
+ mth.cos(theta)
+ ]
+
+for i in range(iterations):
+ state = time_evolution(state)
+ h = npy.dot(state, state)
+ #print(f"{bloch_map(state)[0]}; {bloch_map(state)[1]}")
+ coords = bloch_map(state)
+ coords = sphere2cart(coords[0], coords[1])
+ print(f"{coords[0]}; {coords[1]}; {coords[2]}")
+
+
+
+
+