Skip to content

Commit 51779f2

Browse files
committed
address the comments from admins discussions in 2025-01-06
1 parent 977b7d3 commit 51779f2

26 files changed

+324
-303
lines changed

docs/src/resources/api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ CurrentModule = QuantumToolbox
1111
## [Quantum object (Qobj) and type](@id doc-API:Quantum-object-and-type)
1212

1313
```@docs
14+
Space
15+
Dimensions
16+
GeneralDimensions
1417
AbstractQuantumObject
1518
BraQuantumObject
1619
Bra

docs/src/tutorials/lowrank.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ M = latt.N + 1 # Number of states in the LR basis
4141
Define lr states. Take as initial state all spins up. All other N states are taken as those with miniman Hamming distance to the initial state.
4242

4343
```@example lowrank
44-
ϕ = Vector{QuantumObject{Vector{ComplexF64},KetQuantumObject,M-1}}(undef, M)
44+
ϕ = Vector{QuantumObject{Vector{ComplexF64},KetQuantumObject,Dimensions{M-1}}}(undef, M)
4545
ϕ[1] = kron(fill(basis(2, 1), N_modes)...)
4646
4747
i = 1

src/correlations.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +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)) ||
55-
throw(DimensionMismatch("The quantum objects are not of the same Hilbert dimension."))
54+
check_dimensions(L, ψ0, A, B, C)
5655

5756
kwargs2 = merge((saveat = collect(tlist),), (; kwargs...))
5857
ρt_list = mesolve(L, ψ0, tlist; kwargs2...).states
@@ -137,7 +136,7 @@ function correlation_2op_2t(
137136
HOpType<:Union{OperatorQuantumObject,SuperOperatorQuantumObject},
138137
StateOpType<:Union{KetQuantumObject,OperatorQuantumObject},
139138
}
140-
C = eye(prod(H._dims), dims = H._dims)
139+
C = eye(prod(H.dimensions), dims = H.dimensions)
141140
if reverse
142141
corr = correlation_3op_2t(H, ψ0, tlist, τlist, c_ops, A, B, C; kwargs...)
143142
else

src/negativity.jl

Lines changed: 13 additions & 13 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.dimensions))
4343
try
4444
mask[subsys] = true
4545
catch
@@ -69,16 +69,16 @@ Return the partial transpose of a density matrix ``\rho``, where `mask` is an ar
6969
- `ρ_pt::QuantumObject`: The density matrix with the selected subsystems transposed.
7070
"""
7171
function partial_transpose::QuantumObject{DT,OperatorQuantumObject}, mask::Vector{Bool}) where {DT}
72-
if length(mask) != length._dims)
72+
if length(mask) != length.dimensions)
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
7979
function _partial_transpose::QuantumObject{DT,OperatorQuantumObject}, mask::Vector{Bool}) where {DT<:AbstractArray}
80-
isa._dims, CompoundDimensions) &&
81-
(ρ._to != ρ._from) &&
80+
isa.dimensions, GeneralDimensions) &&
81+
(get_dimensions_to(ρ) != get_dimensions_from(ρ)) &&
8282
throw(ArgumentError("Invalid partial transpose for dims = $(ρ.dims)"))
8383

8484
mask2 = [1 + Int(i) for i in mask]
@@ -87,27 +87,27 @@ function _partial_transpose(ρ::QuantumObject{DT,OperatorQuantumObject}, mask::V
8787
# 2 - the subsystem need be transposed
8888

8989
nsys = length(mask2)
90-
dimslist = dims_to_list._to)
90+
dims = dimensions_to_dims(get_dimensions_to(ρ))
9191
pt_dims = reshape(Vector(1:(2*nsys)), (nsys, 2))
9292
pt_idx = [
93-
[pt_dims[n, mask2[n]] for n in 1:nsys] # origin value in mask2
94-
[pt_dims[n, 3-mask2[n]] for n in 1:nsys] # opposite value in mask2 (1 -> 2, and 2 -> 1)
93+
[pt_dims[n, mask2[n]] for n in 1:nsys] # origin value in mask2
94+
[pt_dims[n, 3-mask2[n]] for n in 1:nsys] # opposite value in mask2 (1 -> 2, and 2 -> 1)
9595
]
9696
return QuantumObject(
97-
reshape(permutedims(reshape.data, (dimslist..., dimslist...)), pt_idx), size(ρ)),
97+
reshape(permutedims(reshape.data, (dims..., dims...)), pt_idx), size(ρ)),
9898
Operator,
99-
Dimensions._dims.to),
99+
Dimensions.dimensions.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.dimensions, GeneralDimensions) &&
106+
(get_dimensions_to(ρ) != get_dimensions_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(dimensions_to_dims(get_dimensions_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, ρ.dimensions)
143143
end

0 commit comments

Comments
 (0)