5959_dfd_set_pillow (dim):: Int = min (max (round (Int, 0.02 * dim), 1 ), 20 )
6060
6161function _DFDIncreaseReduceCondition (u, t, integrator)
62- internal_params = integrator. p
63- dim_list = internal_params . dim_list
64- maxdims = internal_params . maxdims
65- tol_list = internal_params . tol_list
66- increase_list = internal_params . increase_list
67- reduce_list = internal_params . reduce_list
68- pillow_list = internal_params . pillow_list
69- dfd_ρt_cache = internal_params . dfd_ρt_cache
62+ params = integrator. p
63+ dim_list = params . dim_list
64+ maxdims = params . maxdims
65+ tol_list = params . tol_list
66+ increase_list = params . increase_list
67+ reduce_list = params . reduce_list
68+ pillow_list = params . pillow_list
69+ dfd_ρt_cache = params . dfd_ρt_cache
7070
7171 # I need this cache because I can't reshape directly the integrator.u
7272 copyto! (dfd_ρt_cache, u)
@@ -89,18 +89,18 @@ function _DFDIncreaseReduceCondition(u, t, integrator)
8989end
9090
9191function _DFDIncreaseReduceAffect! (integrator)
92- internal_params = integrator. p
93- H = internal_params . H_fun
94- c_ops = internal_params . c_ops_fun
95- e_ops = internal_params . e_ops_fun
96- dim_list = internal_params . dim_list
97- increase_list = internal_params . increase_list
98- reduce_list = internal_params . reduce_list
99- pillow_list = internal_params . pillow_list
100- dim_list_evo_times = internal_params . dim_list_evo_times
101- dim_list_evo = internal_params . dim_list_evo
102- dfd_ρt_cache = internal_params . dfd_ρt_cache
103- dfd_params = internal_params . dfd_params
92+ params = integrator. p
93+ H = params . H_fun
94+ c_ops = params . c_ops_fun
95+ e_ops = params . e_ops_fun
96+ dim_list = params . dim_list
97+ increase_list = params . increase_list
98+ reduce_list = params . reduce_list
99+ pillow_list = params . pillow_list
100+ dim_list_evo_times = params . dim_list_evo_times
101+ dim_list_evo = params . dim_list_evo
102+ dfd_ρt_cache = params . dfd_ρt_cache
103+ dfd_params = params . dfd_params
104104
105105 ρt = vec2mat (dfd_ρt_cache)
106106
@@ -122,7 +122,7 @@ function _DFDIncreaseReduceAffect!(integrator)
122122 fill! (increase_list, false )
123123 fill! (reduce_list, false )
124124 push! (dim_list_evo_times, integrator. t)
125- push! (dim_list_evo, dim_list)
125+ push! (dim_list_evo, copy ( dim_list) )
126126
127127 e_ops2 = map (op -> mat2vec (get_data (op)' ), e_ops (dim_list, dfd_params))
128128 L = liouvillian (H (dim_list, dfd_params), c_ops (dim_list, dfd_params)). data
@@ -131,7 +131,7 @@ function _DFDIncreaseReduceAffect!(integrator)
131131 copyto! (integrator. u, mat2vec (ρt))
132132 # By doing this, we are assuming that the system is time-independent and f is a MatrixOperator
133133 integrator. f = ODEFunction {true,FullSpecialize} (MatrixOperator (L))
134- integrator. p = merge (internal_params , (dfd_ρt_cache = similar (integrator. u),))
134+ integrator. p = merge (params , (dfd_ρt_cache = similar (integrator. u),))
135135 _mesolve_callbacks_new_e_ops! (integrator, e_ops2)
136136
137137 return nothing
@@ -150,15 +150,15 @@ function dfd_mesolveProblem(
150150 kwargs... ,
151151) where {T2<: Integer ,StateOpType<: Union{KetQuantumObject,OperatorQuantumObject} }
152152 length (ψ0. dimensions) != length (maxdims) &&
153- throw (DimensionMismatch (" ' dim_list' and ' maxdims' do not have the same dimension." ))
153+ throw (DimensionMismatch (" ` dim_list` and ` maxdims` do not have the same dimension." ))
154154
155155 dim_list = MVector (ψ0. dims)
156156 H₀ = H (dim_list, dfd_params)
157157 c_ops₀ = c_ops (dim_list, dfd_params)
158158 e_ops₀ = e_ops (dim_list, dfd_params)
159159
160160 dim_list_evo_times = [0.0 ]
161- dim_list_evo = [dim_list]
161+ dim_list_evo = [copy ( dim_list) ]
162162 reduce_list = MVector (ntuple (i -> false , Val (length (dim_list))))
163163 increase_list = MVector (ntuple (i -> false , Val (length (dim_list))))
164164 pillow_list = _dfd_set_pillow .(dim_list)
@@ -235,14 +235,12 @@ function dfd_mesolve(
235235
236236 sol = solve (dfd_prob. prob, alg)
237237
238- ρt = map (
239- i -> QuantumObject (
240- vec2mat (sol. u[i]),
241- type = Operator,
242- dims = sol. prob. p. dim_list_evo[searchsortedlast (sol. prob. p. dim_list_evo_times, sol. t[i])],
243- ),
244- eachindex (sol. t),
245- )
238+ ρt = map (eachindex (sol. t)) do i
239+ idx = findfirst (>= (sol. t[i]), sol. prob. p. dim_list_evo_times)
240+ idx2 = isnothing (idx) ? length (sol. prob. p. dim_list_evo) : (idx == 1 ? 1 : idx - 1 )
241+
242+ return QuantumObject (vec2mat (sol. u[i]), type = Operator, dims = sol. prob. p. dim_list_evo[idx2])
243+ end
246244
247245 return TimeEvolutionSol (
248246 dfd_prob. times,
0 commit comments