qojulia / QuantumOptics.jl

Library for the numerical simulation of closed as well as open quantum systems.
http://qojulia.org
Other
518 stars 101 forks source link

laziness-preserving embed? #330

Closed amilsted closed 1 year ago

amilsted commented 2 years ago

Should there be embed() methods for LazyTensor, LazySum, and LazyProduct that preserve laziness? The method would "embed" each of the component operators. For example:

function embed(basis, indices, op::LazyTensor)
    LazyTensor(basis, indices, op.operators, op.factor)
end

function embed(basis, indices, op::LazySum)
    LazySum(basis, [embed(basis, indices, o) for o in op.operators], op.factors)
end
david-pl commented 2 years ago

To be honest, I thought there already was an embed for LazyTensor (but I guess I was wrong). Would be nice to have all of those methods, of course. Another thing that's also missing is an embed for directsum stuff, but that's a different issue.

amilsted commented 2 years ago

I took another look. Indeed it seems everything is there, but something is going wrong: It looks like the identityoperator() method for the LazyTensor type is not working properly. For a LazyTensor O I get

embed(b123, [1,2], O)
ERROR: ArgumentError: Identity operator not defined for operator type 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}}}}.
amilsted commented 2 years ago

LazySum is different:

embed(b, 1, ls)
ERROR: ArgumentError: Tensor product is not defined for this combination of types of operators: LazySum{FockBasis{Int64}, FockBasis{Int64}, Vector{ComplexF64}, Tuple{Operator{FockBasis{Int64}, FockBasis{Int64}, SparseArrays.SparseMatrixCSC{ComplexF64, Int64}}}}, LazySum{FockBasis{Int64}, FockBasis{Int64}, Vector{ComplexF64}, Tuple{Operator{FockBasis{Int64}, FockBasis{Int64}, SparseArrays.SparseMatrixCSC{ComplexF64, Int64}}}}.
amilsted commented 2 years ago

Maybe we just need a parametric type in the first argument for the identityoperator() method for LazyTensor. For LazySum, we would need to add (tensor) products.

amilsted commented 1 year ago

Mostly fixed in https://github.com/qojulia/QuantumOpticsBase.jl/pull/51