Skip to content

Commit 30ee1c2

Browse files
Change default solver for eigsolve and add GPU tests
1 parent 7265598 commit 30ee1c2

File tree

6 files changed

+44
-13
lines changed

6 files changed

+44
-13
lines changed

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ DiffEqNoiseProcess = "77a26b50-5914-5dd7-bc55-306e6241c503"
1111
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1212
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
1313
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
14-
IncompleteLU = "40713840-3770-5561-ab4c-a76e7d0d7895"
1514
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
1615
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1716
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
@@ -52,7 +51,6 @@ Distributed = "1"
5251
FFTW = "1.5"
5352
GPUArrays = "10, 11"
5453
Graphs = "1.7"
55-
IncompleteLU = "0.2"
5654
KernelAbstractions = "0.9"
5755
LaTeXStrings = "1.2"
5856
LinearAlgebra = "1"

src/QuantumToolbox.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ import SciMLOperators:
4646
IdentityOperator,
4747
update_coefficients!,
4848
concretize
49-
import LinearSolve: LinearProblem, SciMLLinearSolveAlgorithm, KrylovJL_MINRES, KrylovJL_GMRES
49+
import LinearSolve:
50+
LinearProblem, SciMLLinearSolveAlgorithm, KrylovJL_MINRES, KrylovJL_GMRES, UMFPACKFactorization, OperatorAssumptions
5051
import DiffEqBase: get_tstops
5152
import DiffEqCallbacks: PeriodicCallback, FunctionCallingCallback, FunctionCallingAffect, TerminateSteadyState
5253
import OrdinaryDiffEqCore: OrdinaryDiffEqAlgorithm
@@ -58,7 +59,6 @@ import ArrayInterface: allowed_getindex, allowed_setindex!
5859
import Distributed: RemoteChannel
5960
import FFTW: fft, ifft, fftfreq, fftshift
6061
import Graphs: connected_components, DiGraph
61-
import IncompleteLU: ilu
6262
import LaTeXStrings: @L_str
6363
import Pkg
6464
import ProgressMeter: Progress, next!

src/qobj/eigsolve.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,9 @@ function eigsolve(
352352
kwargs...,
353353
)
354354
T = eltype(A)
355-
isH = ishermitian(A)
356-
v0 === nothing && (v0 = normalize!(rand(T, size(A, 1))))
355+
isnothing(v0) && (v0 = normalize!(rand(T, size(A, 1))))
357356

358-
if sigma === nothing
357+
if isnothing(sigma)
359358
res = _eigsolve(
360359
A,
361360
v0,
@@ -371,16 +370,15 @@ function eigsolve(
371370
vals = res.values
372371
else
373372
Aₛ = A - sigma * I
374-
solver === nothing && (solver = isH ? KrylovJL_MINRES() : KrylovJL_GMRES())
373+
isnothing(solver) && (solver = typeof(A) <: SparseMatrixCSC ? UMFPACKFactorization() : KrylovJL_GMRES())
375374

376375
kwargs2 = (; kwargs...)
377-
condition = !haskey(kwargs2, :Pl) && typeof(A) <: SparseMatrixCSC
378-
condition && (kwargs2 = merge(kwargs2, (Pl = ilu(Aₛ, τ = 0.01),)))
379376

380377
!haskey(kwargs2, :abstol) && (kwargs2 = merge(kwargs2, (abstol = tol * 1e-6,)))
381378
!haskey(kwargs2, :reltol) && (kwargs2 = merge(kwargs2, (reltol = tol * 1e-6,)))
379+
!haskey(kwargs2, :assumptions) && (kwargs2 = merge(kwargs2, (assumptions = OperatorAssumptions(true),)))
382380

383-
prob = LinearProblem(Aₛ, v0)
381+
prob = LinearProblem{true}(Aₛ, v0)
384382
linsolve = init(prob, solver; kwargs2...)
385383

386384
Amap = EigsolveInverseMap(T, size(A), linsolve)

test/ext-test/gpu/Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[deps]
22
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
3+
CUDSS = "45b445bb-4962-46a0-9369-b4df9d0f772e"
4+
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
35
QuantumToolbox = "6c2fb7c5-b903-41d2-bc5e-5a7c320b9fab"
46

57
[compat]
6-
CUDA = "5"
8+
CUDA = "5"

test/ext-test/gpu/cuda_ext.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,35 @@ end
264264
@inferred ptrace(ψ, 2)
265265
end
266266
end
267+
268+
@testset "CUDA eigsolve" begin
269+
N = 30
270+
Δ = 0.5
271+
U = 0.1
272+
κ = 0.1
273+
F = 0.5
274+
275+
a = destroy(N)
276+
H = Δ * a' * a + U / 2 * a' * a' * a * a + F * (a + a')
277+
278+
c_ops = [sqrt(κ) * a]
279+
280+
L = liouvillian(H, c_ops)
281+
L_gpu = CuSparseMatrixCSR(L)
282+
283+
vals_cpu, vecs_cpu = eigenstates(L; sparse = true, sigma = 0.01, eigvals = 4, krylovdim = 30)
284+
vals_gpu, vecs_gpu = eigenstates(
285+
L_gpu;
286+
sparse = true,
287+
sigma = 0.01,
288+
eigvals = 4,
289+
krylovdim = 30,
290+
solver = LUFactorization(),
291+
v0 = CUDA.rand(ComplexF64, size(L_gpu, 1)),
292+
)
293+
294+
@test vals_cpu vals_gpu atol = 1e-8
295+
@test all(zip(vecs_cpu, vecs_gpu)) do (v_cpu, v_gpu)
296+
return isapprox(abs(dot(v_cpu.data, Array(v_gpu.data))), 1; atol = 1e-8)
297+
end
298+
end

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ if (GROUP == "CUDA_Ext")
7474
import StaticArraysCore: SVector
7575
using CUDA
7676
using CUDA.CUSPARSE
77-
# CUDA.allowscalar(false) # This is already set in the extension script
77+
using CUDSS
78+
using LinearSolve
7879

7980
QuantumToolbox.about()
8081
CUDA.versioninfo()

0 commit comments

Comments
 (0)