From 94935f80fac8d1275142d73b1a6b6d6492cc8207 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sat, 30 Nov 2019 19:24:20 +0100 Subject: Animate tow level systems --- gnuplot/anim2d.plt | 15 +++++++++++++++ gnuplot/anim3d.plt | 11 +++++++++++ gnuplot/animation.plt | 11 ----------- plot.py | 15 +++++++++++++++ single_dequantify.py | 21 +++++---------------- twoqbit_dequantify.py | 47 ++++++++++++++++++++++++++++++++++++----------- 6 files changed, 82 insertions(+), 38 deletions(-) create mode 100644 gnuplot/anim2d.plt create mode 100644 gnuplot/anim3d.plt delete mode 100644 gnuplot/animation.plt create mode 100644 plot.py 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/anim3d.plt b/gnuplot/anim3d.plt new file mode 100644 index 0000000..99cfe10 --- /dev/null +++ b/gnuplot/anim3d.plt @@ -0,0 +1,11 @@ +set view equal xyz +set parametric +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 using 1:2:3:6 w points palette pointsize 2 pointtype 7#, \ + pause 0.1 +} + +pause mouse close diff --git a/gnuplot/animation.plt b/gnuplot/animation.plt deleted file mode 100644 index 6228a53..0000000 --- a/gnuplot/animation.plt +++ /dev/null @@ -1,11 +0,0 @@ -set view equal xyz -set parametric -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#, \ - pause 0.1 -} - -pause mouse close diff --git a/plot.py b/plot.py new file mode 100644 index 0000000..6d8e449 --- /dev/null +++ b/plot.py @@ -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") + -- cgit v1.2.3-70-g09d2