About Error:"Correlation function is not specified"

Hi there,
I’m new to Julia, and I jumped into this error:

I defined a CustomBath:

physFact = 16/0.33338579560200365
ctoff = 0.012pi
function smsi(x)
if abs(x) <ctoff
a = x/(ctoff^2)
else
a =sign(x)/abs(x)
end
a
end

a1 = 0.003
a2 = 0.25
cT1 = 15
cT2 = 0.25

function f(x)
if x==0
a2piη_hcT2T_h4pi/(physFact*(ctoff^2))+pi*(a1η_h)cT1T_h4pi/(physFact)
else
a2
piη_hsmsi(x)(1+coth(physFactx/(cT2T_h4pi)))exp(-abs(x)/(fc_h2pi))+pi*(a1η_hx)(1+coth(physFactx/(cT1T_h4pi)))exp(-abs(x)/(fc_h2pi))
end
end

bath_f = CustomBath(spectrum = f)

And I used this Bath to build an Annealing Object and solved Redfield to this annealing object:
P_r_f =
epsilon = 0.5

H_s_05 = DenseHamiltonian([(s)->0.035, (s)->epsilon], [-σx, -σz], unit =:ħ)
annealing_r_05 = Annealing(H_s_05, u0, coupling = coupling, bath = bath_f)

U_05 = solve_unitary(annealing_r_05, tf, alg = Tsit5(), abstol = 1e-8)
sol_r_05 = solve_redfield(annealing_r_05,tf,U_05; alg = Tsit5(), abstol = 1e-18,int_atol = 1e-10,tstops=range(0,tf,length=100))

time_list_r_05 = 1:length(sol_r_05)
for t in time_list_r_05
push!(P_r_f, sol_r_05[Int(t)][1,1].re)
end
print(length(time_list_r_05))
scatter(time_list_r_05*tf/length(sol_r_05),P_r_f[1:end], label="rf,ϵ=0.5,T = 128 ",legend = (.4,.65),markersize = 1)

And then the error “correlation function is not specified” showed up with the Stacktrace:

Correlation function is not specified.

Stacktrace:
[1] error(s::String)
@ Base ./error.jl:33
[2] build_correlation(bath::CustomBath)
@ OpenQuantumBase ~/.julia/packages/OpenQuantumBase/Hx01G/src/bath/custom.jl:21
[3] build_redfield_kernel(i::Interaction)
@ OpenQuantumBase ~/.julia/packages/OpenQuantumBase/Hx01G/src/coupling/interaction.jl:159
[4] #112
@ ./array.jl:0 [inlined]
[5] iterate
@ ./generator.jl:47 [inlined]
[6] grow_to!(dest::Vector{Tuple{Any, OpenQuantumBase.AbstractCouplings, Any}}, itr::Base.Generator{Base.Iterators.Filter{OpenQuantumBase.var"#113#115", InteractionSet{Tuple{Interaction}}}, OpenQuantumBase.var"#112#114"})
@ Base ./array.jl:797
[7] collect
@ ./array.jl:721 [inlined]
[8] redfield_from_interactions(iset::InteractionSet{Tuple{Interaction}}, U::ODESolution{ComplexF64, 3, Vector{Matrix{ComplexF64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Matrix{ComplexF64}}}, ODEProblem{Matrix{ComplexF64}, Tuple{Float64, Float64}, true, ODEParams, ODEFunction{true, DiffEqArrayOperator{ComplexF64, Matrix{ComplexF64}, OpenQuantumTools.var"#31#33"}, UniformScaling{Bool}, Nothing, Nothing, typeof(update_coefficients!), Nothing, Nothing, DiffEqArrayOperator{ComplexF64, Matrix{ComplexF64}, OpenQuantumTools.var"#30#32"}, DiffEqArrayOperator{ComplexF64, Matrix{ComplexF64}, OpenQuantumTools.var"#30#32"}, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, DiffEqArrayOperator{ComplexF64, Matrix{ComplexF64}, OpenQuantumTools.var"#31#33"}, UniformScaling{Bool}, Nothing, Nothing, typeof(update_coefficients!), Nothing, Nothing, DiffEqArrayOperator{ComplexF64, Matrix{ComplexF64}, OpenQuantumTools.var"#30#32"}, DiffEqArrayOperator{ComplexF64, Matrix{ComplexF64}, OpenQuantumTools.var"#30#32"}, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Matrix{ComplexF64}}, Vector{Float64}, Vector{Vector{Matrix{ComplexF64}}}, OrdinaryDiffEq.Tsit5Cache{Matrix{ComplexF64}, Matrix{ComplexF64}, Matrix{ComplexF64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats}, Ta::Int64, atol::Float64, rtol::Float64)
@ OpenQuantumBase ~/.julia/packages/OpenQuantumBase/Hx01G/src/coupling/interaction.jl:77
[9] solve_redfield(A::Annealing{DenseHamiltonian{ComplexF64, true}, Vector{ComplexF64}}, tf::Int64, unitary::ODESolution{ComplexF64, 3, Vector{Matrix{ComplexF64}}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Matrix{ComplexF64}}}, ODEProblem{Matrix{ComplexF64}, Tuple{Float64, Float64}, true, ODEParams, ODEFunction{true, DiffEqArrayOperator{ComplexF64, Matrix{ComplexF64}, OpenQuantumTools.var"#31#33"}, UniformScaling{Bool}, Nothing, Nothing, typeof(update_coefficients!), Nothing, Nothing, DiffEqArrayOperator{ComplexF64, Matrix{ComplexF64}, OpenQuantumTools.var"#30#32"}, DiffEqArrayOperator{ComplexF64, Matrix{ComplexF64}, OpenQuantumTools.var"#30#32"}, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, OrdinaryDiffEq.InterpolationData{ODEFunction{true, DiffEqArrayOperator{ComplexF64, Matrix{ComplexF64}, OpenQuantumTools.var"#31#33"}, UniformScaling{Bool}, Nothing, Nothing, typeof(update_coefficients!), Nothing, Nothing, DiffEqArrayOperator{ComplexF64, Matrix{ComplexF64}, OpenQuantumTools.var"#30#32"}, DiffEqArrayOperator{ComplexF64, Matrix{ComplexF64}, OpenQuantumTools.var"#30#32"}, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Matrix{ComplexF64}}, Vector{Float64}, Vector{Vector{Matrix{ComplexF64}}}, OrdinaryDiffEq.Tsit5Cache{Matrix{ComplexF64}, Matrix{ComplexF64}, Matrix{ComplexF64}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}, typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}}, DiffEqBase.DEStats}; vectorize::Bool, int_atol::Float64, int_rtol::Float64, Ta::Int64, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:alg, :abstol, :tstops), Tuple{Tsit5{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}, Float64, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}})
@ OpenQuantumTools ~/.julia/packages/OpenQuantumTools/Eu6Hn/src/QSolver/redfield_solver.jl:29
[10] top-level scope
@ In[122]:8
[11] eval
@ ./boot.jl:373 [inlined]
[12] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1196

I’m wondering if anyone here knows what’s going on here. Thank you so much!

I’ve moved your question to the General Usage category, since it’s not about internals of the julia language.

It’ll be easier for someone to help you if you format your code as a code block, by surrounding it in triple backticks (`).

Agreed about the formatting, as an example, typing

```
bath_f = CustomBath(spectrum = f)
```

will result in

bath_f = CustomBath(spectrum = f)

I’m not familiar with this package or this field of study (so I may be wrong about this), but based on a look at the code, it seems like for solvers other than solve_ame, you need to specify a correlation function when building the CustomBath. The only example I found of using a CustomBath with solve_redfield is in the tests for the package, and that builds the CustomBath as

cfun(x) = x <= 20 ? 1e-4 : 0
bath = CustomBath(correlation=cfun)

i.e. using the correlation argument to specify a correlation function.

1 Like

Cool, thanks for your suggestion!

Thank you so much for your reply! It;'s been very helpful!