QuantumOpticsBase.jl icon indicating copy to clipboard operation
QuantumOpticsBase.jl copied to clipboard

Less eagerly transform `FillArray` data (e.g. `identityoperator()`) into sparse arrays (e.g. `2*identityoperator()` should be FillArray, not sparse)

Open Krastanov opened this issue 2 years ago • 2 comments
trafficstars

Since 0.4 we have Eye+sparse=dense. We should keep the sparsity in situations like this.

Regression reported over slack by Satya Bade:

Hi Stefan, Thanks, I think the problem is with the addition between Eye and a sparse operator, it gives a dense operator! For example, the following code gives an out of memory error (depending on the available RAM)

using QuantumOpticsBase
bs = SpinBasis(1//2)
op = identityoperator(bs) + sigmaz(bs)
tensor([op for _ in 1:16]...)

this is possible with the older versions

Krastanov avatar Jun 21 '23 23:06 Krastanov

This is fixed in https://github.com/qojulia/QuantumOpticsBase.jl/pull/110, but there are still things that can be improved. Namely, the large block of methods with a TODO left in it can be improved by leaning a bit harder into using FillArray and lazy embeds, for scaled identities and for tensor products with identities. Leaving open but renaming

Krastanov avatar Jun 22 '23 16:06 Krastanov

Noting here that FillArrays 1.3 improves on this: https://github.com/JuliaArrays/FillArrays.jl/issues/265

kron is fixed upstream, but addition still gives us dense.

amilsted avatar Jul 05 '23 18:07 amilsted