Skip to content

Commit

Permalink
[add] separation parameter to permute()
Browse files Browse the repository at this point in the history
To customize (or disable) the stroke of the thicker line that is drawn below the wires to separate them
  • Loading branch information
Mc-Zen committed Feb 29, 2024
1 parent 137743c commit 79dd644
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/draw-functions.typ
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@
let dy = draw-params.multi.wire-distance
let width = gate.width
if dy == 0pt { return box(width: width, height: 4pt) }

let separation = gate.data.separation
if separation == auto { separation = draw-params.background }
if type(separation) == color { separation += 3pt }
if type(separation) == length { separation += draw-params.background }

box(
height: dy + 4pt,
inset: (y: 2pt),
Expand All @@ -190,7 +196,9 @@
let to = qubits.at(from)
let y-from = draw-params.center-y-coords.at(from + gate.qubit) - y0
let y-to = draw-params.center-y-coords.at(to + gate.qubit) - y0
place(path(((0pt,y-from), (-width/2, 0pt)), ((width, y-to), (-width/2, 0pt)), stroke: 3pt + draw-params.background))
if separation != none {
place(path(((0pt,y-from), (-width/2, 0pt)), ((width, y-to), (-width/2, 0pt)), stroke: separation))
}
place(path(((-.1pt,y-from), (-width/2, 0pt)), ((width+.1pt, y-to), (-width/2, 0pt)), stroke: draw-params.wire))
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/gates.typ
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@
///
/// - ..qubits (array): Qubit permutation specification.
/// - width (length): Width of the permutation gate.
///
#let permute(..qubits, width: 30pt) = {
mqgate(none, n: qubits.pos().len(), width: width, draw-function: draw-functions.draw-permutation-gate, data: (qubits: qubits.pos(), extent: 2pt))
/// - separation (auto, none, length, color, stroke): Overlapping wires are separated by drawing a thicker line below. With this option, this line can be customized in color or thickness.
#let permute(..qubits, width: 30pt, separation: auto) = {
if qubits.named().len() != 0 {
assert(false, message: "Unexpected named argument `" + qubits.named().keys().first() + "` in function `permute()`")
}
mqgate(none, n: qubits.pos().len(), width: width, draw-function: draw-functions.draw-permutation-gate, data: (qubits: qubits.pos(), extent: 2pt, separation: separation))
}

/// Create an invisible (phantom) gate for reserving space. If `content`
Expand Down
Binary file added tests/gates/permute/ref/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion tests/gates/permute/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

#quantum-circuit(
2, permute(1,0), permute(1,0), 1, permute(2,0,1), 2, [\ ],
2, 4,permute(1,0), 1, [\ ],
2, 4, permute(1,0), 1, [\ ],
2, gate($H$), 5,
)

#pagebreak()

// Test separation parameter
#quantum-circuit(
1,
permute(1,0, separation: none),
permute(1,0, separation: 2pt),
permute(1,0, separation: red),
1, [\ ],
5
)

0 comments on commit 79dd644

Please sign in to comment.