Skip to content

Commit

Permalink
Removing dependency on BloqadeODE in BloqadeKrylov tests. (#621)
Browse files Browse the repository at this point in the history
* removing dependency on BloqadeODE.

* adding back BloqadeLattices and BloqadeWaveforms

* adding compat back.

* removing extras

* removing old packages.
  • Loading branch information
weinbe58 authored Nov 16, 2023
1 parent dbaccc6 commit 967b245
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 75 deletions.
10 changes: 10 additions & 0 deletions lib/BloqadeKrylov/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ ProgressLogging = "0.1"
YaoArrayRegister = "0.9"
YaoSubspaceArrayReg = "0.1"
julia = "1.6"

[extras]
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"

[targets]
test = ["Test", "ForwardDiff", "Random", "SparseArrays", "Yao"]
17 changes: 0 additions & 17 deletions lib/BloqadeKrylov/test/Project.toml

This file was deleted.

30 changes: 7 additions & 23 deletions lib/BloqadeKrylov/test/cfet42_sinX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ using BloqadeWaveforms
using BloqadeKrylov
using BloqadeLattices
using BloqadeExpr: Hamiltonian
using BloqadeODE
using Yao


Expand All @@ -20,24 +19,16 @@ using Yao
clocks = collect(0:1e-3:1.3)
prob = CFETEvolution(reg, clocks, h, CFET4_2())
show(stdout, MIME"text/plain"(), prob)
#@test_throws ArgumentError KrylovEvolution(reg, [-0.1, 0.1], h)
emulate!(prob)


#benchmark against ODE solver:
odereg = zero_state(length(atoms))
ODEprob = SchrodingerProblem(odereg,1.3,h)
show(stdout, MIME"text/plain"(), ODEprob)
emulate!(ODEprob)

@test prob.reg.state ODEprob.reg.state
@test prob.reg.state solution(1.3)

reg = zero_state(length(atoms))
prob = CFETEvolution(reg, clocks, h, CFET4_2())
for info in prob
@test info.clock == clocks[info.step]
@test info.reg.state solution(info.clock)
end


end


Expand All @@ -55,19 +46,12 @@ end
#@test_throws ArgumentError KrylovEvolution(reg, [-0.1, 0.1], h)
emulate!(prob)


#benchmark against ODE solver:
odereg = zero_state(length(atoms))
ODEprob = SchrodingerProblem(odereg,1.3,h)
show(stdout, MIME"text/plain"(), ODEprob)
emulate!(ODEprob)
@test prob.reg.state solution(1.3)

@test prob.reg.state ODEprob.reg.state

prob = CFETEvolution(reg, clocks, h, CFET4_2())
reg = zero_state(length(atoms))
prob = CFETEvolution(reg, clocks, h, CFET4_2(), expmv_backend = expm_multiply!)
for info in prob
@test info.clock == clocks[info.step]
@test info.reg.state solution(info.clock)
end


end
18 changes: 6 additions & 12 deletions lib/BloqadeKrylov/test/cfet65_sinX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ using BloqadeWaveforms
using BloqadeKrylov
using BloqadeLattices
using BloqadeExpr: Hamiltonian
using BloqadeODE
using Yao

include("exact_sol_sinX.jl")


@testset "cfet65_sinX" begin

atoms = generate_sites(ChainLattice(), 1, scale = 1)
Expand All @@ -19,22 +21,14 @@ using Yao
clocks = collect(0:1e-3:1.3)
prob = CFETEvolution(reg, clocks, h, CFET6_5())
show(stdout, MIME"text/plain"(), prob)
#@test_throws ArgumentError KrylovEvolution(reg, [-0.1, 0.1], h)
emulate!(prob)


#benchmark against ODE solver:
odereg = zero_state(length(atoms))
ODEprob = SchrodingerProblem(odereg,1.3,h)
show(stdout, MIME"text/plain"(), ODEprob)
emulate!(ODEprob)

@test prob.reg.state ODEprob.reg.state
@test prob.reg.state solution(1.3)

reg = zero_state(length(atoms))
prob = CFETEvolution(reg, clocks, h, CFET6_5())
for info in prob
@test info.clock == clocks[info.step]
@test info.reg.state solution(info.clock)
end


end
14 changes: 3 additions & 11 deletions lib/BloqadeKrylov/test/cfet811_sinX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ using BloqadeWaveforms
using BloqadeKrylov
using BloqadeLattices
using BloqadeExpr: Hamiltonian
using BloqadeODE
using Yao

@testset "cfet811_sinX" begin
Expand All @@ -21,20 +20,13 @@ using Yao
show(stdout, MIME"text/plain"(), prob)
#@test_throws ArgumentError KrylovEvolution(reg, [-0.1, 0.1], h)
emulate!(prob)


#benchmark against ODE solver:
odereg = zero_state(length(atoms))
ODEprob = SchrodingerProblem(odereg,1.3,h)
show(stdout, MIME"text/plain"(), ODEprob)
emulate!(ODEprob)

@test prob.reg.state ODEprob.reg.state
@test prob.reg.state solution(1.3)

reg = zero_state(length(atoms))
prob = CFETEvolution(reg, clocks, h, CFET8_11())
for info in prob
@test info.clock == clocks[info.step]
@test info.reg.state solution(info.clock)
end


end
18 changes: 18 additions & 0 deletions lib/BloqadeKrylov/test/exact_sol_sinX.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using LinearAlgebra

function evolution_operator(t::Float64)
ϕ = 2.2 * sin* t)^2
U = zeros(ComplexF64, 2,2)
U[1,1] = 1 / sqrt(2)
U[2,1] = 1 / sqrt(2)
U[2,2] = 1 / sqrt(2)
U[1,2] = -1 / sqrt(2)

U * diagm(exp.([-im*ϕ, im*ϕ])) * U'
end

function solution(t)
U = evolution_operator(t)
return U * [1.0, 0.0]

end
2 changes: 1 addition & 1 deletion lib/BloqadeKrylov/test/forwarddiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using ExponentialUtilities
return abs2(statevec(reg)[1])
end
ps = rand(nsites, 2) * scale
ForwardDiff.gradient(loss_atoms, ps)
ForwardDiff.gradient(loss_atoms, ps)
end

@testset "ForwardDiff broken" begin
Expand Down
14 changes: 3 additions & 11 deletions lib/BloqadeKrylov/test/magnus4_sinX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ using BloqadeWaveforms
using BloqadeKrylov
using BloqadeLattices
using BloqadeExpr: Hamiltonian
using BloqadeODE
using Yao

@testset "magnus4_sinX" begin
Expand All @@ -21,18 +20,11 @@ using Yao
show(stdout, MIME"text/plain"(), prob)
#@test_throws ArgumentError KrylovEvolution(reg, [-0.1, 0.1], h)
emulate!(prob)
@test prob.reg.state solution(1.3)


#benchmark against ODE solver:
odereg = zero_state(length(atoms))
ODEprob = SchrodingerProblem(odereg,1.3,h)
show(stdout, MIME"text/plain"(), ODEprob)
emulate!(ODEprob)

@test prob.reg.state ODEprob.reg.state

reg = zero_state(length(atoms))
prob = Magnus4Evolution(reg, clocks, h)
for info in prob
@test info.clock == clocks[info.step]
@test info.reg.state solution(info.clock)
end
end
2 changes: 2 additions & 0 deletions lib/BloqadeKrylov/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Test
using BloqadeKrylov

include("exact_sol_sinX.jl")


if "docstring" in ARGS
# include("docstrings.jl")
Expand Down

0 comments on commit 967b245

Please sign in to comment.