Skip to content

Commit afd3536

Browse files
committed
up
1 parent a01953e commit afd3536

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

example/floquetify.jl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,40 @@ using ZXCalculus.Utils: Parameter
66
using WGLMakie, GraphMakie
77

88
function make_meas_mg(weight::T) where {T<:Integer}
9-
spiders_mg = Multigraph(weight + 1)
9+
spiders_mg = Multigraph(weight * 3 + 1)
10+
11+
for i in 1:weight
12+
add_edge!(spiders_mg, 2 * (i - 1) + 1, 2 * weight + i)
13+
add_edge!(spiders_mg, 2 * (i - 1) + 2, 2 * weight + i)
14+
end
15+
1016
for i in 1:weight
11-
add_edge!(spiders_mg, i, weight + 1, 1)
17+
add_edge!(spiders_mg, 2 * weight + i, 3 * weight + 1)
1218
end
19+
1320
return spiders_mg
1421
end
1522

16-
function make_meas_zxwd(::Type{P}, mg::Multigraph{T}, meas_type::Symbol) where {T<:Integer, P}
17-
weight = nv(mg) - 1
18-
st_vec = [[(meas_type == :X) ? ZXW.Z(zero(P)) : ZXW.X(zero(P)) for _ in 1:weight]..., (meas_type == :X) ? ZXW.X(zero(P)) : ZXW.Z(zero(P))]
23+
function make_meas_zxwd(::Type{P}, mg::Multigraph{T}, meas_type::Symbol) where {T<:Integer,P}
24+
weight = (nv(mg) - 1) // 3
25+
st_vec = [[isodd(i) ? ZXW.Input(i ÷ 2 + 1) : ZXW.Output(i ÷ 2) for i in 1:2*weight]..., [(meas_type == :X) ? ZXW.Z(zero(P)) : ZXW.X(zero(P)) for _ in 1:weight]..., (meas_type == :X) ? ZXW.X(zero(P)) : ZXW.Z(zero(P))]
26+
@show st_vec
1927
return ZXWDiagram(mg, st_vec)
2028
end
2129

2230
weight = 4
2331
meas_mg = make_meas_mg(weight)
2432

33+
xstab_meas_zxwd = make_meas_zxwd(Parameter, meas_mg, :X)
34+
zstab_meas_zxwd = make_meas_zxwd(Parameter, meas_mg, :Z)
35+
36+
ZXCalculus.ZXW.plot(xstab_meas_zxwd)
37+
ZXCalculus.ZXW.plot(zstab_meas_zxwd)
2538

26-
xstab_meas_zxd = make_meas_zxwd(Parameter, meas_mg, :X)
27-
zstab_meas_zxd = make_meas_zxwd(Parameter, meas_mg, :Z)
2839

29-
ZXCalculus.ZXW.plot(xstab_meas_zxd)
40+
concat_zxwd = ZXW.concat!(copy(xstab_meas_zxwd), copy(zstab_meas_zxwd))
3041

31-
typeof(xstab_meas_zxd)
42+
ZXCalculus.ZXW.plot(concat_zxwd)
3243

3344
# Convert requirement checking into linear programming
3445
# Req1: even number of green/red spiders with degree 1 respectively

ext/ZXWCalculusExt.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,36 @@ using WGLMakie.Colors
55
using MLStyle
66
using ZXCalculus: ZXW
77
using ZXCalculus, ZXCalculus.ZXW
8-
using ZXCalculus.ZXW: Z,X
8+
using ZXCalculus.ZXW: Z, X, Input, Output, spider_type
99
using ZXCalculus.ZX.Graphs
1010

11-
function edge_click_action(idx, args...)
12-
red_green_blk = [RGB(1.,0.,0.), RGB(0.,1.,0.), RGB(0.,0.,0.)]
13-
which_color = findfirst(x -> x == p.edge_color[][idx], red_green_blk)
14-
p.edge_color[][idx] = red_green_blk[mod1(which_color+1,length(red_green_blk))]
15-
p.edge_color[] = p.edge_color[]
16-
end
1711

1812
function ZXCalculus.ZXW.plot(zxwd::ZXWDiagram{T,P}; kwargs...) where {T,P}
1913
g = zxwd.mg
2014
f, ax, p = graphplot(g,
2115
edge_width=[2.0 for i in 1:ne(g)],
2216
edge_color=[colorant"black" for i in 1:ne(g)],
23-
node_size=[10 for i in 1:nv(g)],
17+
node_size=[15 for i in 1:nv(g)],
2418
node_color=[
2519
@match spider_type(zxwd, i) begin
2620
Z(p) => colorant"red"
2721
X(p) => colorant"green"
22+
Input => colorant"orange"
23+
Output => colorant"orange"
2824
_ => colorant"yellow"
2925
end for i in 1:nv(g)])
3026

3127
hidedecorations!(ax)
3228
hidespines!(ax)
3329
deregister_interaction!(ax, :rectanglezoom)
30+
31+
function edge_click_action(idx, args...)
32+
red_green_blk = [RGB(1.0, 0.0, 0.0), RGB(0.0, 1.0, 0.0), RGB(0.0, 0.0, 0.0)]
33+
which_color = findfirst(x -> x == p.edge_color[][idx], red_green_blk)
34+
p.edge_color[][idx] = red_green_blk[mod1(which_color + 1, length(red_green_blk))]
35+
p.edge_color[] = p.edge_color[]
36+
end
37+
3438
register_interaction!(ax, :nhover, NodeHoverHighlight(p))
3539
register_interaction!(ax, :ehover, EdgeHoverHighlight(p))
3640
register_interaction!(ax, :ndrag, NodeDrag(p))

src/ZXW/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ function concat!(d1::ZXWDiagram{T,P}, d2::ZXWDiagram{T,P}) where {T,P}
498498
for i = 1:nout(d1)
499499
out_idx = get_output_idx(d1, i)
500500
# output spiders cannot be connected to multiple vertices or with multiedge
501+
@show out_idx
501502
prior_vtx = neighbors(d1, out_idx)[1]
502503
rem_edge!(d1, out_idx, prior_vtx)
503504
# d2 input vtx idx is mapped to the vtx prior to d1 output

0 commit comments

Comments
 (0)