Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order of the gates from draw(::Circuit) #15

Open
jofrevalles opened this issue Dec 22, 2022 · 5 comments
Open

Fix order of the gates from draw(::Circuit) #15

jofrevalles opened this issue Dec 22, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@jofrevalles
Copy link
Member

Summary

The ordering of the gates in a Circuit displayed by the draw(::Circuit) function sometimes is not accurate.

Example

julia> using Quac
julia> circ = Circuit(4); push!(circ, CX(1,3)); push!(circ, H(1)); push!(circ, H(2))
julia> circ

And the plot:
image

The priorities and moments seems to be fine:

julia> circ.lanes
4-element Vector{Vector{Quac.Element{Gate}}}:
 [Quac.Element{Gate}(Control{X}(1, X(3)), [1 => 1, 3 => 1]), Quac.Element{Gate}(H(1), [1 => 2])]
 [Quac.Element{Gate}(H(2), [2 => 1])]
 [Quac.Element{Gate}(Control{X}(1, X(3)), [1 => 1, 3 => 1])]
 []

julia> moments(circ)
2-element Vector{Vector{Gate}}:
 [Control{X}(1, X(3)), H(2)]
 [H(1)]
@jofrevalles jofrevalles added the bug Something isn't working label Dec 22, 2022
@mofeing
Copy link
Member

mofeing commented Dec 22, 2022

Ah yes. This the fault of the draw function.

The problem is that although CX(1,3) and H(2) "live" in the same moment (this is correct behavior), they cannot be drawn in the same "moment" because of overlapping drawings. One of the two needs to be moved to the next moment.

Current solution is to create a "ghost" moment where the overlapping gate is moved (i.e. H(2) in the drawing). A better solution would be to do some kind of circuit compilation.

@jofrevalles
Copy link
Member Author

I think this behavior of the H(2) is the expected for visualization, since it is true that it overlaps with CX(1, 3). Nevertheless, I would think that this shift of H(2) should not affect the rest of the gates (e.g., H(1) in this example).

@mofeing
Copy link
Member

mofeing commented Dec 22, 2022

I agree with you but then you need to compare between moments and do some kind of basic compilation.

@jofrevalles
Copy link
Member Author

Also sometimes I find that the draw function draws empty gates when these are not necessary. As an example:

julia> circ = Circuit(4); push!(circ, Sd(1)); push!(circ, CX(2,4)); push!(circ, CZ(1,4)); push!(circ, X(1))
julia> circ

Produces:
image

@mofeing
Copy link
Member

mofeing commented Dec 28, 2022

mmm strange. this is a bug also.

@jofrevalles can you open another issue with some code to reproduce?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants