Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions tutorials/01_manybody_binary_basis.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
include("../src/mybase.jl")
#include("../src/mybase.jl")
using KaiEDJ



function TestBinaryBasisCreAnni()
Expand All @@ -15,9 +17,9 @@ function TestBinaryBasisCreAnni()
println( ("cdagi|state $x> (for $i-th orbital operations) with isocc_zbase(), isemp_zbase(), NFerSwap(), Ntot() ") )
println( (" ci|state $x> (for $i-th orbital operations) with isocc_zbase(), isemp_zbase(), NFerSwap(), Ntot() ") )
println( "OUTPUT ::" )
println( format(" |{:s}> {:s} {:s} ; nswap={:d} ntot={:d}",getbittaili(x), isocc_zbase(x,i) , isemp_zbase(x,i) , NFerSwap(x,i) , OpNtot(x) ))
println( format(" |{:s}> {:s} {:s} ; nswap={:d} ntot={:d}",getbittaili(cdx), isocc_zbase(cdx,i), isemp_zbase(cdx,i), NFerSwap(cdx,i) , OpNtot(cdx) ))
println( format(" |{:s}> {:s} {:s} ; nswap={:d} ntot={:d}",getbittaili(cx), isocc_zbase(cx,i) , isemp_zbase(cx,i) , NFerSwap(cx,i) , OpNtot(cx) ))
println( KaiEDJ.format(" |{:s}> {:s} {:s} ; nswap={:d} ntot={:d}",getbittaili(x), isocc_zbase(x,i) , isemp_zbase(x,i) , NFerSwap(x,i) , OpNtot(x) ))
println( KaiEDJ.format(" |{:s}> {:s} {:s} ; nswap={:d} ntot={:d}",getbittaili(cdx), isocc_zbase(cdx,i), isemp_zbase(cdx,i), NFerSwap(cdx,i) , OpNtot(cdx) ))
println( KaiEDJ.format(" |{:s}> {:s} {:s} ; nswap={:d} ntot={:d}",getbittaili(cx), isocc_zbase(cx,i) , isemp_zbase(cx,i) , NFerSwap(cx,i) , OpNtot(cx) ))
println("")
end
end
Expand All @@ -37,9 +39,9 @@ function TestBinaryBasisNtot()
println( ("cdagi|state $x> (for $i-th orbital operations)", "isocc_zbase() isemp_zbase(), Ntot()") )
println( (" ci|state $x> (for $i-th orbital operations)", "isocc_zbase() isemp_zbase(), Ntot()") )
println( "OUTPUT ::" )
println( format(" |{:s}> {:s} {:s} ; ntot={:d} ",getbittaili(x), isocc_zbase(x,i) , isemp_zbase(x,i) , OpNtot(x) ))
println( format(" |{:s}> {:s} {:s} ; ntot={:d} ",getbittaili(cdx), isocc_zbase(cdx,i), isemp_zbase(cdx,i), OpNtot(cdx) ))
println( format(" |{:s}> {:s} {:s} ; ntot={:d} ",getbittaili(cx), isocc_zbase(cx,i) , isemp_zbase(cx,i) , OpNtot(cx) ))
println( KaiEDJ.format(" |{:s}> {:s} {:s} ; ntot={:d} ",getbittaili(x), isocc_zbase(x,i) , isemp_zbase(x,i) , OpNtot(x) ))
println( KaiEDJ.format(" |{:s}> {:s} {:s} ; ntot={:d} ",getbittaili(cdx), isocc_zbase(cdx,i), isemp_zbase(cdx,i), OpNtot(cdx) ))
println( KaiEDJ.format(" |{:s}> {:s} {:s} ; ntot={:d} ",getbittaili(cx), isocc_zbase(cx,i) , isemp_zbase(cx,i) , OpNtot(cx) ))
println("")
end
end
Expand Down
8 changes: 5 additions & 3 deletions tutorials/02_manybody_binary_basis_tensor_operation.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
include("../src/mybase.jl")
# include("../src/mybase.jl")
using KaiEDJ


println("")
println(" Vij operation ( Vij |psi> = |psi'> ) :" )
Expand All @@ -7,7 +9,7 @@ for x in 1:3
for i in 1:3
for j in 1:3
x_new = act_vij(x,i,j)
println(format("C({:d}) A({:d}) |{:s}> = {:s}", i, j, getbittaili(x), getbittaili(x_new) ))
println(KaiEDJ.format("C({:d}) A({:d}) |{:s}> = {:s}", i, j, getbittaili(x), getbittaili(x_new) ))
end
end
end
Expand All @@ -18,6 +20,6 @@ for x in 1:6
println("")
for (i,j,k,l) in [ [1,2,3,4], [1,2,2,1], [1,2,1,2], [1,3,2,1] ]
x_new = act_vijkl(x,i,j,k,l)
println(format("CCAA({}) |{:s}> = {:s}", [i,j,k,l], getbittaili(x), getbittaili(x_new) ))
println(KaiEDJ.format("CCAA({}) |{:s}> = {:s}", [i,j,k,l], getbittaili(x), getbittaili(x_new) ))
end
end
4 changes: 2 additions & 2 deletions tutorials/03_manybody_wavefunction_hashingfunction.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include("../src/mybase.jl")

#include("../src/mybase.jl")
using KaiEDJ

println("\n######### PARAMETER SETUP ##########")
norb = 3
Expand Down
4 changes: 2 additions & 2 deletions tutorials/04_manybody_wavefunction.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include("../src/mybase.jl")

#include("../src/mybase.jl")
using KaiEDJ

init_println("PARAMETER SETUP")
norb = 3
Expand Down
19 changes: 10 additions & 9 deletions tutorials/05_manybody_wavefunction_operations.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include("../src/mybase.jl")
#include("../src/mybase.jl")
using KaiEDJ


init_println("PARAMETER SETUP")
Expand Down Expand Up @@ -56,25 +57,25 @@ dimN3 = length(hashfsec[isectorN3])
wfN3_1 = WF(dimN3, hashfsec[isectorN3], hashfinv, isectorN3, Nel )
v0 = collect(1:dimN3)
wfN3_1.Probamp = v0
@show sparse(wfN3_1.Probamp)
@show KaiEDJ.sparse(wfN3_1.Probamp)


println( "" )
println( "wfN3_2 :: " )
wfN3_2 = WF(wfN3_1)
@show sparse(wfN3_2.Probamp)
@show KaiEDJ.sparse(wfN3_2.Probamp)

println( "OpCAWFadd( tij, wfN3_1, wfN3_2 ) " )
OpCAWFadd( tij, wfN3_1, wfN3_2 ; outputlevel= 2)
@show sparse(wfN3_2.Probamp)
@show KaiEDJ.sparse(wfN3_2.Probamp)

println( "OpCWFadd( cdi, wfN3_1, wfN3_2 ) " )
OpCWFadd( cdi, wfN3_1, wfN3_2 )
@show sparse(wfN3_2.Probamp)
@show KaiEDJ.sparse(wfN3_2.Probamp)

println( "OpAWFadd( ci, wfN3_1, wfN3_2 ) " )
OpAWFadd( ci, wfN3_1, wfN3_2 )
@show sparse(wfN3_2.Probamp)
@show KaiEDJ.sparse(wfN3_2.Probamp)

println( "" )
println( "ShowWFBasis(wfN3_1) ")
Expand All @@ -90,7 +91,7 @@ wfN4_1 = WF(dimN4, hashfsec[isectorN4], hashfinv, isectorN4, Nel )

println( "OpCWFadd( cdi, wfN3_1, wfN4_1 ) " )
OpCWFadd( cdi, wfN3_1, wfN4_1 )
@show sparse(wfN4_1.Probamp)
@show KaiEDJ.sparse(wfN4_1.Probamp)

println( "" )
println( "ShowWFBasis(wfN4_1) ")
Expand All @@ -106,8 +107,8 @@ wfN2_1 = WF(dimN2, hashfsec[isectorN2], hashfinv, isectorN2, Nel )

println( "OpAWFadd( ci, wfN3_1, wfN2_1 ) " )
OpAWFadd( ci, wfN3_1, wfN2_1 )
@show sparse(wfN3_1.Probamp)
@show sparse(wfN2_1.Probamp)
@show KaiEDJ.sparse(wfN3_1.Probamp)
@show KaiEDJ.sparse(wfN2_1.Probamp)

println( "" )
println( "ShowWFBasis(wfN2_1) ")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ENV["PROJECT_PATH_ED"]="../envs/KED"
include("../src/mybase.jl")
#ENV["PROJECT_PATH_ED"]="../envs/KED"
#include("../src/mybase.jl")
using KaiEDJ

norb = 3
nspin = 2
Expand Down Expand Up @@ -65,13 +66,13 @@ for opca in tij
ConstructHamil_ij!( H, opca, HashF, HashFInv ; outputlevel=2 )
end

@show issparse(H.MatSparse)
@show KaiEDJ.issparse(H.MatSparse)
@show H.MatSparse
@show ishermitian(H.MatSparse)
@show issymmetric(H.MatSparse)
@show KaiEDJ.ishermitian(H.MatSparse)
@show KaiEDJ.issymmetric(H.MatSparse)
@show count(!iszero, H.MatSparse)

eigensys = eigen( collect(H.MatSparse) )
eigensys = KaiEDJ.eigen( collect(H.MatSparse) )

for evitem in Iterators.enumerate( eigensys.values )
@show evitem
Expand Down
9 changes: 5 additions & 4 deletions tutorials/07_manybody_hamiltonian_impurity.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include("../src/mybase.jl")
#include("../src/mybase.jl")
using KaiEDJ

norb = 1
nspin = 2
Expand Down Expand Up @@ -72,7 +73,7 @@ for opca in Op_ebathl
end

@show H.MatSparse
@show issparse(H.MatSparse)
@show ishermitian(H.MatSparse)
@show issymmetric(H.MatSparse)
@show KaiEDJ.issparse(H.MatSparse)
@show KaiEDJ.ishermitian(H.MatSparse)
@show KaiEDJ.issymmetric(H.MatSparse)
@show count(!iszero, H.MatSparse)
39 changes: 20 additions & 19 deletions tutorials/08_green_function_impurity_continued_fraction.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include("../src/mybase.jl")
#include("../src/mybase.jl")
using KaiEDJ

### Impurity Setup ###
norb = 1
Expand Down Expand Up @@ -37,16 +38,16 @@ for i in 1:nspinorb
end
end
# @show Vil
println( "Vil : " ) ; writedlm(stdout, Vil)
println( "Vil : " ) ; KaiEDJ.writedlm(stdout, Vil)

IndOrbUp = [ i for i in 1:2:2*norb ]
IndOrbDn = [ i for i in 2:2:2*norb ]
IndBathUp = [ i for i in 1:2:2*nbathHalf ]
IndBathDn = [ i for i in 2:2:2*nbathHalf ]
VilUp = Vil[ IndOrbUp, IndBathUp ]
VilDn = Vil[ IndOrbDn, IndBathDn ]
println( "Vil Up : " ) ; writedlm(stdout, VilUp)
println( "Vil Dn : " ) ; writedlm(stdout, VilDn)
println( "Vil Up : " ) ; KaiEDJ.writedlm(stdout, VilUp)
println( "Vil Dn : " ) ; KaiEDJ.writedlm(stdout, VilDn)



Expand All @@ -73,7 +74,7 @@ enew, vnew = BathParamReshapePH( BParamUpPH, nbathHalf )
println( "" )
println( "Initial-parameters :")
println( "ebathl after PH : $(enew)" )
println( "Vil Up after PH : " ) ; writedlm(stdout, vnew)
println( "Vil Up after PH : " ) ; KaiEDJ.writedlm(stdout, vnew)
println( "" )
SParam = (
Hybiw,
Expand All @@ -85,9 +86,9 @@ SParam = (


### Optimizer ##
using Optimization
using KaiEDJ.Optimization
prob = OptimizationProblem(GetCostFromFlatPH, BParamUpPH, SParam)
using OptimizationOptimJL
using KaiEDJ.OptimizationOptimJL
maxiters = 2300
sol = solve(prob, NelderMead() ; maxiters=maxiters)
@show sol.original
Expand All @@ -96,7 +97,7 @@ BParamNew = [ sol... ]
enew, vnew = BathParamReshapePH( BParamNew, nbathHalf )
println("New parameters for Up")
@show enew
writedlm(stdout, vnew)
KaiEDJ.writedlm(stdout, vnew)



Expand Down Expand Up @@ -125,7 +126,7 @@ BParamDnNew = [ sol... ]
ednnew, vdnnew = BathParamReshapePH( BParamDnNew, nbathHalf )
println("New parameters for Dn")
@show ednnew
writedlm(stdout, vdnnew)
KaiEDJ.writedlm(stdout, vdnnew)

println("New parameters in total")
ebathl = zero(ebathl)
Expand All @@ -137,7 +138,7 @@ Vil[ IndOrbUp, IndBathUp ] = deepcopy(vnew)
Vil[ IndOrbDn, IndBathDn ] = deepcopy(vdnnew)
Vil[ IndOrbDn, IndBathDn ] = deepcopy(vnew) ## Impose time-reversal sym naively
@show ebathl
writedlm(stdout, Vil)
KaiEDJ.writedlm(stdout, Vil)



Expand Down Expand Up @@ -231,14 +232,14 @@ for opca in Op_tij
ConstructHamil_ij!( H, opca, HashF, HashFInv ; outputlevel=outputlevel)
end

@show issparse(H.MatSparse)
@show KaiEDJ.issparse(H.MatSparse)
@show H.MatSparse
@show ishermitian(H.MatSparse)
@show issymmetric(H.MatSparse)
@show KaiEDJ.ishermitian(H.MatSparse)
@show KaiEDJ.issymmetric(H.MatSparse)
@show count(!iszero, H.MatSparse)
@show size(H.MatSparse)

using Arpack
using KaiEDJ.Arpack

nev = 10
esAr = eigs( H.MatSparse ; which=:SR , nev = nev )
Expand All @@ -253,7 +254,7 @@ println("diff : ", real(esAr[1] .- esAr[1][1]) )

println("")
println("Ground-states : ")
println( format("nconv = {}, niter = {} , nmult = {}" ,esAr[3], esAr[4], esAr[5] ) )
println( KaiEDJ.format("nconv = {}, niter = {} , nmult = {}" ,esAr[3], esAr[4], esAr[5] ) )
nconvAr = esAr[3]
gsarr = Vector{Any}(undef,nconvAr)
OpSz = GetOpSz(ntot)
Expand All @@ -263,18 +264,18 @@ Szorbval = Vector{ComplexF64}(undef,nconvAr)
for i in 1:nconvAr
gsarr[i] = esAr[2][:,i]
prob_i, indBin = findmax( abs.(gsarr[i]) )
println( format("GS $i : Maximal basis states = {} [{}] N={} p={}",
println( KaiEDJ.format("GS $i : Maximal basis states = {} [{}] N={} p={}",
HashF[indBin], getbittaili(HashF[indBin]), OpNtot(HashF[indBin]), prob_i ))
end
println("")
for i in 1:nconvAr
gsarr[i] = esAr[2][:,i]
prob_i, indBin = findmax( abs.(gsarr[i]) )
println( format("GS $i : Maximal basis states = {} [{}] N={} p={}",
println( KaiEDJ.format("GS $i : Maximal basis states = {} [{}] N={} p={}",
HashF[indBin], getbittaili(HashF[indBin]), OpNtot(HashF[indBin]), prob_i ))
gswf = WF(dimSub, HashF, gsarr[i], wfargs... )
gswfres = WF(dimSub, HashF, wfargs... )
gswf.Probamp = collect( dropzeros!( sparse(gswf.Probamp) ) )
gswf.Probamp = collect( KaiEDJ.dropzeros!( KaiEDJ.sparse(gswf.Probamp) ) )


for opca in OpSz
Expand Down Expand Up @@ -397,7 +398,7 @@ yr2 = GetijarrayFromVecMat( yr2, 1, 1 )

bPlot=true
if bPlot
using Plots
using KaiEDJ.Plots
# writedlm( "log", [ wFreq imag(ydat1) imag(ydat2) imag(ydat1+ydat2) ] )
plot( wFreq, [ imag(ydat) imag(yr2) ] )
end
Expand Down
Loading