Skip to content

Commit aa91919

Browse files
authored
Support new cuquantum version (#2887)
* support new cuquantum version
1 parent 9eb1085 commit aa91919

File tree

6 files changed

+56
-40
lines changed

6 files changed

+56
-40
lines changed

.buildkite/pipeline.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,6 @@ steps:
9999
- "cuTENSOR"
100100
- "cuStateVec"
101101
- "cuTensorNet"
102-
adjustments:
103-
- with:
104-
package: "cuStateVec"
105-
cuda: "12.0"
106-
soft_fail: true
107-
- with:
108-
package: "cuStateVec"
109-
cuda: "13.0"
110-
soft_fail: true
111102
plugins:
112103
- JuliaCI/julia#v1:
113104
version: "1.10"

lib/custatevec/Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "cuStateVec"
22
uuid = "92f7fd98-d22e-4c0d-85a8-6ade11b672fb"
33
authors = ["Katharine Hyatt <kslimes@gmail.com>"]
4-
version = "1.4.0"
4+
version = "1.5.0"
55

66
[deps]
77
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
@@ -12,6 +12,6 @@ cuQuantum_jll = "b75408ef-6fdf-5d74-b65a-7df000ad18e6"
1212
[compat]
1313
CEnum = "0.2, 0.3, 0.4, 0.5"
1414
CUDA = "~5.9"
15-
CUDA_Runtime_Discovery = "0.2, 0.3, 1"
16-
cuQuantum_jll = "25.06"
15+
CUDA_Runtime_Discovery = "1"
16+
cuQuantum_jll = "25.11"
1717
julia = "1.10"

lib/custatevec/src/statevec.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,19 @@ function batchMeasureWithOffset!(sv::CuStateVec, bitordering::Vector{<:Integer},
115115
end
116116

117117
function expectation(sv::CuStateVec, matrix::Union{Matrix, CuMatrix}, basis_bits::Vector{<:Integer})
118+
CT = compute_type(eltype(sv), eltype(matrix))
118119
function bufferSize()
119120
out = Ref{Csize_t}()
120-
custatevecComputeExpectationGetWorkspaceSize(handle(), eltype(sv), sv.nbits, matrix, eltype(matrix), CUSTATEVEC_MATRIX_LAYOUT_COL, length(basis_bits), compute_type(eltype(sv), eltype(matrix)), out)
121+
custatevecComputeExpectationGetWorkspaceSize(handle(), eltype(sv), sv.nbits, matrix, eltype(matrix), CUSTATEVEC_MATRIX_LAYOUT_COL, length(basis_bits), CT, out)
121122
out[]
122123
end
123-
expVal = Ref{Float64}()
124-
residualNorm = Ref{Float64}()
124+
expVal = Ref{Float64}(0.0)
125+
residualNorm = Ref{Float64}(0.0)
125126
with_workspace(handle().cache, bufferSize) do buffer
126-
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))
127+
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))
128+
synchronize()
127129
end
128-
return expVal[], residualNorm[]
130+
return expVal, residualNorm
129131
end
130132

131133
function expectationsOnPauliBasis(sv::CuStateVec, pauliOps::Vector{Vector{Pauli}}, basisInds::Vector{Vector{Int}})

lib/custatevec/src/types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ mutable struct CuStateVec{T}
4646
nbits::UInt32
4747
end
4848
function CuStateVec(T, n_qubits::Int; sv_type::custatevecStateVectorType_t=CUSTATEVEC_STATE_VECTOR_TYPE_ZERO)
49-
data = CUDA.zeros(T, 2^n_qubits)
49+
data = CuVector{T}(undef, 2^n_qubits)
5050
# in most cases, taking the hit here for setting one element
5151
# is cheaper than building the entire thing on the CPU and
5252
# copying it over

lib/custatevec/test/runtests.jl

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,33 @@ using cuStateVec
2626
end
2727
@testset "applyMatrix! and expectation" begin
2828
# build a simple state and compute expectations
29-
n_q = 2
3029
@testset for elty in [ComplexF32, ComplexF64]
31-
H = convert(Matrix{elty}, (1/√2).*[1 1; 1 -1])
32-
X = convert(Matrix{elty}, [0 1; 1 0])
33-
Z = convert(Matrix{elty}, [1 0; 0 -1])
30+
result = (4.1, 0.0)
31+
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]
32+
O = elty[1 2+im; 2-im 3]
33+
n_q = 3
34+
sv = CuStateVec(elty, n_q)
35+
copyto!(sv.data, h_sv)
36+
exp_res = expectation(sv, O, Int32[1])
37+
synchronize()
38+
@test exp_res[1][] result[1] atol=1e-6
39+
@test exp_res[2][] result[2]
40+
41+
n_q = 2
42+
sv = CuStateVec(elty, n_q)
43+
H = convert(Matrix{elty}, (1/√2).*[1 1; 1 -1])
44+
X = convert(Matrix{elty}, [0 1; 1 0])
45+
Z = convert(Matrix{elty}, [1 0; 0 -1])
3446
sv = CuStateVec(elty, n_q)
35-
sv = applyMatrix!(sv, H, false, Int32[0], Int32[])
36-
sv = applyMatrix!(sv, H, false, Int32[1], Int32[])
37-
exp, res = expectation(sv, Z, Int32[1])
38-
@test exp 0.0 atol=1e-6
39-
exp, res = expectation(sv, X, Int32[0])
40-
@test exp 1.0 atol=1e-6
47+
sv = applyMatrix!(sv, X, false, Int32[0], Int32[])
48+
sv = applyMatrix!(sv, X, false, Int32[1], Int32[])
49+
exp, res = expectation(sv, CuMatrix(Z), Int32[0])
50+
synchronize()
51+
@test exp[] -1.0 atol=1e-6
52+
exp, res = expectation(sv, CuMatrix(Z), Int32[1])
53+
@test exp[] -1.0 atol=1e-6
54+
exp, res = expectation(sv, CuMatrix(X), Int32[0])
55+
@test exp[] 0.0 atol=1e-6
4156
end
4257
# build a simple state with controls and compute expectations
4358
n_q = 2
@@ -49,9 +64,11 @@ using cuStateVec
4964
sv = applyMatrix!(sv, H, false, Int32[0], Int32[])
5065
sv = applyMatrix!(sv, X, false, Int32[1], Int32[0]) # CNOT
5166
exp, res = expectation(sv, Z, Int32[0])
52-
@test exp 0.0 atol=1e-6
67+
synchronize()
68+
@test exp[] 0.0 atol=1e-6
5369
exp, res = expectation(sv, X, Int32[0])
54-
@test exp 0.0 atol=1e-6
70+
synchronize()
71+
@test exp[] 0.0 atol=1e-6
5572
end
5673
# with expectationsOnPauliBasis
5774
n_q = 2
@@ -89,22 +106,26 @@ using cuStateVec
89106
(cuStateVec.CUSTATEVEC_MATRIX_MAP_TYPE_MATRIX_INDEXED, fill(0, n_svs), 1),
90107
(cuStateVec.CUSTATEVEC_MATRIX_MAP_TYPE_BROADCAST, fill(0, n_svs), 1),
91108
)
92-
batched_vec = CUDA.zeros(elty, n_svs*2^(n_q))
109+
batched_vec = zeros(elty, n_svs*2^(n_q))
93110
for sv_ix in 0:n_svs-1
94-
CUDA.@allowscalar batched_vec[sv_ix*(2^n_q) + 1] = one(elty)
111+
batched_vec[sv_ix*(2^n_q) + 1] = one(elty)
95112
end
96-
sv = CuStateVec(batched_vec) # padded state vector
113+
sv = CuStateVec(elty, n_svs * n_q) # padded state vector
114+
copyto!(sv.data, batched_vec)
97115
H_batch = CuVector{elty}(repeat(vec(H), n_mats))
98116
sv = applyMatrixBatched!(sv, n_svs, mapping, mat_inds, H_batch, n_mats, false, Int32[0], Int32[])
99117
CUDA.@allowscalar begin
100118
for sv_ix in 0:n_svs-1
101119
ix_begin = sv_ix*2^n_q + 1
102120
ix_end = (sv_ix+1)*2^n_q
103-
sv_ = CuStateVec(sv.data[ix_begin:ix_end])
121+
sv_ = CuStateVec(elty, n_q)
122+
sv_.data .= sv.data[ix_begin:ix_end]
104123
exp, res = expectation(sv_, Z, Int32[0])
105-
@test exp 0.0 atol=1e-6
124+
synchronize()
125+
@test exp[] 0.0 atol=1e-6
106126
exp, res = expectation(sv_, X, Int32[0])
107-
@test exp 1.0 atol=1e-6
127+
synchronize()
128+
@test exp[] 1.0 atol=1e-6
108129
end
109130
end
110131
end
@@ -120,9 +141,11 @@ using cuStateVec
120141
sv = applyMatrix!(sv, H, false, Int32[0], Int32[])
121142
sv = applyMatrix!(sv, X, false, Int32[1], Int32[0]) # CNOT
122143
exp, res = expectation(sv, Z, Int32[0])
123-
@test exp 0.0 atol=1e-6
144+
synchronize()
145+
@test exp[] 0.0 atol=1e-6
124146
exp, res = expectation(sv, X, Int32[0])
125-
@test exp 0.0 atol=1e-6
147+
synchronize()
148+
@test exp[] 0.0 atol=1e-6
126149
end
127150
end
128151
@testset "applyMatrix! and sample" begin

lib/cutensornet/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "cuTensorNet"
22
uuid = "448d79b3-4b49-4e06-a5ea-00c62c0dc3db"
33
authors = ["Katharine Hyatt <kshyatt@gmail.com>"]
4-
version = "1.4.0"
4+
version = "1.5.0"
55

66
[deps]
77
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
@@ -15,7 +15,7 @@ cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1"
1515
CEnum = "0.2, 0.3, 0.4, 0.5"
1616
CUDA = "~5.9"
1717
CUDA_Runtime_Discovery = "0.2, 0.3, 1"
18-
cuQuantum_jll = "25.06"
18+
cuQuantum_jll = "25.11"
1919
cuTENSOR = "2.2"
2020
julia = "1.10"
2121
LinearAlgebra = "1"

0 commit comments

Comments
 (0)