Skip to content

Commit

Permalink
Add nice error message to steadystate for sparse operators
Browse files Browse the repository at this point in the history
  • Loading branch information
david-pl committed Jan 11, 2017
1 parent 660608d commit ad4ac75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/steadystate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ function eigenvector(L::DenseSuperOperator)
end

function eigenvector(L::SparseSuperOperator)
d, v, nconv, niter, nmult, resid = Base.eigs(L.data; nev=1, sigma=1e-30)
d, v, nconv, niter, nmult, resid = try
Base.eigs(L.data; nev=1, sigma=1e-30)
catch err
if isa(err, LinAlg.SingularException)
error("Base.LinAlg.eigs() algorithm failed; try using DenseOperators")
else
rethrow(err)
end
end
data = reshape(v[:,1], length(L.basis_r[1]), length(L.basis_r[2]))
op = DenseOperator(L.basis_r[1], L.basis_r[2], data)
return op/trace(op)
Expand Down
4 changes: 4 additions & 0 deletions test/test_steadystate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ nss = expect(create(fockbasis)*destroy(fockbasis), ρss)
ρss = steadystate.eigenvector(full(Hp), map(full, Jp))
nss = expect(create(fockbasis)*destroy(fockbasis), ρss)
@test n_an - real(nss) < 1e-3


# Test error messages
@test_throws ErrorException steadystate.eigenvector(sx, [sm])

0 comments on commit ad4ac75

Please sign in to comment.