Skip to content

Commit 11e1c83

Browse files
authored
Preserve message type upon use of rescale (#254)
1 parent 5bc9888 commit 11e1c83

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
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.14.0"
4+
version = "0.14.1"
55

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

src/caches/abstractbeliefpropagationcache.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ function rescale_partitions(
382382
isempty(pv_vs) && continue
383383

384384
vn = region_scalar(bpc, pv)
385-
s = isreal(vn) ? sign(vn) : 1.0
386-
vn = s * inv(vn^(1 / length(pv_vs)))
385+
s = isreal(vn) ? sign(vn) : one(vn)
386+
vn = s * vn^(-inv(oftype(vn, length(pv_vs))))
387387
set!(vertices_weights, first(pv_vs), s*vn)
388388
for v in pv_vs[2:length(pv_vs)]
389389
set!(vertices_weights, v, vn)

src/caches/beliefpropagationcache.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function rescale_messages(bp_cache::BeliefPropagationCache, pes::Vector{<:Partit
141141
n *= sign(n)
142142
end
143143

144-
sf = (1 / sqrt(n)) ^ (1 / length(me))
144+
sf = inv(sqrt(n)) ^ inv(oftype(n, length(me)))
145145
set!(mts, pe, sf .* me)
146146
set!(mts, reverse(pe), sf .* mer)
147147
end

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Glob = "1.3.1"
4444
Graphs = "1.12.0"
4545
GraphsFlows = "0.1.1"
4646
ITensorMPS = "0.3.6"
47-
ITensorNetworks = "0.14.0"
47+
ITensorNetworks = "0.14.1"
4848
ITensors = "0.7, 0.8, 0.9"
4949
KrylovKit = "0.8, 0.9, 0.10"
5050
LinearAlgebra = "1.10.0"

test/test_normalize.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ using ITensorNetworks:
44
QuadraticFormNetwork,
55
edge_scalars,
66
norm_sqr_network,
7+
messages,
78
random_tensornetwork,
9+
scalartype,
810
siteinds,
911
vertex_scalars,
1012
rescale
@@ -39,7 +41,7 @@ using Test: @test, @testset
3941

4042
g = named_grid((Lx, Ly))
4143
s = siteinds("S=1/2", g)
42-
x = random_tensornetwork(rng, s; link_space=χ)
44+
x = random_tensornetwork(rng, ComplexF32, s; link_space=χ)
4345

4446
ψ = normalize(x; alg="exact")
4547
@test scalar(norm_sqr_network(ψ); alg="exact") 1.0
@@ -49,6 +51,7 @@ using Test: @test, @testset
4951
x; alg="bp", (cache!)=ψIψ_bpc, update_cache=true, cache_update_kwargs=(; maxiter=20)
5052
)
5153
ψIψ_bpc = ψIψ_bpc[]
54+
@test all(m -> scalartype(only(m)) == ComplexF32, messages(ψIψ_bpc))
5255
@test all(x -> x 1.0, edge_scalars(ψIψ_bpc))
5356
@test all(x -> x 1.0, vertex_scalars(ψIψ_bpc))
5457
@test scalar(QuadraticFormNetwork(ψ); alg="bp", cache_update_kwargs=(; maxiter=20)) 1.0

0 commit comments

Comments
 (0)