%matplotlib inline
import qutip
import numpy as np
import scipy
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from IPython import display
import sys
import pickle
alpha_const_args = [(2, 200), (2,220), (2,240), (2,260), (2,280), (2,300)]
T_const_args = [(2.,200), (2.2,200), (2.4,200), (2.6,200), (2.8,200), (3.,200)]
both_args = [(2.,200), (2.2,220), (2.4,240), (2.6,260), (2.8,280), (3.,300)]
T_const_res = []
for a,T in T_const_args:
with open("results_three_circles_pop_gate_all_dance_one_blob_init_state_%0.3f_%d"%(a,T), "rb") as f:
T_const_res.append(pickle.load(f))
alpha_const_res = []
for a,T in alpha_const_args:
with open("results_three_circles_pop_gate_all_dance_one_blob_init_state_%0.3f_%d"%(a,T), "rb") as f:
alpha_const_res.append(pickle.load(f))
both_res = []
for a,T in both_args:
with open("results_three_circles_pop_gate_all_dance_one_blob_init_state_%0.3f_%d"%(a,T), "rb") as f:
both_res.append(pickle.load(f))
T_const_pur = [(_[-1]**2).tr() for _ in T_const_res]
alpha_const_pur = [(_[-1]**2).tr() for _ in alpha_const_res]
both_pur = [(_[-1]**2).tr() for _ in both_res]
plt.plot([a for a,T in T_const_args], T_const_pur)
plt.xlabel(r'$\alpha_0$')
plt.title(r'Purity-vs-$\alpha_0$ for $T=200$');
plt.plot([T for a,T in alpha_const_args], alpha_const_pur)
plt.xlabel(r'$T$')
plt.title(r'Purity-vs-$T$ for $\alpha_0=2$');
plt.plot(np.log([T for a,T in alpha_const_args]), np.log(1-np.array(alpha_const_pur)))
plt.xlabel(r'$T$')
plt.title(r'loglog Purity-vs-$T$ for $\alpha_0=2$');
A = np.array([np.log([T for a,T in alpha_const_args]),[1]*6]).T
B = np.log(1-np.array(alpha_const_pur))
x = np.linalg.lstsq(A, B)[0]
plt.plot(np.log([T for a,T in alpha_const_args]), np.log(1-np.array(alpha_const_pur)))
plt.plot(np.log([T for a,T in alpha_const_args]), A.dot(x), 'r', alpha=0.4,linewidth=7)
plt.xlabel(r'$T$')
plt.title(r'loglog Purity vs $T$ for $\alpha_0=2$'+'\n'+r'fit: $1-P\propto T^{%.3f}$'%x[0], fontsize=18)
plt.legend(['input','fit']);
A = np.concatenate([np.log(alpha_const_args+T_const_args+both_args).T,[[1]*18]]).T
B = np.log(1-np.array(alpha_const_pur+T_const_pur+both_pur))
x = np.linalg.lstsq(A, B)[0]
f = plt.figure(figsize=(12,8))
s = f.add_subplot(1,1,1,projection='3d')
s.set_xlabel(r'$\log{(\alpha)}$', fontsize=22)
s.set_ylabel(r'$\log{(T)}$', fontsize=22)
s.set_zlabel(r'$\log{(1-P)}$', fontsize=22)
s.set_title(r'log-log $1-P$ vs $\alpha$ and $T$'+'\n'+r'fit: $1-P\propto\alpha^{%.3f}T^{%.3f}$'%(x[0],x[1]),fontsize=24)
s.plot3D(xs=A[:,0],ys=A[:,1],zs=B,label='input',linewidth=1,marker='o')
am,tm = np.meshgrid(np.log(np.linspace(2,3)),np.log(np.linspace(200,300)))
am = am.flatten()
tm = tm.flatten()
res = np.array([am,tm,np.ones_like(am)]).T.dot(x)
s.plot_wireframe(am,tm,res,color='r',label='fit',alpha=0.4,linewidth=1)
for (a, t, _), p in zip(A,B):
s.plot3D([a,a],[t,t],zs=[-5.3,p],color='k',alpha=0.1,linewidth=2)
s.set_zlim3d(-5.3)
s.legend(fontsize=22)
s.view_init(elev=50.,azim=None);
f = plt.figure(figsize=(12,8))
s = f.add_subplot(1,1,1,projection='3d')
s.set_xlabel(r'$\log{(\alpha)}$', fontsize=22)
s.set_ylabel(r'$\log{(T)}$', fontsize=22)
s.set_zlabel(r'$\log{(\Delta)}$', fontsize=22)
s.set_title(r'log-log $\Delta$ vs $\alpha$ and $T$'+'\n'+r'fit: $\Delta\propto\alpha^{%.3f}T^{%.3f}$'%(x[0],x[1]),fontsize=24)
s.plot3D(xs=A[:,0],ys=A[:,1],zs=B,label='input',linewidth=1,marker='o')
am,tm = np.meshgrid(np.log(np.linspace(2,3)),np.log(np.linspace(200,300)))
am = am.flatten()
tm = tm.flatten()
res = np.array([am,tm,np.ones_like(am)]).T.dot(x)
s.plot_wireframe(am,tm,res,color='r',label='fit',alpha=0.4,linewidth=1)
for (a, t, _), p in zip(A,B):
s.plot3D([a,a],[t,t],zs=[-5.3,p],color='k',alpha=0.1,linewidth=2)
s.set_zlim3d(-5.3)
s.legend(fontsize=22)
s.view_init(elev=50.,azim=None);
# Fit wrt alpha_0 and "velocity" of blobs (i.e. alpha0/T)
A = np.concatenate([np.log(alpha_const_args+T_const_args+both_args).T,[[1]*18]]).T
A[:,1] = A[:,0]-A[:,1]
B = np.log(1-np.array(alpha_const_pur+T_const_pur+both_pur))
x = np.linalg.lstsq(A, B)[0]
x
array([-0.02043991, 0.98774758, -0.27095364])
frames = T_const_res[0]
n_frames = len(frames)
alpha0 = 2
T = 200
N = 55
samples = 680000
skip = 200
unit_interval = np.linspace(0,1,samples)[::skip]
unit_interval_radius = np.linspace(0,1,int(samples/(2+2*np.pi/6)))[::skip]
unit_interval_perim = np.linspace(0,1,samples-2*int(samples/(2+2*np.pi/6)))[::skip]
one = np.ones(samples)[::skip]
zero = np.zeros(samples)[::skip]
a_op = qutip.destroy(N)
adag_op = qutip.create(N)
id_op = qutip.identity(N)
zero_op = qutip.zero_oper(N)
num_op = qutip.num(N)
beta0 = alpha0*(-1/2 + 1j*3**0.5/2)
gamma0 = alpha0*(-1/2 - 1j*3**0.5/2)
init_state = (qutip.coherent(N,alpha0)).unit()
alphas_1 = unit_interval_radius[::-1]*alpha0
alphas_2 = unit_interval_radius*alpha0*np.exp(1j*2*np.pi/6)
alphas_3 = alpha0*np.exp(unit_interval_perim[::-1]*1j*2*np.pi/6)
alphas = np.concatenate([alphas_1, alphas_2, alphas_3])
betas = alphas*(-1/2 + 1j*3**0.5/2)
gammas = alphas*(-1/2 - 1j*3**0.5/2)
SKIP=10
time = T*unit_interval[::SKIP]
purity = np.array([(_**2).tr() for _ in frames[::SKIP]])
phases = np.array([[(qutip.coherent(N,a).dag()*_*qutip.coherent(N,b)).tr(),
(qutip.coherent(N,a).dag()*_*qutip.coherent(N,g)).tr()]
for _, a, b, g
in zip(frames[::SKIP],
alphas[::SKIP],
betas[::SKIP],
gammas[::SKIP])])
phases = np.angle(phases)
phases = (phases + 2*np.pi)%(2*np.pi)
populations = np.array([[(qutip.coherent(N,a).dag()*_*qutip.coherent(N,a)).tr(),
(qutip.coherent(N,b).dag()*_*qutip.coherent(N,b)).tr(),
(qutip.coherent(N,g).dag()*_*qutip.coherent(N,g)).tr()]
for _, a, b, g
in zip(frames[::SKIP],
alphas[::SKIP],
betas[::SKIP],
gammas[::SKIP])])
plt.plot(time,purity [:], 'k', alpha=0.5, linewidth=4)
plt.title('Purity vs time');
plt.plot(time,phases [:,0], 'g', alpha=0.5, linewidth=4)
plt.plot(time,phases [:,1], 'r', alpha=0.5, linewidth=4)
plt.title('Phases vs time')
plt.legend([r'$\alpha$ to $\beta$',r'$\alpha$ to $\gamma$']);
plt.plot(time,populations[:], alpha=0.5, linewidth=4)
plt.title('Population vs time')
plt.legend([r'$\alpha$',r'$\beta$',r'$\gamma$']);