matrixjuliadiagonal

How to convert operators into Matrices?


I am trying to find the eigenvalues of a Hamiltonian using the Quantumoptics.jl package. But every time I try to do that it gives me an error saying Methoderror: no method matching eigen(::Operator{FockBasis{Int64}, FockBasis{Int64}, SparseArrays.SparseMatrixCSC{ComplexF64, Int64}})

a = destroy(cavity);
at = create(cavity);

beta= 0.1;

H= beta * at *a
e = eigen(H);

I was expecting an array that gives me the eigenvalues of H. I also tried to H = Matrix(H), but no help


Solution

  • In Julia, you can inspect types using typeof, e.g.,

    > typeof(H)
    Operator{FockBasis{Int64}, FockBasis{Int64}, SparseArrays.SparseMatrixCSC{ComplexF64, Int64}}
    

    If you want to know more about Operators, you can type ?Operator into the REPL to get a quick documentation, consult the package's online documentation for more details, or use dump(H) to see the fields of this structure.

    Therefore, to get the Operator's coefficients, you can use H.data. To retrieve them as a (dense) Matrix, you can use dense(H).data. Though, if you are interested in the eigen values, I would suggest that you directly use eigenstates(H), which is the implementation from the QuantumOptics-package that can directly process Operators and also takes care of the bases, i.e.,

    function eigenstates(op::DenseOpType, n::Int=length(basis(op)); warning=true)
       b = basis(op)
       if ishermitian(op)
           D, V = eigen(Hermitian(op.data), 1:n)
           states = [Ket(b, V[:, k]) for k=1:length(D)]
           return D, states
       # ...
       end
     end