From 7605b69e2093386eea0f634a20cb617093233b7f Mon Sep 17 00:00:00 2001 From: Yi-Te Huang <44385685+ytdHuang@users.noreply.github.com> Date: Mon, 23 Sep 2024 00:22:42 +0800 Subject: [PATCH] fix `rand_unitary` (#230) --- src/qobj/operators.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qobj/operators.jl b/src/qobj/operators.jl index 008f2943..feb15780 100644 --- a/src/qobj/operators.jl +++ b/src/qobj/operators.jl @@ -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) @@ -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)"))