diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 440efcd672..70d74d049e 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -99,15 +99,6 @@ steps: - "cuTENSOR" - "cuStateVec" - "cuTensorNet" - adjustments: - - with: - package: "cuStateVec" - cuda: "12.0" - soft_fail: true - - with: - package: "cuStateVec" - cuda: "13.0" - soft_fail: true plugins: - JuliaCI/julia#v1: version: "1.10" diff --git a/lib/custatevec/Project.toml b/lib/custatevec/Project.toml index 3d198a3b6a..e58ce514b6 100644 --- a/lib/custatevec/Project.toml +++ b/lib/custatevec/Project.toml @@ -1,7 +1,7 @@ name = "cuStateVec" uuid = "92f7fd98-d22e-4c0d-85a8-6ade11b672fb" authors = ["Katharine Hyatt "] -version = "1.4.0" +version = "1.5.0" [deps] CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" @@ -12,6 +12,6 @@ cuQuantum_jll = "b75408ef-6fdf-5d74-b65a-7df000ad18e6" [compat] CEnum = "0.2, 0.3, 0.4, 0.5" CUDA = "~5.9" -CUDA_Runtime_Discovery = "0.2, 0.3, 1" -cuQuantum_jll = "25.06" +CUDA_Runtime_Discovery = "1" +cuQuantum_jll = "25.11" julia = "1.10" diff --git a/lib/custatevec/src/statevec.jl b/lib/custatevec/src/statevec.jl index 765605e5f2..45efdcc144 100644 --- a/lib/custatevec/src/statevec.jl +++ b/lib/custatevec/src/statevec.jl @@ -115,17 +115,19 @@ function batchMeasureWithOffset!(sv::CuStateVec, bitordering::Vector{<:Integer}, end function expectation(sv::CuStateVec, matrix::Union{Matrix, CuMatrix}, basis_bits::Vector{<:Integer}) + CT = compute_type(eltype(sv), eltype(matrix)) function bufferSize() out = Ref{Csize_t}() - custatevecComputeExpectationGetWorkspaceSize(handle(), eltype(sv), sv.nbits, matrix, eltype(matrix), CUSTATEVEC_MATRIX_LAYOUT_COL, length(basis_bits), compute_type(eltype(sv), eltype(matrix)), out) + custatevecComputeExpectationGetWorkspaceSize(handle(), eltype(sv), sv.nbits, matrix, eltype(matrix), CUSTATEVEC_MATRIX_LAYOUT_COL, length(basis_bits), CT, out) out[] end - expVal = Ref{Float64}() - residualNorm = Ref{Float64}() + expVal = Ref{Float64}(0.0) + residualNorm = Ref{Float64}(0.0) with_workspace(handle().cache, bufferSize) do buffer - custatevecComputeExpectation(handle(), sv.data, eltype(sv), sv.nbits, expVal, Float64, residualNorm, matrix, eltype(matrix), CUSTATEVEC_MATRIX_LAYOUT_COL, convert(Vector{Int32}, basis_bits), length(basis_bits), compute_type(eltype(sv), eltype(matrix)), buffer, sizeof(buffer)) + custatevecComputeExpectation(handle(), sv.data, eltype(sv), sv.nbits, expVal, Float64, residualNorm, matrix, eltype(matrix), CUSTATEVEC_MATRIX_LAYOUT_COL, convert(Vector{Int32}, basis_bits), length(basis_bits), CT, buffer, sizeof(buffer)) + synchronize() end - return expVal[], residualNorm[] + return expVal, residualNorm end function expectationsOnPauliBasis(sv::CuStateVec, pauliOps::Vector{Vector{Pauli}}, basisInds::Vector{Vector{Int}}) diff --git a/lib/custatevec/src/types.jl b/lib/custatevec/src/types.jl index 11488f79d4..206cadf61f 100644 --- a/lib/custatevec/src/types.jl +++ b/lib/custatevec/src/types.jl @@ -46,7 +46,7 @@ mutable struct CuStateVec{T} nbits::UInt32 end function CuStateVec(T, n_qubits::Int; sv_type::custatevecStateVectorType_t=CUSTATEVEC_STATE_VECTOR_TYPE_ZERO) - data = CUDA.zeros(T, 2^n_qubits) + data = CuVector{T}(undef, 2^n_qubits) # in most cases, taking the hit here for setting one element # is cheaper than building the entire thing on the CPU and # copying it over diff --git a/lib/custatevec/test/runtests.jl b/lib/custatevec/test/runtests.jl index c616d70472..2aa443f60c 100644 --- a/lib/custatevec/test/runtests.jl +++ b/lib/custatevec/test/runtests.jl @@ -26,18 +26,33 @@ using cuStateVec end @testset "applyMatrix! and expectation" begin # build a simple state and compute expectations - n_q = 2 @testset for elty in [ComplexF32, ComplexF64] - H = convert(Matrix{elty}, (1/√2).*[1 1; 1 -1]) - X = convert(Matrix{elty}, [0 1; 1 0]) - Z = convert(Matrix{elty}, [1 0; 0 -1]) + result = (4.1, 0.0) + h_sv = elty[0.0, 0.1*im, 0.1+0.1im, 0.1+0.2im, 0.2+0.2im, 0.3+0.3im, 0.3+0.4im, 0.4+0.5im] + O = elty[1 2+im; 2-im 3] + n_q = 3 + sv = CuStateVec(elty, n_q) + copyto!(sv.data, h_sv) + exp_res = expectation(sv, O, Int32[1]) + synchronize() + @test exp_res[1][] ≈ result[1] atol=1e-6 + @test exp_res[2][] ≈ result[2] + + n_q = 2 + sv = CuStateVec(elty, n_q) + H = convert(Matrix{elty}, (1/√2).*[1 1; 1 -1]) + X = convert(Matrix{elty}, [0 1; 1 0]) + Z = convert(Matrix{elty}, [1 0; 0 -1]) sv = CuStateVec(elty, n_q) - sv = applyMatrix!(sv, H, false, Int32[0], Int32[]) - sv = applyMatrix!(sv, H, false, Int32[1], Int32[]) - exp, res = expectation(sv, Z, Int32[1]) - @test exp ≈ 0.0 atol=1e-6 - exp, res = expectation(sv, X, Int32[0]) - @test exp ≈ 1.0 atol=1e-6 + sv = applyMatrix!(sv, X, false, Int32[0], Int32[]) + sv = applyMatrix!(sv, X, false, Int32[1], Int32[]) + exp, res = expectation(sv, CuMatrix(Z), Int32[0]) + synchronize() + @test exp[] ≈ -1.0 atol=1e-6 + exp, res = expectation(sv, CuMatrix(Z), Int32[1]) + @test exp[] ≈ -1.0 atol=1e-6 + exp, res = expectation(sv, CuMatrix(X), Int32[0]) + @test exp[] ≈ 0.0 atol=1e-6 end # build a simple state with controls and compute expectations n_q = 2 @@ -49,9 +64,11 @@ using cuStateVec sv = applyMatrix!(sv, H, false, Int32[0], Int32[]) sv = applyMatrix!(sv, X, false, Int32[1], Int32[0]) # CNOT exp, res = expectation(sv, Z, Int32[0]) - @test exp ≈ 0.0 atol=1e-6 + synchronize() + @test exp[] ≈ 0.0 atol=1e-6 exp, res = expectation(sv, X, Int32[0]) - @test exp ≈ 0.0 atol=1e-6 + synchronize() + @test exp[] ≈ 0.0 atol=1e-6 end # with expectationsOnPauliBasis n_q = 2 @@ -89,22 +106,26 @@ using cuStateVec (cuStateVec.CUSTATEVEC_MATRIX_MAP_TYPE_MATRIX_INDEXED, fill(0, n_svs), 1), (cuStateVec.CUSTATEVEC_MATRIX_MAP_TYPE_BROADCAST, fill(0, n_svs), 1), ) - batched_vec = CUDA.zeros(elty, n_svs*2^(n_q)) + batched_vec = zeros(elty, n_svs*2^(n_q)) for sv_ix in 0:n_svs-1 - CUDA.@allowscalar batched_vec[sv_ix*(2^n_q) + 1] = one(elty) + batched_vec[sv_ix*(2^n_q) + 1] = one(elty) end - sv = CuStateVec(batched_vec) # padded state vector + sv = CuStateVec(elty, n_svs * n_q) # padded state vector + copyto!(sv.data, batched_vec) H_batch = CuVector{elty}(repeat(vec(H), n_mats)) sv = applyMatrixBatched!(sv, n_svs, mapping, mat_inds, H_batch, n_mats, false, Int32[0], Int32[]) CUDA.@allowscalar begin for sv_ix in 0:n_svs-1 ix_begin = sv_ix*2^n_q + 1 ix_end = (sv_ix+1)*2^n_q - sv_ = CuStateVec(sv.data[ix_begin:ix_end]) + sv_ = CuStateVec(elty, n_q) + sv_.data .= sv.data[ix_begin:ix_end] exp, res = expectation(sv_, Z, Int32[0]) - @test exp ≈ 0.0 atol=1e-6 + synchronize() + @test exp[] ≈ 0.0 atol=1e-6 exp, res = expectation(sv_, X, Int32[0]) - @test exp ≈ 1.0 atol=1e-6 + synchronize() + @test exp[] ≈ 1.0 atol=1e-6 end end end @@ -120,9 +141,11 @@ using cuStateVec sv = applyMatrix!(sv, H, false, Int32[0], Int32[]) sv = applyMatrix!(sv, X, false, Int32[1], Int32[0]) # CNOT exp, res = expectation(sv, Z, Int32[0]) - @test exp ≈ 0.0 atol=1e-6 + synchronize() + @test exp[] ≈ 0.0 atol=1e-6 exp, res = expectation(sv, X, Int32[0]) - @test exp ≈ 0.0 atol=1e-6 + synchronize() + @test exp[] ≈ 0.0 atol=1e-6 end end @testset "applyMatrix! and sample" begin diff --git a/lib/cutensornet/Project.toml b/lib/cutensornet/Project.toml index c571ac29e1..f0f7415ee0 100644 --- a/lib/cutensornet/Project.toml +++ b/lib/cutensornet/Project.toml @@ -1,7 +1,7 @@ name = "cuTensorNet" uuid = "448d79b3-4b49-4e06-a5ea-00c62c0dc3db" authors = ["Katharine Hyatt "] -version = "1.4.0" +version = "1.5.0" [deps] CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" @@ -15,7 +15,7 @@ cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1" CEnum = "0.2, 0.3, 0.4, 0.5" CUDA = "~5.9" CUDA_Runtime_Discovery = "0.2, 0.3, 1" -cuQuantum_jll = "25.06" +cuQuantum_jll = "25.11" cuTENSOR = "2.2" julia = "1.10" LinearAlgebra = "1"