Commit 53186161 authored by YesunHuang's avatar YesunHuang
Browse files

Add search EG, change to MC

parent 8b75662a
8.504252126063031048e-01 6.159167701233412284e-01 4.083229876658757591e-03 3.363680601354011035e-01 1.026186037329982037e+00 2.532999024522191713e-08 7.799378698513548258e-01 1.247430110698539485e+00 8.165369915088850350e-01
1.190595297648824324e+00 2.859287804691468815e-01 4.071219530853088971e-03 4.859556000547396448e-01 6.524392900120529193e-01 0.000000000000000000e+00 2.422774814529283227e-01 5.628755560805057123e-02 8.229972577099768649e-02
8.304152076038018304e-01 6.953862852588570398e-01 4.613714741142841205e-03 3.206311188252628508e-01 9.850366182413495819e-01 0.000000000000000000e+00 4.488107786945175759e-01 1.107887802581773329e+00 4.595156360437313570e-01
6.603301650825412761e-01 7.571026217328219454e-01 2.897378267178192263e-03 2.355091939453928807e-01 1.108825736377869742e+00 1.583081600164562175e-09 7.277414444227433554e-01 1.051833733915400249e+00 6.488353112664243527e-01
1.000500250125062607e+00 4.049479952612412004e-01 5.052004738758779541e-03 4.020144744559120964e-01 8.072832680844672648e-01 0.000000000000000000e+00 4.720156028491975242e-01 1.048847732060691929e+00 6.283004475566326130e-01
1.210605302651325710e+00 2.362022756088887621e-01 3.797724391111367837e-03 4.938927822987800309e-01 5.965439879142794277e-01 0.000000000000000000e+00 3.481270584479571051e-01 3.289264671073166557e-01 3.192308253476208169e-01
7.903951975987993928e-01 7.864160657844714297e-01 3.583934215528710322e-03 3.008242895285851981e-01 1.122703963590018672e+00 3.258067623528783767e-09 7.057779970446347306e-01 1.028526001468489159e+00 6.205908855577872973e-01
1.300650325162581167e+00 2.535743375962021262e-01 6.425662403797866191e-03 5.315393654516056277e-01 6.254476918088034409e-01 0.000000000000000000e+00 3.077588425525021321e-01 2.718505938607197400e-02 6.444187397384508464e-02
3.001500750375187376e+00 6.428004934630343788e-03 3.571995065369656854e-03 9.126295101624102291e-01 5.628902361174871471e-02 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
1.980990495247623828e+00 5.574945545843259381e-02 4.250544541567407436e-03 7.585413365095762250e-01 2.347367605042578742e-01 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
'''
Name: SFG_search.py
Desriptption:
Email: yesunhuang@mail.ustc.edu.cn
OpenSource: https://github.com/yesunhuang
Msg: For super computer
Author: YesunHuang
Date: 2021-06-05 21:15:28
'''
#import area
from qutip import*
import numpy as np
from scipy import math
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from matplotlib.pyplot import MultipleLocator
import time
'''
@name: BuildOperator_Exact
@fuction: Helper function for mesolve
@param {float} Ea
@param {float} deltaB
@param {float} g
@return {qobj} operator
'''
def BuildOperator_Exact(Ea:float,DeltaB:float,g:float):
Na=int(max(math.ceil(Ea*Ea+6*Ea),4)); Nb=2*psi0_l[1]; Nc=Nb
psi0=tensor(basis(Na,psi0_l[0]),basis(Nb,psi0_l[1]),basis(Nc,psi0_l[2]))
a=tensor(destroy(Na),qeye(Nb),qeye(Nc))
b=tensor(qeye(Na),destroy(Nb),qeye(Nc))
c=tensor(qeye(Na),qeye(Nb),destroy(Nc))
H=g*(a.dag()*b*c.dag()+a*b.dag()*c)+Ea*(a.dag()+a)+DeltaB*b.dag()*b
c_ops=[]
c_ops.append(np.sqrt(kappa_a)*a)
c_ops.append(np.sqrt(kappa_b)*b)
c_ops.append(np.sqrt(kappa_c)*c)
psiIdeal=tensor(basis(Nb,psi0_l[2]),basis(Nc,psi0_l[1]))
idealState=psiIdeal*psiIdeal.dag()
operator={'Hamilton':H,'Collapse':c_ops,'Initial_state':psi0,'Ideal_state':idealState,'track':[b.dag()*b,\
c.dag()*c,\
a.dag()*a,\
b.dag()*b.dag()*b*b,\
c.dag()*c.dag()*c*c,\
b.dag()*c.dag()*b*c]}
return operator
'''
@name: SearchForMax
@fuction: Search for max
@param {list} array
@return {int} maxIndex
'''
def SearchForMax(array:list):
max=0
maxIndex=0
for i in range(len(array)):
if array[i]>max:
max=array[i]
maxIndex=i
return maxIndex
#parameters
kappa_a=2;kappa_b=2;kappa_c=2
psi0_l=[0,3,0]
Ea=1
g=np.linspace(0.1,4,10)
Ntraj=100
DeltaB=0
tlist=np.linspace(0,20,2000)
opts=Options()
opts.store_states=True
opts.rhs_reuse=True
#opts.use_openmp=True
#data storage
data=np.zeros([np.size(g),9])
#solve for data
if __name__=="__main__":
for j in range(0,np.size(g)):
op=BuildOperator_Exact(Ea,DeltaB,g[j])
output=mcsolve(op['Hamilton'],op['Initial_state'],tlist,op['Collapse'],op['track'],ntraj=Ntraj,options=opts)
maxIndex=SearchForMax(output.expect[1])
data[j][0]=tlist[maxIndex] #t
data[j][1]=output.expect[0][maxIndex] #Nb
data[j][2]=output.expect[1][maxIndex] #Nc
data[j][3]=output.expect[2][maxIndex] #Na
rho=output.states[0][maxIndex]*output.states[0][maxIndex].dag()
for k in range(1,Ntraj):
rho+=output.states[k][maxIndex]*output.states[k][maxIndex].dag()
rho=1/Ntraj*rho
rho_bc=rho.ptrace([1,2])
data[j][4]=entropy_vn(rho_bc) #(A,BC) Entanglement
data[j][5]=expect(op['Ideal_state'],rho_bc) #Fidelity
data[j][6]=output.expect[3][maxIndex]/(data[j][1]*data[j][1]) #g2b
data[j][7]=output.expect[4][maxIndex]/(data[j][2]*data[j][2]) #g2c
data[j][8]=output.expect[5][maxIndex]/(data[j][1]*data[j][2]) #g2bc
#save data
np.savetxt('Data/EgData_DeltaB_'+str(DeltaB)+'_Ea_'+str(Ea)+'_g_'+str(g[0])+'-'+str(g[-1])+'.txt',data)
np.save('Data/EgData_DeltaB_'+str(DeltaB)+'_Ea_'+str(Ea)+'_g_'+str(g[0])+'-'+str(g[-1])+'.npy',data)
#!/bin/sh
#SBATCH -J SFG_Search
#SBATCH -o job-%j.log
#SBATCH -e job-%j.err
#SBATCH -N 4 -n 16
cd /gpfs/home/quaninfo/yesunhuang/SFG
python SFG_search_Eg.py
import numpy as np
from scipy import math
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
from matplotlib.pyplot import MultipleLocator
import time
#load data
Ea=1
DeltaB=0
g_s=0.1;g_e=4.0
data=np.load('Data/EgData_DeltaB_'+str(DeltaB)+'_Ea_'+str(Ea)+'_g_'+str(g_s)+'-'+str(g_e)+'.npy')
g=np.linspace(g_s,g_e,np.size(data,0))
#print population
fig, axes = plt.subplots(3,1 , figsize=(3,18))
axes[0].set_xlabel(r'$g$')
axes[1].set_xlabel(r'$g$')
axes[1].set_xlabel(r'$g$')
axes[0].set_ylabel(r'$\langle b^{\dagger}b\rangle$')
axes[1].set_ylabel(r'$\langle c^{\dagger}c\rangle$')
axes[2].set_ylabel(r'$\langle a^{\dagger}a\rangle$')
axes[0].plot(g,data[...,1],linestyle='-')
axes[1].plot(g,data[...,2],linestyle='-')
axes[2].plot(g,data[...,3],linestyle='-')
fig.savefig('imgs/EgPopulation_DeltaB_'+str(DeltaB)+'_Ea_'+str(Ea)+'_g_'+str(g_s)+'-'+str(g_e)+'.svg',dpi=600,format='svg',bbox_inches='tight')
#print other data
fig, axes = plt.subplots(3,2,figsize=(12,18))
axes[0,0].set_xlabel(r'$\Delta_b$')
axes[0,1].set_xlabel(r'$\Delta_b$')
axes[1,0].set_xlabel(r'$\Delta_b$')
axes[1,1].set_xlabel(r'$\Delta_b$')
axes[2,0].set_xlabel(r'$\Delta_b$')
axes[2,1].set_xlabel(r'$\Delta_b$')
#axes[0,1].set_ylim(0,5)
#axes[1,0].set_ylim(0,2)
#axes[1,1].set_ylim(0,2)
#axes[2,0].set_ylim(0,2)
axes[0,0].plot(g,data[...,4],linestyle='-.')
axes[0,1].plot(g,data[...,5],linestyle='-.')
axes[1,0].plot(g,data[...,6],linestyle='-.')
axes[1,1].plot(g,data[...,7],linestyle='-.')
axes[2,0].plot(g,data[...,8],linestyle='-.')
axes[2,1].plot(g,data[...,0],linestyle='-.')
axes[0,0].set_ylabel(r'$Entanglement$')
axes[0,1].set_ylabel(r'$Fidelity$')
axes[1,0].set_ylabel(r'$g_2b$')
axes[1,1].set_ylabel(r'$g_2c$')
axes[2,0].set_ylabel(r'$g_2bc$')
axes[2,1].set_ylabel(r'$t_max$')
fig.savefig('imgs/EgOtherData_DeltaB_'+str(DeltaB)+'_Ea_'+str(Ea)+'_g_'+str(g_s)+'-'+str(g_e)+'.svg',dpi=600,format='svg',bbox_inches='tight')
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment