-
Notifications
You must be signed in to change notification settings - Fork 15
Cluster expansions #47
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
Open
gsommers
wants to merge
45
commits into
JoeyT1994:main
Choose a base branch
from
gsommers:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
9ad09bf
local version PEPO
gsommers 27229fa
minor changes test
gsommers dd56cb2
split main() into many functions, added bp
gsommers 09db0c6
expect_bmps
gsommers 56db073
fixed typo expect_bmps
gsommers 14bb36e
adding print statements
gsommers 8ae6305
added time checks, use_gpu for expect_bmps
gsommers 1f44ba2
fixed small bugs
gsommers 9b3c8d0
merged from big fork
gsommers 8576d83
Project.toml
gsommers 06469eb
merge main
gsommers 29634a8
PEPO_2d_ising no more ITensorNetworks
gsommers 1608c31
fixed dependencies in PEPO_2d_ising.jl
gsommers 5a43d66
fixed another bug
gsommers bf71a37
merged from local
gsommers 7dfad00
cluster folder
gsommers bcc34b7
started implementing expect-corrected
gsommers bf30dee
fixed typos in compatibility
gsommers bec5ebf
joey's version
gsommers aa7fdcb
gpu for bp
gsommers 5a30bb9
time evolution kicked Ising
gsommers 2c99aa0
linkdim is now virtualdim
gsommers dd68ee8
update Project, add error tracking
gsommers 402a5b8
use_gpu option for boundary mps
gsommers 76fe4b1
nMerge remote-tracking branch 'hpc/clusters' into clusters
gsommers 2bd6ccb
tracking BP message diffs
gsommers 48ba539
coeffs and op_strings in free_energy
gsommers ef1d623
norm_factors with kwargs
gsommers 7f73463
cluster expansions
gsommers d7dc2a0
merge from origin
gsommers 24f81e5
merged from clusters branch
gsommers 6354948
bp message diffs
gsommers 29fd0f6
merge from laptop branch
gsommers ad05ebe
added comments
gsommers 93f6283
added comments
gsommers f6c4654
removed finite temp evolution
gsommers 36b51b8
example with cluster expansions
gsommers e6bd010
cluster expansion examples
gsommers ce6c49e
removed extraneous packages from Project
gsommers 00370f5
cleaned up Project.toml
gsommers 1c2f735
changes from clusters branch
gsommers 26a1ec2
merge from clusters
gsommers 9fb5c49
cluster cumulant seems buggygit st!
gsommers 0356915
maybe fixed?
gsommers d04aefa
fixed boundary_edges
gsommers 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,9 +1,12 @@ | ||
| *.jl.*.cov | ||
| *.jl.cov | ||
| *.jl.mem | ||
| *.~ | ||
| /docs/Manifest*.toml | ||
| /docs/build/ | ||
|
|
||
| Manifest.toml | ||
| .vscode/ | ||
| .DS_Store | ||
| .DS_Store | ||
| .* | ||
| *.ipynb |
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,128 @@ | ||
| using TensorNetworkQuantumSimulator | ||
| using NamedGraphs | ||
| using NamedGraphs: AbstractNamedGraph | ||
| using Graphs | ||
|
|
||
| const G = Graphs | ||
| const NG = NamedGraphs | ||
| const TN = TensorNetworkQuantumSimulator | ||
| using HyperDualNumbers | ||
| using Adapt: adapt | ||
| using Dictionaries | ||
|
|
||
| function prep_insertions(obs) | ||
| if isnothing(obs) | ||
| return (coeffs = identity, op_strings = v->"I") | ||
| end | ||
| op_strings, verts, _ = TN.collectobservable(obs) | ||
| @assert length(verts) <= 2 | ||
|
|
||
| function hyper_coeff(v) | ||
| if v==verts[1] | ||
| return Hyper(0,1,0,0) | ||
| elseif length(verts)==2 && v==verts[2] | ||
| return Hyper(0,0,1,0) | ||
| else | ||
| return 1 | ||
| end | ||
| end | ||
|
|
||
| function insertion_operator(v) | ||
| if v==verts[1] | ||
| return op_strings[1] | ||
| elseif length(verts)==2 && v==verts[2] | ||
| return op_strings[2] | ||
| else | ||
| return "I" | ||
| end | ||
| end | ||
| return (coeffs = hyper_coeff, op_strings = insertion_operator) | ||
| end | ||
|
|
||
| """ | ||
| Cluster expansion. See clustercorrections.jl | ||
| """ | ||
| function cluster_weights(bpc::BeliefPropagationCache, clusters::Vector, egs::Vector, interaction_graph; obs = nothing) | ||
|
|
||
| kwargs = prep_insertions(obs) | ||
|
|
||
| logZbp = TN.free_energy(bpc; kwargs...) | ||
| isempty(egs) && return [0], [[logZbp]], [[1]] | ||
|
|
||
| circuit_lengths = sort(unique([c.weight for c=clusters])) | ||
|
|
||
| # Rescale the messages, but deal with the vertices separately | ||
| TN.rescale_messages!(bpc) | ||
| vns = Dictionary(TN.vertex_scalar(bpc, v; use_epsilon = true, kwargs...) for v=vertices(network(bpc).tensornetwork.graph)) | ||
|
|
||
| # calculate weight of each generalized loop first | ||
| wts = TN.weights(bpc, egs; rescales = vns, kwargs...) | ||
|
|
||
| logZs = Array{Array}(undef, length(circuit_lengths) + 1) | ||
| logZs[1] = [logZbp] | ||
|
|
||
| coeffs = Array{Array}(undef, length(circuit_lengths) + 1) | ||
| coeffs[1] = [1] | ||
|
|
||
| # now calculate contribution to logZ from each cluster | ||
| for (cl_i, cl)=enumerate(circuit_lengths) | ||
| clusters_cl = filter(c->c.weight==cl, clusters) | ||
| logZs[cl_i + 1] = [prod([prod(fill(wts[l],c.multiplicities[l])) for l=c.loop_ids]) for c=clusters_cl] | ||
| coeffs[cl_i + 1] = [TN.ursell_function(c, interaction_graph) for c=clusters_cl] | ||
| end | ||
|
|
||
| return vcat([0],circuit_lengths), logZs, coeffs | ||
| end | ||
|
|
||
| """ | ||
| Cluster cumulant expansion. See cumulant-clustercorrections.jl | ||
| """ | ||
| function cc_weights(bpc::BeliefPropagationCache, regions::Vector, counting_nums::Dict; obs = nothing, rescale::Bool = false) | ||
|
|
||
| kwargs = prep_insertions(obs) | ||
|
|
||
| use_g = findall(gg->counting_nums[gg] != 0, regions) | ||
| egs = [induced_subgraph(network(bpc).tensornetwork.graph, gg)[1] for gg=regions[use_g]] | ||
|
|
||
| isempty(egs) && return logZbp, [], [] | ||
|
|
||
| # Rescale the messages, but deal with the vertices separately | ||
| if rescale | ||
| TN.rescale_messages!(bpc) | ||
| vns = Dictionary(TN.vertex_scalar(bpc, v; use_epsilon = true, kwargs...) for v=vertices(network(bpc).tensornetwork.graph)) | ||
| else | ||
| vns = Dictionary(1 for v=vertices(network(bpc).tensornetwork.graph)) | ||
| end | ||
|
|
||
| # calculate weight of each cluster first | ||
| wts = TN.weights(bpc, egs; rescales = vns, project_out = false, kwargs...) | ||
|
|
||
| return log.(wts), [counting_nums[gg] for gg=regions[use_g]] | ||
| end | ||
|
|
||
| """ | ||
| onepoint or twopoint connected correlation function, using cluster cumulant expansion | ||
| """ | ||
| function cc_correlation(bpc::BeliefPropagationCache, regions::Vector, counting_nums::Dict, obs) | ||
| logZs, cnums = cc_weights(bpc, regions, counting_nums; obs = obs) | ||
| op_strings, verts, _ = TN.collectobservable(obs) | ||
| if length(verts)==1 | ||
| return sum(logZs .* cnums).epsilon1 | ||
| else | ||
| return sum(logZs .* cnums).epsilon12 | ||
| end | ||
| end | ||
|
|
||
| """ | ||
| onepoint or twopoint connected correlation function, using cluster expansion | ||
| """ | ||
| function cluster_correlation(bpc::BeliefPropagationCache, clusters::Vector, egs::Vector, interaction_graph, obs) | ||
| cluster_wts, logZs, ursells = cluster_weights(bpc, clusters, egs, interaction_graph; obs = obs) | ||
| op_strings, verts, _ = TN.collectobservable(obs) | ||
| cumul_dat = cumsum([sum([logZs[i][j] * ursells[i][j] for j=1:length(logZs[i])]) for i=1:length(logZs)]) | ||
| if length(verts)==1 | ||
| return cluster_wts, [d.epsilon1 for d=cumul_dat] | ||
| else | ||
| return cluster_wts, [d.epsilon12 for d=cumul_dat] | ||
| end | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| using TensorNetworkQuantumSimulator | ||
| const TN = TensorNetworkQuantumSimulator | ||
|
|
||
| using ITensors | ||
|
|
||
| using NamedGraphs | ||
| using Graphs | ||
| const NG = NamedGraphs | ||
| const G = Graphs | ||
| using NamedGraphs.NamedGraphGenerators: named_grid, named_hexagonal_lattice_graph | ||
|
|
||
| using LinearAlgebra: norm | ||
|
|
||
| using EinExprs: Greedy | ||
|
|
||
| using Random | ||
| Random.seed!(1634) | ||
|
|
||
| include("../cluster/expect-corrected.jl") | ||
|
|
||
| function main(nx,ny) | ||
| χ = 3 | ||
| ITensors.disable_warn_order() | ||
| gs = [ | ||
| (named_grid((nx, 1)), "line", 0,-1), | ||
| (named_hexagonal_lattice_graph(nx, ny), "hexagonal", 6,11), | ||
| (named_grid((nx, ny)), "square", 4,11), | ||
| ] | ||
|
|
||
| states = [] | ||
| for (g, g_str, smallest_loop_size, wmax) in gs | ||
| println("*****************************************") | ||
| println("Testing for $g_str lattice with $(NG.nv(g)) vertices") | ||
| wmax = min(wmax, NG.nv(g)) | ||
| ψ = TN.random_tensornetworkstate(ComplexF32, g, "S=1/2"; bond_dimension = χ) | ||
|
|
||
| ψ = normalize(ψ; alg = "bp") | ||
| ψIψ = BeliefPropagationCache(ψ) | ||
| ψIψ = update(ψIψ) | ||
|
|
||
| # BP expectation value | ||
| v = first(center(g)) | ||
| expect_bp = real(expect(ψIψ, ("Z", [v]))) | ||
| expect_exact_v = real(expect(ψ, ("Z", [v]); alg = "exact")) | ||
| clusters, egs, ig = TN.enumerate_clusters(g, wmax; must_contain=[v], min_deg = 1, min_v = smallest_loop_size) | ||
| cluster_wts, expects = cluster_correlation(ψIψ,clusters, egs, ig, ("Z", [v])) | ||
|
|
||
|
|
||
| regs = Dict() | ||
| cnums = Dict() | ||
|
|
||
| cc_wts = [1; smallest_loop_size:wmax;] | ||
| for w=cc_wts | ||
| regs[w],_,cnums[w]=TN.build_region_family_correlation(g,v,v,w) | ||
| end | ||
|
|
||
| expects_cc = Dict() | ||
| for w=cc_wts | ||
| expects_cc[w] = real(cc_correlation(ψIψ,regs[w], cnums[w], ("Z", [v]))) | ||
| end | ||
|
|
||
| println("Bp expectation value for Z on site $(v) is $expect_bp") | ||
| println("Cluster expansion expectation values: $(cluster_wts), $(real.(expects))") | ||
| println("Cluster cumulant expansion: $(cc_wts), $([expects_cc[w] for w=cc_wts])") | ||
| println("Exact expectation value is $expect_exact_v") | ||
|
|
||
| println("***********************************") | ||
| u = neighbors(g, v)[1] | ||
| obs = (["Z","Z"], [u,v]) | ||
| expect_exact_u = real(expect(ψ, ("Z", [u]); alg = "exact")) | ||
| expect_exact = real(expect(ψ,obs; alg = "exact")) - expect_exact_u * expect_exact_v | ||
| println("Calculating connected correlation function between $(v) and $(u)") | ||
|
|
||
| clusters, egs, ig = TN.enumerate_clusters(g, max(1,min(wmax,2*smallest_loop_size)); must_contain=[u,v], min_deg = 1, min_v = 2) | ||
|
|
||
| cluster_wts, expects = cluster_correlation(ψIψ,clusters, egs, ig, obs) | ||
|
|
||
| regs = Dict() | ||
| cnums = Dict() | ||
|
|
||
| cc_wts = [2;3:wmax;] | ||
| for w=cc_wts | ||
| regs[w],_,cnums[w]=TN.build_region_family_correlation(g,u,v,w) | ||
| end | ||
|
|
||
| expects_cc = Dict() | ||
| for w=cc_wts | ||
| expects_cc[w] = real(cc_correlation(ψIψ,regs[w], cnums[w], obs)) | ||
| end | ||
| println("Cluster expansion expectation values: $(cluster_wts), $(real.(expects))") | ||
| println("Cluster cumulant expansion: $(cc_wts), $([expects_cc[w] for w=cc_wts])") | ||
|
|
||
| println("Exact expectation value is $expect_exact") | ||
| push!(states, ψ) | ||
| end | ||
| return states | ||
| 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are those
cluster/files supposed to be part of the PR?