-
Notifications
You must be signed in to change notification settings - Fork 19
Normalize #192
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
Merged
Merged
Normalize #192
Changes from all commits
Commits
Show all changes
101 commits
Select commit
Hold shift + click to select a range
ec7ec3b
New BP alternating update
JoeyT1994 bd05519
Working BP DMRG Solver
JoeyT1994 e116388
Merge remote-tracking branch 'upstream/main' into bp_alternating_update
JoeyT1994 cd2b139
New Changes
JoeyT1994 6391bfa
Merge remote-tracking branch 'upstream/main' into bp_alternating_update
JoeyT1994 fa91e7c
Merge remote-tracking branch 'upstream/main' into bp_alternating_update
JoeyT1994 201882a
Small changes
JoeyT1994 7228fb5
Changes
JoeyT1994 75d0c3b
Utils additions
JoeyT1994 c90139b
More stuff
JoeyT1994 e87e1b3
Big Improvements
JoeyT1994 8d780a8
Refactor code
JoeyT1994 e62ae0f
Save stuff
JoeyT1994 371492d
Commit 1
JoeyT1994 5138e51
Changes
JoeyT1994 275191a
Changes
JoeyT1994 194fba3
working implementation
JoeyT1994 50369c1
working implementation
JoeyT1994 0e5e5d8
Remove old changes
JoeyT1994 4bc0183
Revert
JoeyT1994 9e14f14
Revert
JoeyT1994 0a7355e
Revert
JoeyT1994 b07b978
Revert
JoeyT1994 440c267
Revert
JoeyT1994 ed7befa
Remove files
JoeyT1994 322dca4
Revert
JoeyT1994 54f41c0
Revert
JoeyT1994 dc0e132
Revert
JoeyT1994 2af3984
revert
JoeyT1994 30786bc
Working version
JoeyT1994 f0d4fc8
Merge branch 'ITensor:main' into bp_dmrg_alt_method
JoeyT1994 ed5037e
Improvements
JoeyT1994 e61e58c
Merge remote-tracking branch 'upstream/main' into bp_dmrg_alt_method
JoeyT1994 6998077
merge
JoeyT1994 511e09f
Merge branch 'bp_dmrg_alt_method' of github.com:JoeyT1994/ITensorNetw…
JoeyT1994 ed0c069
Improvements
JoeyT1994 553a983
Simplify
JoeyT1994 005b0e5
Change
JoeyT1994 af68e63
Working first commit
JoeyT1994 0704609
Revert some files
JoeyT1994 e1344f0
Revert expect
JoeyT1994 66319b0
Revert some changes
JoeyT1994 b098d44
Update src/caches/beliefpropagationcache.jl
JoeyT1994 b296277
Update src/caches/beliefpropagationcache.jl
JoeyT1994 1c87d22
Update src/normalize.jl
JoeyT1994 f88b21c
Merge remote-tracking branch 'upstream/main' into normalize!
JoeyT1994 6a8d4b9
Renormalize messages against themselves first
JoeyT1994 c845947
Blah
JoeyT1994 90c7251
Merge remote-tracking branch 'origin/main'
JoeyT1994 86f3087
Merge remote-tracking branch 'upstream/main'
JoeyT1994 6ff0cd5
Bug fix in current ortho. Change test
JoeyT1994 34e8e5e
Merge remote-tracking branch 'upstream/main'
JoeyT1994 d096722
Fix bug
JoeyT1994 70a3f7e
Merge remote-tracking branch 'upstream/main'
JoeyT1994 2cb7f85
Refactor and bring down upstream changes
JoeyT1994 73e9e1e
Merge remote-tracking branch 'origin/main' into normalize!
JoeyT1994 4f4e2e5
Remove erroneous file
JoeyT1994 620da37
Allow rescaling flat networks with bp
JoeyT1994 180183e
Make generic to other algorithms
JoeyT1994 9d64fe8
Merge remote-tracking branch 'upstream/main'
JoeyT1994 9d6c1bc
File removed
JoeyT1994 ae17245
Merge remote-tracking branch 'upstream/main'
JoeyT1994 b648353
Merge remote-tracking branch 'upstream/main'
JoeyT1994 4e7d189
Merge remote-tracking branch 'upstream/main'
JoeyT1994 83c92b0
Merge remote-tracking branch 'upstream/main'
JoeyT1994 6f024ee
Merge remote-tracking branch 'upstream/main'
JoeyT1994 1106403
Merge remote-tracking branch 'upstream/main'
JoeyT1994 bc7c238
Merge
JoeyT1994 22e7dbb
Improvements
JoeyT1994 e057da0
Merge remote-tracking branch 'upstream/main' into normalize!
JoeyT1994 dea3b6c
Version update
JoeyT1994 4fa8d92
Update src/caches/abstractbeliefpropagationcache.jl
JoeyT1994 153d205
Update src/normalize.jl
JoeyT1994 f7c8733
Formatting. Delete contraction_sequence_to_graph code
JoeyT1994 da56c33
Rescale local tensors first
JoeyT1994 1f9ec52
Use RegionScalar not dot
JoeyT1994 ed605cd
Contraction sequence test
JoeyT1994 6c528df
Comment out more
JoeyT1994 e6c0a21
Better default cache construction in expect
JoeyT1994 05d2e73
Rename vs_to_rescale -> verts_to_rescale
JoeyT1994 40f9228
Remove vs to rescale from exact function
JoeyT1994 00cc700
Revert commit
JoeyT1994 e6b753e
Remove EinExprs Tests
JoeyT1994 d35d812
Rescale message -> rescale messages
JoeyT1994 92d8243
All but HyPar for EinExprs tests
JoeyT1994 29ff795
Update src/caches/abstractbeliefpropagationcache.jl
JoeyT1994 f4c6952
Fix imports on contraction seq test
JoeyT1994 026e500
Merge branch 'normalize!' of github.com:JoeyT1994/ITensorNetworks.jl …
JoeyT1994 2df7e92
Formatting
JoeyT1994 17ccf85
Centre around scaling function
JoeyT1994 5641d32
Merge remote-tracking branch 'upstream/main'
JoeyT1994 4394909
Merge remote-tracking branch 'upstream/main' into TensorNetworkFitting
JoeyT1994 2141045
Improvements
JoeyT1994 0abc928
Fix small bilinaer form constructor bug for QNs
JoeyT1994 77b7bf1
Revert change
JoeyT1994 15b9c9d
Bug fix
JoeyT1994 f824905
verts -> vertices
JoeyT1994 e7e6134
Update version
JoeyT1994 1bb92fd
Define in terms of a map_vertices_function
JoeyT1994 1634aef
Update src/abstractitensornetwork.jl
JoeyT1994 e7a0182
Restore map_vertex_data
JoeyT1994 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "ITensorNetworks" | ||
uuid = "2919e153-833c-4bdc-8836-1ea460a35fc7" | ||
authors = ["Matthew Fishman <[email protected]>, Joseph Tindall <[email protected]> and contributors"] | ||
version = "0.13.6" | ||
version = "0.13.7" | ||
|
||
[deps] | ||
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using LinearAlgebra: normalize | ||
|
||
function rescale(tn::AbstractITensorNetwork; alg="exact", kwargs...) | ||
JoeyT1994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return rescale(Algorithm(alg), tn; kwargs...) | ||
end | ||
|
||
function rescale(alg::Algorithm"exact", tn::AbstractITensorNetwork; kwargs...) | ||
logn = logscalar(alg, tn; kwargs...) | ||
vs = collect(vertices(tn)) | ||
c = inv(exp(logn / length(vs))) | ||
vertices_weights = Dictionary(vs, [c for v in vs]) | ||
return scale(tn, vertices_weights) | ||
end | ||
|
||
function rescale( | ||
alg::Algorithm, | ||
tn::AbstractITensorNetwork, | ||
args...; | ||
(cache!)=nothing, | ||
cache_construction_kwargs=default_cache_construction_kwargs(alg, tn), | ||
update_cache=isnothing(cache!), | ||
cache_update_kwargs=default_cache_update_kwargs(alg), | ||
kwargs..., | ||
) | ||
if isnothing(cache!) | ||
cache! = Ref(cache(alg, tn; cache_construction_kwargs...)) | ||
end | ||
|
||
if update_cache | ||
cache![] = update(cache![]; cache_update_kwargs...) | ||
end | ||
|
||
cache![] = rescale(cache![], args...; kwargs...) | ||
|
||
return tensornetwork(cache![]) | ||
end | ||
|
||
function LinearAlgebra.normalize(tn::AbstractITensorNetwork; alg="exact", kwargs...) | ||
return normalize(Algorithm(alg), tn; kwargs...) | ||
end | ||
|
||
function LinearAlgebra.normalize( | ||
alg::Algorithm"exact", tn::AbstractITensorNetwork; kwargs... | ||
) | ||
logn = logscalar(alg, inner_network(tn, tn); kwargs...) | ||
vs = collect(vertices(tn)) | ||
c = inv(exp(logn / (2*length(vs)))) | ||
vertices_weights = Dictionary(vs, [c for v in vs]) | ||
return scale(tn, vertices_weights) | ||
end | ||
|
||
function LinearAlgebra.normalize( | ||
alg::Algorithm, | ||
tn::AbstractITensorNetwork; | ||
(cache!)=nothing, | ||
cache_construction_function=tn -> | ||
cache(alg, tn; default_cache_construction_kwargs(alg, tn)...), | ||
update_cache=isnothing(cache!), | ||
cache_update_kwargs=default_cache_update_kwargs(alg), | ||
cache_construction_kwargs=(;), | ||
) | ||
norm_tn = inner_network(tn, tn) | ||
if isnothing(cache!) | ||
cache! = Ref(cache(alg, norm_tn; cache_construction_kwargs...)) | ||
end | ||
|
||
vs = collect(vertices(tn)) | ||
verts = vcat([ket_vertex(norm_tn, v) for v in vs], [bra_vertex(norm_tn, v) for v in vs]) | ||
norm_tn = rescale(alg, norm_tn; verts, cache!, update_cache, cache_update_kwargs) | ||
|
||
return ket_network(norm_tn) | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@eval module $(gensym()) | ||
using ITensorNetworks: | ||
BeliefPropagationCache, | ||
QuadraticFormNetwork, | ||
edge_scalars, | ||
norm_sqr_network, | ||
random_tensornetwork, | ||
siteinds, | ||
vertex_scalars, | ||
rescale | ||
using ITensors: dag, inner, scalar | ||
using Graphs: SimpleGraph, uniform_tree | ||
using LinearAlgebra: normalize | ||
using NamedGraphs: NamedGraph | ||
using NamedGraphs.NamedGraphGenerators: named_grid, named_comb_tree | ||
using StableRNGs: StableRNG | ||
using TensorOperations: TensorOperations | ||
using Test: @test, @testset | ||
@testset "Normalize" begin | ||
|
||
#First lets do a flat tree | ||
nx, ny = 2, 3 | ||
χ = 2 | ||
rng = StableRNG(1234) | ||
|
||
g = named_comb_tree((nx, ny)) | ||
tn = random_tensornetwork(rng, g; link_space=χ) | ||
|
||
tn_r = rescale(tn; alg="exact") | ||
@test scalar(tn_r; alg="exact") ≈ 1.0 | ||
|
||
tn_r = rescale(tn; alg="bp") | ||
@test scalar(tn_r; alg="exact") ≈ 1.0 | ||
|
||
#Now a state on a loopy graph | ||
Lx, Ly = 3, 2 | ||
χ = 2 | ||
rng = StableRNG(1234) | ||
|
||
g = named_grid((Lx, Ly)) | ||
s = siteinds("S=1/2", g) | ||
x = random_tensornetwork(rng, s; link_space=χ) | ||
|
||
ψ = normalize(x; alg="exact") | ||
@test scalar(norm_sqr_network(ψ); alg="exact") ≈ 1.0 | ||
|
||
ψIψ_bpc = Ref(BeliefPropagationCache(QuadraticFormNetwork(x))) | ||
ψ = normalize(x; alg="bp", (cache!)=ψIψ_bpc, update_cache=true) | ||
ψIψ_bpc = ψIψ_bpc[] | ||
@test all(x -> x ≈ 1.0, edge_scalars(ψIψ_bpc)) | ||
@test all(x -> x ≈ 1.0, vertex_scalars(ψIψ_bpc)) | ||
@test scalar(QuadraticFormNetwork(ψ); alg="bp") ≈ 1.0 | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.