QuantumBFS / Yao.jl

Extensible, Efficient Quantum Algorithm Design for Humans.
https://yaoquantum.org
Other
918 stars 119 forks source link

plot error? #439

Open Wangwei-Lan opened 1 year ago

Wangwei-Lan commented 1 year ago

Hello,

I plotted a circuit in jupyter notebook in one cell, it worked fine. However, I continue to plot another circuit in the next cell, it always give me error. See below circuit1 = chain(1, put(1=>H)); plot(circuit1) circuit2 = chain(1, put(1=>X)); plot(circuit2) The first one gives me the correct H gate, but I run the second code, circuit2 always gives me the same plot as circuit1, which is incorrect since it is an X gate. I am not quite sure whether it is a bug or it is because the setup on my computer is wrong. Could you help me verify that?

GiggleLiu commented 1 year ago

Maybe I know which editor are you using? I tried VSCode, it plots correctly.

Wangwei-Lan commented 1 year ago

I am not using an editor, I used Jupiter notebook. For Vscode, it works fine.

Egg12138 commented 1 year ago

I met a problem alike yesterday.

(Both in Jupyter notebook & VSCode builtin jupyter notebook) platform: WSL Ubuntu20.04LTS. using Yao, YaoPlots

step1

In one block, I wrote: chainYHZ = chain(3, put(1=>Y), put(2=>Z), put(3=>Z), repeat(Z, 1:3)) plot(chainYHZ)

output is as expected: Y-Z Z-Z Z-Z

step2

then I ran another block of codes: chainYHH = chain(3, put(1=>Y), put(2=>H), put(3=>H)) plot(chainYHH)

output is wrong: Y Z Z

step3

I clean the output of the step1 block the output of step2 immediately changed into the correct chain: Y H H

step4

I re-executed the step1 block, step2 block changed again: Y Z Z

step5

I cleared output of step1 block again, (yeah, the step2 output remain correct: Y H H ) then I added a new block after step2 block, denoted by step5 block. chain5 = chain(3, put(1=>X), put(2=>H), put(3=>X)) plot(chain5)

the output is: Y H Y

step6

repeat: I clear the step2 output, the step5 block plot correctly: X H X

step7

I insert a new block after step1 block, wrong plots happened again.

step8

I use println(chainXXX) , the output is always correct but julia plots incorrectly when plot outputs of other code blocks exist. I don't know why. (I'm new for Yao.jl so I'm not sure whether it's a feature...)

step9

even if I using Plots, same things happened.

GiggleLiu commented 1 year ago

The plotting backend we are using is Luxor. IIUC, it is a wield interaction between Luxor and Jupyter. @cormullion do you have any idea? Maybe this issue is related: https://github.com/JuliaGraphics/Luxor.jl/issues/226

GiggleLiu commented 1 year ago

FYI: the reltated code block is https://github.com/QuantumBFS/YaoPlots.jl/blob/0157a3e8d57113d6219a8dba9d2f320f99fc1395/src/vizcircuit.jl#L463

Egg12138 commented 1 year ago

The plotting backend we are using is Luxor. IIUC, it is a wield interaction between Luxor and Jupyter. @cormullion do you have any idea? Maybe this issue is related: https://github.com/JuliaGraphics/Luxor.jl/issues/226

thanks. I'll try the solution in the quoted issues.

cormullion commented 1 year ago

I think this is the infamous "SVG/Jupyter cell interaction" problem, summarised by knuesel here: https://github.com/MakieOrg/Makie.jl/issues/952#issuecomment-842413678

ie

SVGs in different cells in a Jupyter notebook share definitions, which is usually not what you want.

A related issue was found in Pluto (https://github.com/JuliaGraphics/Luxor.jl/issues/228) - but Pluto handles SVGs more carefully than Jupyter and doesn't have this problem.

cormullion commented 1 year ago

Since this is a common problem people encounter when using Jupyter, I'll add a workaround to the next Luxor release. (Very large SVGs might take a bit longer to display, perhaps...)

Screenshot 2022-12-08 at 11 10 07
GiggleLiu commented 1 year ago

Thanks, that would be great!

Egg12138 commented 1 year ago

Since this is a common problem people encounter when using Jupyter, I'll add a workaround to the next Luxor release. (Very large SVGs might take a bit longer to display, perhaps...)

Screenshot 2022-12-08 at 11 10 07

That's awesome.Thanks!

cormullion commented 1 year ago

hopefully fixed in Luxor 3.6.0.