Skip to content

Commit aa01c99

Browse files
committed
introduce internal field _dims
1 parent 2930089 commit aa01c99

23 files changed

+228
-209
lines changed

ext/QuantumToolboxCUDAExt.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,58 +10,59 @@ import SparseArrays: SparseVector, SparseMatrixCSC
1010
1111
If `A.data` is a dense array, return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA.CuArray` for gpu calculations.
1212
"""
13-
CuArray(A::QuantumObject{Tq}) where {Tq<:Union{Vector,Matrix}} = QuantumObject(CuArray(A.data), A.type, A.dims)
13+
CuArray(A::QuantumObject{Tq}) where {Tq<:Union{Vector,Matrix}} = QuantumObject(CuArray(A.data), A.type, A._dims)
1414

1515
@doc raw"""
1616
CuArray{T}(A::QuantumObject)
1717
1818
If `A.data` is a dense array, return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA.CuArray` with element type `T` for gpu calculations.
1919
"""
20-
CuArray{T}(A::QuantumObject{Tq}) where {T,Tq<:Union{Vector,Matrix}} = QuantumObject(CuArray{T}(A.data), A.type, A.dims)
20+
CuArray{T}(A::QuantumObject{Tq}) where {T,Tq<:Union{Vector,Matrix}} = QuantumObject(CuArray{T}(A.data), A.type, A._dims)
2121

2222
@doc raw"""
2323
CuSparseVector(A::QuantumObject)
2424
2525
If `A.data` is a sparse vector, return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA.CUSPARSE.CuSparseVector` for gpu calculations.
2626
"""
27-
CuSparseVector(A::QuantumObject{<:SparseVector}) = QuantumObject(CuSparseVector(A.data), A.type, A.dims)
27+
CuSparseVector(A::QuantumObject{<:SparseVector}) = QuantumObject(CuSparseVector(A.data), A.type, A._dims)
2828

2929
@doc raw"""
3030
CuSparseVector{T}(A::QuantumObject)
3131
3232
If `A.data` is a sparse vector, return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA.CUSPARSE.CuSparseVector` with element type `T` for gpu calculations.
3333
"""
34-
CuSparseVector{T}(A::QuantumObject{<:SparseVector}) where {T} = QuantumObject(CuSparseVector{T}(A.data), A.type, A.dims)
34+
CuSparseVector{T}(A::QuantumObject{<:SparseVector}) where {T} =
35+
QuantumObject(CuSparseVector{T}(A.data), A.type, A._dims)
3536

3637
@doc raw"""
3738
CuSparseMatrixCSC(A::QuantumObject)
3839
3940
If `A.data` is in the type of `SparseMatrixCSC`, return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA.CUSPARSE.CuSparseMatrixCSC` for gpu calculations.
4041
"""
41-
CuSparseMatrixCSC(A::QuantumObject{<:SparseMatrixCSC}) = QuantumObject(CuSparseMatrixCSC(A.data), A.type, A.dims)
42+
CuSparseMatrixCSC(A::QuantumObject{<:SparseMatrixCSC}) = QuantumObject(CuSparseMatrixCSC(A.data), A.type, A._dims)
4243

4344
@doc raw"""
4445
CuSparseMatrixCSC{T}(A::QuantumObject)
4546
4647
If `A.data` is in the type of `SparseMatrixCSC`, return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA.CUSPARSE.CuSparseMatrixCSC` with element type `T` for gpu calculations.
4748
"""
4849
CuSparseMatrixCSC{T}(A::QuantumObject{<:SparseMatrixCSC}) where {T} =
49-
QuantumObject(CuSparseMatrixCSC{T}(A.data), A.type, A.dims)
50+
QuantumObject(CuSparseMatrixCSC{T}(A.data), A.type, A._dims)
5051

5152
@doc raw"""
5253
CuSparseMatrixCSR(A::QuantumObject)
5354
5455
If `A.data` is in the type of `SparseMatrixCSC`, return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA.CUSPARSE.CuSparseMatrixCSR` for gpu calculations.
5556
"""
56-
CuSparseMatrixCSR(A::QuantumObject{<:SparseMatrixCSC}) = QuantumObject(CuSparseMatrixCSR(A.data), A.type, A.dims)
57+
CuSparseMatrixCSR(A::QuantumObject{<:SparseMatrixCSC}) = QuantumObject(CuSparseMatrixCSR(A.data), A.type, A._dims)
5758

5859
@doc raw"""
5960
CuSparseMatrixCSR(A::QuantumObject)
6061
6162
If `A.data` is in the type of `SparseMatrixCSC`, return a new [`QuantumObject`](@ref) where `A.data` is in the type of `CUDA.CUSPARSE.CuSparseMatrixCSR` with element type `T` for gpu calculations.
6263
"""
6364
CuSparseMatrixCSR{T}(A::QuantumObject{<:SparseMatrixCSC}) where {T} =
64-
QuantumObject(CuSparseMatrixCSR{T}(A.data), A.type, A.dims)
65+
QuantumObject(CuSparseMatrixCSR{T}(A.data), A.type, A._dims)
6566

6667
@doc raw"""
6768
cu(A::QuantumObject; word_size::Int=64)

src/correlations.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function correlation_3op_2t(
5151
ψ0 = steadystate(L)
5252
end
5353

54-
allequal((L.dims, ψ0.dims, A.dims, B.dims, C.dims)) ||
54+
allequal((L._dims, ψ0._dims, A._dims, B._dims, C._dims)) ||
5555
throw(DimensionMismatch("The quantum objects are not of the same Hilbert dimension."))
5656

5757
kwargs2 = merge((saveat = collect(tlist),), (; kwargs...))
@@ -137,7 +137,7 @@ function correlation_2op_2t(
137137
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
138138
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject},
139139
}
140-
C = eye(prod(H.dims), dims = H.dims)
140+
C = eye(prod(H._dims), dims = H._dims)
141141
if reverse
142142
corr = correlation_3op_2t(H, ψ0, tlist, τlist, c_ops, A, B, C; kwargs...)
143143
else

src/negativity.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ julia> round(negativity(ρ, 2), digits=2)
3939
```
4040
"""
4141
function negativity::QuantumObject, subsys::Int; logarithmic::Bool = false)
42-
mask = fill(false, length.dims))
42+
mask = fill(false, length._dims))
4343
try
4444
mask[subsys] = true
4545
catch
@@ -68,17 +68,17 @@ Return the partial transpose of a density matrix ``\rho``, where `mask` is an ar
6868
# Returns
6969
- `ρ_pt::QuantumObject`: The density matrix with the selected subsystems transposed.
7070
"""
71-
function partial_transpose::QuantumObject{T,OperatorQuantumObject}, mask::Vector{Bool}) where {T}
72-
if length(mask) != length.dims)
71+
function partial_transpose::QuantumObject{DT,OperatorQuantumObject}, mask::Vector{Bool}) where {DT}
72+
if length(mask) != length._dims)
7373
throw(ArgumentError("The length of \`mask\` should be equal to the length of \`ρ.dims\`."))
7474
end
7575
return _partial_transpose(ρ, mask)
7676
end
7777

7878
# for dense matrices
79-
function _partial_transpose::QuantumObject{<:AbstractArray,OperatorQuantumObject}, mask::Vector{Bool})
80-
isa.dims, CompoundDimensions) &&
81-
.to != ρ.from) &&
79+
function _partial_transpose::QuantumObject{DT,OperatorQuantumObject}, mask::Vector{Bool}) where {DT<:AbstractArray}
80+
isa._dims, CompoundDimensions) &&
81+
._to != ρ._from) &&
8282
throw(ArgumentError("Invalid partial transpose for dims = $(ρ.dims)"))
8383

8484
mask2 = [1 + Int(i) for i in mask]
@@ -87,7 +87,7 @@ function _partial_transpose(ρ::QuantumObject{<:AbstractArray,OperatorQuantumObj
8787
# 2 - the subsystem need be transposed
8888

8989
nsys = length(mask2)
90-
dimslist = dims_to_list.to)
90+
dimslist = dims_to_list._to)
9191
pt_dims = reshape(Vector(1:(2*nsys)), (nsys, 2))
9292
pt_idx = [
9393
[pt_dims[n, mask2[n]] for n in 1:nsys] # origin value in mask2
@@ -96,18 +96,18 @@ function _partial_transpose(ρ::QuantumObject{<:AbstractArray,OperatorQuantumObj
9696
return QuantumObject(
9797
reshape(permutedims(reshape.data, (dimslist..., dimslist...)), pt_idx), size(ρ)),
9898
Operator,
99-
Dimensions.dims.to),
99+
Dimensions._dims.to),
100100
)
101101
end
102102

103103
# for sparse matrices
104104
function _partial_transpose::QuantumObject{<:AbstractSparseArray,OperatorQuantumObject}, mask::Vector{Bool})
105-
isa.dims, CompoundDimensions) &&
106-
.to != ρ.from) &&
105+
isa._dims, CompoundDimensions) &&
106+
._to != ρ._from) &&
107107
throw(ArgumentError("Invalid partial transpose for dims = $(ρ.dims)"))
108108

109109
M, N = size(ρ)
110-
dimsTuple = Tuple(dims_to_list.to))
110+
dimsTuple = Tuple(dims_to_list._to))
111111
colptr = ρ.data.colptr
112112
rowval = ρ.data.rowval
113113
nzval = ρ.data.nzval
@@ -139,5 +139,5 @@ function _partial_transpose(ρ::QuantumObject{<:AbstractSparseArray,OperatorQuan
139139
end
140140
end
141141

142-
return QuantumObject(sparse(I_pt, J_pt, V_pt, M, N), Operator, ρ.dims)
142+
return QuantumObject(sparse(I_pt, J_pt, V_pt, M, N), Operator, ρ._dims)
143143
end

0 commit comments

Comments
 (0)