|
186 | 186 | # Redirect to `sesolve` |
187 | 187 | sol_me5 = mesolve(H, ψ0, tlist, progress_bar = Val(false)) |
188 | 188 |
|
| 189 | + # standard deviation |
| 190 | + std_mc = dropdims(sqrt.(mean(abs2.(sol_mc.expect), dims = 2) .- abs2.(mean(sol_mc.expect, dims = 2))), dims = 2) |
| 191 | + std_mc2 = |
| 192 | + dropdims(sqrt.(mean(abs2.(sol_mc2.expect), dims = 2) .- abs2.(mean(sol_mc2.expect, dims = 2))), dims = 2) |
| 193 | + |
189 | 194 | ρt_mc = [ket2dm.(normalize.(states)) for states in sol_mc_states.states] |
190 | 195 | expect_mc_states = mapreduce(states -> expect.(Ref(e_ops[1]), states), hcat, ρt_mc) |
191 | 196 | expect_mc_states_mean = sum(expect_mc_states, dims = 2) / size(expect_mc_states, 2) |
|
202 | 207 | @test prob_me.prob.f.f isa MatrixOperator |
203 | 208 | @test prob_mc.prob.f.f isa MatrixOperator |
204 | 209 | @test isket(sol_me5.states[1]) |
205 | | - @test sum(abs, sol_mc.expect .- sol_me.expect) / length(tlist) < 0.1 |
206 | | - @test sum(abs, sol_mc2.expect .- sol_me.expect) / length(tlist) < 0.1 |
| 210 | + @test all(isapprox.(average_states(sol_mc), sol_me.states; atol = 0.1)) |
| 211 | + @test all(isapprox.(average_states(sol_mc2), sol_me.states; atol = 0.1)) |
| 212 | + @test all(isapprox.(average_expect(sol_mc), sol_me.expect; atol = 0.1)) |
| 213 | + @test all(isapprox.(average_expect(sol_mc2), sol_me.expect; atol = 0.1)) |
| 214 | + @test all(std_expect(sol_mc) .≈ std_mc) |
| 215 | + @test all(std_expect(sol_mc2) .≈ std_mc2) |
207 | 216 | @test sum(abs, vec(expect_mc_states_mean) .- vec(sol_me.expect[1, saveat_idxs])) / length(tlist) < 0.1 |
208 | 217 | @test sum(abs, vec(expect_mc_states_mean2) .- vec(sol_me.expect[1, saveat_idxs])) / length(tlist) < 0.1 |
209 | | - @test sum(abs, sol_sse.expect .- sol_me.expect) / length(tlist) < 0.1 |
210 | | - @test sum(abs, sol_sme.expect .- sol_me.expect) / length(tlist) < 0.1 |
211 | | - @test sum(abs, sol_sme3.expect .- sol_me.expect) / length(tlist) < 0.1 |
| 218 | + @test sum(abs, average_expect(sol_sse) .- sol_me.expect) / length(tlist) < 0.1 |
| 219 | + @test sum(abs, average_expect(sol_sme) .- sol_me.expect) / length(tlist) < 0.1 |
| 220 | + @test sum(abs, average_expect(sol_sme3) .- sol_me.expect) / length(tlist) < 0.1 |
212 | 221 | @test length(sol_me.times) == length(tlist) |
213 | 222 | @test length(sol_me.states) == 1 |
214 | 223 | @test size(sol_me.expect) == (length(e_ops), length(tlist)) |
|
221 | 230 | @test sol_me3.expect[1, saveat_idxs] ≈ expect(e_ops[1], sol_me3.states) atol = 1e-6 |
222 | 231 | @test all([sol_me3.states[i] ≈ vector_to_operator(sol_me4.states[i]) for i in eachindex(saveat)]) |
223 | 232 | @test length(sol_mc.times) == length(tlist) |
224 | | - @test size(sol_mc.expect) == (length(e_ops), length(tlist)) |
| 233 | + @test size(sol_mc.expect) == (length(e_ops), 500, length(tlist)) |
225 | 234 | @test length(sol_mc_states.times) == length(tlist) |
226 | 235 | @test sol_mc_states.expect === nothing |
| 236 | + @test average_expect(sol_mc_states) === nothing |
| 237 | + @test std_expect(sol_mc_states) === nothing |
227 | 238 | @test length(sol_sse.times) == length(tlist) |
228 | | - @test size(sol_sse.expect) == (length(e_ops), length(tlist)) |
| 239 | + @test size(sol_sse.expect) == (length(e_ops), 500, length(tlist)) |
229 | 240 | @test length(sol_sme.times) == length(tlist) |
230 | | - @test size(sol_sme.expect) == (length(e_ops), length(tlist)) |
| 241 | + @test size(sol_sme.expect) == (length(e_ops), 500, length(tlist)) |
231 | 242 | @test isnothing(sol_sse.measurement) |
232 | 243 | @test isnothing(sol_sme.measurement) |
233 | 244 | @test size(sol_sse2.measurement) == (length(c_ops), 20, length(tlist) - 1) |
|
336 | 347 |
|
337 | 348 | @test sol_se.expect ≈ sol_se_td.expect atol = 1e-6 * length(tlist) |
338 | 349 | @test sol_me.expect ≈ sol_me_td.expect atol = 1e-6 * length(tlist) |
339 | | - @test sol_mc.expect ≈ sol_mc_td.expect atol = 1e-2 * length(tlist) |
| 350 | + @test average_expect(sol_mc) ≈ average_expect(sol_mc_td) atol = 1e-2 * length(tlist) |
340 | 351 | # @test sol_sse.expect ≈ sol_sse_td.expect atol = 1e-2 * length(tlist) |
341 | 352 |
|
342 | 353 | H_td2 = QobjEvo(H_td) |
|
350 | 361 |
|
351 | 362 | @test sol_se.expect ≈ sol_se_td2.expect atol = 1e-6 * length(tlist) |
352 | 363 | @test sol_me.expect ≈ sol_me_td2.expect atol = 1e-6 * length(tlist) |
353 | | - @test sol_mc.expect ≈ sol_mc_td2.expect atol = 1e-2 * length(tlist) |
| 364 | + @test average_expect(sol_mc) ≈ average_expect(sol_mc_td2) atol = 1e-2 * length(tlist) |
354 | 365 | # @test sol_sse.expect ≈ sol_sse_td2.expect atol = 1e-2 * length(tlist) |
355 | 366 |
|
356 | 367 | @testset "Memory Allocations (mesolve)" begin |
|
542 | 553 | @inferred mesolve(L_td, ψ0, tlist, c_ops, e_ops = e_ops, progress_bar = Val(false), params = p) |
543 | 554 | end |
544 | 555 |
|
545 | | - @testset "Type Inference mcsolve" begin |
| 556 | + @testset "Type Inference mcsolve and statistical analysis functions" begin |
546 | 557 | @inferred mcsolveEnsembleProblem( |
547 | 558 | H, |
548 | 559 | ψ0, |
|
553 | 564 | progress_bar = Val(false), |
554 | 565 | rng = rng, |
555 | 566 | ) |
556 | | - @inferred mcsolve(H, ψ0, tlist, c_ops, ntraj = 5, e_ops = e_ops, progress_bar = Val(false), rng = rng) |
| 567 | + sol1 = |
| 568 | + @inferred mcsolve(H, ψ0, tlist, c_ops, ntraj = 5, e_ops = e_ops, progress_bar = Val(false), rng = rng) |
| 569 | + sol2 = @inferred mcsolve(H, ψ0_int, tlist, c_ops, ntraj = 5, progress_bar = Val(false), rng = rng) |
557 | 570 | @inferred mcsolve(H, ψ0, tlist, c_ops, ntraj = 5, progress_bar = Val(true), rng = rng) |
558 | 571 | @inferred mcsolve(H, ψ0, [0, 10], c_ops, ntraj = 5, progress_bar = Val(false), rng = rng) |
559 | | - @inferred mcsolve(H, ψ0_int, tlist, c_ops, ntraj = 5, progress_bar = Val(false), rng = rng) |
560 | 572 | @inferred mcsolve( |
561 | 573 | H, |
562 | 574 | ψ0, |
|
578 | 590 | params = p, |
579 | 591 | rng = rng, |
580 | 592 | ) |
| 593 | + |
| 594 | + @inferred average_states(sol1) |
| 595 | + @inferred average_expect(sol1) |
| 596 | + @inferred std_expect(sol1) |
| 597 | + @inferred average_states(sol2) |
| 598 | + @inferred average_expect(sol2) |
| 599 | + @inferred std_expect(sol2) |
581 | 600 | end |
582 | 601 |
|
583 | 602 | @testset "Type Inference ssesolve" begin |
|
763 | 782 | ) |
764 | 783 |
|
765 | 784 | @test sol_mc1.expect ≈ sol_mc2.expect atol = 1e-10 |
766 | | - @test sol_mc1.runs_expect ≈ sol_mc2.runs_expect atol = 1e-10 |
767 | 785 | @test sol_mc1.col_times ≈ sol_mc2.col_times atol = 1e-10 |
768 | 786 | @test sol_mc1.col_which ≈ sol_mc2.col_which atol = 1e-10 |
769 | 787 |
|
770 | | - @test sol_mc1.runs_expect ≈ sol_mc3.runs_expect[:, 1:500, :] atol = 1e-10 |
| 788 | + @test sol_mc1.expect ≈ sol_mc3.expect[:, 1:500, :] atol = 1e-10 |
771 | 789 |
|
772 | 790 | @test sol_sse1.expect ≈ sol_sse2.expect atol = 1e-10 |
773 | | - @test sol_sse1.runs_expect ≈ sol_sse2.runs_expect atol = 1e-10 |
774 | 791 |
|
775 | | - @test sol_sse1.runs_expect ≈ sol_sse3.runs_expect[:, 1:50, :] atol = 1e-10 |
| 792 | + @test sol_sse1.expect ≈ sol_sse3.expect[:, 1:50, :] atol = 1e-10 |
776 | 793 |
|
777 | 794 | @test sol_sme1.expect ≈ sol_sme2.expect atol = 1e-10 |
778 | | - @test sol_sme1.runs_expect ≈ sol_sme2.runs_expect atol = 1e-10 |
779 | 795 |
|
780 | | - @test sol_sme1.runs_expect ≈ sol_sme3.runs_expect[:, 1:50, :] atol = 1e-10 |
| 796 | + @test sol_sme1.expect ≈ sol_sme3.expect[:, 1:50, :] atol = 1e-10 |
781 | 797 | end |
782 | 798 | end |
783 | 799 |
|
|
818 | 834 | t_l = LinRange(0, 20 / γ1, 1000) |
819 | 835 | sol_me = mesolve(H, psi0, t_l, c_ops, e_ops = [sp1 * sm1, sp2 * sm2], progress_bar = false) # Here we don't put Val(false) because we want to test the support for Bool type |
820 | 836 | sol_mc = mcsolve(H, psi0, t_l, c_ops, e_ops = [sp1 * sm1, sp2 * sm2], progress_bar = Val(false)) |
821 | | - @test sum(abs.(sol_mc.expect[1:2, :] .- sol_me.expect[1:2, :])) / length(t_l) < 0.1 |
| 837 | + @test sum(abs.(average_expect(sol_mc) .- sol_me.expect)) / length(t_l) < 0.1 |
822 | 838 | @test expect(sp1 * sm1, sol_me.states[end]) ≈ expect(sigmap() * sigmam(), ptrace(sol_me.states[end], 1)) |
823 | 839 | end |
824 | 840 | end |
0 commit comments