|
1 | | -import OrdinaryDiffEq, DiffEqCallbacks, StochasticDiffEq |
| 1 | +using QuantumOpticsBase |
| 2 | +using QuantumOpticsBase: check_samebases, check_multiplicable |
2 | 3 |
|
3 | | -export @skiptimechecks |
| 4 | +import OrdinaryDiffEq, DiffEqCallbacks |
4 | 5 |
|
5 | 6 | const DiffArray = Union{Vector{ComplexF64}, Array{ComplexF64, 2}} |
6 | 7 |
|
| 8 | +function recast! end |
| 9 | + |
7 | 10 | """ |
8 | 11 | integrate(tspan::Vector{Float64}, df::Function, x0::Vector{ComplexF64}, |
9 | 12 | state::T, dstate::T, fout::Function; kwargs...) |
@@ -86,98 +89,6 @@ function (c::SteadyStateCondtion)(rho,t,integrator) |
86 | 89 | end |
87 | 90 |
|
88 | 91 |
|
89 | | - |
90 | | -""" |
91 | | - integrate_stoch(tspan::Vector{Float64}, df::Function, dg::Vector{Function}, x0::Vector{ComplexF64}, |
92 | | - state::T, dstate::T, fout::Function; kwargs...) |
93 | | -
|
94 | | -Integrate using StochasticDiffEq |
95 | | -""" |
96 | | -function integrate_stoch(tspan::Vector{Float64}, df::Function, dg::Function, x0::Vector{ComplexF64}, |
97 | | - state::T, dstate::T, fout::Function, n::Int; |
98 | | - save_everystep = false, callback=nothing, |
99 | | - alg::StochasticDiffEq.StochasticDiffEqAlgorithm=StochasticDiffEq.EM(), |
100 | | - noise_rate_prototype = nothing, |
101 | | - noise_prototype_classical = nothing, |
102 | | - noise=nothing, |
103 | | - ncb=nothing, |
104 | | - kwargs...) where T |
105 | | - |
106 | | - function df_(dx::Vector{ComplexF64}, x::Vector{ComplexF64}, p, t) |
107 | | - recast!(x, state) |
108 | | - recast!(dx, dstate) |
109 | | - df(t, state, dstate) |
110 | | - recast!(dstate, dx) |
111 | | - end |
112 | | - |
113 | | - function dg_(dx::Union{Vector{ComplexF64}, Array{ComplexF64, 2}}, |
114 | | - x::Vector{ComplexF64}, p, t) |
115 | | - recast!(x, state) |
116 | | - dg(dx, t, state, dstate, n) |
117 | | - end |
118 | | - |
119 | | - function fout_(x::Vector{ComplexF64}, t::Float64, integrator) |
120 | | - recast!(x, state) |
121 | | - fout(t, state) |
122 | | - end |
123 | | - |
124 | | - nc = isa(noise_prototype_classical, Nothing) ? 0 : size(noise_prototype_classical)[2] |
125 | | - if isa(noise, Nothing) && n > 0 |
126 | | - if n + nc == 1 |
127 | | - noise_ = StochasticDiffEq.RealWienerProcess(0.0, 0.0) |
128 | | - else |
129 | | - noise_ = StochasticDiffEq.RealWienerProcess!(0.0, zeros(n + nc)) |
130 | | - end |
131 | | - else |
132 | | - noise_ = noise |
133 | | - end |
134 | | - if isa(noise_rate_prototype, Nothing) |
135 | | - if n > 1 || nc > 1 || (n > 0 && nc > 0) |
136 | | - noise_rate_prototype = zeros(ComplexF64, length(x0), n + nc) |
137 | | - end |
138 | | - end |
139 | | - |
140 | | - out_type = pure_inference(fout, Tuple{eltype(tspan),typeof(state)}) |
141 | | - |
142 | | - out = DiffEqCallbacks.SavedValues(Float64,out_type) |
143 | | - |
144 | | - scb = DiffEqCallbacks.SavingCallback(fout_,out,saveat=tspan, |
145 | | - save_everystep=save_everystep, |
146 | | - save_start = false) |
147 | | - |
148 | | - full_cb = OrdinaryDiffEq.CallbackSet(callback, ncb, scb) |
149 | | - |
150 | | - prob = StochasticDiffEq.SDEProblem{true}(df_, dg_, x0,(tspan[1],tspan[end]), |
151 | | - noise=noise_, |
152 | | - noise_rate_prototype=noise_rate_prototype) |
153 | | - |
154 | | - sol = StochasticDiffEq.solve( |
155 | | - prob, |
156 | | - alg; |
157 | | - reltol = 1.0e-3, |
158 | | - abstol = 1.0e-3, |
159 | | - save_everystep = false, save_start = false, |
160 | | - save_end = false, |
161 | | - callback=full_cb, kwargs...) |
162 | | - |
163 | | - out.t,out.saveval |
164 | | -end |
165 | | - |
166 | | -""" |
167 | | - integrate_stoch |
168 | | -
|
169 | | -Define fout if it was omitted. |
170 | | -""" |
171 | | -function integrate_stoch(tspan::Vector{Float64}, df::Function, dg::Function, x0::Vector{ComplexF64}, |
172 | | - state::T, dstate::T, ::Nothing, n::Int; kwargs...) where T |
173 | | - function fout(t::Float64, state::T) |
174 | | - copy(state) |
175 | | - end |
176 | | - integrate_stoch(tspan, df, dg, x0, state, dstate, fout, n; kwargs...) |
177 | | -end |
178 | | - |
179 | | - |
180 | | - |
181 | 92 | const QO_CHECKS = Ref(true) |
182 | 93 | """ |
183 | 94 | @skiptimechecks |
|
0 commit comments