diff options
author | Dennis Kobert <dennis@kobert.dev> | 2019-11-30 19:24:20 +0100 |
---|---|---|
committer | Dennis Kobert <dennis@kobert.dev> | 2019-11-30 19:24:20 +0100 |
commit | 94935f80fac8d1275142d73b1a6b6d6492cc8207 (patch) | |
tree | 837c34f9db9426e74daefa8ba7e11b96ba527484 | |
parent | e1172e94602f4cf003392409d9543d17c31881dc (diff) |
Animate tow level systems
-rw-r--r-- | gnuplot/anim2d.plt | 15 | ||||
-rw-r--r-- | gnuplot/anim3d.plt (renamed from gnuplot/animation.plt) | 2 | ||||
-rw-r--r-- | plot.py | 15 | ||||
-rw-r--r-- | single_dequantify.py | 21 | ||||
-rw-r--r-- | twoqbit_dequantify.py | 47 |
5 files changed, 72 insertions, 28 deletions
diff --git a/gnuplot/anim2d.plt b/gnuplot/anim2d.plt new file mode 100644 index 0000000..38b8d5a --- /dev/null +++ b/gnuplot/anim2d.plt @@ -0,0 +1,15 @@ +set size square +set xrange [-1.1:1.1] +set yrange [-1.1:1.1] +set xlabel "Re(V)" +set ylabel "Im(V)" +set xzeroaxis +set yzeroaxis +set object circle at 0,0 size 1 + +do for [ii=start:end] { + plot 'data' every ::1::ii * states using 4:5:6 w points palette pointsize 2 pointtype 7 + pause 0.1 +} + +pause mouse close diff --git a/gnuplot/animation.plt b/gnuplot/anim3d.plt index 6228a53..99cfe10 100644 --- a/gnuplot/animation.plt +++ b/gnuplot/anim3d.plt @@ -4,7 +4,7 @@ set isosamples 34,34 do for [ii=start:end] { splot cos(u)*cos(v),cos(u)*sin(v),sin(u) w l lc rgb "#42a4f5", \ - 'data' every ::1::ii * states w points palette pointsize 2 pointtype 7#, \ + 'data' every ::1::ii * states using 1:2:3:6 w points palette pointsize 2 pointtype 7#, \ pause 0.1 } @@ -0,0 +1,15 @@ +import os +import subprocess + + +def plot(start, end, states = 1, script = "anim3d.plt"): + path = 'gnuplot/' + if os.name == 'nt': + path.replace('/','\\') + subprocess.run(["gnuplot", + "-e", f"states={states};", + "-e", f"start={start};" , + "-e", f"end={end};", + "-c", path + script]) + + diff --git a/single_dequantify.py b/single_dequantify.py index f43f9f1..99ebdc4 100644 --- a/single_dequantify.py +++ b/single_dequantify.py @@ -1,5 +1,5 @@ import sys -import subprocess +import plot import math as mth import cmath as cmt import numpy as npy @@ -7,7 +7,7 @@ import scipy.linalg as sla dt = 0.08 iterations = 100 -state_num = 1 +state_num = 3 H = npy.array([[1,0],[0,2]]) @@ -40,8 +40,6 @@ def sphere2cart(phi, theta): -1 * mth.cos(theta) ] -f = open("data", "w") - states = [] for i in range(state_num): (alpha, beta) = init_state(i) @@ -49,7 +47,7 @@ for i in range(state_num): state = npy.array([alpha / norm, beta / norm]) states.append(state) - +f = open("data", "w") for i in range(iterations): for j in range(state_num): (phi, theta) = bloch_map(states[j]) @@ -57,18 +55,9 @@ for i in range(iterations): colour = i / iterations if state_num > 1: colour = j / state_num - f.write(f"{coords[0]}; {coords[1]}; {coords[2]}; {colour}\n") + f.write(f"{coords[0]}; {coords[1]}; {coords[2]}; 0; 0; {colour}\n") states[j] = time_evolution(states[j]) - f.close() -import os +plot.plot(1, iterations, state_num, "anim2d.plt") -path = 'gnuplot/' -if os.name == 'nt': - path.replace('/','\\') -subprocess.run(["gnuplot", - "-e", f"states={state_num};", - "-e", f"start={iterations};" , - "-e", f"end={iterations};", - "-c", path + "animation.plt"]) diff --git a/twoqbit_dequantify.py b/twoqbit_dequantify.py index b6e0abb..efc3304 100644 --- a/twoqbit_dequantify.py +++ b/twoqbit_dequantify.py @@ -1,3 +1,5 @@ +import sys +import plot import subprocess import math as mth import cmath as cmt @@ -8,23 +10,36 @@ alpha = 2 beta = 0 gamma = 1 delta = 1+1j +state_num = 1 norm = npy.linalg.norm([alpha, beta, gamma, delta]) state = npy.array([alpha / norm, beta / norm, gamma / norm, delta / norm]) dt = 0.05 -iterations = 20 +iterations = 200 -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]] 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]] +if len(sys.argv) == 3: + alpha = complex(sys.argv[1]) + beta = complex(sys.argv[2]) + +def init_state(i): + alpha = 1 + beta = 1 + if state_num > 1: + alpha = i / state_num + beta = (state_num - i) / state_num + H = npy.array([[1,0,0,1j],[0,2,0,0],[0,0,3,0],[-1j,0,0,4]]) + return ([alpha, beta, gamma, delta], H) + def time_evolution(state, dt = dt): - return npy.dot(state, sla.expm(-1j * dt * H)) + return (npy.dot(state[0], sla.expm(-1j * dt * state[1])), state[1]) def fibration(state): x0=npy.dot(npy.conj(state),npy.dot(M0,state)) @@ -37,14 +52,24 @@ def fibration(state): return ([x0.real,x1.real,x2.real,x3,x4]) -f = open("data", "w") - -for i in range(iterations + 1): - hopf_state = fibration(state) - f.write(f"{hopf_state[3]}; {hopf_state[4]}; {(i + 1) / (iterations + 1)}\n") - print(hopf_state) - state = time_evolution(state) +states = [] +for i in range(state_num): + (co, H) = init_state(i) + norm = npy.linalg.norm(co) + state = npy.array([co[0] / norm, co[1] / norm, co[2] / norm, co[3] / norm]) + states.append((state, H)) +f = open("data", "w") +for i in range(iterations): + for j in range(state_num): + hopf_state = fibration(states[j][0]) + colour = i / iterations + if state_num > 1: + colour = j / state_num + f.write(f"{hopf_state[0]}; {hopf_state[1]}; {hopf_state[2]}; {hopf_state[3]}; {hopf_state[4]}; {colour}\n") + states[j] = time_evolution(states[j]) f.close() -subprocess.run(["gnuplot", "gnuplot_2d.plt"]) +#plot.plot(iterations, iterations, state_num, "anim3d.plt") +plot.plot(iterations, iterations, state_num, "anim2d.plt") + |