ITensor / ITensor/ITensorNetworks.jl

More convenient `IndsNetwork` constructors

Open
#86 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
128
Forks
23
Avg merge
4d 7h
Merged PRs (30d)
7

Description

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")]

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the constructor examples in the issue, then read src/indsnetwork.jl around the constructors reported at lines 44, 51, 61, 132, and 136. Compare the working dictionary-based form with the failing vector and keyword forms. Done means the shown IndsNetwork construction variants work consistently without the reported MethodError or UndefVarError.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.