Skip to content

Commit 852d27f

Browse files
committed
formatting changes removed
1 parent beb0f37 commit 852d27f

8 files changed

+689
-641
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ docs/source/examples/
33
docs/source/tutorial/_tutorial.rst
44
.ipynb_checkpoints
55
*_files/
6+
Manifest.toml
7+
/.vscode/**

src/mcwf.jl

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,15 @@ Integrate a single Monte Carlo wave function trajectory.
322322
* `kwargs`: Further arguments are passed on to the ode solver.
323323
"""
324324
function integrate_mcwf(dmcwf::T, jumpfun::J, tspan,
325-
psi0, seed, fout;
326-
display_beforeevent=false, display_afterevent=false,
327-
display_jumps=false,
328-
rng_state=nothing,
329-
save_everystep=false, callback=nothing,
330-
saveat=tspan,
331-
alg=OrdinaryDiffEq.DP5(),
332-
kwargs...) where {T, J}
325+
psi0, seed, fout;
326+
display_beforeevent=false, display_afterevent=false,
327+
display_jumps=false,
328+
rng_state=nothing,
329+
save_everystep=false, callback=nothing,
330+
saveat=tspan,
331+
alg=OrdinaryDiffEq.DP5(),
332+
return_problem=false,
333+
kwargs...) where {T,J}
333334

334335
tspan_ = convert(Vector{float(eltype(tspan))}, tspan)
335336
# Display before or after events
@@ -388,7 +389,14 @@ function integrate_mcwf(dmcwf::T, jumpfun::J, tspan,
388389

389390
prob = OrdinaryDiffEq.ODEProblem{true}(df_, as_vector(psi0), (tspan_[1],tspan_[end]))
390391

391-
sol = OrdinaryDiffEq.solve(
392+
if return_problem
393+
if display_jumps
394+
return Dict("out" => out, "jump_t" => jump_t, "jump_index" => jump_index, "prob" => prob, "alg" => alg, "solve_kwargs" => (reltol=1.0e-6, abstol=1.0e-8, save_everystep=false, save_start=false, save_end=false, callback=full_cb, kwargs...))
395+
else
396+
return Dict("out" => out, "prob" => prob, "alg" => alg, "solve_kwargs" => (reltol=1.0e-6, abstol=1.0e-8, save_everystep=false, save_start=false, save_end=false, callback=full_cb, kwargs...))
397+
end
398+
else
399+
sol = OrdinaryDiffEq.solve(
392400
prob,
393401
alg;
394402
reltol = 1.0e-6,
@@ -397,10 +405,11 @@ function integrate_mcwf(dmcwf::T, jumpfun::J, tspan,
397405
save_end = false,
398406
callback=full_cb, kwargs...)
399407

400-
if display_jumps
401-
return out.t, out.saveval, jump_t, jump_index
402-
else
403-
return out.t, out.saveval
408+
if display_jumps
409+
return out.t, out.saveval, jump_t, jump_index
410+
else
411+
return out.t, out.saveval
412+
end
404413
end
405414
end
406415

src/stochastic_base.jl

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import DiffEqCallbacks, StochasticDiffEq, OrdinaryDiffEq
1111
Integrate using StochasticDiffEq
1212
"""
1313
function integrate_stoch(tspan, df, dg, x0,
14-
state, dstate, fout, n;
15-
save_everystep = false, callback=nothing, saveat=tspan,
16-
alg=StochasticDiffEq.EM(),
17-
noise_rate_prototype = nothing,
18-
noise_prototype_classical = nothing,
19-
noise=nothing,
20-
ncb=nothing,
21-
kwargs...)
14+
state, dstate, fout, n;
15+
save_everystep = false, callback=nothing, saveat=tspan,
16+
alg=StochasticDiffEq.EM(),
17+
noise_rate_prototype = nothing,
18+
noise_prototype_classical = nothing,
19+
noise=nothing,
20+
ncb=nothing,
21+
return_problem=false,
22+
kwargs...)
2223

2324
function df_(dx, x, p, t)
2425
recast!(state,x)
@@ -65,10 +66,13 @@ function integrate_stoch(tspan, df, dg, x0,
6566
full_cb = OrdinaryDiffEq.CallbackSet(callback, ncb, scb)
6667

6768
prob = StochasticDiffEq.SDEProblem{true}(df_, dg_, x0,(tspan[1],tspan[end]),
68-
noise=noise_,
69-
noise_rate_prototype=noise_rate_prototype)
69+
noise=noise_,
70+
noise_rate_prototype=noise_rate_prototype)
7071

71-
sol = StochasticDiffEq.solve(
72+
if return_problem
73+
return Dict("out" => out, "prob" => prob, "alg" => alg, "solve_kwargs" => (reltol=1.0e-3, abstol=1.0e-3, save_everystep=false, save_start=false, save_end=false, callback=full_cb, kwargs...))
74+
else
75+
sol = StochasticDiffEq.solve(
7276
prob,
7377
alg;
7478
reltol = 1.0e-3,
@@ -77,7 +81,8 @@ function integrate_stoch(tspan, df, dg, x0,
7781
save_end = false,
7882
callback=full_cb, kwargs...)
7983

80-
out.t,out.saveval
84+
return out.t, out.saveval
85+
end
8186
end
8287

8388
"""

src/timeevolution_base.jl

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ function recast! end
1212
Integrate using OrdinaryDiffEq
1313
"""
1414
function integrate(tspan, df::F, x0,
15-
state, dstate, fout;
16-
alg = OrdinaryDiffEq.DP5(),
17-
steady_state = false, tol = 1e-3, save_everystep = false, saveat=tspan,
18-
callback = nothing, kwargs...) where {F}
15+
state, dstate, fout;
16+
alg = OrdinaryDiffEq.DP5(),
17+
steady_state = false, tol = 1e-3, save_everystep = false, saveat=tspan,
18+
callback = nothing, return_problem=false, kwargs...) where {F}
1919

2020
function df_(dx, x, p, t)
2121
recast!(state,x)
@@ -42,33 +42,37 @@ function integrate(tspan, df::F, x0,
4242
save_start = false,
4343
tdir = first(tspan)<last(tspan) ? one(eltype(tspan)) : -one(eltype(tspan)))
4444

45-
prob = OrdinaryDiffEq.ODEProblem{true}(df_, x0,(convert(tType, tspan[1]),convert(tType, tspan[end])))
46-
47-
if steady_state
48-
affect! = function (integrator)
49-
!save_everystep && scb.affect!(integrator,true)
50-
OrdinaryDiffEq.terminate!(integrator)
51-
end
52-
_cb = OrdinaryDiffEq.DiscreteCallback(
53-
SteadyStateCondtion(copy(state),tol,state),
54-
affect!;
55-
save_positions = (false,false))
56-
cb = OrdinaryDiffEq.CallbackSet(_cb,scb)
57-
else
58-
cb = scb
59-
end
45+
prob = OrdinaryDiffEq.ODEProblem{true}(df_, x0,(convert(tType, tspan[1]),convert(tType, tspan[end])))
46+
47+
if steady_state
48+
affect! = function (integrator)
49+
!save_everystep && scb.affect!(integrator,true)
50+
OrdinaryDiffEq.terminate!(integrator)
51+
end
52+
_cb = OrdinaryDiffEq.DiscreteCallback(
53+
SteadyStateCondtion(copy(state),tol,state),
54+
affect!;
55+
save_positions = (false,false))
56+
cb = OrdinaryDiffEq.CallbackSet(_cb,scb)
57+
else
58+
cb = scb
59+
end
6060

6161
full_cb = OrdinaryDiffEq.CallbackSet(callback,cb)
6262

63-
sol = OrdinaryDiffEq.solve(
64-
prob,
65-
alg;
66-
reltol = 1.0e-6,
67-
abstol = 1.0e-8,
68-
save_everystep = false, save_start = false,
69-
save_end = false,
70-
callback=full_cb, kwargs...)
71-
out.t,out.saveval
63+
if return_problem
64+
return Dict("out" => out, "prob" => prob, "alg" => alg, "solve_kwargs" => (reltol=1.0e-6, abstol=1.0e-8, save_everystep=false, save_start=false, save_end=false, callback=full_cb, kwargs...))
65+
else
66+
sol = OrdinaryDiffEq.solve(
67+
prob,
68+
alg;
69+
reltol=1.0e-6,
70+
abstol=1.0e-8,
71+
save_everystep=false, save_start=false,
72+
save_end=false,
73+
callback=full_cb, kwargs...)
74+
return out.t, out.saveval
75+
end
7276
end
7377

7478
function integrate(tspan, df, x0,

test/test_stochastic_schroedinger.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@ function fstoch_2(t, psi)
4949
end
5050

5151
# Non-dynamic Schrödinger
52-
tout, ψt4 = stochastic.schroedinger(T, ψ0, H, [zero_op, zero_op]; dt=0.1dt)
52+
tout, ψt4 = stochastic.schroedinger(T, ψ0, H, [zero_op, zero_op]; dt=0.1dt, seed=1)
53+
rslt4 = stochastic.schroedinger(T, ψ0, H, [zero_op, zero_op]; dt=0.1dt, seed=1, return_problem=true)
54+
sol = StochasticDiffEq.solve(rslt4["prob"], rslt4["alg"]; rslt4["solve_kwargs"]...)
55+
@test ψt4 == rslt4["out"].saveval
5356
# Dynamic Schrödinger
54-
tout, ψt1 = stochastic.schroedinger_dynamic(T, ψ0, fdeterm, fstoch_1; dt=0.1dt)
57+
tout, ψt1 = stochastic.schroedinger_dynamic(T, ψ0, fdeterm, fstoch_1; dt=0.1dt, seed=1)
58+
rslt1 = stochastic.schroedinger(T, ψ0, H, [zero_op, zero_op]; dt=0.1dt, seed=1, return_problem=true)
59+
sol = StochasticDiffEq.solve(rslt1["prob"], rslt1["alg"]; rslt1["solve_kwargs"]...)
60+
@test ψt1 == rslt1["out"].saveval
5561
tout, ψt2 = stochastic.schroedinger_dynamic(T, ψ0, fdeterm, fstoch_2; noise_processes=3, dt=0.1dt)
5662

5763
# Test equivalence to Schrödinger equation with zero noise

0 commit comments

Comments
 (0)