More convenient `IndsNetwork` constructors
mtfishman opened this issue · comments
Make it easier to construct an IndsNetwork
from an underlying graph. This works:
julia> is = IndsNetwork(path_graph(3); site_space=Dictionary(1:3, siteinds("S=1/2", 3)), link_space=2)
IndsNetwork{Int64, Index{Int64}} with 3 vertices:
3-element Vector{Int64}:
1
2
3
and 2 edge(s):
1 => 2
2 => 3
with vertex data:
3-element Dictionary{Int64, Vector{Index{Int64}}}
1 │ Index{Int64}[(dim=2|id=679|"S=1/2,Site,n=1")]
2 │ Index{Int64}[(dim=2|id=978|"S=1/2,Site,n=2")]
3 │ Index{Int64}[(dim=2|id=650|"S=1/2,Site,n=3")]
and edge data:
2-element Dictionary{NamedGraphs.NamedEdge{Int64}, Vector{Index{Int64}}}
1 => 2 │ Index{Int64}[(dim=2|id=951|"1↔2")]
2 => 3 │ Index{Int64}[(dim=2|id=103|"2↔3")]
but this currently fails:
julia> is = IndsNetwork(path_graph(3); site_space=siteinds("S=1/2", 3), link_space=2)
ERROR: MethodError: no method matching site_space_map(::Type{Int64}, ::Type{Index{Int64}}, ::NamedGraphs.NamedGraph{Int64}, ::Vector{Index{Int64}})
Closest candidates are:
site_space_map(::Type, ::Type{<:Index}, ::var"##322", ::AbstractDictionary{<:Any, Vector{<:Index}}) where var"##322" at ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:331
site_space_map(::Type, ::Type{<:Index}, ::var"##323", ::AbstractDictionary{<:Any, <:Index}) where var"##323" at ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:331
site_space_map(::Type, ::Type{<:Index}, ::var"##324", ::AbstractDictionary{<:Any, Vector{Int64}}) where var"##324" at ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:331
...
Stacktrace:
[1] IndsNetwork{Int64, Index{Int64}}(g::NamedGraphs.NamedGraph{Int64}, link_space::Int64, site_space::Vector{Index{Int64}})
@ ITensorNetworks ~/.julia/packages/ITensorNetworks/REB7V/src/indsnetwork.jl:44
[2] IndsNetwork{Int64, Index{Int64}}(g::SimpleGraph{Int64}, link_space::Int64, site_space::Vector{Index{Int64}})
@ ITensorNetworks ~/.julia/packages/ITensorNetworks/REB7V/src/indsnetwork.jl:51
[3] (IndsNetwork{Int64})(::Type{DataGraphs.IsUnderlyingGraph{SimpleGraph{Int64}}}, g::SimpleGraph{Int64}, link_space::Int64, site_space::Vector{Index{Int64}})
@ ITensorNetworks ~/.julia/packages/ITensorNetworks/REB7V/src/indsnetwork.jl:56
[4] IndsNetwork
@ ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:331 [inlined]
[5] (IndsNetwork{Int64})(::Type{DataGraphs.IsUnderlyingGraph{SimpleGraph{Int64}}}, g::SimpleGraph{Int64}; link_space::Int64, site_space::Vector{Index{Int64}})
@ ITensorNetworks ~/.julia/packages/ITensorNetworks/REB7V/src/indsnetwork.jl:132
[6] #_#38
@ ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:338 [inlined]
[7] IndsNetwork(::Type{DataGraphs.IsUnderlyingGraph{SimpleGraph{Int64}}}, g::SimpleGraph{Int64}; kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:site_space, :link_space), Tuple{Vector{Index{Int64}}, Int64}}})
@ ITensorNetworks ~/.julia/packages/ITensorNetworks/REB7V/src/indsnetwork.jl:136
[8] #IndsNetwork#40
@ ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:338 [inlined]
[9] top-level scope
@ REPL[33]:1
Also some related issues:
julia> IndsNetwork(path_graph(3), 2, Dictionary(1:3, siteinds("S=1/2", 3)))
ERROR: UndefVarError: links_space not defined
Stacktrace:
[1] IndsNetwork(::Type{DataGraphs.IsUnderlyingGraph{SimpleGraph{Int64}}}, g::SimpleGraph{Int64}, link_space::Int64, site_space::Dictionary{Int64, Index{Int64}})
@ ITensorNetworks ~/.julia/packages/ITensorNetworks/REB7V/src/indsnetwork.jl:61
[2] IndsNetwork(g::SimpleGraph{Int64}, link_space::Int64, site_space::Dictionary{Int64, Index{Int64}})
@ ITensorNetworks ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:331
[3] top-level scope
@ REPL[38]:1
julia> IndsNetwork{Int}(path_graph(3), 2, siteinds("S=1/2", 3))
ERROR: MethodError: no method matching site_space_map(::Type{Int64}, ::Type{Index{Int64}}, ::NamedGraphs.NamedGraph{Int64}, ::Vector{Index{Int64}})
Closest candidates are:
site_space_map(::Type, ::Type{<:Index}, ::var"##322", ::AbstractDictionary{<:Any, Vector{<:Index}}) where var"##322" at ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:331
site_space_map(::Type, ::Type{<:Index}, ::var"##323", ::AbstractDictionary{<:Any, <:Index}) where var"##323" at ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:331
site_space_map(::Type, ::Type{<:Index}, ::var"##324", ::AbstractDictionary{<:Any, Vector{Int64}}) where var"##324" at ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:331
...
Stacktrace:
[1] IndsNetwork{Int64, Index{Int64}}(g::NamedGraphs.NamedGraph{Int64}, link_space::Int64, site_space::Vector{Index{Int64}})
@ ITensorNetworks ~/.julia/packages/ITensorNetworks/REB7V/src/indsnetwork.jl:44
[2] IndsNetwork{Int64, Index{Int64}}(g::SimpleGraph{Int64}, link_space::Int64, site_space::Vector{Index{Int64}})
@ ITensorNetworks ~/.julia/packages/ITensorNetworks/REB7V/src/indsnetwork.jl:51
[3] (IndsNetwork{Int64})(::Type{DataGraphs.IsUnderlyingGraph{SimpleGraph{Int64}}}, g::SimpleGraph{Int64}, link_space::Int64, site_space::Vector{Index{Int64}})
@ ITensorNetworks ~/.julia/packages/ITensorNetworks/REB7V/src/indsnetwork.jl:56
[4] (IndsNetwork{Int64})(g::SimpleGraph{Int64}, link_space::Int64, site_space::Vector{Index{Int64}})
@ ITensorNetworks ~/.julia/packages/SimpleTraits/l1ZsK/src/SimpleTraits.jl:331
[5] top-level scope
@ REPL[40]:1
which both should do the same as this one that is working:
julia> IndsNetwork{Int}(path_graph(3), 2, Dictionary(1:3, siteinds("S=1/2", 3)))
IndsNetwork{Int64, Index{Int64}} with 3 vertices:
3-element Vector{Int64}:
1
2
3
and 2 edge(s):
1 => 2
2 => 3
with vertex data:
3-element Dictionary{Int64, Vector{Index{Int64}}}
1 │ Index{Int64}[(dim=2|id=795|"S=1/2,Site,n=1")]
2 │ Index{Int64}[(dim=2|id=27|"S=1/2,Site,n=2")]
3 │ Index{Int64}[(dim=2|id=844|"S=1/2,Site,n=3")]
and edge data:
2-element Dictionary{NamedGraphs.NamedEdge{Int64}, Vector{Index{Int64}}}
1 => 2 │ Index{Int64}[(dim=2|id=923|"1↔2")]
2 => 3 │ Index{Int64}[(dim=2|id=789|"2↔3")]