Skip to content

Commit 82f5652

Browse files
JoeyT1994mtfishman
andauthored
Improve the BilinearForm Constructor (#234)
Co-authored-by: Matt Fishman <[email protected]>
1 parent 51264e2 commit 82f5652

9 files changed

+50
-143
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensorNetworks"
22
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7"
33
authors = ["Matthew Fishman <[email protected]>, Joseph Tindall <[email protected]> and contributors"]
4-
version = "0.13.5"
4+
version = "0.13.6"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/ITensorNetworks.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ include("formnetworks/abstractformnetwork.jl")
3131
include("formnetworks/bilinearformnetwork.jl")
3232
include("formnetworks/linearformnetwork.jl")
3333
include("formnetworks/quadraticformnetwork.jl")
34-
include("contraction_tree_to_graph.jl")
3534
include("gauging.jl")
3635
include("utils.jl")
3736
include("update_observer.jl")

src/contraction_tree_to_graph.jl

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/formnetworks/bilinearformnetwork.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ function Base.copy(blf::BilinearFormNetwork)
5252
)
5353
end
5454

55+
function itensor_identity_map(i_pairs::Vector)
56+
return prod(i_pairs; init=ITensor(one(Bool))) do i_pair
57+
return delta(Bool, dag(first(i_pair)), last(i_pair))
58+
end
59+
end
60+
5561
function BilinearFormNetwork(
5662
bra::AbstractITensorNetwork,
5763
ket::AbstractITensorNetwork;
@@ -60,9 +66,13 @@ function BilinearFormNetwork(
6066
)
6167
@assert issetequal(flatten_siteinds(bra), flatten_siteinds(ket))
6268
link_space = isempty(flatten_siteinds(bra)) ? 1 : nothing
63-
operator_inds = union_all_inds(siteinds(ket), dual_site_index_map(siteinds(ket)))
64-
# TODO: Define and use `identity_network` here.
65-
O = ITensorNetwork(Op("I"), operator_inds; link_space)
69+
s = siteinds(ket)
70+
s_mapped = dual_site_index_map(s)
71+
operator_inds = union_all_inds(s, s_mapped)
72+
73+
O = ITensorNetwork(operator_inds; link_space) do v
74+
return inds -> itensor_identity_map(s[v] .=> s_mapped[v])
75+
end
6676
return BilinearFormNetwork(O, bra, ket; dual_site_index_map, kwargs...)
6777
end
6878

src/gauging.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ function VidalITensorNetwork(
134134
if isnothing(cache!)
135135
cache! = Ref(default_norm_cache(ψ))
136136
end
137-
cache![] = update(cache![]; cache_update_kwargs...)
137+
138+
if update_cache
139+
cache![] = update(cache![]; cache_update_kwargs...)
140+
end
141+
138142
return vidalitensornetwork_preserve_cache(ψ; cache=cache![], kwargs...)
139143
end
140144

test/test_contraction_sequence.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@eval module $(gensym())
2-
using EinExprs: Exhaustive, Greedy, HyPar
2+
using EinExprs: Exhaustive, Greedy
33
using ITensorNetworks:
44
contraction_sequence, norm_sqr_network, random_tensornetwork, siteinds
55
using ITensors: ITensors, contract
@@ -49,9 +49,10 @@ using Test: @test, @testset
4949
Pkg.rm("KaHyPar"; io=devnull)
5050
res_kahypar_bipartite = contract(tn; sequence=seq_kahypar_bipartite)[]
5151
@test res_optimal res_kahypar_bipartite
52-
seq_einexprs_kahypar = contraction_sequence(tn; alg="einexpr", optimizer=HyPar())
53-
res_einexprs_kahypar = contract(tn; sequence=seq_einexprs_kahypar)[]
54-
@test res_einexprs_kahypar res_optimal
52+
#These tests were leading to CI issues that need to be investigated
53+
# seq_einexprs_kahypar = contraction_sequence(tn; alg="einexpr", optimizer=HyPar())
54+
# res_einexprs_kahypar = contract(tn; sequence=seq_einexprs_kahypar)[]
55+
# @test res_einexprs_kahypar ≈ res_optimal
5556
end
5657
end
5758
end

test/test_contraction_sequence_to_graph.jl

Lines changed: 0 additions & 48 deletions
This file was deleted.

test/test_expect.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ using Test: @test, @testset
4040
sz_exact = expect(ψ, "Sz"; alg="exact")
4141
@test sz_bp sz_exact
4242

43-
#Test with QNS, product state so should be immediately exact
43+
#Test with Quantum Numbers, product state so BP should be exact
4444
L, χ = 2, 2
4545
g = named_grid((L, L))
4646
s = siteinds("S=1/2", g; conserve_qns=true)
47+
4748
ψ = ITensorNetwork(v -> isodd(sum(v)) ? "" : "", s)
4849

4950
sz_bp = expect(ψ, "Sz"; alg="bp")

test/test_forms.jl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@eval module $(gensym())
22
using DataGraphs: underlying_graph
33
using Graphs: nv
4-
using NamedGraphs.NamedGraphGenerators: named_grid
4+
using NamedGraphs.NamedGraphGenerators: named_comb_tree, named_grid
55
using ITensorNetworks:
66
BeliefPropagationCache,
77
BilinearFormNetwork,
@@ -12,16 +12,18 @@ using ITensorNetworks:
1212
dual_index_map,
1313
environment,
1414
flatten_siteinds,
15+
inner,
1516
ket_network,
1617
ket_vertex,
1718
operator_network,
1819
random_tensornetwork,
20+
scalar,
1921
siteinds,
2022
state_vertices,
2123
tensornetwork,
2224
union_all_inds,
2325
update
24-
using ITensors: contract, dag, inds, prime, random_itensor
26+
using ITensors: Index, contract, dag, inds, prime, random_itensor, sim
2527
using LinearAlgebra: norm
2628
using StableRNGs: StableRNG
2729
using TensorOperations: TensorOperations
@@ -84,5 +86,25 @@ using Test: @test, @testset
8486
∂qf_∂v_bp = contract(∂qf_∂v_bp)
8587
∂qf_∂v_bp /= norm(∂qf_∂v_bp)
8688
@test ∂qf_∂v_bp ∂qf_∂v
89+
90+
#Test having non-uniform number of site indices per vertex
91+
g = named_comb_tree((3, 3))
92+
s = siteinds("S=1/2", g)
93+
s = union_all_inds(s, sim(s))
94+
s[(1, 1)] = Index[]
95+
s[(3, 3)] = Index[first(s[(3, 3)])]
96+
χ = 2
97+
rng = StableRNG(1234)
98+
ψket = random_tensornetwork(rng, ComplexF64, s; link_space=χ)
99+
ψbra = random_tensornetwork(rng, ComplexF64, s; link_space=χ)
100+
101+
blf = BilinearFormNetwork(ψbra, ψket)
102+
@test scalar(blf; alg="exact") inner(ψbra, ψket; alg="exact")
103+
104+
lf = LinearFormNetwork(ψbra, ψket)
105+
@test scalar(lf; alg="exact") inner(ψbra, ψket; alg="exact")
106+
107+
qf = QuadraticFormNetwork(ψket)
108+
@test scalar(qf; alg="exact") inner(ψket, ψket; alg="exact")
87109
end
88110
end

0 commit comments

Comments
 (0)