Skip to content

Commit 7dcde1e

Browse files
committed
up
1 parent afd3536 commit 7dcde1e

File tree

4 files changed

+137
-21
lines changed

4 files changed

+137
-21
lines changed

example/Manifest.toml

+70-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
julia_version = "1.10.5"
44
manifest_format = "2.0"
5-
project_hash = "24e2f52bad586677e1dd04df66690bcdbd35cb59"
5+
project_hash = "b42a5fb017e826acfad69bafa7d12157ff542c4c"
66

77
[[deps.AbstractFFTs]]
88
deps = ["LinearAlgebra"]
@@ -87,6 +87,12 @@ git-tree-sha1 = "441db9f0399bcfb4eeb8b891a6b03f7acc5dc731"
8787
uuid = "a9ab73d0-e05c-5df1-8fde-d6a4645b8d8e"
8888
version = "0.2.2"
8989

90+
[[deps.BenchmarkTools]]
91+
deps = ["JSON", "Logging", "Printf", "Profile", "Statistics", "UUIDs"]
92+
git-tree-sha1 = "f1dff6729bc61f4d49e140da1af55dcd1ac97b2f"
93+
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
94+
version = "1.5.0"
95+
9096
[[deps.BitBasis]]
9197
deps = ["LinearAlgebra", "StaticArrays"]
9298
git-tree-sha1 = "fe126b4ca000cdd8de9bf2b94ec40ec27b4b1f7f"
@@ -152,6 +158,12 @@ weakdeps = ["SparseArrays"]
152158
[deps.ChainRulesCore.extensions]
153159
ChainRulesCoreSparseArraysExt = "SparseArrays"
154160

161+
[[deps.CodecBzip2]]
162+
deps = ["Bzip2_jll", "TranscodingStreams"]
163+
git-tree-sha1 = "e7c529cc31bb85b97631b922fa2e6baf246f5905"
164+
uuid = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd"
165+
version = "0.8.4"
166+
155167
[[deps.CodecZlib]]
156168
deps = ["TranscodingStreams", "Zlib_jll"]
157169
git-tree-sha1 = "bce6804e5e6044c6daab27bb533d1295e4a2e759"
@@ -197,6 +209,12 @@ git-tree-sha1 = "08c8b6831dc00bfea825826be0bc8336fc369860"
197209
uuid = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
198210
version = "1.0.2"
199211

212+
[[deps.CommonSubexpressions]]
213+
deps = ["MacroTools"]
214+
git-tree-sha1 = "cda2cfaebb4be89c9084adaca7dd7333369715c5"
215+
uuid = "bbf7d656-a473-5ed7-a52c-81e309532950"
216+
version = "0.3.1"
217+
200218
[[deps.Compat]]
201219
deps = ["TOML", "UUIDs"]
202220
git-tree-sha1 = "8ae8d32e09f0dcf42a36b90d4e17f5dd2e4c4215"
@@ -266,6 +284,18 @@ git-tree-sha1 = "cd6756e833c377e0ce9cd63fb97689a255f12323"
266284
uuid = "04572ae6-984a-583e-9378-9577a1c2574d"
267285
version = "1.33.4+0"
268286

287+
[[deps.DiffResults]]
288+
deps = ["StaticArraysCore"]
289+
git-tree-sha1 = "782dd5f4561f5d267313f23853baaaa4c52ea621"
290+
uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
291+
version = "1.1.0"
292+
293+
[[deps.DiffRules]]
294+
deps = ["IrrationalConstants", "LogExpFunctions", "NaNMath", "Random", "SpecialFunctions"]
295+
git-tree-sha1 = "23163d55f885173722d1e4cf0f6110cdbaf7e272"
296+
uuid = "b552c78f-8df3-52c6-915a-8e097449b14b"
297+
version = "1.15.1"
298+
269299
[[deps.Distributed]]
270300
deps = ["Random", "Serialization", "Sockets"]
271301
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
@@ -410,6 +440,16 @@ git-tree-sha1 = "9c68794ef81b08086aeb32eeaf33531668d5f5fc"
410440
uuid = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8"
411441
version = "1.3.7"
412442

443+
[[deps.ForwardDiff]]
444+
deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "LinearAlgebra", "LogExpFunctions", "NaNMath", "Preferences", "Printf", "Random", "SpecialFunctions"]
445+
git-tree-sha1 = "cf0fe81336da9fb90944683b8c41984b08793dad"
446+
uuid = "f6369f11-7733-5829-9624-2563aa707210"
447+
version = "0.10.36"
448+
weakdeps = ["StaticArrays"]
449+
450+
[deps.ForwardDiff.extensions]
451+
ForwardDiffStaticArraysExt = "StaticArrays"
452+
413453
[[deps.FreeType]]
414454
deps = ["CEnum", "FreeType2_jll"]
415455
git-tree-sha1 = "907369da0f8e80728ab49c1c7e09327bf0d6d999"
@@ -593,19 +633,14 @@ deps = ["CRlibm_jll", "MacroTools", "RoundingEmulator"]
593633
git-tree-sha1 = "01fa84a20be8c7c867edf3b9ef33ac15f4089c1a"
594634
uuid = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
595635
version = "0.22.15"
636+
weakdeps = ["DiffRules", "ForwardDiff", "IntervalSets", "RecipesBase"]
596637

597638
[deps.IntervalArithmetic.extensions]
598639
IntervalArithmeticDiffRulesExt = "DiffRules"
599640
IntervalArithmeticForwardDiffExt = "ForwardDiff"
600641
IntervalArithmeticRecipesBaseExt = "RecipesBase"
601642
IntervalArithmeticsIntervalSetsExt = "IntervalSets"
602643

603-
[deps.IntervalArithmetic.weakdeps]
604-
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"
605-
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
606-
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
607-
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
608-
609644
[[deps.IntervalSets]]
610645
git-tree-sha1 = "dba9ddf07f77f60450fe5d2e2beb9854d9a49bd0"
611646
uuid = "8197267c-284f-5f27-9208-e0e47529a953"
@@ -662,6 +697,18 @@ git-tree-sha1 = "c84a835e1a09b289ffcd2271bf2a337bbdda6637"
662697
uuid = "aacddb02-875f-59d6-b918-886e6ef4fbf8"
663698
version = "3.0.3+0"
664699

700+
[[deps.JuMP]]
701+
deps = ["LinearAlgebra", "MacroTools", "MathOptInterface", "MutableArithmetics", "OrderedCollections", "PrecompileTools", "Printf", "SparseArrays"]
702+
git-tree-sha1 = "82bc707a67639be45ec9abf3a7640af19c4172fe"
703+
uuid = "4076af6c-e467-56ae-b986-b466b2749572"
704+
version = "1.23.1"
705+
706+
[deps.JuMP.extensions]
707+
JuMPDimensionalDataExt = "DimensionalData"
708+
709+
[deps.JuMP.weakdeps]
710+
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
711+
665712
[[deps.KernelDensity]]
666713
deps = ["Distributions", "DocStringExtensions", "FFTW", "Interpolations", "StatsBase"]
667714
git-tree-sha1 = "7d703202e65efa1369de1279c162b915e245eed1"
@@ -830,6 +877,12 @@ version = "0.4.2"
830877
deps = ["Base64"]
831878
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
832879

880+
[[deps.MathOptInterface]]
881+
deps = ["BenchmarkTools", "CodecBzip2", "CodecZlib", "DataStructures", "ForwardDiff", "JSON", "LinearAlgebra", "MutableArithmetics", "NaNMath", "OrderedCollections", "PrecompileTools", "Printf", "SparseArrays", "SpecialFunctions", "Test", "Unicode"]
882+
git-tree-sha1 = "5b246fca5420ae176d65ed43a2d0ee5897775216"
883+
uuid = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
884+
version = "1.31.2"
885+
833886
[[deps.MathTeXEngine]]
834887
deps = ["AbstractTrees", "Automa", "DataStructures", "FreeTypeAbstraction", "GeometryBasics", "LaTeXStrings", "REPL", "RelocatableFolders", "UnicodeFun"]
835888
git-tree-sha1 = "e1641f32ae592e415e3dbae7f4a188b5316d4b62"
@@ -878,6 +931,12 @@ git-tree-sha1 = "055a7c49a626e17a8c99bcaaf472d0de60848929"
878931
uuid = "7ebac608-6c66-46e6-9856-b5f43e107bac"
879932
version = "0.3.0"
880933

934+
[[deps.MutableArithmetics]]
935+
deps = ["LinearAlgebra", "SparseArrays", "Test"]
936+
git-tree-sha1 = "d0a6b1096b584a2b88efb70a92f8cb8c881eb38a"
937+
uuid = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
938+
version = "1.4.6"
939+
881940
[[deps.NaNMath]]
882941
deps = ["OpenLibm_jll"]
883942
git-tree-sha1 = "0877504529a3e5c3343c6f8b4c0381e57e4387e4"
@@ -1093,6 +1152,10 @@ version = "1.4.3"
10931152
deps = ["Unicode"]
10941153
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
10951154

1155+
[[deps.Profile]]
1156+
deps = ["Printf"]
1157+
uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
1158+
10961159
[[deps.ProgressMeter]]
10971160
deps = ["Distributed", "Printf"]
10981161
git-tree-sha1 = "8f6bc219586aef8baf0ff9a5fe16ee9c70cb65e4"

example/Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
33
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
4+
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
45
WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"
56
ZXCalculus = "3525faa3-032d-4235-a8d4-8c2939a218dd"

example/floquetify.jl

+58-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using ZXCalculus.ZXW
44
using ZXCalculus.ZX.Multigraphs, ZXCalculus.ZX.Graphs
55
using ZXCalculus.Utils: Parameter
66
using WGLMakie, GraphMakie
7+
using ZXCalculus.ZX.MLStyle
78

89
function make_meas_mg(weight::T) where {T<:Integer}
910
spiders_mg = Multigraph(weight * 3 + 1)
@@ -23,7 +24,27 @@ end
2324
function make_meas_zxwd(::Type{P}, mg::Multigraph{T}, meas_type::Symbol) where {T<:Integer,P}
2425
weight = (nv(mg) - 1) // 3
2526
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
27+
return ZXWDiagram(mg, st_vec)
28+
end
29+
30+
function make_after_rewrite_mg()
31+
spiders_mg = Multigraph(22)
32+
edge_list = [(1, 11), (2, 10), (3, 14), (4, 15), (5, 18), (6, 19), (7, 21), (8, 20), (9, 10), (10, 11), (11, 12), (12, 13), (12, 19), (13, 14), (13, 20), (14, 15), (15, 16), (17, 18), (18, 19), (20, 21), (21, 22)]
33+
for edg in edge_list
34+
add_edge!(spiders_mg, edg[1], edg[2])
35+
end
36+
return spiders_mg
37+
end
38+
39+
function make_after_rewrite_zxw(::Type{P}, mg::Multigraph{T},meas_type::Symbol) where {T,P}
40+
num_input_outputs = 8
41+
num_other_spiders = 14
42+
st_vec = [[isodd(i) ? ZXW.Input(i ÷ 2 + 1) : ZXW.Output(i ÷ 2) for i in 1:num_input_outputs]..., [(meas_type == :X) ? ZXW.Z(zero(P)) : ZXW.X(zero(P)) for _ in 1:num_other_spiders]...]
43+
if meas_type == :X
44+
st_vec[12:13] = [ZXW.X(zero(P)), ZXW.X(zero(P))]
45+
else
46+
st_vec[12:13] = [ZXW.Z(zero(P)), ZXW.Z(zero(P))]
47+
end
2748
return ZXWDiagram(mg, st_vec)
2849
end
2950

@@ -38,12 +59,42 @@ ZXCalculus.ZXW.plot(zstab_meas_zxwd)
3859

3960

4061
concat_zxwd = ZXW.concat!(copy(xstab_meas_zxwd), copy(zstab_meas_zxwd))
62+
res_zxwd = ZXW.concat!(copy(concat_zxwd), copy(concat_zxwd))
63+
res_zxwd = ZXW.concat!(res_zxwd, copy(concat_zxwd))
64+
65+
ZXCalculus.ZXW.plot(res_zxwd)
66+
67+
after_rewrite_mg = make_after_rewrite_mg()
68+
after_rewrite_zxwd_x = make_after_rewrite_zxw(Parameter, after_rewrite_mg, :X)
69+
after_rewrite_zxwd_z = make_after_rewrite_zxw(Parameter, after_rewrite_mg, :Z)
70+
71+
ZXCalculus.ZXW.plot(after_rewrite_zxwd_x)
72+
73+
two_layer_after_rewrite_zxwd = ZXW.concat!(copy(after_rewrite_zxwd_x), copy(after_rewrite_zxwd_z))
4174

42-
ZXCalculus.ZXW.plot(concat_zxwd)
75+
ZXCalculus.ZXW.plot(two_layer_after_rewrite_zxwd)
76+
77+
four_layer_after_rewrite_zxwd = ZXW.concat!(copy(two_layer_after_rewrite_zxwd), copy(two_layer_after_rewrite_zxwd))
78+
79+
ZXCalculus.ZXW.plot(four_layer_after_rewrite_zxwd)
4380

4481
# Convert requirement checking into linear programming
45-
# Req1: even number of green/red spiders with degree 1 respectively
46-
# Req2: Causallity must not be violated in the colored version, assign variables to the vertices
47-
# Req3: in the finished zx-diagram, a spider will have either degree 1 or 3
48-
# Req4: topology of the finished diagram will be nice, i.e planar
49-
# Isn't this just extracting circuit from ZX-Diagram? It is proven to be #P-Complete. Need to search
82+
83+
function has_only_dg1_3_spiders(zxwd::ZXWDiagram{T,P}) where {T,P}
84+
# Req3: in the finished zx-diagram, a spider will have either degree 1 or 3
85+
86+
87+
end
88+
89+
function has_even_dg1_zx_spiders(zxwd::ZXWDiagram{T,P}) where {T,P}
90+
# Req1: even number of green/red spiders with degree 1 respectively
91+
92+
end
93+
94+
95+
function extract_k_qubit_circuit(zxwd::ZXWDiagram{T,P}) where {T,P}
96+
# Req2: Causallity must not be violated in the colored version, assign variables to the vertices
97+
# Req4: topology of the finished diagram will be nice, i.e planar
98+
# Isn't this just extracting circuit from ZX-Diagram? It is proven to be #P-Complete. Need to search
99+
100+
end

ext/ZXWCalculusExt.jl

+8-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using ZXCalculus.ZX.Graphs
1111

1212
function ZXCalculus.ZXW.plot(zxwd::ZXWDiagram{T,P}; kwargs...) where {T,P}
1313
g = zxwd.mg
14+
1415
f, ax, p = graphplot(g,
1516
edge_width=[2.0 for i in 1:ne(g)],
1617
edge_color=[colorant"black" for i in 1:ne(g)],
@@ -19,19 +20,19 @@ function ZXCalculus.ZXW.plot(zxwd::ZXWDiagram{T,P}; kwargs...) where {T,P}
1920
@match spider_type(zxwd, i) begin
2021
Z(p) => colorant"red"
2122
X(p) => colorant"green"
22-
Input => colorant"orange"
23-
Output => colorant"orange"
24-
_ => colorant"yellow"
25-
end for i in 1:nv(g)])
23+
Input(q) => colorant"orange"
24+
Output(q) => colorant"magenta"
25+
_ => colorant"black"
26+
end for i in 1:nv(g)],kwargs...)
2627

2728
hidedecorations!(ax)
2829
hidespines!(ax)
2930
deregister_interaction!(ax, :rectanglezoom)
3031

3132
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))]
33+
print("Enter the color: ")
34+
which_color = readline()
35+
p.edge_color[][idx] = parse(Colorant, which_color)
3536
p.edge_color[] = p.edge_color[]
3637
end
3738

0 commit comments

Comments
 (0)