-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Problem Description
QuTiP
is also preparing the direct_sum
function here: qutip/qutip#2662
I think we should also start to think about implementing it.
Just put some thoughts I have in my mind below.
Proposed Solution
For the internal Space
and Dimensions
structure
we should add a new
struct SumSpace <: AbstractSpace
same as QuTiP
.
For the type
field
Seems that QuTiP
only allows the output of direct_sum
to be SuperOperator()
.
For the data
field
Thanks to the function hvcat
in Julia
's standard library, we can just add a method to it, and everything seems to be easy:
const _QobjConcatGroup = Union{QuantumObject,Number}
function Base.hvcat(rows::Tuple{Vararg{Int}}, X1::_QobjConcatGroup, X::_QobjConcatGroup...)
new_data = hvcat(rows, get_data(X1), (get_data.(X))...)
new_dimensions = # implement with SumSpace
return Qobj(new_data, SuperOperator(), new_dimensions)
end
QuantumToolbox.get_data(n::Number) = n
some examples:
m11 = Qobj([
3 3 3;
3 3 3;
3 3 3
])
m22 = Qobj([
2 2;
2 2
])
m12 = 1im * Qobj([
1 1;
1 1;
1 1
])
[
m11 m12;
m12' m22
].data
5×5 Matrix{Complex{Int64}}:
3+0im 3+0im 3+0im 0+1im 0+1im
3+0im 3+0im 3+0im 0+1im 0+1im
3+0im 3+0im 3+0im 0+1im 0+1im
0-1im 0-1im 0-1im 2+0im 2+0im
0-1im 0-1im 0-1im 2+0im 2+0im
x = sigmax()
ψ = 2im * basis(2, 1)
[
x ψ;
ψ' 3
].data
3×3 SparseMatrixCSC{ComplexF64, Int64} with 5 stored entries:
⋅ 1.0+0.0im ⋅
1.0+0.0im ⋅ 0.0+2.0im
⋅ 0.0-2.0im 3.0-0.0im
Alternate Solutions
One thing I'm not quite sure is the type _QobjConcatGroup = Union{QuantumObject,Number}
for hvcat
. I think this might cause piracy issues (especially for Number
-type).
But we need the Number
type for the second example above.
One way to avoid this issue is that we wrap the number as Qobj(3)
. In QuTiP
, this has the type Qobj(3).type = 'scalar'
. Not sure what should we call it in Julia
, because Scalar()
is used by StaticArrays
, and ScalarOperator()
is used by SciMLOperators
.
Additional Context
No response