I am trying to eliminate the type instabilities that might cause my code (shown below) of an iterative solver to some non linear system of equations to become slow:
using Printf,Plots, TimerOutputs
include("ccd-helper.jl")
function ccd_by_hand(maxitr)
initialize_cc_variables()
nv::Int64 = deserialize("nv.jlbin")
nocc::Int64 = deserialize("nocc.jlbin")
erhf::Float64 = deserialize("erhf.jlbin")
R2 = TensorMap(zeros(Float64,nv,nv,nocc,nocc),ℝ^nv ⊗ ℝ^nv , ℝ^nocc ⊗ ℝ^nocc)
println("R2 is of type $(typeof(R2))")
R2u = TensorMap(zeros(Float64,nv,nv,nocc,nocc),ℝ^nv ⊗ ℝ^nv , ℝ^nocc ⊗ ℝ^nocc)
R_iter = copy(R2)
Scaled_R2 = copy(R2)
T2_old::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}= initialize_t2_only()
println("T2 is of type $(typeof(T2_old))")
normtol=1.0e-8
e_new::Float64 = calculate_ECCD(T2_old)
e_old::Float64 = copy(0.0)
etol = 1.0e-10
p_max = 6# Maximum number of previous iterations to store for DIIS
p_min = 2 # DIIS will start after this many iterations
R_iter_storage = Array{typeof(R2)}(undef, 0)
T2_storage::Vector{typeof(T2_old)} = Array{typeof(T2_old)}(undef, 0)
R2_storage = Array{typeof(R2)}(undef, 0)
println("R2_storage is of type $(typeof(R2_storage))")
println("Starting CCD Iterations with Convergence Criteria as ||R₂||<$normtol , ΔE<$etol and max iterations=$maxitr")
println("-----------------------------------------------------------------------------------------------")
for i in 1:maxitr
@printf("\n-------------------------\nStarting Iteration: %d Current Total Energy: %.8f\n", i, e_new+erhf)
println("Energy before updating = $(e_old+erhf)")
# R2 = calculate_residual(T2_old,R2u,R2)
R2 = calculate_residual_memeff(T2_old)
println("R2 is of type $(typeof(R2))")
T2_old = update_T2(T2_old,R2,Scaled_R2)
println("T2 is of type $(typeof(T2_old))")
conv::Bool,r2norm::Float64 = check_convergence(R2,normtol,e_old,e_new,etol)
if conv
@printf("CCD Converged in %d iterations, no further updates required,current ||R2||=%.10f and ΔE = %.12f\n\n-------------------------\nE_Total = %.8f\n", i,r2norm,abs(e_old-e_new),e_new+erhf)
break
end
R_iter = calculate_R_iter(R_iter,R2)
@printf("CCD Not Converged in %d iterations, current ||R2|| = %.10f and ΔE = %.12f \n", i,r2norm,abs(e_old-e_new))
if i >= p_min #DIIS starts
println("DIIS is being implemented in iteration $i")
# if i >= p_min + p_max - 1
if length(R_iter_storage)>=p_max # Adjusted condition to start popping correctly
popfirst!(R_iter_storage)
popfirst!(T2_storage)
popfirst!(R2_storage)
end
push!(R_iter_storage, copy(R_iter))
push!(T2_storage, copy(T2_old))
push!(R2_storage, copy(R2))
#update T2 via DIIS
p::Int64 = length(R_iter_storage)
diis_result = PerformDiis(R_iter_storage,p,T2_storage,R2_storage)
if diis_result==false
# T2_old = update_T2(T2_old,R2,fvv,foo)
nothing
else
T2_old = diis_result
# println("DIIS has updated T2")
# display(T2_old)
end
elseif i == p_min - 1 #DIIS starts next iteration so add current stuff to memory
println("DIIS will start in next iteration")
push!(R_iter_storage, copy(R_iter))
push!(T2_storage, copy(T2_old))
push!(R2_storage, copy(R2))
just_show_Bmatrix(R_iter_storage,length(R_iter_storage),T2_storage,R2_storage)
else
println("DIIS start is still far away")
# No change to memory
end
e_old = e_new
e_new = calculate_ECCD(T2_old)
println("Energy after updating = $(e_new+erhf)\n-------------------------\n")
end
end
maxitr = 100;
@code_warntype ccd_by_hand(maxitr);
ccd_by_hand(maxitr)
On running the @code_warntype
macro on the function ccd_by_hand(..)
, I get the following output :
MethodInstance for ccd_by_hand(::Int64)
from ccd_by_hand(maxitr) @ Main ~/Desktop/Andreas Köhn/phase 1.5/code/tensorkit/ccd-memeff.jl:3
Arguments
#self#::Core.Const(ccd_by_hand)
maxitr::Int64
Locals
@_3::Union{Nothing, Tuple{Int64, Int64}}
R2_storage::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
T2_storage::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
R_iter_storage::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
p_min::Int64
p_max::Int64
etol::Float64
e_old::Float64
e_new::Float64
normtol::Float64
T2_old::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
Scaled_R2::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
R_iter::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
R2u::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
R2::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
erhf::Float64
nocc::Int64
nv::Int64
@_21::Int64
i::Int64
diis_result::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
p::Int64
r2norm::Float64
conv::Bool
@_27::Any
@_28::Any
@_29::Any
@_30::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
@_31::Any
@_32::Float64
@_33::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
@_34::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
@_35::Bool
@_36::Any
@_37::Int64
@_38::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
@_39::Float64
@_40::Any
Body::Nothing
1 ── Core.NewvarNode(:(@_3))
│ Core.NewvarNode(:(R2_storage))
│ Core.NewvarNode(:(T2_storage))
│ Core.NewvarNode(:(R_iter_storage))
│ Core.NewvarNode(:(p_min))
│ Core.NewvarNode(:(p_max))
│ Core.NewvarNode(:(etol))
│ Core.NewvarNode(:(e_old))
│ Core.NewvarNode(:(e_new))
│ Core.NewvarNode(:(normtol))
│ Core.NewvarNode(:(T2_old))
│ Core.NewvarNode(:(Scaled_R2))
│ Core.NewvarNode(:(R_iter))
│ Core.NewvarNode(:(R2u))
│ Core.NewvarNode(:(R2))
│ Core.NewvarNode(:(erhf))
│ Core.NewvarNode(:(nocc))
│ Core.NewvarNode(:(nv))
│ Main.initialize_cc_variables()
│ %20 = Main.deserialize("nv.jlbin")::Any
│ (@_27 = %20)
│ %22 = (@_27 isa Main.Int64)::Bool
└─── goto #3 if not %22
2 ── goto #4
3 ── %25 = Base.convert(Main.Int64, @_27)::Any
└─── (@_27 = Core.typeassert(%25, Main.Int64))
4 ┄─ (nv = @_27::Int64)
│ %28 = Main.deserialize("nocc.jlbin")::Any
│ (@_28 = %28)
│ %30 = (@_28 isa Main.Int64)::Bool
└─── goto #6 if not %30
5 ── goto #7
6 ── %33 = Base.convert(Main.Int64, @_28)::Any
└─── (@_28 = Core.typeassert(%33, Main.Int64))
7 ┄─ (nocc = @_28::Int64)
│ %36 = Main.deserialize("erhf.jlbin")::Any
│ (@_29 = %36)
│ %38 = (@_29 isa Main.Float64)::Bool
└─── goto #9 if not %38
8 ── goto #10
9 ── %41 = Base.convert(Main.Float64, @_29)::Any
└─── (@_29 = Core.typeassert(%41, Main.Float64))
10 ┄ (erhf = @_29::Float64)
│ %44 = Main.zeros(Main.Float64, nv, nv, nocc, nocc)::Array{Float64, 4}
│ %45 = (Main.ℝ ^ nv)::CartesianSpace
│ %46 = (Main.ℝ ^ nv)::CartesianSpace
│ %47 = (%45 ⊗ %46)::ProductSpace{CartesianSpace, 2}
│ %48 = (Main.ℝ ^ nocc)::CartesianSpace
│ %49 = (Main.ℝ ^ nocc)::CartesianSpace
│ %50 = (%48 ⊗ %49)::ProductSpace{CartesianSpace, 2}
│ (R2 = Main.TensorMap(%44, %47, %50))
│ %52 = Main.typeof(R2)::Core.Const(TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}})
│ %53 = Base.string("R2 is of type ", %52)::String
│ Main.println(%53)
│ %55 = Main.zeros(Main.Float64, nv, nv, nocc, nocc)::Array{Float64, 4}
│ %56 = (Main.ℝ ^ nv)::CartesianSpace
│ %57 = (Main.ℝ ^ nv)::CartesianSpace
│ %58 = (%56 ⊗ %57)::ProductSpace{CartesianSpace, 2}
│ %59 = (Main.ℝ ^ nocc)::CartesianSpace
│ %60 = (Main.ℝ ^ nocc)::CartesianSpace
│ %61 = (%59 ⊗ %60)::ProductSpace{CartesianSpace, 2}
│ (R2u = Main.TensorMap(%55, %58, %61))
│ (R_iter = Main.copy(R2))
│ (Scaled_R2 = Main.copy(R2))
│ %65 = Main.initialize_t2_only()::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
│ %66 = Main.TrivialTensorMap::Core.Const(TrivialTensorMap)
│ %67 = Main.CartesianSpace::Core.Const(CartesianSpace)
│ %68 = Core.apply_type(Main.Matrix, Main.Float64)::Core.Const(Matrix{Float64})
│ %69 = Core.apply_type(%66, %67, 2, 2, %68)::Core.Const(TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}})
│ (@_30 = %65)
│ %71 = (@_30 isa %69)::Core.Const(true)
└─── goto #12 if not %71
11 ─ goto #13
12 ─ Core.Const(:(Base.convert(%69, @_30)))
└─── Core.Const(:(@_30 = Core.typeassert(%74, %69)))
13 ┄ (T2_old = @_30)
│ %77 = Main.typeof(T2_old)::Core.Const(TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}})
│ %78 = Base.string("T2 is of type ", %77)::String
│ Main.println(%78)
│ (normtol = 1.0e-8)
│ %81 = Main.calculate_ECCD(T2_old)::Any
│ (@_31 = %81)
│ %83 = (@_31 isa Main.Float64)::Bool
└─── goto #15 if not %83
14 ─ goto #16
15 ─ %86 = Base.convert(Main.Float64, @_31)::Any
└─── (@_31 = Core.typeassert(%86, Main.Float64))
16 ┄ (e_new = @_31::Float64)
│ %89 = Main.copy(0.0)::Core.Const(0.0)
│ (@_32 = %89)
│ %91 = (@_32::Core.Const(0.0) isa Main.Float64)::Core.Const(true)
└─── goto #18 if not %91
17 ─ goto #19
18 ─ Core.Const(:(Base.convert(Main.Float64, @_32)))
└─── Core.Const(:(@_32 = Core.typeassert(%94, Main.Float64)))
19 ┄ (e_old = @_32::Core.Const(0.0))
│ (etol = 1.0e-10)
│ (p_max = 6)
│ (p_min = 2)
│ %100 = Main.Array::Core.Const(Array)
│ %101 = Main.typeof(R2)::Core.Const(TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}})
│ %102 = Core.apply_type(%100, %101)::Core.Const(Array{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}})
│ %103 = Main.undef::Core.Const(UndefInitializer())
│ (R_iter_storage = (%102)(%103, 0))
│ %105 = Main.Array::Core.Const(Array)
│ %106 = Main.typeof(T2_old)::Core.Const(TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}})
│ %107 = Core.apply_type(%105, %106)::Core.Const(Array{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}})
│ %108 = Main.undef::Core.Const(UndefInitializer())
│ %109 = (%107)(%108, 0)::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
│ %110 = Main.Vector::Core.Const(Vector)
│ %111 = Main.typeof(T2_old)::Core.Const(TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}})
│ %112 = Core.apply_type(%110, %111)::Core.Const(Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}})
│ (@_33 = %109)
│ %114 = (@_33 isa %112)::Core.Const(true)
└─── goto #21 if not %114
20 ─ goto #22
21 ─ Core.Const(:(Base.convert(%112, @_33)))
└─── Core.Const(:(@_33 = Core.typeassert(%117, %112)))
22 ┄ (T2_storage = @_33)
│ %120 = Main.Array::Core.Const(Array)
│ %121 = Main.typeof(R2)::Core.Const(TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}})
│ %122 = Core.apply_type(%120, %121)::Core.Const(Array{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}})
│ %123 = Main.undef::Core.Const(UndefInitializer())
│ (R2_storage = (%122)(%123, 0))
│ %125 = Main.typeof(R2_storage)::Core.Const(Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}})
│ %126 = Base.string("R2_storage is of type ", %125)::String
│ Main.println(%126)
│ %128 = Base.string("Starting CCD Iterations with Convergence Criteria as ||R₂||<", normtol::Core.Const(1.0e-8), " , ΔE<", etol::Core.Const(1.0e-10), " and max iterations=", maxitr)::String
│ Main.println(%128)
│ Main.println("-----------------------------------------------------------------------------------------------")
│ %131 = (1:maxitr)::Core.PartialStruct(UnitRange{Int64}, Any[Core.Const(1), Int64])
│ (@_3 = Base.iterate(%131))
│ %133 = (@_3 === nothing)::Bool
│ %134 = Base.not_int(%133)::Bool
└─── goto #57 if not %134
23 ┄ Core.NewvarNode(:(@_21))
│ Core.NewvarNode(:(diis_result))
│ Core.NewvarNode(:(p))
│ Core.NewvarNode(:(r2norm))
│ Core.NewvarNode(:(conv))
│ %141 = @_3::Tuple{Int64, Int64}
│ (i = Core.getfield(%141, 1))
│ %143 = Core.getfield(%141, 2)::Int64
│ %144 = Base.getproperty(Printf, :format)::Core.Const(Printf.format)
│ %145 = Main.stdout::IO
│ %146 = i::Int64
│ %147 = (e_new + erhf)::Float64
│ (%144)(%145, Printf.Format{Base.CodeUnits{UInt8, String}, Tuple{Printf.Spec{Val{'d'}}, Printf.Spec{Val{'f'}}}}(UInt8[0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x53, 0x74, 0x61, 0x72, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x49, 0x74, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x25, 0x64, 0x20, 0x20, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x20, 0x45, 0x6e, 0x65, 0x72, 0x67, 0x79, 0x3a, 0x20, 0x25, 0x2e, 0x38, 0x66, 0x0a], UnitRange{Int64}[1:47, 50:73, 78:78], (%.0d, %.8f), 2), %146, %147)
│ %149 = (e_old + erhf)::Float64
│ %150 = Base.string("Energy before updating = ", %149)::String
│ Main.println(%150)
│ (R2 = Main.calculate_residual_memeff(T2_old))
│ %153 = Main.typeof(R2)::Core.Const(TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}})
│ %154 = Base.string("R2 is of type ", %153)::String
│ Main.println(%154)
│ %156 = Main.update_T2(T2_old, R2, Scaled_R2)::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
│ %157 = Main.TrivialTensorMap::Core.Const(TrivialTensorMap)
│ %158 = Main.CartesianSpace::Core.Const(CartesianSpace)
│ %159 = Core.apply_type(Main.Matrix, Main.Float64)::Core.Const(Matrix{Float64})
│ %160 = Core.apply_type(%157, %158, 2, 2, %159)::Core.Const(TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}})
│ (@_34 = %156)
│ %162 = (@_34 isa %160)::Core.Const(true)
└─── goto #25 if not %162
24 ─ goto #26
25 ─ Core.Const(:(Base.convert(%160, @_34)))
└─── Core.Const(:(@_34 = Core.typeassert(%165, %160)))
26 ┄ (T2_old = @_34)
│ %168 = Main.typeof(T2_old)::Core.Const(TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}})
│ %169 = Base.string("T2 is of type ", %168)::String
│ Main.println(%169)
│ %171 = Main.check_convergence(R2, normtol::Core.Const(1.0e-8), e_old, e_new, etol::Core.Const(1.0e-10))::Tuple{Bool, Any}
│ %172 = Base.indexed_iterate(%171, 1)::Core.PartialStruct(Tuple{Bool, Int64}, Any[Bool, Core.Const(2)])
│ %173 = Core.getfield(%172, 1)::Bool
│ (@_21 = Core.getfield(%172, 2))
│ %175 = Base.indexed_iterate(%171, 2, @_21::Core.Const(2))::Core.PartialStruct(Tuple{Any, Int64}, Any[Any, Core.Const(3)])
│ %176 = Core.getfield(%175, 1)::Any
│ (@_35 = %173)
│ %178 = (@_35 isa Main.Bool)::Core.Const(true)
└─── goto #28 if not %178
27 ─ goto #29
28 ─ Core.Const(:(Base.convert(Main.Bool, @_35)))
└─── Core.Const(:(@_35 = Core.typeassert(%181, Main.Bool)))
29 ┄ (conv = @_35)
│ (@_36 = %176)
│ %185 = (@_36 isa Main.Float64)::Bool
└─── goto #31 if not %185
30 ─ goto #32
31 ─ %188 = Base.convert(Main.Float64, @_36)::Any
└─── (@_36 = Core.typeassert(%188, Main.Float64))
32 ┄ (r2norm = @_36::Float64)
└─── goto #34 if not conv
33 ─ %192 = Base.getproperty(Printf, :format)::Core.Const(Printf.format)
│ %193 = Main.stdout::IO
│ %194 = i::Int64
│ %195 = r2norm::Float64
│ %196 = (e_old - e_new)::Float64
│ %197 = Main.abs(%196)::Float64
│ %198 = (e_new + erhf)::Float64
│ (%192)(%193, Printf.Format{Base.CodeUnits{UInt8, String}, Tuple{Printf.Spec{Val{'d'}}, Printf.Spec{Val{'f'}}, Printf.Spec{Val{'f'}}, Printf.Spec{Val{'f'}}}}(UInt8[0x43, 0x43, 0x44, 0x20, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x67, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x25, 0x64, 0x20, 0x69, 0x74, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x20, 0x6e, 0x6f, 0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72, 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x73, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x2c, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x7c, 0x7c, 0x52, 0x32, 0x7c, 0x7c, 0x3d, 0x25, 0x2e, 0x31, 0x30, 0x66, 0x20, 0x61, 0x6e, 0x64, 0x20, 0xce, 0x94, 0x45, 0x20, 0x3d, 0x20, 0x25, 0x2e, 0x31, 0x32, 0x66, 0x0a, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x45, 0x5f, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x25, 0x2e, 0x38, 0x66, 0x0a], UnitRange{Int64}[1:17, 20:75, 81:91, 97:134, 139:139], (%.0d, %.10f, %.12f, %.8f), 4), %194, %195, %197, %198)
└─── goto #57
34 ─ (R_iter = Main.calculate_R_iter(R_iter, R2))
│ %202 = Base.getproperty(Printf, :format)::Core.Const(Printf.format)
│ %203 = Main.stdout::IO
│ %204 = i::Int64
│ %205 = r2norm::Float64
│ %206 = (e_old - e_new)::Float64
│ %207 = Main.abs(%206)::Float64
│ (%202)(%203, Printf.Format{Base.CodeUnits{UInt8, String}, Tuple{Printf.Spec{Val{'d'}}, Printf.Spec{Val{'f'}}, Printf.Spec{Val{'f'}}}}(UInt8[0x43, 0x43, 0x44, 0x20, 0x4e, 0x6f, 0x74, 0x20, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x67, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x20, 0x25, 0x64, 0x20, 0x69, 0x74, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x20, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x20, 0x7c, 0x7c, 0x52, 0x32, 0x7c, 0x7c, 0x20, 0x3d, 0x20, 0x25, 0x2e, 0x31, 0x30, 0x66, 0x20, 0x61, 0x6e, 0x64, 0x20, 0xce, 0x94, 0x45, 0x20, 0x3d, 0x20, 0x25, 0x2e, 0x31, 0x32, 0x66, 0x20, 0x0a], UnitRange{Int64}[1:21, 24:53, 59:69, 75:76], (%.0d, %.10f, %.12f), 3), %204, %205, %207)
│ %209 = (i >= p_min::Core.Const(2))::Bool
└─── goto #46 if not %209
35 ─ %211 = Base.string("DIIS is being implemented in iteration ", i)::String
│ Main.println(%211)
│ %213 = Main.length(R_iter_storage)::Int64
│ %214 = (%213 >= p_max::Core.Const(6))::Bool
└─── goto #37 if not %214
36 ─ Main.popfirst!(R_iter_storage)
│ Main.popfirst!(T2_storage)
└─── Main.popfirst!(R2_storage)
37 ┄ %219 = R_iter_storage::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
│ %220 = Main.copy(R_iter)::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
│ Main.push!(%219, %220)
│ %222 = T2_storage::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
│ %223 = Main.copy(T2_old)::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
│ Main.push!(%222, %223)
│ %225 = R2_storage::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
│ %226 = Main.copy(R2)::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
│ Main.push!(%225, %226)
│ %228 = Main.length(R_iter_storage)::Int64
│ (@_37 = %228)
│ %230 = (@_37 isa Main.Int64)::Core.Const(true)
└─── goto #39 if not %230
38 ─ goto #40
39 ─ Core.Const(:(Base.convert(Main.Int64, @_37)))
└─── Core.Const(:(@_37 = Core.typeassert(%233, Main.Int64)))
40 ┄ (p = @_37)
│ (diis_result = Main.PerformDiis(R_iter_storage, p, T2_storage, R2_storage))
│ %237 = (diis_result == false)::Core.Const(false)
└─── goto #42 if not %237
41 ─ Core.Const(:(Main.nothing))
└─── Core.Const(:(goto %253))
42 ┄ %241 = diis_result::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
│ %242 = Main.TrivialTensorMap::Core.Const(TrivialTensorMap)
│ %243 = Main.CartesianSpace::Core.Const(CartesianSpace)
│ %244 = Core.apply_type(Main.Matrix, Main.Float64)::Core.Const(Matrix{Float64})
│ %245 = Core.apply_type(%242, %243, 2, 2, %244)::Core.Const(TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}})
│ (@_38 = %241)
│ %247 = (@_38 isa %245)::Core.Const(true)
└─── goto #44 if not %247
43 ─ goto #45
44 ─ Core.Const(:(Base.convert(%245, @_38)))
└─── Core.Const(:(@_38 = Core.typeassert(%250, %245)))
45 ┄ (T2_old = @_38)
└─── goto #49
46 ─ %254 = i::Int64
│ %255 = (p_min::Core.Const(2) - 1)::Core.Const(1)
│ %256 = (%254 == %255)::Bool
└─── goto #48 if not %256
47 ─ Main.println("DIIS will start in next iteration")
│ %259 = R_iter_storage::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
│ %260 = Main.copy(R_iter)::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
│ Main.push!(%259, %260)
│ %262 = T2_storage::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
│ %263 = Main.copy(T2_old)::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
│ Main.push!(%262, %263)
│ %265 = R2_storage::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
│ %266 = Main.copy(R2)::TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}
│ Main.push!(%265, %266)
│ %268 = R_iter_storage::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
│ %269 = Main.length(R_iter_storage)::Int64
│ %270 = T2_storage::Vector{TrivialTensorMap{CartesianSpace, 2, 2, Matrix{Float64}}}
│ Main.just_show_Bmatrix(%268, %269, %270, R2_storage)
└─── goto #49
48 ─ Main.println("DIIS start is still far away")
49 ┄ %274 = e_new::Float64
│ (@_39 = %274)
│ %276 = (@_39 isa Main.Float64)::Core.Const(true)
└─── goto #51 if not %276
50 ─ goto #52
51 ─ Core.Const(:(Base.convert(Main.Float64, @_39)))
└─── Core.Const(:(@_39 = Core.typeassert(%279, Main.Float64)))
52 ┄ (e_old = @_39)
│ %282 = Main.calculate_ECCD(T2_old)::Any
│ (@_40 = %282)
│ %284 = (@_40 isa Main.Float64)::Bool
└─── goto #54 if not %284
53 ─ goto #55
54 ─ %287 = Base.convert(Main.Float64, @_40)::Any
└─── (@_40 = Core.typeassert(%287, Main.Float64))
55 ┄ (e_new = @_40::Float64)
│ %290 = (e_new + erhf)::Float64
│ %291 = Base.string("Energy after updating = ", %290, "\n-------------------------\n")::String
│ Main.println(%291)
│ (@_3 = Base.iterate(%131, %143))
│ %294 = (@_3 === nothing)::Bool
│ %295 = Base.not_int(%294)::Bool
└─── goto #57 if not %295
56 ─ goto #23
57 ┄ return nothing
Now I know that whenever any variable has the type ::Any
, in the output, that indicates type instability and must be eliminated. However, there seem to be variables name @_27
and @_28
which are type unstable, however these are not any variables that I have declared or used ? Are they some kind of intermediates ? How can I figure out where exactly these instabilitites are happening and fix them?