Skip to content

Commit 7605b69

Browse files
authored
fix rand_unitary (#230)
1 parent 5af51a2 commit 7605b69

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/qobj/operators.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function rand_unitary(dimensions::Union{AbstractVector{Int},Tuple}, ::Val{:haar}
4848
# Because inv(Λ) ⋅ R has real and strictly positive elements, Q · Λ is therefore Haar distributed.
4949
Λ = diag(R) # take the diagonal elements of R
5050
Λ ./= abs.(Λ) # rescaling the elements
51-
return QuantumObject(dense_to_sparse(Q * Diagonal(Λ)); type = Operator, dims = dimensions)
51+
return QuantumObject(sparse_to_dense(Q * Diagonal(Λ)); type = Operator, dims = dimensions)
5252
end
5353
function rand_unitary(dimensions::Union{AbstractVector{Int},Tuple}, ::Val{:exp})
5454
N = prod(dimensions)
@@ -59,7 +59,7 @@ function rand_unitary(dimensions::Union{AbstractVector{Int},Tuple}, ::Val{:exp})
5959
# generate Hermitian matrix
6060
H = QuantumObject((Z + Z') / 2; type = Operator, dims = dimensions)
6161

62-
return exp(-1.0im * H)
62+
return sparse_to_dense(exp(-1.0im * H))
6363
end
6464
rand_unitary(dimensions::Union{AbstractVector{Int},Tuple}, ::Val{T}) where {T} =
6565
throw(ArgumentError("Invalid distribution: $(T)"))

0 commit comments

Comments
 (0)