Skip to content

Commit

Permalink
edit randunitary methods
Browse files Browse the repository at this point in the history
  • Loading branch information
apkille committed Nov 24, 2024
1 parent 9a66a46 commit 34e2b22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ LRUCache = "1"
LinearAlgebra = "1"
QuantumInterface = "0.3.3"
Random = "1"
RandomMatrices = "0.5"
RecursiveArrayTools = "3"
SparseArrays = "1"
Strided = "1, 2"
Expand Down
19 changes: 16 additions & 3 deletions src/state_definitions.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using RandomMatrices
"""
randstate([T=ComplexF64,] basis)
Expand All @@ -16,7 +15,14 @@ randstate(b) = randstate(ComplexF64, b)
Returns a Haar random pure state of dimension `length(b)` by applying a Haar random unitary to a fixed pure state.
"""
randstate_haar(b::Basis) = Ket(b, rand(Haar(2), length(b), 2)[:,1])
function randstate_haar(b::Basis)
dim = length(b)
mat = rand(ComplexF64, dim, dim)
q, r = qr(mat)
d = Diagonal([r[i, i] / abs(r[i, i]) for i in 1:dim])
data = q * d
return Ket(b, data[:,1])
end

"""
randoperator([T=ComplexF64,] b1[, b2])
Expand All @@ -33,7 +39,14 @@ randoperator(b) = randoperator(ComplexF64, b)
Returns a Haar random unitary matrix of dimension `length(b)`.
"""
randunitary_haar(b::Basis) = DenseOperator(b, b, rand(Haar(2), length(b), 2))
function randunitary_haar(b::Basis)
dim = length(b)
mat = rand(ComplexF64, dim, dim)
q, r = qr(mat)
d = Diagonal([r[i, i] / abs(r[i, i]) for i in 1:dim])
data = q * d
DenseOperator(b, b, data)
end

"""
thermalstate(H,T)
Expand Down

0 comments on commit 34e2b22

Please sign in to comment.