@@ -7,10 +7,13 @@ The Auxiliary Density Operators for HEOM model.
77
88# Fields
99- `data` : the vectorized auxiliary density operators
10- - `dims ` : the dimension list of the coupling operator (should be equal to the system dims ).
10+ - `dimensions ` : the dimension list of the coupling operator (should be equal to the system dimensions ).
1111- `N` : the number of auxiliary density operators
1212- `parity`: the parity label (`EVEN` or `ODD`).
1313
14+ !!! note "`dims` property"
15+ For a given `ados::ADOs`, `ados.dims` or `getproperty(ados, :dims)` returns its `dimensions` in the type of integer-vector.
16+
1417# Methods
1518One can obtain the density matrix for specific index (`idx`) by calling : `ados[idx]`.
1619`HierarchicalEOM.jl` also supports the following calls (methods) :
2629"""
2730struct ADOs
2831 data:: SparseVector{ComplexF64,Int64}
29- dims :: SVector
32+ dimensions :: Dimensions
3033 N:: Int
3134 parity:: AbstractParity
32- end
3335
34- # these functions are for forward compatibility
35- ADOs (data:: SparseVector{ComplexF64,Int64} , dim:: Int , N:: Int , parity:: AbstractParity ) = ADOs (data, [dim], N, parity)
36- ADOs (data:: SparseVector{ComplexF64,Int64} , dims:: AbstractVector , N:: Int , parity:: AbstractParity ) =
37- ADOs (data, SVector {length(dims),Int} (dims), N, parity)
36+ function ADOs (data:: AbstractVector , dims, N:: Int , parity:: AbstractParity )
37+ dimensions = _gen_dimensions (dims)
38+ Vsize = size (data, 1 )
39+ ((Vsize / N) == prod (dimensions)^ 2 ) || error (" The `dimensions` is not consistent with the ADOs number `N`." )
40+ return new (sparsevec (data), dimensions, N, parity)
41+ end
42+ end
3843
3944@doc raw """
4045 ADOs(V, N, parity)
@@ -45,16 +50,7 @@ Generate the object of auxiliary density operators for HEOM model.
4550- `N::Int` : the number of auxiliary density operators.
4651- `parity::AbstractParity` : the parity label (`EVEN` or `ODD`). Default to `EVEN`.
4752"""
48- function ADOs (V:: AbstractVector , N:: Int , parity:: AbstractParity = EVEN)
49- # check the dimension of V
50- d = size (V, 1 )
51- dim = √ (d / N)
52- if isinteger (dim)
53- return ADOs (sparsevec (V), SVector {1,Int} (Int (dim)), N, parity)
54- else
55- error (" The dimension of vector is not consistent with the ADOs number \" N\" ." )
56- end
57- end
53+ ADOs (V:: AbstractVector , N:: Int , parity:: AbstractParity = EVEN) = ADOs (V, isqrt (Int (size (V, 1 ) / N)), N, parity)
5854
5955@doc raw """
6056 ADOs(ρ, N, parity)
@@ -67,11 +63,20 @@ Generate the object of auxiliary density operators for HEOM model.
6763"""
6864function ADOs (ρ:: QuantumObject , N:: Int = 1 , parity:: AbstractParity = EVEN)
6965 _ρ = sparsevec (ket2dm (ρ). data)
70- return ADOs (sparsevec (_ρ. nzind, _ρ. nzval, N * length (_ρ)), ρ. dims , N, parity)
66+ return ADOs (sparsevec (_ρ. nzind, _ρ. nzval, N * length (_ρ)), ρ. dimensions , N, parity)
7167end
7268ADOs (ρ, N:: Int = 1 , parity:: AbstractParity = EVEN) =
7369 error (" HierarchicalEOM doesn't support input `ρ` with type : $(typeof (ρ)) " )
7470
71+ function Base. getproperty (ados:: ADOs , key:: Symbol )
72+ # a comment here to avoid bad render by JuliaFormatter
73+ if key === :dims
74+ return dimensions_to_dims (getfield (ados, :dimensions ))
75+ else
76+ return getfield (ados, key)
77+ end
78+ end
79+
7580Base. checkbounds (A:: ADOs , i:: Int ) =
7681 ((i > A. N) || (i < 1 )) ? error (" Attempt to access $(A. N) -element ADOs at index [$(i) ]" ) : nothing
7782
@@ -92,31 +97,33 @@ Base.lastindex(A::ADOs) = length(A)
9297function Base. getindex (A:: ADOs , i:: Int )
9398 checkbounds (A, i)
9499
95- D = prod (A. dims )
100+ D = prod (A. dimensions )
96101 sup_dim = D^ 2
97102 back = sup_dim * i
98- return QuantumObject (reshape (A. data[(back- sup_dim+ 1 ): back], D, D), Operator, A. dims )
103+ return QuantumObject (reshape (A. data[(back- sup_dim+ 1 ): back], D, D), Operator, A. dimensions )
99104end
100105
101106function Base. getindex (A:: ADOs , r:: UnitRange{Int} )
102107 checkbounds (A, r[1 ])
103108 checkbounds (A, r[end ])
104109
105110 result = []
106- D = prod (A. dims )
111+ D = prod (A. dimensions )
107112 sup_dim = D^ 2
108113 for i in r
109114 back = sup_dim * i
110- push! (result, QuantumObject (reshape (A. data[(back- sup_dim+ 1 ): back], D, D), Operator, A. dims ))
115+ push! (result, QuantumObject (reshape (A. data[(back- sup_dim+ 1 ): back], D, D), Operator, A. dimensions ))
111116 end
112117 return result
113118end
114119Base. getindex (A:: ADOs , :: Colon ) = getindex (A, 1 : lastindex (A))
115120
116121Base. iterate (A:: ADOs , state:: Int = 1 ) = state > length (A) ? nothing : (A[state], state + 1 )
117122
118- Base. show (io:: IO , A:: ADOs ) =
119- print (io, " $(A. N) Auxiliary Density Operators with $(A. parity) and (system) dims = $(A. dims) \n " )
123+ Base. show (io:: IO , A:: ADOs ) = print (
124+ io,
125+ " $(A. N) Auxiliary Density Operators with $(A. parity) and (system) dims = $(_get_dims_string (A. dimensions)) \n " ,
126+ )
120127Base. show (io:: IO , m:: MIME"text/plain" , A:: ADOs ) = show (io, A)
121128
122129@doc raw """
@@ -130,8 +137,8 @@ Return the density matrix of the reduced state (system) from a given auxiliary d
130137- `ρ::QuantumObject` : The density matrix of the reduced state
131138"""
132139function getRho (ados:: ADOs )
133- D = prod (ados. dims )
134- return QuantumObject (reshape (ados. data[1 : (D^ 2 )], D, D), Operator, ados. dims )
140+ D = prod (ados. dimensions )
141+ return QuantumObject (reshape (ados. data[1 : (D^ 2 )], D, D), Operator, ados. dimensions )
135142end
136143
137144@doc raw """
@@ -168,9 +175,9 @@ where ``O`` is the operator and ``\rho`` is the reduced density operator in the
168175function QuantumToolbox. expect (op, ados:: ADOs ; take_real:: Bool = true )
169176 if op isa HEOMSuperOp
170177 _check_sys_dim_and_ADOs_num (op, ados)
171- exp_val = dot (transpose (_Tr (eltype (ados), ados. dims , ados. N)), (SparseMatrixCSC (op) * ados). data)
178+ exp_val = dot (transpose (_Tr (eltype (ados), ados. dimensions , ados. N)), (SparseMatrixCSC (op) * ados). data)
172179 else
173- _op = HandleMatrixType (op, ados. dims , " op (observable)" ; type = Operator)
180+ _op = HandleMatrixType (op, ados. dimensions , " op (observable)" ; type = Operator)
174181 exp_val = tr (_op. data * getRho (ados). data)
175182 end
176183
@@ -198,7 +205,7 @@ where ``O`` is the operator and ``\rho`` is the reduced density operator in one
198205- `exp_val` : The expectation value
199206"""
200207function QuantumToolbox. expect (op, ados_list:: Vector{ADOs} ; take_real:: Bool = true )
201- dims = ados_list[1 ]. dims
208+ dimensions = ados_list[1 ]. dimensions
202209 N = ados_list[1 ]. N
203210 for i in 2 : length (ados_list)
204211 _check_sys_dim_and_ADOs_num (ados_list[1 ], ados_list[i])
@@ -208,9 +215,9 @@ function QuantumToolbox.expect(op, ados_list::Vector{ADOs}; take_real::Bool = tr
208215 _check_sys_dim_and_ADOs_num (op, ados_list[1 ])
209216 _op = op
210217 else
211- _op = HEOMSuperOp (spre (op), EVEN, dims , N)
218+ _op = HEOMSuperOp (spre (op), EVEN, dimensions , N)
212219 end
213- tr_op = transpose (_Tr (eltype (op), dims , N)) * SparseMatrixCSC (_op). data
220+ tr_op = transpose (_Tr (eltype (op), dimensions , N)) * SparseMatrixCSC (_op). data
214221
215222 exp_val = [dot (tr_op, ados. data) for ados in ados_list]
216223
0 commit comments