Skip to content

Commit

Permalink
better visualization of labeled multi-qubit circuits (#55)
Browse files Browse the repository at this point in the history
* update

* update

* update

* to basic style

* update

* update vizcircuit

* fix tests

* fix tests

* rm wg
  • Loading branch information
GiggleLiu authored Jun 4, 2022
1 parent 2cf8b4d commit 64e6f54
Show file tree
Hide file tree
Showing 19 changed files with 298 additions and 176 deletions.
11 changes: 5 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@ GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Multigraphs = "7ebac608-6c66-46e6-9856-b5f43e107bac"
Viznet = "52a3aca4-6234-47fd-b74a-806bdf78ede9"
YaoBlocks = "418bc28f-b43b-5e0b-a6e7-61bbc1a2c1df"
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
ZXCalculus = "3525faa3-032d-4235-a8d4-8c2939a218dd"

[compat]
BitBasis = "0.7, 0.8"
BitBasis = "0.8"
Colors = "0.11, 0.12"
Compose = "0.8, 0.9"
GraphPlot = "0.5"
Graphs = "1.6"
Graphs = "1.7"
Multigraphs = "0.3"
Viznet = "0.3.1"
YaoBlocks = "0.12, 0.13"
ZXCalculus = "0.5"
Yao = "0.8"
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"

[targets]
test = ["Test", "Yao"]
test = ["Test"]
16 changes: 12 additions & 4 deletions examples/circuits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ using Compose, Cairo

_save(str) = PNG(joinpath(@__DIR__, str))

YaoPlots.CircuitStyles.linecolor[] = "#000000"
lighttheme!()
YaoPlots.CircuitStyles.gate_bgcolor[] = "white" # default is transparent
# qft circuit
vizcircuit(qft_circuit(5)) |> _save("qft.png")

# labeled and time evolution
vizcircuit(chain(control(5, 3, (2,4)=>matblock(rand_unitary(4); tag="label")),
put(5, (2,4)=>matblock(rand_unitary(4); tag="label")), time_evolve(put(5, 2=>X), 0.2))) |> _save("labelled.png")

# variational circuit
vizcircuit(variational_circuit(5)) |> _save("variational.png")
# vizcircuit(variational_circuit(5; mode=:Merged))
Expand All @@ -18,7 +23,7 @@ vizcircuit(general_U4()) |> _save("u4.png")
vizcircuit(rand_supremacy2d(2, 2, 8)) |> _save("supremacy2d.png")

# google 52 qubit
vizcircuit(rand_google53(10)) |> _save("google53.png")
vizcircuit(rand_google53(5); scale=0.5) |> _save("google53.png")

# control blocks
vizcircuit(chain(control(5, (2,-3), 4=>X), control(5, (-4, -2), 1=>Z))) |> _save("controls.png")
Expand All @@ -35,11 +40,14 @@ chain(5, [put(5, 2=>ConstGate.Sdag), put(5, 3=>ConstGate.Tdag),
put(5, (2,3)=>ConstGate.SWAP), put(5, (1,)=>ConstGate.P0), put(5, (1,)=>ConstGate.I2),
put(5, (2,)=>ConstGate.P1), put(5, (1,)=>ConstGate.Pu), put(5, (1,)=>ConstGate.Pd),
put(5, (2,)=>ConstGate.T),
put(5, (2,)=>phase(0.4π)),
put(5, (2,)=>shift(0.4π)),
]) |> vizcircuit |> _save("constgates.png")

chain(5, [put(5, (2,3)=>label(SWAP, "SWAP")'), put(5, 2=>label(I2, "id")), put(5, 2=>label(X, "X")), control(5, (5,3), (2,4,1)=>put(3, (1,3)=>label(SWAP, "SWAP")))]) |> vizcircuit |> _save("multiqubit.png")
chain(5, [put(5, (2,3)=>matblock(Matrix(SWAP), tag="SWAP")'), put(5, 2=>matblock(mat(I2), tag="id")), put(5, 2=>label(X, "X")), control(5, (5,3), (2,4,1)=>put(3, (1,3)=>label(SWAP, "SWAP")))]) |> vizcircuit |> _save("multiqubit.png")

YaoPlots.CircuitStyles.linecolor[] = "#FFFFFF"
YaoPlots.darktheme!()
YaoPlots.CircuitStyles.gate_bgcolor[] = "transparent" # default is transparent
# qft circuit
vizcircuit(qft_circuit(5)) |> _save("qft-white.png")

Binary file modified examples/constgates.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/controls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/cxx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/google53.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/labelled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/measure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/multiqubit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/qft-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/qft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/reflect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/supremacy2d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/u4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/variational.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/helperblock.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using YaoBlocks
using Yao.YaoBlocks
export LabelBlock

"""
Expand Down
Loading

0 comments on commit 64e6f54

Please sign in to comment.