Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize #192

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ec7ec3b
New BP alternating update
JoeyT1994 May 6, 2024
bd05519
Working BP DMRG Solver
JoeyT1994 May 9, 2024
e116388
Merge remote-tracking branch 'upstream/main' into bp_alternating_update
JoeyT1994 May 9, 2024
cd2b139
New Changes
JoeyT1994 May 14, 2024
6391bfa
Merge remote-tracking branch 'upstream/main' into bp_alternating_update
JoeyT1994 May 14, 2024
fa91e7c
Merge remote-tracking branch 'upstream/main' into bp_alternating_update
JoeyT1994 May 15, 2024
201882a
Small changes
JoeyT1994 May 16, 2024
7228fb5
Changes
JoeyT1994 May 31, 2024
75d0c3b
Utils additions
JoeyT1994 May 31, 2024
c90139b
More stuff
JoeyT1994 Jun 2, 2024
e87e1b3
Big Improvements
JoeyT1994 Jun 7, 2024
8d780a8
Refactor code
JoeyT1994 Jun 7, 2024
e62ae0f
Save stuff
JoeyT1994 Jun 11, 2024
371492d
Commit 1
JoeyT1994 Jun 12, 2024
5138e51
Changes
JoeyT1994 Jun 12, 2024
275191a
Changes
JoeyT1994 Jun 12, 2024
194fba3
working implementation
JoeyT1994 Jun 12, 2024
50369c1
working implementation
JoeyT1994 Jun 12, 2024
0e5e5d8
Remove old changes
JoeyT1994 Jun 12, 2024
4bc0183
Revert
JoeyT1994 Jun 12, 2024
9e14f14
Revert
JoeyT1994 Jun 12, 2024
0a7355e
Revert
JoeyT1994 Jun 12, 2024
b07b978
Revert
JoeyT1994 Jun 12, 2024
440c267
Revert
JoeyT1994 Jun 12, 2024
ed7befa
Remove files
JoeyT1994 Jun 12, 2024
322dca4
Revert
JoeyT1994 Jun 12, 2024
54f41c0
Revert
JoeyT1994 Jun 12, 2024
dc0e132
Revert
JoeyT1994 Jun 12, 2024
2af3984
revert
JoeyT1994 Jun 12, 2024
30786bc
Working version
JoeyT1994 Jun 14, 2024
f0d4fc8
Merge branch 'ITensor:main' into bp_dmrg_alt_method
JoeyT1994 Jun 14, 2024
ed5037e
Improvements
JoeyT1994 Jun 14, 2024
e61e58c
Merge remote-tracking branch 'upstream/main' into bp_dmrg_alt_method
JoeyT1994 Jun 14, 2024
6998077
merge
JoeyT1994 Jun 14, 2024
511e09f
Merge branch 'bp_dmrg_alt_method' of github.com:JoeyT1994/ITensorNetw…
JoeyT1994 Jun 14, 2024
ed0c069
Improvements
JoeyT1994 Jun 14, 2024
553a983
Simplify
JoeyT1994 Jun 15, 2024
005b0e5
Change
JoeyT1994 Jun 16, 2024
af68e63
Working first commit
JoeyT1994 Jun 16, 2024
0704609
Revert some files
JoeyT1994 Jun 16, 2024
e1344f0
Revert expect
JoeyT1994 Jun 16, 2024
66319b0
Revert some changes
JoeyT1994 Jun 16, 2024
b098d44
Update src/caches/beliefpropagationcache.jl
JoeyT1994 Jun 16, 2024
b296277
Update src/caches/beliefpropagationcache.jl
JoeyT1994 Jun 16, 2024
1c87d22
Update src/normalize.jl
JoeyT1994 Jun 16, 2024
f88b21c
Merge remote-tracking branch 'upstream/main' into normalize!
JoeyT1994 Jun 26, 2024
6a8d4b9
Renormalize messages against themselves first
JoeyT1994 Jun 26, 2024
c845947
Blah
JoeyT1994 Sep 13, 2024
90c7251
Merge remote-tracking branch 'origin/main'
JoeyT1994 Oct 17, 2024
86f3087
Merge remote-tracking branch 'upstream/main'
JoeyT1994 Oct 17, 2024
6ff0cd5
Bug fix in current ortho. Change test
JoeyT1994 Oct 17, 2024
34e8e5e
Merge remote-tracking branch 'upstream/main'
JoeyT1994 Nov 22, 2024
d096722
Fix bug
JoeyT1994 Nov 26, 2024
70a3f7e
Merge remote-tracking branch 'upstream/main'
JoeyT1994 Dec 5, 2024
2cb7f85
Refactor and bring down upstream changes
JoeyT1994 Dec 10, 2024
73e9e1e
Merge remote-tracking branch 'origin/main' into normalize!
JoeyT1994 Dec 10, 2024
4f4e2e5
Remove erroneous file
JoeyT1994 Dec 10, 2024
620da37
Allow rescaling flat networks with bp
JoeyT1994 Dec 10, 2024
180183e
Make generic to other algorithms
JoeyT1994 Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor and bring down upstream changes
  • Loading branch information
JoeyT1994 committed Dec 10, 2024
commit 2cb7f853c6b89f15d84590149031c445e299b37d
14 changes: 9 additions & 5 deletions src/caches/beliefpropagationcache.jl
Original file line number Diff line number Diff line change
@@ -326,11 +326,15 @@ function normalize_messages(bp_cache::BeliefPropagationCache, pes::Vector{<:Part
mts = messages(bp_cache)
for pe in pes
me, mer = only(mts[pe]), only(mts[reverse(pe)])
JoeyT1994 marked this conversation as resolved.
Show resolved Hide resolved
set!(mts, pe, ITensor[me / norm(me)])
set!(mts, reverse(pe), ITensor[mer / norm(mer)])
n = region_scalar(bp_cache, pe)
set!(mts, pe, ITensor[(1 / sqrt(n)) * me])
set!(mts, reverse(pe), ITensor[(1 / sqrt(n)) * mer])
me, mer = normalize(me), normalize(mer)
n = dot(me, mer)
if isreal(n) && n < 0
set!(mts, pe, ITensor[(sgn(n) / sqrt(abs(n))) * me])
set!(mts, reverse(pe), ITensor[(1 / sqrt(abs(n))) * mer])
else
set!(mts, pe, ITensor[(1 / sqrt(n)) * me])
set!(mts, reverse(pe), ITensor[(1 / sqrt(n)) * mer])
end
end
return bp_cache
end
33 changes: 15 additions & 18 deletions src/normalize.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
using LinearAlgebra

function rescale(tn::AbstractITensorNetwork, c::Number, vs=collect(vertices(tn)))
tn = copy(tn)
for v in vs
tn[v] *= c
end
return tn
end

function LinearAlgebra.normalize(tn::AbstractITensorNetwork; alg="exact", kwargs...)
return normalize(Algorithm(alg), tn; kwargs...)
end

function LinearAlgebra.normalize(alg::Algorithm"exact", tn::AbstractITensorNetwork)
norm_tn = norm_sqr_network(tn)
log_norm = logscalar(alg, norm_tn)
tn = copy(tn)
L = length(vertices(tn))
c = exp(log_norm / L)
for v in vertices(tn)
tn[v] = tn[v] / sqrt(c)
end
return tn
norm_tn = QuadraticFormNetwork(tn)
c = exp(logscalar(alg, norm_tn) / (2 * length(vertices(tn))))
return rescale(tn, 1 / c)
end

function LinearAlgebra.normalize(
@@ -40,17 +42,12 @@ function LinearAlgebra.normalize(
v_ket, v_bra = ket_vertex(norm_tn, v), bra_vertex(norm_tn, v)
pv = only(partitionvertices(cache![], [v_ket]))
vn = region_scalar(cache![], pv)
state = tn[v] / sqrt(vn)
state_dag = copy(dag(state))
state_dag = replaceinds(
state_dag, inds(state_dag), dual_index_map(norm_tn).(inds(state_dag))
)
set!(vertices_states, v_ket, state)
set!(vertices_states, v_bra, state_dag)
tn[v] = state
norm_tn = rescale(norm_tn, 1 / sqrt(vn), [v_ket, v_bra])
set!(vertices_states, v_ket, norm_tn[v_ket])
set!(vertices_states, v_bra, norm_tn[v_bra])
end

cache![] = update_factors(cache![], vertices_states)

return tn
return ket_network(norm_tn)
end