Skip to content

Commit f19c3e3

Browse files
committed
fix test
1 parent cbc860e commit f19c3e3

File tree

5 files changed

+125
-115
lines changed

5 files changed

+125
-115
lines changed

project/map_config_back.jl

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using UnitDiskMapping, UnitDiskMapping.TikzGraph
2+
using UnitDiskMapping: safe_get
3+
using GraphTensorNetworks, Graphs
4+
5+
function all_configurations(p::Pattern)
6+
mlocs, mg, mpins = mapped_graph(p)
7+
gp = Independence(mg, openvertices=mpins)
8+
res = solve(gp, "configs max")
9+
configs = []
10+
for element in res
11+
for bs in element.c.data
12+
push!(configs, bs)
13+
end
14+
end
15+
mats = Matrix{Int}[]
16+
@show configs
17+
for config in configs
18+
m, n = size(p)
19+
mat = zeros(Int, m, n)
20+
for (loc, c) in zip(mlocs, config)
21+
if !iszero(c)
22+
mat[loc.x, loc.y] = true
23+
end
24+
end
25+
if rotr90(mat) mats && rotl90(mat) mats && rot180(mat) mats &&
26+
mat[end:-1:1,:] mats && mat[:,end:-1:1] mats && # reflect x, y
27+
Matrix(mat') mats && mat[end:-1:1,end:-1:1] mats # reflect diag, offdiag
28+
push!(mats, mat)
29+
end
30+
end
31+
return mats
32+
end
33+
34+
function viz_matrix!(c, mat0, mat, dx, dy)
35+
m, n = size(mat)
36+
for i=1:m
37+
for j=1:n
38+
x, y = j+dx, i+dy
39+
cell = mat0[i,j]
40+
if isempty(cell)
41+
#Node(x, y; fill="black", minimum_size="0.01cm") >> c
42+
elseif cell.doubled
43+
filled = iszero(safe_get(mat, i,j-1)) && iszero(safe_get(mat,i,j+1))
44+
Node(x+0.4, y; fill=filled ? "black" : "white", minimum_size="0.4cm") >> c
45+
filled = iszero(safe_get(mat, i-1,j)) && iszero(safe_get(mat,i+1,j))
46+
Node(x, y+0.4; fill=filled ? "black" : "white", minimum_size="0.4cm") >> c
47+
else
48+
Node(x, y; fill=mat[i,j] > 0 ? "black" : "white", minimum_size="0.4cm") >> c
49+
end
50+
end
51+
end
52+
end
53+
54+
function vizback(p; filename)
55+
configs = all_configurations(p)
56+
smat = source_matrix(p)
57+
mmat = mapped_matrix(p)
58+
slocs, sg, spins = source_graph(p)
59+
mlocs, mg, mpins = mapped_graph(p)
60+
m, n = size(p)
61+
img = canvas() do c
62+
for (ic, mconfig) in enumerate(configs)
63+
if ic % 2 == 0
64+
dx = 2n+3
65+
else
66+
dx = 0
67+
end
68+
dy = -(m+1)*((ic-1) ÷ 2 -1)
69+
Mesh(1+dx, n+dx, 1+dy, m+dy) >> c
70+
viz_bonds!(c, mlocs, mg, dx, dy)
71+
viz_matrix!(c, mmat, mconfig, dx, dy)
72+
PlainText(n+1+dx, m/2+0.5+dy, "\$\\rightarrow\$") >> c
73+
sconfig = UnitDiskMapping.map_config_back!(p, 1, 1, mconfig)
74+
dx += n+1
75+
Mesh(1+dx, n+dx, 1+dy, m+dy) >> c
76+
viz_bonds!(c, slocs, sg, dx, dy)
77+
viz_matrix!(c, smat, sconfig, dx, dy)
78+
end
79+
end
80+
writepdf(filename, img)
81+
end
82+
function viz_bonds!(c, locs, g, dx, dy)
83+
for e in edges(g)
84+
a = locs[e.src]
85+
b = locs[e.dst]
86+
Line((a.y+dx, a.x+dy), (b.y+dx, b.x+dy); line_width="2pt") >> c
87+
end
88+
end

project/viz_flowchart.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ function draw_flowchart()
2424
end
2525
end
2626

27-
write("_local/flowchart.tex", draw_flowchart())
28-
run(`latexmk -pdf _local/flowchart.tex`)
27+
writepdf("_local/flowchart.tex", draw_flowchart())

project/vizgadget.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ using UnitDiskMapping: crossing_ruleset, Pattern, source_graph, mapped_graph
44
function command_graph!(canvas, locs, graph, pins, dx, dy, r, name)
55
for (i,loc) in enumerate(locs)
66
if count(==(loc), locs) == 2
7-
Node(loc[1]+dx, loc[2]+dy, fill="none", id="ext-$name$i", minimum_size="$(1.5*r)cm") >> canvas
7+
Node(loc[1]+dx, loc[2]+dy, fill="black", draw="none", id="$name$i", minimum_size="0cm") >> canvas
8+
Node(loc[1]+dx+0.4, loc[2]+dy, fill="black", draw="none", id="$name$i-A", minimum_size="$(r)cm") >> canvas
9+
Node(loc[1]+dx, loc[2]+dy+0.4, fill="black", draw="none", id="$name$i-B", minimum_size="$(r)cm") >> canvas
10+
else
11+
Node(loc[1]+dx, loc[2]+dy, fill=ipins ? "red" : "black", draw="none", id="$name$i", minimum_size="$(r)cm") >> canvas
812
end
9-
Node(loc[1]+dx, loc[2]+dy, fill=ipins ? "red" : "black", draw="none", id="$name$i", minimum_size="$(r)cm") >> canvas
1013
end
1114
for e in edges(graph)
1215
Line("$name$(e.src)", "$name$(e.dst)"; line_width=1.0) >> canvas
@@ -35,9 +38,7 @@ end
3538

3639
function pattern2tikz(folder::String)
3740
for p in crossing_ruleset
38-
open(joinpath(folder, string(typeof(p).name.name)*"-udg.tex"), "w") do f
39-
write(f, viz_gadget(p))
40-
end
41+
writepdf(joinpath(folder, string(typeof(p).name.name)*"-udg.tex"), viz_gadget(p))
4142
end
4243
end
4344

project/vizugrid.jl

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/mapping.jl

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,35 +90,6 @@ function print_ugrid(io::IO, content::AbstractMatrix)
9090
end
9191
end
9292
end
93-
export print_config
94-
print_config(mr::MappingResult, config::AbstractMatrix) = print_config(stdout, mr, config)
95-
function print_config(io::IO, mr::MappingResult, config::AbstractMatrix)
96-
content = mr.grid_graph.content
97-
@assert size(content) == size(config)
98-
for i=1:size(content, 1)
99-
for j=1:size(content, 2)
100-
cell = content[i, j]
101-
@assert !(cell.connected || cell.doubled)
102-
if !isempty(cell)
103-
if !iszero(config[i,j])
104-
print(io, "")
105-
else
106-
print(io, "")
107-
end
108-
else
109-
if !iszero(config[i,j])
110-
error("configuration not valid, there is not vertex at location $((i,j)).")
111-
end
112-
print(io, "")
113-
end
114-
print(io, " ")
115-
end
116-
if i!=size(content, 1)
117-
println(io)
118-
end
119-
end
120-
end
121-
12293
Base.copy(ug::UGrid) = UGrid(ug.lines, ug.padding, copy(ug.content))
12394

12495
# TODO:
@@ -418,3 +389,33 @@ end
418389
map_configs_back(r::MappingResult{<:Cell}, configs::AbstractVector) = unapply_gadgets!(copy(r.grid_graph), r.mapping_history, copy.(configs))[2]
419390
default_simplifier_ruleset(::UnWeighted) = vcat([rotated_and_reflected(rule) for rule in simplifier_ruleset]...)
420391
default_simplifier_ruleset(::Weighted) = weighted.(default_simplifier_ruleset(UnWeighted()))
392+
393+
export print_config
394+
print_config(mr::MappingResult, config::AbstractMatrix) = print_config(stdout, mr, config)
395+
function print_config(io::IO, mr::MappingResult, config::AbstractMatrix)
396+
content = mr.grid_graph.content
397+
@assert size(content) == size(config)
398+
for i=1:size(content, 1)
399+
for j=1:size(content, 2)
400+
cell = content[i, j]
401+
@assert !(cell.connected || cell.doubled)
402+
if !isempty(cell)
403+
if !iszero(config[i,j])
404+
print(io, "")
405+
else
406+
print(io, "")
407+
end
408+
else
409+
if !iszero(config[i,j])
410+
error("configuration not valid, there is not vertex at location $((i,j)).")
411+
end
412+
print(io, "")
413+
end
414+
print(io, " ")
415+
end
416+
if i!=size(content, 1)
417+
println(io)
418+
end
419+
end
420+
end
421+

0 commit comments

Comments
 (0)