From 756abb9734f2f83211adbc591c42d30e576e47e7 Mon Sep 17 00:00:00 2001 From: GiggleLiu Date: Fri, 26 Apr 2024 12:28:16 +0800 Subject: [PATCH] update --- examples/hard-core-lattice-gas/main.jl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/hard-core-lattice-gas/main.jl b/examples/hard-core-lattice-gas/main.jl index c4310ae..2b82f01 100644 --- a/examples/hard-core-lattice-gas/main.jl +++ b/examples/hard-core-lattice-gas/main.jl @@ -15,16 +15,16 @@ a, b = (1, 0), (0.5, 0.5*sqrt(3)) Na, Nb = 10, 10 -sites = [a .* i .+ b .* j for i=1:Na, j=1:Nb] +sites = vec([50 .* (a .* i .+ b .* j) for i=1:Na, j=1:Nb]) # There exists blockade interactions between hard-core particles. # We connect two lattice sites within blockade radius by an edge. # Two ends of an edge can not both be occupied by particles. -blockade_radius = 1.1 +blockade_radius = 55 using GenericTensorNetworks: show_graph, unit_disk_graph using GenericTensorNetworks.Graphs: edges, nv graph = unit_disk_graph(vec(sites), blockade_radius) -show_graph(graph; locs=sites, texts=fill("", length(sites))) +show_graph(graph, sites; texts=fill("", length(sites))) # These constraints defines an independent set problem that characterized by the following energy based model. # Let $G = (V, E)$ be a graph, where $V$ is the set of vertices and $E$ is the set of edges. @@ -59,15 +59,14 @@ partition_func[] # The marginal probabilities can be computed with the [`marginals`](@ref) function, which measures how likely a site is occupied. mars = marginals(pmodel) -show_graph(graph; locs=sites, vertex_colors=[(b = mars[[i]][2]; (1-b, 1-b, 1-b)) for i in 1:nv(graph)], texts=fill("", nv(graph))) +show_graph(graph, sites; vertex_colors=[(b = mars[[i]][2]; (1-b, 1-b, 1-b)) for i in 1:nv(graph)], texts=fill("", nv(graph))) # The can see the sites at the corner is more likely to be occupied. # To obtain two-site correlations, one can set the variables to query marginal probabilities manually. pmodel2 = TensorNetworkModel(problem, β; mars=[[e.src, e.dst] for e in edges(graph)]) mars = marginals(pmodel2); # We show the probability that both sites on an edge are not occupied -show_graph(graph; locs=sites, edge_colors=[(b = mars[[e.src, e.dst]][1, 1]; (1-b, 1-b, 1-b)) for e in edges(graph)], texts=fill("", nv(graph)), - edge_line_widths=edge_colors=[8*mars[[e.src, e.dst]][1, 1] for e in edges(graph)]) +show_graph(graph, sites; edge_colors=[(b = mars[[e.src, e.dst]][1, 1]; (1-b, 1-b, 1-b)) for e in edges(graph)], texts=fill("", nv(graph)), config=GraphDisplayConfig(; edge_line_width=5)) # ## The most likely configuration # The MAP and MMAP can be used to get the most likely configuration given an evidence. @@ -78,7 +77,7 @@ mars = marginals(pmodel3) logp, config = most_probable_config(pmodel3) # The log probability is 102. Let us visualize the configuration. -show_graph(graph; locs=sites, vertex_colors=[(1-b, 1-b, 1-b) for b in config], texts=fill("", nv(graph))) +show_graph(graph, sites; vertex_colors=[(1-b, 1-b, 1-b) for b in config], texts=fill("", nv(graph))) # The number of particles is sum(config) @@ -87,7 +86,7 @@ pmodel3 = TensorNetworkModel(problem, β; evidence=Dict(1=>0)) logp2, config2 = most_probable_config(pmodel) # The log probability is 99, which is much smaller. -show_graph(graph; locs=sites, vertex_colors=[(1-b, 1-b, 1-b) for b in config2], texts=fill("", nv(graph))) +show_graph(graph, sites; vertex_colors=[(1-b, 1-b, 1-b) for b in config2], texts=fill("", nv(graph))) # The number of particles is sum(config2)