Skip to content

Commit

Permalink
slightly modyfing base
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekGardas committed Nov 24, 2020
1 parent 710bee4 commit 1c90bab
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/base.jl
Expand Up @@ -146,6 +146,17 @@ function MPS(O::MPO)
ψ
end

function Base.randn(::Type{MPS{T}}, D::Int, rank::Union{Vector, NTuple}) where {T}
L = length(rank)
ψ = MPS(T, L)
ψ[1] = randn(T, 1, rank[1], D)
for i 2:(L-1)
ψ[i] = randn(T, D, rank[i], D)
end
ψ[end] = randn(T, D, rank[end], 1)
ψ
end

function Base.randn(::Type{MPS{T}}, L::Int, D::Int, d::Int) where {T}
ψ = MPS(T, L)
ψ[1] = randn(T, 1, d, D)
Expand Down
21 changes: 21 additions & 0 deletions test/base.jl
Expand Up @@ -23,6 +23,27 @@ T = ComplexF64
@test ϕ ψ

show(ψ)

dims = (3, 2, 5, 4)
@info "Veryfing ψ of arbitrary rank" dims

ψ = randn(MPS{T}, D, dims)
@test verify_bonds(ψ) == nothing

@test ψ == ψ
@test ψ ψ

@test length(ψ) == length(dims)
@test size(ψ) == (length(dims), )
@test eltype(ψ) == ComplexF64
@test rank(ψ) == dims
@test bond_dimension(ψ) D

ϕ = copy(ψ)
@test ϕ == ψ
@test ϕ ψ

show(ψ)
end

@testset "Random MPO" begin
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Expand Up @@ -22,11 +22,11 @@ if CUDA.functional() && CUDA.has_cutensor() && false
end

push!(my_tests,
# "base.jl",
"base.jl",
# "contractions.jl",
# "compressions.jl",
# "ising.jl",
"search.jl"
# "search.jl"
)

for my_test in my_tests
Expand Down
2 changes: 1 addition & 1 deletion test/search.jl
Expand Up @@ -76,7 +76,7 @@ end
β = get_prop(ig, )
rank = get_prop(ig, :rank)

@info "Generating Gibbs state - |ρ>" d L rank β ϵ
@info "Generating Gibbs state - |ρ>" L rank β ϵ

ψ = ones(rank...)

Expand Down

0 comments on commit 1c90bab

Please sign in to comment.