# ###### set up Hamiltonian and initial states no_checks = dict(check_pcon=False, check_symm=False, check_herm=False) H_BFM = hamiltonian(static, dynamic, basis=basis, **no_checks) # define initial Fock state through strings s_f = "".join("1" for i in range(Nf)) + "".join("0" for i in range(L - Nf)) s_b = "".join("1" for i in range(Nb)) # basis.index accepts strings and returns the index which corresponds to that state in the basis list i_0 = basis.index(s_b, s_f) # find index of product state in basis psi_0 = np.zeros(basis.Ns) # allocate space for state psi_0[i_0] = 1.0 # set MB state to be the given product state print("H-space size: {:d}, initial state: |{:s}>|{:s}>".format( basis.Ns, s_b, s_f)) # ###### time evolve initial state and measure entanglement between species t = Floquet_t_vec(Omega, 10, len_T=10) # t.vals=times, t.i=initial time, t.T=drive period psi_t = H_BFM.evolve(psi_0, t.i, t.vals, iterate=True) # measure observable Sent_args = dict(basis=basis, sub_sys_A="left") meas = obs_vs_time(psi_t, t.vals, {}, Sent_args=Sent_args) # read off measurements Entropy_t = meas["Sent_time"]["Sent_A"] # ###### # configuring plots plt.plot(t / t.T, Entropy_t) plt.xlabel("$\\mathrm{driving\\ cycle}$", fontsize=18) plt.ylabel('$S_\\mathrm{ent}(t)$', fontsize=18) plt.grid(True) plt.tick_params(labelsize=16) plt.tight_layout()
def test(): for _r in range(10): # 10 random realisations ##### define model parameters ##### L=4 # system size J=1.0 # spin interaction g=uniform(0.2,1.5) # transverse field h=uniform(0.2,1.5) # parallel field Omega=uniform(8.0,10.0) # drive frequency # ##### set up alternating Hamiltonians ##### # define time-reversal symmetric periodic step drive drive_args=[Omega] # compute basis in the 0-total momentum and +1-parity sector basis=spin_basis_1d(L=L,a=1,kblock=0,pblock=1) # define PBC site-coupling lists for operators x_field_pos=[[+g,i] for i in range(L)] x_field_neg=[[-g,i] for i in range(L)] z_field=[[h,i] for i in range(L)] J_nn=[[J,i,(i+1)%L] for i in range(L)] # PBC # static and dynamic lists for time-dep H static=[["zz",J_nn],["z",z_field],["x",x_field_pos]] dynamic=[["zz",J_nn,drive,drive_args], ["z",z_field,drive,drive_args],["x",x_field_neg,drive,drive_args]] # static and dynamic lists for step drive static1=[["zz",J_nn],["z",z_field]] static2=[["x",x_field_pos]] # loop over dtypes for _i in dtypes.keys(): dtype = dtypes[_i] atol = atols[_i] # compute Hamiltonians H=0.5*hamiltonian(static,dynamic,dtype=dtype,basis=basis) H1=hamiltonian(static1,[],dtype=dtype,basis=basis) H2=hamiltonian(static2,[],dtype=dtype,basis=basis) # ##### define time vector of stroboscopic times with 100 cycles ##### t=Floquet_t_vec(Omega,20,len_T=1) # t.vals=times, t.i=init. time, t.T=drive period # ##### calculate exact Floquet eigensystem ##### t_list=np.array([0.0,t.T/4.0,3.0*t.T/4.0])+np.finfo(float).eps # times to evaluate H dt_list=np.array([t.T/4.0,t.T/2.0,t.T/4.0]) # time step durations to apply H for ### # call Floquet class for evodict a coutinous H from a Hamiltonian object Floq_Hevolve=Floquet({'H':H,'T':t.T,'atol':1E-16,'rtol':1E-16},n_jobs=2) EF_Hevolve=Floq_Hevolve.EF # read off quasienergies # call Floquet class for evodict a step H from a Hamiltonian object Floq_H=Floquet({'H':H,'t_list':t_list,'dt_list':dt_list},n_jobs=2) EF_H=Floq_H.EF # read off quasienergies # call Floquet class for evodict a step H from a list of Hamiltonians Floq_Hlist=Floquet({'H_list':[H1,H2,H1],'dt_list':dt_list},n_jobs=2) # call Floquet class EF_Hlist=Floq_Hlist.EF try: np.testing.assert_allclose(EF_H,EF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(EF_H,EF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') except AssertionError: print('dtype, (g,h,Omega) =', dtype, (g,h,Omega)) print('exiting in line', lineno()+1) exit() ### # call Floquet class for evodict a coutinous H from a Hamiltonian object Floq_Hevolve=Floquet({'H':H,'T':t.T,'atol':1E-16,'rtol':1E-16},n_jobs=randint(2)+1,VF=True) EF_Hevolve=Floq_Hevolve.EF VF_Hevolve=Floq_Hevolve.VF # call Floquet class for evodict a step H from a Hamiltonian object Floq_H=Floquet({'H':H,'t_list':t_list,'dt_list':dt_list},n_jobs=randint(2)+1,VF=True) EF_H=Floq_H.EF # read off quasienergies VF_H=Floq_H.VF # read off Floquet states # call Floquet class for evodict a step H from a list of Hamiltonians Floq_Hlist=Floquet({'H_list':[H1,H2,H1],'dt_list':dt_list},n_jobs=randint(2)+1,VF=True) # call Floquet class EF_Hlist=Floq_Hlist.EF VF_Hlist=Floq_Hlist.VF try: np.testing.assert_allclose(EF_H,EF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(VF_H,VF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(EF_H,EF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(VF_H,VF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') except AssertionError: print('dtype, (g,h,Omega) =', dtype, (g,h,Omega)) print('exiting in line', lineno()+1) exit() ### # call Floquet class for evodict a coutinous H from a Hamiltonian object Floq_Hevolve=Floquet({'H':H,'T':t.T,'atol':1E-16,'rtol':1E-16},n_jobs=randint(2)+1,VF=True,UF=True) EF_Hevolve=Floq_Hevolve.EF VF_Hevolve=Floq_Hevolve.VF UF_Hevolve=Floq_Hevolve.UF # call Floquet class for evodict a step H from a Hamiltonian object Floq_H=Floquet({'H':H,'t_list':t_list,'dt_list':dt_list},n_jobs=randint(2)+1,VF=True,UF=True) EF_H=Floq_H.EF # read off quasienergies VF_H=Floq_H.VF # read off Floquet states UF_H=Floq_H.UF # call Floquet class for evodict a step H from a list of Hamiltonians Floq_Hlist=Floquet({'H_list':[H1,H2,H1],'dt_list':dt_list},n_jobs=randint(2)+1,VF=True,UF=True) # call Floquet class EF_Hlist=Floq_Hlist.EF VF_Hlist=Floq_Hlist.VF UF_Hlist=Floq_Hlist.UF try: np.testing.assert_allclose(EF_H,EF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(VF_H,VF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(UF_H,UF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(EF_H,EF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(VF_H,VF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(UF_H,UF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') except AssertionError: print('dtype, (g,h,Omega) =', dtype, (g,h,Omega)) print('exiting in line', lineno()+1) exit() ### # call Floquet class for evodict a coutinous H from a Hamiltonian object Floq_Hevolve=Floquet({'H':H,'T':t.T,'atol':1E-16,'rtol':1E-16},n_jobs=randint(2)+1,VF=True,UF=True,HF=True) EF_Hevolve=Floq_Hevolve.EF VF_Hevolve=Floq_Hevolve.VF UF_Hevolve=Floq_Hevolve.UF HF_Hevolve=Floq_Hevolve.HF # call Floquet class for evodict a step H from a Hamiltonian object Floq_H=Floquet({'H':H,'t_list':t_list,'dt_list':dt_list},n_jobs=randint(2)+1,VF=True,UF=True,HF=True) EF_H=Floq_H.EF # read off quasienergies VF_H=Floq_H.VF # read off Floquet states UF_H=Floq_H.UF HF_H=Floq_H.HF # call Floquet class for evodict a step H from a list of Hamiltonians Floq_Hlist=Floquet({'H_list':[H1,H2,H1],'dt_list':dt_list},n_jobs=randint(2)+1,VF=True,UF=True,HF=True) # call Floquet class EF_Hlist=Floq_Hlist.EF VF_Hlist=Floq_Hlist.VF UF_Hlist=Floq_Hlist.UF HF_Hlist=Floq_Hlist.HF try: np.testing.assert_allclose(EF_H,EF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(VF_H,VF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(UF_H,UF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(HF_H,HF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(EF_H,EF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(VF_H,VF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(UF_H,UF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(HF_H,HF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') except AssertionError: print('dtype, (g,h,Omega) =', dtype, (g,h,Omega)) print('exiting in line', lineno()+1) exit() ### # call Floquet class for evodict a coutinous H from a Hamiltonian object Floq_Hevolve=Floquet({'H':H,'T':t.T,'atol':1E-16,'rtol':1E-16},n_jobs=randint(2)+1,VF=True,UF=True,HF=True,thetaF=True) EF_Hevolve=Floq_Hevolve.EF VF_Hevolve=Floq_Hevolve.VF UF_Hevolve=Floq_Hevolve.UF HF_Hevolve=Floq_Hevolve.HF thetaF_Hevolve=Floq_Hevolve.thetaF # call Floquet class for evodict a step H from a Hamiltonian object Floq_H=Floquet({'H':H,'t_list':t_list,'dt_list':dt_list},n_jobs=randint(2)+1,VF=True,UF=True,HF=True,thetaF=True) EF_H=Floq_H.EF # read off quasienergies VF_H=Floq_H.VF # read off Floquet states UF_H=Floq_H.UF HF_H=Floq_H.HF thetaF_H=Floq_H.thetaF # call Floquet class for evodict a step H from a list of Hamiltonians Floq_Hlist=Floquet({'H_list':[H1,H2,H1],'dt_list':dt_list},n_jobs=randint(2)+1,VF=True,UF=True,HF=True,thetaF=True) # call Floquet class EF_Hlist=Floq_Hlist.EF VF_Hlist=Floq_Hlist.VF UF_Hlist=Floq_Hlist.UF HF_Hlist=Floq_Hlist.HF thetaF_Hlist=Floq_Hlist.thetaF try: np.testing.assert_allclose(EF_H,EF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(VF_H,VF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(UF_H,UF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(HF_H,HF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(thetaF_H,thetaF_Hlist,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(EF_H,EF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(VF_H,VF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(UF_H,UF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(HF_H,HF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') np.testing.assert_allclose(thetaF_H,thetaF_Hevolve,atol=atol,err_msg='Failed Floquet object comparison!') except AssertionError: print('dtype, (g,h,Omega) =', dtype, (g,h,Omega)) print('exiting in line', lineno()+1) exit() print("Floquet class random check {} finished successfully".format(_r))
# static single-particle V_dot[:Ns] = H.static.dot(V[Ns:]) V_dot[Ns:] = -H.static.dot(V[:Ns]) # dynamic single-particle for func,Hd in H.dynamic.items(): V_dot[:Ns] += func(time)*Hd.dot(V[Ns:]) V_dot[Ns:] -= func(time)*Hd.dot(V[:Ns]) return V_dot ##### time evolutino t=Floquet_t_vec(Omega,20,len_T=1) for stack_state in [0,1]: y_genevolve = evolve(V[:,0],t.i,t.f,SO_real,real=True,stack_state=True,f_params=(H,)) y = H.evolve(V[:,0],t.i,t.f,stack_state=stack_state) np.testing.assert_allclose(y-y_genevolve,0.0,atol=1E-6,err_msg='Failed evolve_scalar comparison!') y_genevolve = evolve(V[:,0],t.i,t.vals,SO_real,real=True,stack_state=True,f_params=(H,)) y = H.evolve(V[:,0],t.i,t.vals,stack_state=stack_state) np.testing.assert_allclose(y-y_genevolve,0.0,atol=1E-6,err_msg='Failed evolve_list comparison!')
# compute semi-classical Hamiltonian H_{sc}(t) H_sc = hamiltonian(static_sc, dynamic_sc, dtype=np.float64, basis=basis_sc) # ##### define initial state ##### # define atom ground state #psi_at_i=np.array([1.0,0.0]) # spin-down eigenstate of \sigma^z in QuSpin 0.2.3 or older psi_at_i = np.array( [0.0, 1.0]) # spin-down eigenstate of \sigma^z in QuSpin 0.2.6 or newer # define photon coherent state with mean photon number Nph psi_ph_i = coherent_state(np.sqrt(Nph), Nph_tot + 1) # compute atom-photon initial state as a tensor product psi_i = np.kron(psi_at_i, psi_ph_i) # ##### calculate time evolution ##### # define time vector over 30 driving cycles with 100 points per period t = Floquet_t_vec(Omega, 30) # t.i = initial time, t.T = driving period # evolve atom-photon state with Hamiltonian H psi_t = H.evolve(psi_i, t.i, t.vals, iterate=True, rtol=1E-9, atol=1E-9) # evolve atom GS with semi-classical Hamiltonian H_sc psi_sc_t = H_sc.evolve(psi_at_i, t.i, t.vals, iterate=True, rtol=1E-9, atol=1E-9) # ##### define observables ##### # define observables parameters obs_args = {"basis": basis, "check_herm": False, "check_symm": False} obs_args_sc = {"basis": basis_sc, "check_herm": False, "check_symm": False} # in atom-photon Hilbert space
L=50 # number of lattice sites i_CM = L//2-0.5 # centre of chain ### static model parameters J=1.0 # hopping mu_trap=0.002 # harmonic trap strength U=1.0 # mean-field (GPE) interaction ### periodic driving A=1.0 # drive amplitude Omega=3.0 # drive frequency def drive(t,Omega): return np.exp(-1j*A*np.sin(Omega*t) ) def drive_conj(t,Omega): return np.exp(+1j*A*np.sin(Omega*t) ) drive_args=[Omega] # drive arguments t=Floquet_t_vec(Omega,30,len_T=1) # time vector, 30 stroboscopic periods ### site-couping lists hopping=[[-J,i,(i+1)%L] for i in range(L)] trap=[[mu_trap*(i-i_CM)**2,i] for i in range(L)] ### operator strings for single-particle Hamiltonian static=[['n',trap]] dynamic=[["+-",hopping,drive,drive_args],["-+",hopping,drive_conj,drive_args]] # define single-particle basis basis = boson_basis_1d(L,Nb=1,sps=2) # Nb=1 boson and sps=2 states per site [empty and filled] ### build Hamiltonian H=hamiltonian(static,dynamic,basis=basis,dtype=np.complex128) # calculate eigenvalues and eigenvectors of free particle E,V=H.eigh() def GPE(time,phi):
from __future__ import print_function, division # import sys, os quspin_path = os.path.join(os.getcwd(), "../../") sys.path.insert(0, quspin_path) # from quspin.tools.Floquet import Floquet_t_vec # Floquet time vector import numpy as np # generic math functions # Omega = 4.5 # drive frequency # define time vector with three stages of evolution, labelled by "up", "const" and "down" t = Floquet_t_vec(Omega, 10, len_T=10, N_up=3, N_down=2) print(t) ##### attibutes referring to total time vector # time points values print(t.vals) # total number of periods print(t.N) # driving period print(t.T) # step size print(t.dt) # initial, final time and total time duration print(t.i, t.f, t.tot) # length of time vector and length within a period print(t.len, t.len_T) ##### attributes referring to stroboscopic times only # indices of stroboscopic times print(t.strobo.inds) # values of stroboscopic times print(t.strobo.vals)
from quspin.operators import hamiltonian # Hamiltonian and observables from quspin.tools.Floquet import Floquet_t_vec import numpy as np from numpy.random import uniform, seed, shuffle, randint # pseudo random numbers seed() """ This test only makes sure the floquet_t_vec class runs. """ Omega = uniform(3.0, 10.0) # drive frequency N_const = randint(100) #### t = Floquet_t_vec(Omega, N_const, len_T=100) t.vals t.i t.f t.T t.dt t.len len(t) t.len_T t.N t.strobo.vals t.strobo.inds ####
# spin-1 Hzz_1 = hamiltonian([["zz",Jzz_1]],[],basis=basis_1,dtype=np.float64) Hx_1 = hamiltonian([["+",hx_1],["-",hx_1]],[],basis=basis_1,dtype=np.float64) # ###### calculate initial states ###### # calculating bandwidth for non-driven hamiltonian [E_12_min],psi_12 = Hzz_12.eigsh(k=1,which="SA") # [E_1_min],psi_1 = Hzz_1.eigsh(k=1,which="SA") # set up the initial states psi0_12 = psi_12.ravel() psi0_1 = psi_1.ravel() # ###### time evolution ###### # stroboscopic time vector nT = 200 # number of periods to evolve to t=Floquet_t_vec(Omega,nT,len_T=1) # t.vals=t, t.i=initial time, t.T=drive period # creating generators of time evolution using exp_op class U1_12 = exp_op(Hzz_12+A*Hx_12,a=-1j*t.T/4) U2_12 = exp_op(Hzz_12-A*Hx_12,a=-1j*t.T/2) U1_1 = exp_op(Hzz_1+A*Hx_1,a=-1j*t.T/4) U2_1 = exp_op(Hzz_1-A*Hx_1,a=-1j*t.T/2) # user-defined generator for stroboscopic dynamics def evolve_gen(psi0,nT,*U_list): yield psi0 for i in range(nT): # loop over number of periods for U in U_list: # loop over unitaries psi0 = U.dot(psi0) yield psi0 # get generator objects for time-evolved states psi_12_t = evolve_gen(psi0_12,nT,U2_12,U1_12,U2_12) psi_1_t = evolve_gen(psi0_1,nT,U2_1,U1_1,U2_1)