qojulia / QuantumCumulants.jl

Generalized mean-field equations in open quantum systems
Other
66 stars 13 forks source link

Correlation functions with time dependent Hamiltonians fails to solve #171

Open leonbello opened 1 year ago

leonbello commented 1 year ago

I am trying to calculate the correlation functions for a time-dependent Hamiltonian:

# Hilbert space
h1 = FockSpace(:cavity1)
h2 = FockSpace(:cavity2)
h3 = FockSpace(:cavity3)

h = h1 ⊗ h2 ⊗ h3 

# Operators
a1 = Destroy(h, :(a1), 1)
a2 = Destroy(h, :(a2), 2)
a3 = Destroy(h, :(a3), 3)

# Symbolically define the cavity parameters
@cnumbers η_1 η_3 θ_1 θ_2 g_2
@syms t::Real

@register f_1(t) 
@register f_2(t) 
@register f_3(t) 
@register f_4(t) 
@register f_5(t)

# Define the Hamiltonian
H = -f_1(t)*η_3*(a3 + a3') + f_2(t)*θ_2*(a2'*a3 + a2*a3') + f_3(t)*g_2*(a2*a2 + a2'*a2') +
    f_4(t)*θ_1*(a1'*a2 + a1*a2') + f_5(t)*η_1*(a1 + a1')

# Define the dissipators
J = [a1, a2, a3]
rates = γ

Solving the meanfield equations works as expected,

@named sys = ODESystem(me)

# Parameter values
ps = [η_3; θ_2; g_2; θ_1; η_1]

# Initial state
u0 = zeros(ComplexF64, length(me))

prob = ODEProblem(sys, u0, (start_time, stop_time), ps.=>pulse_amps)
sol = solve(prob, Tsit5(), maxiters=1e7, saveat=t_list)

but solving for the correlation functions give an error which I was not able to isolate:


@named csys = ODESystem(c)
u0_c = correlation_u0(c, sol.u[end])
p0_c = correlation_p0(c, sol.u[end], ps.=>pulse_amps)

prob_c = ODEProblem(csys, u0_c, (start_time, 5*stop_time), p0_c)

The ODEProblem object is created as intended, but trying to solve the problem returns an error:

sol_c = solve(prob_c, RK4(), save_idxs=1)

>> UndefVarError: `t` not defined

Stacktrace:
  [1] macro expansion
    @ [~/.julia/packages/SymbolicUtils/H684H/src/code.jl:395](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/~/.julia/packages/SymbolicUtils/H684H/src/code.jl:395) [inlined]
  [2] macro expansion
    @ [~/.julia/packages/Symbolics/3jLt1/src/build_function.jl:520](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/~/.julia/packages/Symbolics/3jLt1/src/build_function.jl:520) [inlined]
  [3] macro expansion
    @ [~/.julia/packages/SymbolicUtils/H684H/src/code.jl:352](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/~/.julia/packages/SymbolicUtils/H684H/src/code.jl:352) [inlined]
  [4] macro expansion
    @ [~/.julia/packages/RuntimeGeneratedFunctions/TAGuS/src/RuntimeGeneratedFunctions.jl:139](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/~/.julia/packages/RuntimeGeneratedFunctions/TAGuS/src/RuntimeGeneratedFunctions.jl:139) [inlined]
  [5] macro expansion
    @ [./none:0](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/none:0) [inlined]
  [6] generated_callfunc
    @ [./none:0](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/none:0) [inlined]
  [7] (::RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :τ), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x56476eeb, 0x038659b5, 0xa85c227f, 0xc226b7b7, 0xcc501726), Expr})(::Vector{ComplexF64}, ::Vector{ComplexF64}, ::Tuple{Float64, Float64, ComplexF64, Float64, Float64, Float64}, ::Float64)
    @ RuntimeGeneratedFunctions [~/.julia/packages/RuntimeGeneratedFunctions/TAGuS/src/RuntimeGeneratedFunctions.jl:126](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/~/.julia/packages/RuntimeGeneratedFunctions/TAGuS/src/RuntimeGeneratedFunctions.jl:126)
  [8] f
    @ [~/.julia/packages/ModelingToolkit/xecyK/src/systems/diffeqs/abstractodesystem.jl:286](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/~/.julia/packages/ModelingToolkit/xecyK/src/systems/diffeqs/abstractodesystem.jl:286) [inlined]
  [9] Void
    @ [~/.julia/packages/SciMLBase/qp2gL/src/utils.jl:468](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/~/.julia/packages/SciMLBase/qp2gL/src/utils.jl:468) [inlined]
 [10] (::FunctionWrappers.CallWrapper{Nothing})(f::SciMLBase.Void{ModelingToolkit.var"#f#522"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :τ), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x2592f7ee, 0x0935354f, 0xa063172c, 0x5b7ceb2b, 0xe473f033), Expr}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :τ), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x56476eeb, 0x038659b5, 0xa85c227f, 0xc226b7b7, 0xcc501726), Expr}}}, arg1::Vector{ComplexF64}, arg2::Vector{ComplexF64}, arg3::Tuple{Float64, Float64, ComplexF64, Float64, Float64, Float64}, arg4::Float64)
    @ FunctionWrappers [~/.julia/packages/FunctionWrappers/Q5cBx/src/FunctionWrappers.jl:65](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/~/.julia/packages/FunctionWrappers/Q5cBx/src/FunctionWrappers.jl:65)
 [11] macro expansion
    @ [~/.julia/packages/FunctionWrappers/Q5cBx/src/FunctionWrappers.jl:137](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/~/.julia/packages/FunctionWrappers/Q5cBx/src/FunctionWrappers.jl:137) [inlined]
...
    @ [~/.julia/packages/DiffEqBase/HoOGI/src/solve.jl:945](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/~/.julia/packages/DiffEqBase/HoOGI/src/solve.jl:945) [inlined]
 [25] solve(prob::ODEProblem{Vector{ComplexF64}, Tuple{Int64, Int64}, true, Tuple{Float64, Float64, ComplexF64, Float64, Float64, Float64}, ODEFunction{true, SciMLBase.AutoSpecialize, ModelingToolkit.var"#f#522"{RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋arg1, :ˍ₋arg2, :τ), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x2592f7ee, 0x0935354f, 0xa063172c, 0x5b7ceb2b, 0xe473f033), Expr}, RuntimeGeneratedFunctions.RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1, :ˍ₋arg2, :τ), ModelingToolkit.var"#_RGF_ModTag", ModelingToolkit.var"#_RGF_ModTag", (0x56476eeb, 0x038659b5, 0xa85c227f, 0xc226b7b7, 0xcc501726), Expr}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Vector{Symbol}, Symbol, Vector{Symbol}, ModelingToolkit.var"#570#generated_observed#530"{Bool, ODESystem, Dict{Any, Any}}, Nothing, ODESystem}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, args::RK4{typeof(OrdinaryDiffEq.trivial_limiter!), typeof(OrdinaryDiffEq.trivial_limiter!), Static.False}; sensealg::Nothing, u0::Nothing, p::Nothing, wrap::Val{true}, kwargs::Base.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:save_idxs,), Tuple{Int64}}})
    @ DiffEqBase [~/.julia/packages/DiffEqBase/HoOGI/src/solve.jl:882](https://file+.vscode-resource.vscode-cdn.net/Users/leonbello/embedded-amplifiers-control/_research/notebooks/~/.julia/packages/DiffEqBase/HoOGI/src/solve.jl:882)
 [26] top-level scope

Would appreciate any help on what I may be doing wrong.

david-pl commented 1 year ago

@leonbello yeah that's a known problem where functionality is missing for correlation functions. We'd need to additionally substitute t with the time parameter of the correlation function.

You can check #93 for a more detailed discussion and a workaround that may do the trick. It's still an open issue to get this working out of the box though.