We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1bd3e44 commit 4efceb8Copy full SHA for 4efceb8
Project.toml
@@ -1,7 +1,7 @@
1
name = "ITensorNetworks"
2
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
3
authors = ["Matthew Fishman <[email protected]>, Joseph Tindall <[email protected]> and contributors"]
4
-version = "0.11.11"
+version = "0.11.12"
5
6
[deps]
7
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
src/sitetype.jl
@@ -11,18 +11,25 @@ function ITensors.siteind(d::Integer, v; addtags="", kwargs...)
11
return ITensors.addtags(Index(d; tags="Site, $addtags", kwargs...), vertex_tag(v))
12
end
13
14
-function ITensors.siteinds(sitetypes::AbstractDictionary, g::AbstractGraph; kwargs...)
15
- is = IndsNetwork(g)
16
- for v in vertices(g)
17
- is[v] = [siteind(sitetypes[v], vertex_tag(v); kwargs...)]
18
- end
19
- return is
+to_siteinds_callable(x) = Returns(x)
+function to_siteinds_callable(x::AbstractDictionary)
+ return Base.Fix1(getindex, x) ∘ keytype(x)
+end
+
+function ITensors.siteinds(x, g::AbstractGraph; kwargs...)
20
+ return siteinds(to_siteinds_callable(x), g; kwargs...)
21
22
-function ITensors.siteinds(sitetype, g::AbstractGraph; kwargs...)
23
- return siteinds(Dictionary(vertices(g), fill(sitetype, nv(g))), g; kwargs...)
+function to_siteind(x, vertex; kwargs...)
24
+ return [siteind(x, vertex_tag(vertex); kwargs...)]
25
26
27
+to_siteind(x::Index, vertex; kwargs...) = [x]
28
29
function ITensors.siteinds(f::Function, g::AbstractGraph; kwargs...)
- return siteinds(Dictionary(vertices(g), map(v -> f(v), vertices(g))), g; kwargs...)
30
+ is = IndsNetwork(g)
31
+ for v in vertices(g)
32
+ is[v] = to_siteind(f(v), v; kwargs...)
33
+ end
34
+ return is
35
test/test_sitetype.jl
@@ -3,7 +3,7 @@ using DataGraphs: vertex_data
using Dictionaries: Dictionary
using Graphs: nv, vertices
using ITensorNetworks: IndsNetwork, siteinds
-using ITensors: SiteType, hastags, space
+using ITensors: Index, SiteType, hastags, space
using ITensors.NDTensors: dim
8
using NamedGraphs.NamedGraphGenerators: named_grid
9
using Test: @test, @testset
@@ -18,6 +18,16 @@ using Test: @test, @testset
fdim(v::Tuple) = space(SiteType(ftype(v)))
testtag = "TestTag"
+ d1 = map(v -> Index(2), vertices(g))
+ d2 = map(v -> "S=1/2", vertices(g))
+ for x in (v -> d1[v], d1, v -> d2[v], d2)
+ s = siteinds(x, g)
+ @test s[1, 1] isa Vector{<:Index}
+ @test s[1, 2] isa Vector{<:Index}
+ @test s[2, 1] isa Vector{<:Index}
+ @test s[2, 2] isa Vector{<:Index}
# uniform string sitetype
s_us = siteinds(sitetypes[1], g; addtags=testtag)
@test s_us isa IndsNetwork
0 commit comments