Skip to content

Commit

Permalink
Fix kwargs bug, fix two_spin_rho bug (#38)
Browse files Browse the repository at this point in the history
* Fix kwargs bug, fix two_spin_rho bug
* rename tests for analytic models, update changelog, closes #39, #40
  • Loading branch information
zmorrell committed May 27, 2022
1 parent 73c69e6 commit 09d6153
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ QuantumAnnealing.jl Change Log
==============================

### Staged
- Add Gibbs distribution
- Add Gibbs distribution (#34)
- Fix kwargs bug in simulate_de (#39)
- Fix analytic two spin model for non-integer s (#40)

### v0.2.0
- Add a generic Magnus expansion solver for any order
Expand Down
2 changes: 1 addition & 1 deletion src/simulate_de.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function simulate_de(ising_model, annealing_time, annealing_schedule, reltol; ab

s_range = (0.0, 1.0)
prob = DifferentialEquations.ODEProblem(schrod_eq, initial_state, s_range, annealing_time)
sol = DifferentialEquations.solve(prob, abstol=abstol, reltol=reltol, alg_hints=[:nonstiff], kwargs...)
sol = DifferentialEquations.solve(prob; abstol=abstol, reltol=reltol, alg_hints=[:nonstiff], kwargs...)

state = sol(1)
density = state * state'
Expand Down
2 changes: 1 addition & 1 deletion test/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end

function two_spin_ρ(t; s=1.0)
s0 = 1/2*cos/4*s*sqrt(1+64*t^2/π^2))*sqrt(1-sin/2*s)) +
(8im*t*sqrt(1-sin/2*s)) + sqrt(1+sin/2*s)))*sin/4*s*sqrt(1+64*t^2/π^2))/(2*sqrt(1+64*t^2/π^2))
(8im*t*sqrt(1-sin/2*s))/π + sqrt(1+sin/2*s)))*sin/4*s*sqrt(1+64*t^2/π^2))/(2*sqrt(1+64*t^2/π^2))
s1 = -(cos/4*s*sqrt(1+64*t^2/π^2))*(1+sin/2*s)) +
((-cos/2*s) + 8im*t*(1+sin/2*s))/π)*(sin/4*s*sqrt(1+64*t^2/π^2))))/(sqrt(1+64*t^2/π^2))
)/(2*sqrt(1+sin/2*s)))
Expand Down
22 changes: 22 additions & 0 deletions test/simulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ end
end
end

@testset "analytic models, unitary check" begin
@testset "one qubit model" begin
s_vals = 0.0:0.5:1.0
for s in s_vals
ρ = one_spin_ρ(100.0, s=s)
@test tr(ρ) == 1
end
end

@testset "two qubit model" begin
s_vals = 0.0:0.5:1.0
for s in s_vals
ρ = two_spin_ρ(100.0, s=s)
@test tr(ρ) == 1
end
end
end

@testset "simulate, generic magnus expansion" begin
@testset "1 qubit, adaptive, orders 1 to 8" begin
Expand Down Expand Up @@ -424,6 +441,11 @@ end
@test isapprox(one_spin_ρ(1.0), ρ)
end

@testset "1 qubit, function schedule, analytical solution with kwargs" begin
ρ = simulate_de(one_spin_model, 1.0, AS_CIRCULAR, 1e-6, saveat=[1])
@test isapprox(one_spin_ρ(1.0), ρ)
end

@testset "2 qubit, function schedule, analytical solution" begin
ρ = simulate_de(two_spin_model, 1.0, AS_CIRCULAR, 1e-6)
@test isapprox(two_spin_ρ(1.0), ρ)
Expand Down

0 comments on commit 09d6153

Please sign in to comment.