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

Fix ProjTTN constructor for mixed input vertex types #165

Merged
merged 3 commits into from
May 2, 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: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ITensorNetworks"
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
authors = ["Matthew Fishman <[email protected]> and contributors"]
version = "0.10.1"
version = "0.10.2"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
16 changes: 15 additions & 1 deletion src/treetensornetworks/projttns/projttn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,24 @@ struct ProjTTN{V,Pos<:Union{Indices{V},NamedEdge{V}}} <: AbstractProjTTN{V}
pos::Pos
operator::TTN{V}
environments::Dictionary{NamedEdge{V},ITensor}
global function _ProjTTN(pos, operator::TTN, environments::Dictionary)
return new{vertextype(operator),Indices{vertextype(operator)}}(
Indices{vertextype(operator)}(pos),
operator,
convert(Dictionary{NamedEdge{vertextype(operator)},ITensor}, environments),
)
end
global function _ProjTTN(pos::NamedEdge, operator::TTN, environments::Dictionary)
return new{vertextype(operator),NamedEdge{vertextype(operator)}}(
convert(NamedEdge{vertextype(operator)}, pos),
operator,
convert(Dictionary{NamedEdge{vertextype(operator)},ITensor}, environments),
)
end
end

function ProjTTN(pos, operator::TTN, environments::Dictionary)
return ProjTTN(Indices(pos), operator, environments)
return _ProjTTN(pos, operator, environments)
end

function ProjTTN(operator::TTN)
Expand Down
2 changes: 2 additions & 0 deletions test/test_treetensornetworks/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[deps]
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
ITensorNetworks = "2919e153-833c-4bdc-8836-1ea460a35fc7"
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19"
15 changes: 12 additions & 3 deletions test/test_treetensornetworks/test_position.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
@eval module $(gensym())
using Dictionaries: Dictionary, Indices
using Graphs: vertices
using ITensors: ITensors
using ITensorNetworks: ProjTTN, ttn, environments, position, siteinds
using ITensors: ITensors, ITensor
using ITensorNetworks: ITensorNetwork, ProjTTN, ttn, environments, position, siteinds
using ITensorNetworks.ModelHamiltonians: ModelHamiltonians
using NamedGraphs.NamedGraphGenerators: named_comb_tree
using NamedGraphs: NamedEdge
using NamedGraphs.NamedGraphGenerators: named_comb_tree, named_path_graph
using Test: @test, @testset

@testset "ProjTTN position" begin
Expand Down Expand Up @@ -47,4 +49,11 @@ using Test: @test, @testset
ITensors.disable_auto_fermion()
end
end
@testset "ProjTTN construction regression test" begin
pos = Indices{Tuple{String,Int}}()
g = named_path_graph(2)
operator = ttn(ITensorNetwork{Any}(g))
environments = Dictionary{NamedEdge{Any},ITensor}()
@test ProjTTN(pos, operator, environments) isa ProjTTN{Any,Indices{Any}}
end
end
Loading