Fix order of the gates from `draw(::Circuit)`
Opened this issue · 5 comments
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
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)]
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.
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).
I agree with you but then you need to compare between moments and do some kind of basic compilation.
mmm strange. this is a bug also.
@jofrevalles can you open another issue with some code to reproduce?