From e7f621129405650ed980aedc6450f03a7c85cfdf Mon Sep 17 00:00:00 2001 From: Phillip Weinberg Date: Wed, 15 Nov 2023 15:56:33 -0500 Subject: [PATCH 1/5] removing dependency on BloqadeODE. --- lib/BloqadeKrylov/Project.toml | 16 +++++++++---- lib/BloqadeKrylov/test/Project.toml | 17 -------------- lib/BloqadeKrylov/test/cfet42_sinX.jl | 30 ++++++------------------ lib/BloqadeKrylov/test/cfet65_sinX.jl | 18 +++++--------- lib/BloqadeKrylov/test/cfet811_sinX.jl | 14 +++-------- lib/BloqadeKrylov/test/exact_sol_sinX.jl | 18 ++++++++++++++ lib/BloqadeKrylov/test/forwarddiff.jl | 2 +- lib/BloqadeKrylov/test/magnus4_sinX.jl | 14 +++-------- lib/BloqadeKrylov/test/runtests.jl | 2 ++ 9 files changed, 52 insertions(+), 79 deletions(-) delete mode 100644 lib/BloqadeKrylov/test/Project.toml create mode 100644 lib/BloqadeKrylov/test/exact_sol_sinX.jl diff --git a/lib/BloqadeKrylov/Project.toml b/lib/BloqadeKrylov/Project.toml index b3fd8bc55..5febe3be3 100644 --- a/lib/BloqadeKrylov/Project.toml +++ b/lib/BloqadeKrylov/Project.toml @@ -5,8 +5,6 @@ version = "0.1.8" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" BloqadeExpr = "bd27d05e-4ce1-5e79-84dd-c5d7d508abe2" -BloqadeLattices = "bd27d05e-4ce1-5e79-84dd-c5d7d508bbe4" -BloqadeWaveforms = "bd27d05e-4ce1-5e79-84dd-c5d7d508bbe7" Configurations = "5218b696-f38b-4ac9-8b61-a12ec717816d" ExponentialUtilities = "d4d017d3-3776-5f7e-afef-a10c40355c18" GaussQuadrature = "d54b0c1a-921d-58e0-8e36-89d8069c0969" @@ -18,8 +16,6 @@ YaoSubspaceArrayReg = "bd27d05e-4ce1-5e79-84dd-c5d7d508ade2" [compat] Adapt = "3" BloqadeExpr = "0.1" -BloqadeLattices = "0.1" -BloqadeWaveforms = "0.1" Configurations = "0.17" ExponentialUtilities = "1" GaussQuadrature = "0.5" @@ -27,3 +23,15 @@ ProgressLogging = "0.1" YaoArrayRegister = "0.9" YaoSubspaceArrayReg = "0.1" julia = "1.6" + +[extras] +BloqadeLattices = "bd27d05e-4ce1-5e79-84dd-c5d7d508bbe4" +BloqadeWaveforms = "bd27d05e-4ce1-5e79-84dd-c5d7d508bbe7" +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", "BloqadeLattices", "BloqadeWaveforms", "ForwardDiff", "Random", "SparseArrays", "Yao"] diff --git a/lib/BloqadeKrylov/test/Project.toml b/lib/BloqadeKrylov/test/Project.toml deleted file mode 100644 index 4d1aa9aa9..000000000 --- a/lib/BloqadeKrylov/test/Project.toml +++ /dev/null @@ -1,17 +0,0 @@ -[deps] -BloqadeExpr = "bd27d05e-4ce1-5e79-84dd-c5d7d508abe2" -BloqadeLattices = "bd27d05e-4ce1-5e79-84dd-c5d7d508bbe4" -BloqadeODE = "bd27d05e-4ce1-5e79-84dd-c5d7d508bbe5" -BloqadeWaveforms = "bd27d05e-4ce1-5e79-84dd-c5d7d508bbe7" -ExponentialUtilities = "d4d017d3-3776-5f7e-afef-a10c40355c18" -ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" -LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c" -YaoArrayRegister = "e600142f-9330-5003-8abb-0ebd767abc51" -YaoSubspaceArrayReg = "bd27d05e-4ce1-5e79-84dd-c5d7d508ade2" - -[compat] -ForwardDiff = "0.10.32" diff --git a/lib/BloqadeKrylov/test/cfet42_sinX.jl b/lib/BloqadeKrylov/test/cfet42_sinX.jl index 79340d397..4c8bbb1c7 100644 --- a/lib/BloqadeKrylov/test/cfet42_sinX.jl +++ b/lib/BloqadeKrylov/test/cfet42_sinX.jl @@ -5,7 +5,6 @@ using BloqadeWaveforms using BloqadeKrylov using BloqadeLattices using BloqadeExpr: Hamiltonian -using BloqadeODE using Yao @@ -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 @@ -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 diff --git a/lib/BloqadeKrylov/test/cfet65_sinX.jl b/lib/BloqadeKrylov/test/cfet65_sinX.jl index 384f44a29..7f2bc0ab1 100644 --- a/lib/BloqadeKrylov/test/cfet65_sinX.jl +++ b/lib/BloqadeKrylov/test/cfet65_sinX.jl @@ -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) @@ -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 diff --git a/lib/BloqadeKrylov/test/cfet811_sinX.jl b/lib/BloqadeKrylov/test/cfet811_sinX.jl index f75e99b58..909b0f306 100644 --- a/lib/BloqadeKrylov/test/cfet811_sinX.jl +++ b/lib/BloqadeKrylov/test/cfet811_sinX.jl @@ -5,7 +5,6 @@ using BloqadeWaveforms using BloqadeKrylov using BloqadeLattices using BloqadeExpr: Hamiltonian -using BloqadeODE using Yao @testset "cfet811_sinX" begin @@ -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 diff --git a/lib/BloqadeKrylov/test/exact_sol_sinX.jl b/lib/BloqadeKrylov/test/exact_sol_sinX.jl new file mode 100644 index 000000000..0117f38b0 --- /dev/null +++ b/lib/BloqadeKrylov/test/exact_sol_sinX.jl @@ -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 diff --git a/lib/BloqadeKrylov/test/forwarddiff.jl b/lib/BloqadeKrylov/test/forwarddiff.jl index 483f0df5b..695ccf312 100644 --- a/lib/BloqadeKrylov/test/forwarddiff.jl +++ b/lib/BloqadeKrylov/test/forwarddiff.jl @@ -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 diff --git a/lib/BloqadeKrylov/test/magnus4_sinX.jl b/lib/BloqadeKrylov/test/magnus4_sinX.jl index 7877968de..b88f3ae2a 100644 --- a/lib/BloqadeKrylov/test/magnus4_sinX.jl +++ b/lib/BloqadeKrylov/test/magnus4_sinX.jl @@ -5,7 +5,6 @@ using BloqadeWaveforms using BloqadeKrylov using BloqadeLattices using BloqadeExpr: Hamiltonian -using BloqadeODE using Yao @testset "magnus4_sinX" begin @@ -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 diff --git a/lib/BloqadeKrylov/test/runtests.jl b/lib/BloqadeKrylov/test/runtests.jl index 0a2a1ba1d..90f6bef22 100644 --- a/lib/BloqadeKrylov/test/runtests.jl +++ b/lib/BloqadeKrylov/test/runtests.jl @@ -1,6 +1,8 @@ using Test using BloqadeKrylov +include("exact_sol_sinX.jl") + if "docstring" in ARGS # include("docstrings.jl") From 9afc121e74e367a1ee6bca024bf23fb51932927d Mon Sep 17 00:00:00 2001 From: Phillip Weinberg Date: Wed, 15 Nov 2023 15:58:34 -0500 Subject: [PATCH 2/5] adding back BloqadeLattices and BloqadeWaveforms --- lib/BloqadeKrylov/Project.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/BloqadeKrylov/Project.toml b/lib/BloqadeKrylov/Project.toml index 5febe3be3..5418e37be 100644 --- a/lib/BloqadeKrylov/Project.toml +++ b/lib/BloqadeKrylov/Project.toml @@ -5,6 +5,8 @@ version = "0.1.8" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" BloqadeExpr = "bd27d05e-4ce1-5e79-84dd-c5d7d508abe2" +BloqadeLattices = "bd27d05e-4ce1-5e79-84dd-c5d7d508bbe4" +BloqadeWaveforms = "bd27d05e-4ce1-5e79-84dd-c5d7d508bbe7" Configurations = "5218b696-f38b-4ac9-8b61-a12ec717816d" ExponentialUtilities = "d4d017d3-3776-5f7e-afef-a10c40355c18" GaussQuadrature = "d54b0c1a-921d-58e0-8e36-89d8069c0969" From 3de8248bb1dfc4ced5b3848b1b518a47d44cb2fb Mon Sep 17 00:00:00 2001 From: Phillip Weinberg Date: Wed, 15 Nov 2023 16:00:28 -0500 Subject: [PATCH 3/5] adding compat back. --- lib/BloqadeKrylov/Project.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/BloqadeKrylov/Project.toml b/lib/BloqadeKrylov/Project.toml index 5418e37be..d0c4d1fab 100644 --- a/lib/BloqadeKrylov/Project.toml +++ b/lib/BloqadeKrylov/Project.toml @@ -18,6 +18,8 @@ YaoSubspaceArrayReg = "bd27d05e-4ce1-5e79-84dd-c5d7d508ade2" [compat] Adapt = "3" BloqadeExpr = "0.1" +BloqadeLattices = "0.1" +BloqadeWaveforms = "0.1" Configurations = "0.17" ExponentialUtilities = "1" GaussQuadrature = "0.5" From da0747751e01a3e48b22a70a52ebb1549c615ebc Mon Sep 17 00:00:00 2001 From: Phillip Weinberg Date: Wed, 15 Nov 2023 16:00:46 -0500 Subject: [PATCH 4/5] removing extras --- lib/BloqadeKrylov/Project.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/BloqadeKrylov/Project.toml b/lib/BloqadeKrylov/Project.toml index d0c4d1fab..7c20f040b 100644 --- a/lib/BloqadeKrylov/Project.toml +++ b/lib/BloqadeKrylov/Project.toml @@ -29,8 +29,6 @@ YaoSubspaceArrayReg = "0.1" julia = "1.6" [extras] -BloqadeLattices = "bd27d05e-4ce1-5e79-84dd-c5d7d508bbe4" -BloqadeWaveforms = "bd27d05e-4ce1-5e79-84dd-c5d7d508bbe7" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" From 5c4c2ede255a586fc94d0b81c6c3540fb8599f93 Mon Sep 17 00:00:00 2001 From: Phillip Weinberg Date: Wed, 15 Nov 2023 16:08:30 -0500 Subject: [PATCH 5/5] removing old packages. --- lib/BloqadeKrylov/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/BloqadeKrylov/Project.toml b/lib/BloqadeKrylov/Project.toml index 7c20f040b..e442c1a82 100644 --- a/lib/BloqadeKrylov/Project.toml +++ b/lib/BloqadeKrylov/Project.toml @@ -36,4 +36,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c" [targets] -test = ["Test", "BloqadeLattices", "BloqadeWaveforms", "ForwardDiff", "Random", "SparseArrays", "Yao"] +test = ["Test", "ForwardDiff", "Random", "SparseArrays", "Yao"]