Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
exAClior committed Sep 12, 2024
1 parent afd3536 commit 7dcde1e
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 21 deletions.
77 changes: 70 additions & 7 deletions example/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.5"
manifest_format = "2.0"
project_hash = "24e2f52bad586677e1dd04df66690bcdbd35cb59"
project_hash = "b42a5fb017e826acfad69bafa7d12157ff542c4c"

[[deps.AbstractFFTs]]
deps = ["LinearAlgebra"]
Expand Down Expand Up @@ -87,6 +87,12 @@ git-tree-sha1 = "441db9f0399bcfb4eeb8b891a6b03f7acc5dc731"
uuid = "a9ab73d0-e05c-5df1-8fde-d6a4645b8d8e"
version = "0.2.2"

[[deps.BenchmarkTools]]
deps = ["JSON", "Logging", "Printf", "Profile", "Statistics", "UUIDs"]
git-tree-sha1 = "f1dff6729bc61f4d49e140da1af55dcd1ac97b2f"
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
version = "1.5.0"

[[deps.BitBasis]]
deps = ["LinearAlgebra", "StaticArrays"]
git-tree-sha1 = "fe126b4ca000cdd8de9bf2b94ec40ec27b4b1f7f"
Expand Down Expand Up @@ -152,6 +158,12 @@ weakdeps = ["SparseArrays"]
[deps.ChainRulesCore.extensions]
ChainRulesCoreSparseArraysExt = "SparseArrays"

[[deps.CodecBzip2]]
deps = ["Bzip2_jll", "TranscodingStreams"]
git-tree-sha1 = "e7c529cc31bb85b97631b922fa2e6baf246f5905"
uuid = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd"
version = "0.8.4"

[[deps.CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "bce6804e5e6044c6daab27bb533d1295e4a2e759"
Expand Down Expand Up @@ -197,6 +209,12 @@ git-tree-sha1 = "08c8b6831dc00bfea825826be0bc8336fc369860"
uuid = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
version = "1.0.2"

[[deps.CommonSubexpressions]]
deps = ["MacroTools"]
git-tree-sha1 = "cda2cfaebb4be89c9084adaca7dd7333369715c5"
uuid = "bbf7d656-a473-5ed7-a52c-81e309532950"
version = "0.3.1"

[[deps.Compat]]
deps = ["TOML", "UUIDs"]
git-tree-sha1 = "8ae8d32e09f0dcf42a36b90d4e17f5dd2e4c4215"
Expand Down Expand Up @@ -266,6 +284,18 @@ git-tree-sha1 = "cd6756e833c377e0ce9cd63fb97689a255f12323"
uuid = "04572ae6-984a-583e-9378-9577a1c2574d"
version = "1.33.4+0"

[[deps.DiffResults]]
deps = ["StaticArraysCore"]
git-tree-sha1 = "782dd5f4561f5d267313f23853baaaa4c52ea621"
uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
version = "1.1.0"

[[deps.DiffRules]]
deps = ["IrrationalConstants", "LogExpFunctions", "NaNMath", "Random", "SpecialFunctions"]
git-tree-sha1 = "23163d55f885173722d1e4cf0f6110cdbaf7e272"
uuid = "b552c78f-8df3-52c6-915a-8e097449b14b"
version = "1.15.1"

[[deps.Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down Expand Up @@ -410,6 +440,16 @@ git-tree-sha1 = "9c68794ef81b08086aeb32eeaf33531668d5f5fc"
uuid = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8"
version = "1.3.7"

[[deps.ForwardDiff]]
deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "LinearAlgebra", "LogExpFunctions", "NaNMath", "Preferences", "Printf", "Random", "SpecialFunctions"]
git-tree-sha1 = "cf0fe81336da9fb90944683b8c41984b08793dad"
uuid = "f6369f11-7733-5829-9624-2563aa707210"
version = "0.10.36"
weakdeps = ["StaticArrays"]

[deps.ForwardDiff.extensions]
ForwardDiffStaticArraysExt = "StaticArrays"

[[deps.FreeType]]
deps = ["CEnum", "FreeType2_jll"]
git-tree-sha1 = "907369da0f8e80728ab49c1c7e09327bf0d6d999"
Expand Down Expand Up @@ -593,19 +633,14 @@ deps = ["CRlibm_jll", "MacroTools", "RoundingEmulator"]
git-tree-sha1 = "01fa84a20be8c7c867edf3b9ef33ac15f4089c1a"
uuid = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
version = "0.22.15"
weakdeps = ["DiffRules", "ForwardDiff", "IntervalSets", "RecipesBase"]

[deps.IntervalArithmetic.extensions]
IntervalArithmeticDiffRulesExt = "DiffRules"
IntervalArithmeticForwardDiffExt = "ForwardDiff"
IntervalArithmeticRecipesBaseExt = "RecipesBase"
IntervalArithmeticsIntervalSetsExt = "IntervalSets"

[deps.IntervalArithmetic.weakdeps]
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"

[[deps.IntervalSets]]
git-tree-sha1 = "dba9ddf07f77f60450fe5d2e2beb9854d9a49bd0"
uuid = "8197267c-284f-5f27-9208-e0e47529a953"
Expand Down Expand Up @@ -662,6 +697,18 @@ git-tree-sha1 = "c84a835e1a09b289ffcd2271bf2a337bbdda6637"
uuid = "aacddb02-875f-59d6-b918-886e6ef4fbf8"
version = "3.0.3+0"

[[deps.JuMP]]
deps = ["LinearAlgebra", "MacroTools", "MathOptInterface", "MutableArithmetics", "OrderedCollections", "PrecompileTools", "Printf", "SparseArrays"]
git-tree-sha1 = "82bc707a67639be45ec9abf3a7640af19c4172fe"
uuid = "4076af6c-e467-56ae-b986-b466b2749572"
version = "1.23.1"

[deps.JuMP.extensions]
JuMPDimensionalDataExt = "DimensionalData"

[deps.JuMP.weakdeps]
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"

[[deps.KernelDensity]]
deps = ["Distributions", "DocStringExtensions", "FFTW", "Interpolations", "StatsBase"]
git-tree-sha1 = "7d703202e65efa1369de1279c162b915e245eed1"
Expand Down Expand Up @@ -830,6 +877,12 @@ version = "0.4.2"
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[deps.MathOptInterface]]
deps = ["BenchmarkTools", "CodecBzip2", "CodecZlib", "DataStructures", "ForwardDiff", "JSON", "LinearAlgebra", "MutableArithmetics", "NaNMath", "OrderedCollections", "PrecompileTools", "Printf", "SparseArrays", "SpecialFunctions", "Test", "Unicode"]
git-tree-sha1 = "5b246fca5420ae176d65ed43a2d0ee5897775216"
uuid = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
version = "1.31.2"

[[deps.MathTeXEngine]]
deps = ["AbstractTrees", "Automa", "DataStructures", "FreeTypeAbstraction", "GeometryBasics", "LaTeXStrings", "REPL", "RelocatableFolders", "UnicodeFun"]
git-tree-sha1 = "e1641f32ae592e415e3dbae7f4a188b5316d4b62"
Expand Down Expand Up @@ -878,6 +931,12 @@ git-tree-sha1 = "055a7c49a626e17a8c99bcaaf472d0de60848929"
uuid = "7ebac608-6c66-46e6-9856-b5f43e107bac"
version = "0.3.0"

[[deps.MutableArithmetics]]
deps = ["LinearAlgebra", "SparseArrays", "Test"]
git-tree-sha1 = "d0a6b1096b584a2b88efb70a92f8cb8c881eb38a"
uuid = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
version = "1.4.6"

[[deps.NaNMath]]
deps = ["OpenLibm_jll"]
git-tree-sha1 = "0877504529a3e5c3343c6f8b4c0381e57e4387e4"
Expand Down Expand Up @@ -1093,6 +1152,10 @@ version = "1.4.3"
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[deps.Profile]]
deps = ["Printf"]
uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"

[[deps.ProgressMeter]]
deps = ["Distributed", "Printf"]
git-tree-sha1 = "8f6bc219586aef8baf0ff9a5fe16ee9c70cb65e4"
Expand Down
1 change: 1 addition & 0 deletions example/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"
ZXCalculus = "3525faa3-032d-4235-a8d4-8c2939a218dd"
65 changes: 58 additions & 7 deletions example/floquetify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using ZXCalculus.ZXW
using ZXCalculus.ZX.Multigraphs, ZXCalculus.ZX.Graphs
using ZXCalculus.Utils: Parameter
using WGLMakie, GraphMakie
using ZXCalculus.ZX.MLStyle

function make_meas_mg(weight::T) where {T<:Integer}
spiders_mg = Multigraph(weight * 3 + 1)
Expand All @@ -23,7 +24,27 @@ end
function make_meas_zxwd(::Type{P}, mg::Multigraph{T}, meas_type::Symbol) where {T<:Integer,P}
weight = (nv(mg) - 1) // 3
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))]
@show st_vec
return ZXWDiagram(mg, st_vec)
end

function make_after_rewrite_mg()
spiders_mg = Multigraph(22)
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)]
for edg in edge_list
add_edge!(spiders_mg, edg[1], edg[2])
end
return spiders_mg
end

function make_after_rewrite_zxw(::Type{P}, mg::Multigraph{T},meas_type::Symbol) where {T,P}
num_input_outputs = 8
num_other_spiders = 14
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]...]
if meas_type == :X
st_vec[12:13] = [ZXW.X(zero(P)), ZXW.X(zero(P))]
else
st_vec[12:13] = [ZXW.Z(zero(P)), ZXW.Z(zero(P))]
end
return ZXWDiagram(mg, st_vec)
end

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


concat_zxwd = ZXW.concat!(copy(xstab_meas_zxwd), copy(zstab_meas_zxwd))
res_zxwd = ZXW.concat!(copy(concat_zxwd), copy(concat_zxwd))
res_zxwd = ZXW.concat!(res_zxwd, copy(concat_zxwd))

ZXCalculus.ZXW.plot(res_zxwd)

after_rewrite_mg = make_after_rewrite_mg()
after_rewrite_zxwd_x = make_after_rewrite_zxw(Parameter, after_rewrite_mg, :X)
after_rewrite_zxwd_z = make_after_rewrite_zxw(Parameter, after_rewrite_mg, :Z)

ZXCalculus.ZXW.plot(after_rewrite_zxwd_x)

two_layer_after_rewrite_zxwd = ZXW.concat!(copy(after_rewrite_zxwd_x), copy(after_rewrite_zxwd_z))

ZXCalculus.ZXW.plot(concat_zxwd)
ZXCalculus.ZXW.plot(two_layer_after_rewrite_zxwd)

four_layer_after_rewrite_zxwd = ZXW.concat!(copy(two_layer_after_rewrite_zxwd), copy(two_layer_after_rewrite_zxwd))

ZXCalculus.ZXW.plot(four_layer_after_rewrite_zxwd)

# Convert requirement checking into linear programming
# Req1: even number of green/red spiders with degree 1 respectively
# Req2: Causallity must not be violated in the colored version, assign variables to the vertices
# Req3: in the finished zx-diagram, a spider will have either degree 1 or 3
# Req4: topology of the finished diagram will be nice, i.e planar
# Isn't this just extracting circuit from ZX-Diagram? It is proven to be #P-Complete. Need to search

function has_only_dg1_3_spiders(zxwd::ZXWDiagram{T,P}) where {T,P}
# Req3: in the finished zx-diagram, a spider will have either degree 1 or 3


end

function has_even_dg1_zx_spiders(zxwd::ZXWDiagram{T,P}) where {T,P}
# Req1: even number of green/red spiders with degree 1 respectively

end


function extract_k_qubit_circuit(zxwd::ZXWDiagram{T,P}) where {T,P}
# Req2: Causallity must not be violated in the colored version, assign variables to the vertices
# Req4: topology of the finished diagram will be nice, i.e planar
# Isn't this just extracting circuit from ZX-Diagram? It is proven to be #P-Complete. Need to search

end
15 changes: 8 additions & 7 deletions ext/ZXWCalculusExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using ZXCalculus.ZX.Graphs

function ZXCalculus.ZXW.plot(zxwd::ZXWDiagram{T,P}; kwargs...) where {T,P}
g = zxwd.mg

f, ax, p = graphplot(g,
edge_width=[2.0 for i in 1:ne(g)],
edge_color=[colorant"black" for i in 1:ne(g)],
Expand All @@ -19,19 +20,19 @@ function ZXCalculus.ZXW.plot(zxwd::ZXWDiagram{T,P}; kwargs...) where {T,P}
@match spider_type(zxwd, i) begin
Z(p) => colorant"red"
X(p) => colorant"green"
Input => colorant"orange"
Output => colorant"orange"
_ => colorant"yellow"
end for i in 1:nv(g)])
Input(q) => colorant"orange"
Output(q) => colorant"magenta"
_ => colorant"black"
end for i in 1:nv(g)],kwargs...)

hidedecorations!(ax)
hidespines!(ax)
deregister_interaction!(ax, :rectanglezoom)

function edge_click_action(idx, args...)
red_green_blk = [RGB(1.0, 0.0, 0.0), RGB(0.0, 1.0, 0.0), RGB(0.0, 0.0, 0.0)]
which_color = findfirst(x -> x == p.edge_color[][idx], red_green_blk)
p.edge_color[][idx] = red_green_blk[mod1(which_color + 1, length(red_green_blk))]
print("Enter the color: ")
which_color = readline()
p.edge_color[][idx] = parse(Colorant, which_color)
p.edge_color[] = p.edge_color[]
end

Expand Down

0 comments on commit 7dcde1e

Please sign in to comment.