diff --git a/Project.toml b/Project.toml index 84c64d5..086a32e 100644 --- a/Project.toml +++ b/Project.toml @@ -14,10 +14,6 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" YaoHIR = "6769671a-fce8-4286-b3f7-6099e1b1298a" YaoLocations = "66df03fb-d475-48f7-b449-3d9064bf085b" -[weakdeps] -Karnak = "cd156443-31ad-4f6f-850f-a93ee5f75905" -CairoMakie = "" - [compat] Expronicon = "0.10.3" Graphs = "1" @@ -27,7 +23,6 @@ OMEinsum = "0.7" YaoHIR = "0.2" YaoLocations = "0.1" julia = "1.9" -Karnak = "1.0.0" [extras] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/src/Utils/plot.jl b/src/Utils/plot.jl deleted file mode 100644 index 35e3243..0000000 --- a/src/Utils/plot.jl +++ /dev/null @@ -1,69 +0,0 @@ -using ZXCalculus -using Karnak -using Graphs -using Multigraphs: adjacency_matrix -using NetworkLayout -using Colors -using MLStyle -using YaoPlots -using Yao - -using CairoMakie - - - -function simplify!(rule, cir) - match_pos = match(rule, circ) - rewrite!(rule, cir, match_id) -end - - - -function drawZXWDiagram(zxwd::ZXWDiagram) - g = zxwd.mg - vertexlabels = Vector{String}(undef, nv(zxwd.mg)) - for (idx, vtx) in zxwd.st - vertexlabels[idx] = string(vtx)[15:end] - end - vertexfillcolors = Vector{RGB}(undef, nv(zxwd.mg)) - green = RGB(0, 1, 0) - red = RGB(1, 0, 0) - yellow = RGB(1, 1, 0) - black = RGB(0, 0, 0) - white = RGB(1, 1, 1) - for (idx, v) in zxwd.st - curcolor = @match v begin - X(_) => red - Z(_) => green - D => yellow - H => yellow - W => black - _ => white - end - vertexfillcolors[idx] = curcolor - end - initialpos, pin = Dict(), Dict() - for (idx, input) in enumerate(zxwd.inputs) - initialpos[input] = (-2, idx) - pin[input] = (true, true) - end - - for (idx, output) in enumerate(zxwd.outputs) - initialpos[output] = (nv(zxwd.mg) / length(zxwd.inputs), idx) - pin[output] = (true, true) - end - - layout = SFDP(; initialpos = initialpos, pin = pin) - @drawsvg begin - background("black") - sethue("grey40") - fontsize(8) - drawgraph( - g, - layout = layout, - vertexlabels = vertexlabels, - vertexfillcolors = vertexfillcolors, - ) - end 600 400 -end - diff --git a/test/plot.jl b/test/plot.jl deleted file mode 100644 index 44ef1cb..0000000 --- a/test/plot.jl +++ /dev/null @@ -1,346 +0,0 @@ -# bring in includes -function yao_circ() - return chain( - 5, - put(5, 5 => Rx(π)), - put(5, 5 => Yao.H), - put(5, 5 => Rz(0)), - cnot(5, 5, 4), - put(5, 5 => Rz(7 * π / 4)), - cnot(5, 5, 1), - put(5, 5 => Rz(π / 4)), - cnot(5, 5, 4), - put(5, 4 => Rz(π / 4)), - put(5, 4 => Rz(7 * π / 4)), - cnot(5, 5, 1), - cnot(5, 4, 1), - put(5, 5 => Rz(π / 4)), - put(5, 1 => Rz(π / 4)), - put(5, 4 => Rz(π / 4)), - cnot(5, 4, 1), - cnot(5, 5, 4), - put(5, 5 => Rz(7 * π / 4)), - cnot(5, 5, 3), - put(5, 5 => Rz(π / 4)), - cnot(5, 5, 4)put(5, 4 => Rz(π / 4)), - put(5, 5 => Rz(7 * π / 4)), - cnot(5, 5, 3), - cnot(5, 4, 3), - put(5, 5 => Rz(π / 4)), - put(5, 3 => Rz(π / 4)), - put(5, 4 => Rz(7 * π / 4)), - put(5, 5 => Yao.H), - - # cir, - # Val{:H}(), - # 5, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 4, - # 3, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 5, - # 4, - # )push_gate!( - # cir, - # Val{:H}(), - # 5, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 5, - # 3, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # 7 // 4, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 5, - # 2, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # 1 // 4, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 5, - # 3, - # )push_gate!( - # cir, - # Val{:Z}(), - # 3, - # 1 // 4, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # 7 // 4, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 5, - # 2, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 3, - # 2, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # 1 // 4, - # )push_gate!( - # cir, - # Val{:H}(), - # 5, - # )push_gate!( - # cir, - # Val{:Z}(), - # 2, - # 1 // 4, - # )push_gate!( - # cir, - # Val{:Z}(), - # 3, - # 7 // 4, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 3, - # 2, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 5, - # 3, - # )push_gate!( - # cir, - # Val{:H}(), - # 5, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 5, - # 2, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # 7 // 4, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 5, - # 1, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # 1 // 4, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 5, - # 2, - # )push_gate!( - # cir, - # Val{:Z}(), - # 2, - # 1 // 4, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # 7 // 4, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 5, - # 1, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 2, - # 1, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # 1 // 4, - # )push_gate!( - # cir, - # Val{:Z}(), - # 1, - # 1 // 4, - # )push_gate!( - # cir, - # Val{:Z}(), - # 2, - # 7 // 4, - # )push_gate!( - # cir, - # Val{:H}(), - # 5, - # )push_gate!( - # cir, - # Val{:Z}(), - # 5, - # )push_gate!( - # cir, - # Val{:CNOT}(), - # 2, - # 1, - # )push_gate!(cir, Val{:CNOT}(), 5, 2)push_gate!(cir, Val{:CNOT}(), 5, 1), - ) -end - -yc = yao_circ() -vizcircuit(yc) - -function gen_cir() - cir = ZXDiagram(5) - push_gate!(cir, Val{:X}(), 5, 1 // 1) - push_gate!(cir, Val{:H}(), 5) - push_gate!(cir, Val{:Z}(), 5) - push_gate!(cir, Val{:CNOT}(), 5, 4) - push_gate!(cir, Val{:Z}(), 5, 7 // 4) - push_gate!(cir, Val{:CNOT}(), 5, 1) - push_gate!(cir, Val{:Z}(), 5, 1 // 4) - push_gate!(cir, Val{:CNOT}(), 5, 4) - push_gate!(cir, Val{:Z}(), 4, 1 // 4) - push_gate!(cir, Val{:Z}(), 5, 7 // 4) - push_gate!(cir, Val{:CNOT}(), 5, 1) - push_gate!(cir, Val{:CNOT}(), 4, 1) - push_gate!(cir, Val{:Z}(), 5, 1 // 4) - push_gate!(cir, Val{:Z}(), 1, 1 // 4) - push_gate!(cir, Val{:Z}(), 4, 7 // 4) - push_gate!(cir, Val{:CNOT}(), 4, 1) - push_gate!(cir, Val{:CNOT}(), 5, 4) - push_gate!(cir, Val{:Z}(), 5, 7 // 4) - push_gate!(cir, Val{:CNOT}(), 5, 3) - push_gate!(cir, Val{:Z}(), 5, 1 // 4) - push_gate!(cir, Val{:CNOT}(), 5, 4) - push_gate!(cir, Val{:Z}(), 4, 1 // 4) - push_gate!(cir, Val{:Z}(), 5, 7 // 4) - push_gate!(cir, Val{:CNOT}(), 5, 3) - push_gate!(cir, Val{:CNOT}(), 4, 3) - push_gate!(cir, Val{:Z}(), 5, 1 // 4) - push_gate!(cir, Val{:Z}(), 3, 1 // 4) - push_gate!(cir, Val{:Z}(), 4, 7 // 4) - push_gate!(cir, Val{:H}(), 5) - push_gate!(cir, Val{:Z}(), 5) - push_gate!(cir, Val{:CNOT}(), 4, 3) - push_gate!(cir, Val{:CNOT}(), 5, 4) - push_gate!(cir, Val{:H}(), 5) - push_gate!(cir, Val{:Z}(), 5) - push_gate!(cir, Val{:CNOT}(), 5, 3) - push_gate!(cir, Val{:Z}(), 5, 7 // 4) - push_gate!(cir, Val{:CNOT}(), 5, 2) - push_gate!(cir, Val{:Z}(), 5, 1 // 4) - push_gate!(cir, Val{:CNOT}(), 5, 3) - push_gate!(cir, Val{:Z}(), 3, 1 // 4) - push_gate!(cir, Val{:Z}(), 5, 7 // 4) - push_gate!(cir, Val{:CNOT}(), 5, 2) - push_gate!(cir, Val{:CNOT}(), 3, 2) - push_gate!(cir, Val{:Z}(), 5, 1 // 4) - push_gate!(cir, Val{:H}(), 5) - push_gate!(cir, Val{:Z}(), 2, 1 // 4) - push_gate!(cir, Val{:Z}(), 3, 7 // 4) - push_gate!(cir, Val{:Z}(), 5) - push_gate!(cir, Val{:CNOT}(), 3, 2) - push_gate!(cir, Val{:CNOT}(), 5, 3) - push_gate!(cir, Val{:H}(), 5) - push_gate!(cir, Val{:Z}(), 5) - push_gate!(cir, Val{:CNOT}(), 5, 2) - push_gate!(cir, Val{:Z}(), 5, 7 // 4) - push_gate!(cir, Val{:CNOT}(), 5, 1) - push_gate!(cir, Val{:Z}(), 5, 1 // 4) - push_gate!(cir, Val{:CNOT}(), 5, 2) - push_gate!(cir, Val{:Z}(), 2, 1 // 4) - push_gate!(cir, Val{:Z}(), 5, 7 // 4) - push_gate!(cir, Val{:CNOT}(), 5, 1) - push_gate!(cir, Val{:CNOT}(), 2, 1) - push_gate!(cir, Val{:Z}(), 5, 1 // 4) - push_gate!(cir, Val{:Z}(), 1, 1 // 4) - push_gate!(cir, Val{:Z}(), 2, 7 // 4) - push_gate!(cir, Val{:H}(), 5) - push_gate!(cir, Val{:Z}(), 5) - push_gate!(cir, Val{:CNOT}(), 2, 1) - push_gate!(cir, Val{:CNOT}(), 5, 2) - push_gate!(cir, Val{:CNOT}(), 5, 1) - return cir -end - -circ = gen_cir() -circ2 = phase_teleportation(circ) -tcount(circ) -tcount(circ2) -ex_circ = clifford_simplification(circ2) -tcount(ex_circ) - - -# Example data -circuit_names = ["Before Simplification", "After Simplification"] -circuit_values = [28, 8] # Replace these with your actual values - -fig = Figure(resolution = (600, 400)) -ax = Axis(fig, xlabel = "Circuit", ylabel = "T Counts") - -barplot(1:2, circuit_values, - axis = (xticks = (1:2, circuit_names), - ylabel = "T Counts", - title = "Simplification Performance"), - ) -barplot!(circuit_names, circuit_values) -fig[1, 1] = ax - -# Save the figure to a file -save("~/Desktop/tcounts.png", fig) - -# Example data -circuit_names = ["Before Simplification", "After Simplification"] -circuit_values = [5, 3] # Replace these with your actual values - -bar(circuit_names, circuit_values, - title = "Comparison of Quantum Circuits", - xlabel = "Circuit", - ylabel = "Criterion", - label = false) - -zxwd = ZXWDiagram(2) -push_gate!(zxwd, Val(:H), 1) -push_gate!(zxwd, Val(:H), 2) - -push_gate!(zxwd, Val(:CZ), 1, 2) -push_gate!(zxwd, Val(:X), 1, Parameter(Val(:PiUnit), :a); autoconvert = false) -push_gate!(zxwd, Val(:X), 2, Parameter(Val(:PiUnit), :b); autoconvert = false) - -drawZXWDiagram(zxwd) - -zxwd_diff_a = diff_diagram(copy(zxwd), :a) -drawZXWDiagram(zxwd_diff_a)