Addition of LazyTensor and LazySum
mabuni1998 opened this issue · 1 comments
mabuni1998 commented
The current implementation for +(a::LazyTensor,b::LazyTensor) does not allow operators acting on different spaces. See the following:
julia>b = FockBasis(2);
julia> a = destroy(b);
julia> LazyTensor(b⊗b,[1,2],(a,a))+LazyTensor(b⊗b,[1,2],(a,a))
ERROR: ArgumentError: Addition of LazyTensor operators is only defined in case both operators act nontrivially on the same, single tensor factor.
Stacktrace:
[1] +(a::LazyTensor{CompositeBasis{Vector{Int64}, Tuple{FockBasis{Int64}, FockBasis{Int64}}}, CompositeBasis{Vector{Int64}, Tuple{FockBasis{Int64}, FockBasis{Int64}}}, ComplexF64, Vector{Int64}, Tuple{Operator{FockBasis{Int64}, FockBasis{Int64}, SparseArrays.SparseMatrixCSC{ComplexF64, Int64}}, Operator{FockBasis{Int64}, FockBasis{Int64}, SparseArrays.SparseMatrixCSC{ComplexF64, Int64}}}}, b::LazyTensor{CompositeBasis{Vector{Int64}, Tuple{FockBasis{Int64}, FockBasis{Int64}}}, CompositeBasis{Vector{Int64}, Tuple{FockBasis{Int64}, FockBasis{Int64}}}, ComplexF64, Vector{Int64}, Tuple{Operator{FockBasis{Int64}, FockBasis{Int64}, SparseArrays.SparseMatrixCSC{ComplexF64, Int64}}, Operator{FockBasis{Int64}, FockBasis{Int64}, SparseArrays.SparseMatrixCSC{ComplexF64, Int64}}}})
@ QuantumOpticsBase C:\Users\Matias\.julia\packages\QuantumOpticsBase\tj3Ta\src\operators_lazytensor.jl:102
[2] top-level scope
@ REPL[5]:1
One could create a LazySum operator of the two LazyTensor objects, something like:
function Base.:+(op1::LazyTensor{B1,B2},op2::LazyTensor{B1,B2}) where {B1,B2}
LazySum(op1,op2)
end
Similarly, one could add:
function Base.:+(op1::LazySum{B1,B2},op2::LazyTensor{B1,B2}) where {B1,B2}
op1+LazySum(op2)
end
Is there a reason this is not a good idea?
amilsted commented
Think we have this now?