From 3c5f2981c616e7375a3155d4bfaffec6e361ff89 Mon Sep 17 00:00:00 2001 From: Ruben Erlenstedt Date: Sat, 30 Nov 2019 16:55:12 +0100 Subject: Adapt time evolution for 2qbit --- .gitignore | 3 ++- gnuplot_2q.plt | 7 +++++++ plotting.py | 57 --------------------------------------------------- single_dequantify.py | 11 +++++----- twoqbit_dequantify.py | 49 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 64 deletions(-) create mode 100644 gnuplot_2q.plt delete mode 100644 plotting.py create mode 100644 twoqbit_dequantify.py diff --git a/.gitignore b/.gitignore index 0c7b4fc..86b607b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -data +data* +plotting.py __pycache__ diff --git a/gnuplot_2q.plt b/gnuplot_2q.plt new file mode 100644 index 0000000..6614b49 --- /dev/null +++ b/gnuplot_2q.plt @@ -0,0 +1,7 @@ +set view equal xyz +set parametric +set isosamples 34,34 +splot cos(u)*cos(v),cos(u)*sin(v),sin(u) w l lc rgb "#42a4f5" +replot 'data2q' w points palette pointsize 2 pointtype 7 +; +pause mouse close diff --git a/plotting.py b/plotting.py deleted file mode 100644 index 57116c1..0000000 --- a/plotting.py +++ /dev/null @@ -1,57 +0,0 @@ -import math as mth -import cmath as cmt -import numpy as npy -from mpl_toolkits.mplot3d import Axes3D -import matplotlib.pyplot as plt -from itertools import product, combinations -from matplotlib.patches import FancyArrowPatch -from mpl_toolkits.mplot3d import proj3d - - -class Arrow3D(FancyArrowPatch): - - def __init__(self, xs, ys, zs, *args, **kwargs): - FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs) - self._verts3d = xs, ys, zs - - def draw(self, renderer): - xs3d, ys3d, zs3d = self._verts3d - xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) - self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) - FancyArrowPatch.draw(self, renderer) - - -def kugel(historie): - fig = plt.figure() - ax = fig.gca(projection='3d') - - # draw sphere - u, v = npy.mgrid[0:2*npy.pi:20j, 0:npy.pi:10j] - x = npy.cos(u)*npy.sin(v) - y = npy.sin(u)*npy.sin(v) - z = npy.cos(v) - ax.plot_wireframe(x, y, z, color="r") - - # draw a time evolution - for blochpunkt in historie: - x = mth.cos(blochpunkt[1]) * mth.cos(blochpunkt[0]) - y = mth.cos(blochpunkt[1]) * mth.sin(blochpunkt[0]) - z = mth.sin(blochpunkt[1]) - a = Arrow3D([0, x], [0, y], [0, z], mutation_scale=20, - lw=1, arrowstyle="-|>", color="k") - ax.add_artist(a) - plt.show() - -def phi(phi): - ax = plt.axes() - plt.grid() - - x = mth.cos(phi[0]) - y = mth.sin(phi[0]) - - ax.arrow(0, 0, 0.5, 0.5, head_width=0.05, head_length=0.07) - plt.title('Zeitentwicklung von phi') - - plt.xlim(-1.1,1.1) - plt.ylim(-1.1,1.1) - plt.show() diff --git a/single_dequantify.py b/single_dequantify.py index 8e801a1..db2ed0c 100644 --- a/single_dequantify.py +++ b/single_dequantify.py @@ -5,7 +5,7 @@ import cmath as cmt import numpy as npy import scipy.linalg as sla -alpha = 3 +alpha = 0 beta = 1 norm = npy.linalg.norm([alpha, beta]) @@ -14,7 +14,7 @@ state = npy.array([alpha / norm, beta / norm]) dt = 0.1 iterations = 61 -H = npy.array([[2,0],[0,3]]) +H = npy.array([[2,1j],[-1j,3]]) def time_evolution(state, dt = dt): return npy.dot(state, sla.expm(-1j * dt * H)) @@ -36,13 +36,12 @@ def sphere2cart(phi, theta): historie = npy.array([bloch_map(state)]) f = open("data", "w") -for i in range(iterations): - state = time_evolution(state) - h = npy.dot(state, state) +for i in range(iterations + 1): historie = npy.vstack([historie,bloch_map(state)]) (phi, theta) = bloch_map(state) coords = sphere2cart(phi, theta) - f.write(f"{coords[0]}; {coords[1]}; {coords[2]}; {(i + 1) / iterations}\n") + f.write(f"{coords[0]}; {coords[1]}; {coords[2]}; {(i + 1) / (iterations + 1)}\n") + state = time_evolution(state) f.close() diff --git a/twoqbit_dequantify.py b/twoqbit_dequantify.py new file mode 100644 index 0000000..9165a12 --- /dev/null +++ b/twoqbit_dequantify.py @@ -0,0 +1,49 @@ +import subprocess +import math as mth +import cmath as cmt +import numpy as npy +import scipy.linalg as sla + +alpha = 1 +beta = 1 +gamma = 1 +delta = 1 + +norm = npy.linalg.norm([alpha, beta, gamma, delta]) +state = npy.array([alpha / norm, beta / norm, gamma / norm, delta / norm]) + +dt = 0.1 +iterations = 5 + +H = npy.array([[1,0,0,0],[0,2,0,0],[0,0,3,0],[0,0,0,4]]) + +M0 = [[1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,-1]] +M1 = [[0,0,1,0],[0,0,0,1],[1,0,0,0],[0,1,0,0]] +M2 = [[0,0,-1j,0],[0,0,0,-1j],[1j,0,0,0],[0,1j,0,0]] +M3 = [[0,0,0,1],[0,0,-1,0],[0,-1,0,0],[1,0,0,0]] + + +def time_evolution(state, dt = dt): + return npy.dot(state, sla.expm(-1j * dt * H)) + +def fibration(state): + x0=npy.dot(npy.conj(state),npy.dot(M0,state)) + x1=npy.dot(npy.conj(state),npy.dot(M1,state)) + x2=npy.dot(npy.conj(state),npy.dot(M2,state)) + V=npy.dot(state,npy.dot(M3,state)) + x3=V.real + x4=V.imag + + return ([x0.real,x1.real,x2.real,x3,x4]) + + +f = open("data2q", "w") + +for i in range(iterations + 1): + hopf_state = fibration(state) + f.write(f"{hopf_state[0]}; {hopf_state[1]}; {hopf_state[2]}; {(i + 1) / (iterations + 1)}\n") + state = time_evolution(state) + +f.close() + +subprocess.run(["gnuplot", "gnuplot_2q.plt"]) -- cgit v1.2.3-54-g00ecf From fc949f6605f114d27cafc835b1bc7fa3027050b3 Mon Sep 17 00:00:00 2001 From: Ruben Erlenstedt Date: Sat, 30 Nov 2019 17:32:02 +0100 Subject: Plot x3 and x4 of hopf coordinates in 2D --- gnuplot_2d.plt | 11 +++++++++++ gnuplot_2q.plt | 7 ------- twoqbit_dequantify.py | 19 ++++++++++--------- 3 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 gnuplot_2d.plt delete mode 100644 gnuplot_2q.plt diff --git a/gnuplot_2d.plt b/gnuplot_2d.plt new file mode 100644 index 0000000..b3bf993 --- /dev/null +++ b/gnuplot_2d.plt @@ -0,0 +1,11 @@ +set size square +#plot cos(x),sin(y) w l lc rgb "#42a4f5" +set xrange [-1.1:1.1] +set yrange [-1.1:1.1] +set xlabel "Re(V)" +set ylabel "Im(V)" +set xzeroaxis +set yzeroaxis +plot 'data' w points palette pointsize 2 pointtype 7 +; +pause mouse close diff --git a/gnuplot_2q.plt b/gnuplot_2q.plt deleted file mode 100644 index 6614b49..0000000 --- a/gnuplot_2q.plt +++ /dev/null @@ -1,7 +0,0 @@ -set view equal xyz -set parametric -set isosamples 34,34 -splot cos(u)*cos(v),cos(u)*sin(v),sin(u) w l lc rgb "#42a4f5" -replot 'data2q' w points palette pointsize 2 pointtype 7 -; -pause mouse close diff --git a/twoqbit_dequantify.py b/twoqbit_dequantify.py index 9165a12..b6e0abb 100644 --- a/twoqbit_dequantify.py +++ b/twoqbit_dequantify.py @@ -4,18 +4,18 @@ import cmath as cmt import numpy as npy import scipy.linalg as sla -alpha = 1 -beta = 1 +alpha = 2 +beta = 0 gamma = 1 -delta = 1 +delta = 1+1j norm = npy.linalg.norm([alpha, beta, gamma, delta]) state = npy.array([alpha / norm, beta / norm, gamma / norm, delta / norm]) -dt = 0.1 -iterations = 5 +dt = 0.05 +iterations = 20 -H = npy.array([[1,0,0,0],[0,2,0,0],[0,0,3,0],[0,0,0,4]]) +H = npy.array([[1,0,0,1j],[0,2,0,0],[0,0,3,0],[-1j,0,0,4]]) M0 = [[1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,-1]] M1 = [[0,0,1,0],[0,0,0,1],[1,0,0,0],[0,1,0,0]] @@ -37,13 +37,14 @@ def fibration(state): return ([x0.real,x1.real,x2.real,x3,x4]) -f = open("data2q", "w") +f = open("data", "w") for i in range(iterations + 1): hopf_state = fibration(state) - f.write(f"{hopf_state[0]}; {hopf_state[1]}; {hopf_state[2]}; {(i + 1) / (iterations + 1)}\n") + f.write(f"{hopf_state[3]}; {hopf_state[4]}; {(i + 1) / (iterations + 1)}\n") + print(hopf_state) state = time_evolution(state) f.close() -subprocess.run(["gnuplot", "gnuplot_2q.plt"]) +subprocess.run(["gnuplot", "gnuplot_2d.plt"]) -- cgit v1.2.3-54-g00ecf