Skip to content

Commit

Permalink
fix rand_unitary (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
ytdHuang authored Sep 22, 2024
1 parent 5af51a2 commit 7605b69
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/qobj/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function rand_unitary(dimensions::Union{AbstractVector{Int},Tuple}, ::Val{:haar}
# Because inv(Λ) ⋅ R has real and strictly positive elements, Q · Λ is therefore Haar distributed.
Λ = diag(R) # take the diagonal elements of R
Λ ./= abs.(Λ) # rescaling the elements
return QuantumObject(dense_to_sparse(Q * Diagonal(Λ)); type = Operator, dims = dimensions)
return QuantumObject(sparse_to_dense(Q * Diagonal(Λ)); type = Operator, dims = dimensions)
end
function rand_unitary(dimensions::Union{AbstractVector{Int},Tuple}, ::Val{:exp})
N = prod(dimensions)
Expand All @@ -59,7 +59,7 @@ function rand_unitary(dimensions::Union{AbstractVector{Int},Tuple}, ::Val{:exp})
# generate Hermitian matrix
H = QuantumObject((Z + Z') / 2; type = Operator, dims = dimensions)

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

0 comments on commit 7605b69

Please sign in to comment.