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

Composite basis + embed lead to incompatible bases when used together with tensor #323

Closed gtlandi closed 2 years ago

gtlandi commented 2 years ago

Hi. There seem to be an issue with the way that embed defines the composite basis. Consider the following example:

b = SpinBasis(1//2); op1 = tensor(one(b), sigmaz(b)) B = CompositeBasis([b,b]) op2 = embed(B, 2, sigmaz(b))

When I try to multiply op1*op2, it raises a "IncompatibleBases()" error. From what I could gather, somehow the typeof(op.basis_l) are different in the two cases.

ChristophHotter commented 2 years ago

Hi @gtlandi , Thank you for the issue. The function CompositeBasis() should not get a vector as argument. If you write B = CompositeBasis(b,b) instead it works.

@david-pl should I change CompositeBasis(bases) = CompositeBasis([length(b) for b ∈ bases], bases) in https://github.com/qojulia/QuantumOpticsBase.jl/blob/f3c23a275f9ec5c92616834ab578507459239919/src/bases.jl#L64 to CompositeBasis(bases::Tuple) = CompositeBasis([length(b) for b ∈ bases], bases), to get a MethodError for vectors?

gtlandi commented 2 years ago

Oh. I see. Thank you for the feedback!

david-pl commented 2 years ago

@ChristophHotter CompositeBasis(bases::Vector) = CompositeBasis((bases...,)) should do the trick.