diff --git a/src/contract.jl b/src/contract.jl index f584f8a..a5a2fd3 100644 --- a/src/contract.jl +++ b/src/contract.jl @@ -117,7 +117,7 @@ function projcontract( end if length(results) == 1 - return results[1] + return results end res = if length(patchorder) > 0 diff --git a/src/partitionedmps.jl b/src/partitionedmps.jl index 4a3c7ca..864b376 100644 --- a/src/partitionedmps.jl +++ b/src/partitionedmps.jl @@ -6,6 +6,7 @@ struct PartitionedMPS data::OrderedDict{Projector,SubDomainMPS} function PartitionedMPS(data::AbstractVector{SubDomainMPS}) + length(data) > 0 || error("Empty data") sites_all = [siteinds(prjmps) for prjmps in data] for n in 2:length(data) Set(sites_all[n]) == Set(sites_all[1]) || error("Sitedims mismatch") @@ -32,9 +33,10 @@ end ITensors.siteinds(obj::PartitionedMPS) = siteindices(obj) """ -Get the number of sites in the PartitionedMPS +Get the number of the data in the PartitionedMPS. +This is NOT the number of sites in the PartitionedMPS. """ -Base.length(obj::PartitionedMPS) = length(first(obj.data)) +Base.length(obj::PartitionedMPS) = length(obj.data) """ Indexing for PartitionedMPS. This is deprecated and will be removed in the future. diff --git a/src/projector.jl b/src/projector.jl index b97ea92..7ac7c5c 100644 --- a/src/projector.jl +++ b/src/projector.jl @@ -30,7 +30,9 @@ Projector(singleproj::Pair{Index{T},Int}) where {T} = Projector(Dict{Index,Int}(singleproj.first => singleproj.second)) function Base.hash(p::Projector, h::UInt) - tmp = hash(collect(Iterators.flatten(((hash(k, h), hash(v, h)) for (k, v) in p.data)))) + tmp = hash( + sort(collect(Iterators.flatten(((hash(k, h), hash(v, h)) for (k, v) in p.data)))) + ) return Base.hash(tmp, h) end diff --git a/test/partitionedmps_tests.jl b/test/partitionedmps_tests.jl index f928cfd..70196db 100644 --- a/test/partitionedmps_tests.jl +++ b/test/partitionedmps_tests.jl @@ -1,10 +1,11 @@ using Test using ITensors +using ITensorMPS import PartitionedMPSs: Projector, project, SubDomainMPS, PartitionedMPS -@testset "PartitionedMPS.jl" begin +@testset "partitionedmps.jl" begin @testset "two blocks" begin N = 3 sitesx = [Index(2, "x=$n") for n in 1:N] @@ -22,6 +23,10 @@ import PartitionedMPSs: Projector, project, SubDomainMPS, PartitionedMPS @test_throws ErrorException PartitionedMPS([prjΨ, prjΨ1]) @test_throws ErrorException PartitionedMPS([prjΨ1, prjΨ1]) + # Iterator and length + @test length(PartitionedMPS(prjΨ1)) == 1 + @test length([(k, v) for (k, v) in PartitionedMPS(prjΨ1)]) == 1 + Ψreconst = PartitionedMPS(prjΨ1) + PartitionedMPS(prjΨ2) @test Ψreconst[1] == prjΨ1 @test Ψreconst[2] == prjΨ2