Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove RandomMatrices as a dependency #180

Merged
merged 4 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
QuantumInterface = "5717a53b-5d69-4fa3-b976-0bf2f97ca1e5"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RandomMatrices = "2576dda1-a324-5b11-aa66-c48ed7e3c618"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Strided = "5e0ebb24-38b0-5f93-81fe-25c709ecae67"
Expand All @@ -28,7 +27,6 @@ LRUCache = "1"
LinearAlgebra = "1"
QuantumInterface = "0.3.3"
Random = "1"
RandomMatrices = "0.5"
RecursiveArrayTools = "3"
SparseArrays = "1"
Strided = "1, 2"
Expand Down
17 changes: 14 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,12 @@ 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)
return Ket(b, q[:,1])
end

"""
randoperator([T=ComplexF64,] b1[, b2])
Expand All @@ -33,7 +37,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
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
QuantumInterface = "5717a53b-5d69-4fa3-b976-0bf2f97ca1e5"
QuantumOptics = "6e0679c1-51ea-5a7c-ac74-d61b76210b0c"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RandomMatrices = "2576dda1-a324-5b11-aa66-c48ed7e3c618"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Strided = "5e0ebb24-38b0-5f93-81fe-25c709ecae67"
Expand Down
5 changes: 2 additions & 3 deletions test/test_jet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function (::MayThrowIsOk)(report_type::Type{<:InferenceErrorReport}, @nospeciali
end

# imported to be declared as modules filtered out from analysis result
using LinearAlgebra, LRUCache, Strided, StridedViews, Dates, SparseArrays, RandomMatrices
using LinearAlgebra, LRUCache, Strided, StridedViews, Dates, SparseArrays

@testset "jet" begin
if get(ENV,"JET_TEST","")=="true"
Expand All @@ -31,8 +31,7 @@ using LinearAlgebra, LRUCache, Strided, StridedViews, Dates, SparseArrays, Rando
AnyFrameModule(Strided),
AnyFrameModule(StridedViews),
AnyFrameModule(Dates),
AnyFrameModule(SparseArrays),
AnyFrameModule(RandomMatrices))
AnyFrameModule(SparseArrays))
)
@show rep
@test length(JET.get_reports(rep)) <= 29
Expand Down
Loading