Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sparse superoperator acting on sparse operator not defined #220

Closed
ericphanson opened this issue Jun 28, 2018 · 2 comments
Closed

Sparse superoperator acting on sparse operator not defined #220

ericphanson opened this issue Jun 28, 2018 · 2 comments

Comments

@ericphanson
Copy link

ericphanson commented Jun 28, 2018

It seems like multiplication of sparse superoperators on sparse operators is not defined. For example,

using QuantumOptics
A = GenericBasis(2)
so = spre(identityoperator(A))
ρ = basisstate(A,1) |> dm |> sparse
so * ρ 

results in

MethodError: no method matching *(::QuantumOptics.superoperators.SparseSuperOperator, ::QuantumOptics.operators_sparse.SparseOperator)
Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...) at operators.jl:424
  *(::QuantumOptics.states.Bra, ::QuantumOptics.operators.Operator) at C:\Users\Eric-d2\.julia\v0.6\QuantumOptics\src\operators_dense.jl:74
  *(::QuantumOptics.operators_dense.DenseOperator, ::QuantumOptics.operators.Operator) at C:\Users\Eric-d2\.julia\v0.6\QuantumOptics\src\operators_dense.jl:62
  ...

This seems strange!

Edit: bases.multiplicable(so,ρ) returns true in this example as well.

@david-pl
Copy link
Member

Thanks for pointing that out. Seems like we simply missed that. I will add the function asap. In the meantime you can just add the following function which I quickly drafted to make things work:

using QuantumOptics
import Base.*

function *(a::SuperOperator, b::SparseOperator)
    QuantumOptics.superoperators.check_multiplicable(a, b)
    data = a.data*reshape(b.data, length(b.data))
    SparseOperator(a.basis_l[1], a.basis_l[2], reshape(data, length(a.basis_l[1]), length(a.basis_l[2])))
end

A = GenericBasis(2)
so = spre(identityoperator(A))
ρ = basisstate(A,1) |> dm |> sparse
so * ρ

As a remark: please be aware that sparse-sparse multiplication in Julia is currently not that efficient. So if you are planning to use this product of a superoperator and an operator in a time-critical function it might be better to leave ρ dense.

@david-pl
Copy link
Member

david-pl commented Jul 3, 2018

I implemented the function as shown above. You can pull the latest master branch to use it (type Pkg.checkout("QuantumOptics") until a new release is drafted.

@david-pl david-pl closed this as completed Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants