Skip to content

Commit 4394909

Browse files
committed
Merge remote-tracking branch 'upstream/main' into TensorNetworkFitting
2 parents 17ccf85 + 5641d32 commit 4394909

File tree

6 files changed

+47
-9
lines changed

6 files changed

+47
-9
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ repos:
1212
exclude_types: [markdown] # incompatible with Literate.jl
1313

1414
- repo: "https://github.com/domluna/JuliaFormatter.jl"
15-
rev: v2.1.1
15+
rev: v2.1.2
1616
hooks:
1717
- id: "julia-formatter"

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: 2 additions & 1 deletion
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,6 +49,7 @@ 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+
#These tests were leading to CI issues that need to be investigated
5253
# seq_einexprs_kahypar = contraction_sequence(tn; alg="einexpr", optimizer=HyPar())
5354
# res_einexprs_kahypar = contract(tn; sequence=seq_einexprs_kahypar)[]
5455
# @test res_einexprs_kahypar ≈ res_optimal

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)