Skip to content

Commit

Permalink
[docs] improve guide, refactor some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mc-Zen committed Sep 27, 2023
1 parent 6d8ae06 commit 0ddb6f2
Show file tree
Hide file tree
Showing 10 changed files with 724 additions and 627 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Create circuit diagrams by calling the function `quantum-circuit()` with any num
<img alt="Bell Circuit" src="docs/images/bell.svg" style="max-width: 100%; padding: 10px 10px; box-shadow: 1pt 1pt 10pt 0pt #AAAAAA; border-radius: 4pt; box-sizing: border-box; background: white">
</h3>

Refer to the [user guide](https://github.com/Mc-Zen/quill/blob/main/docs/guide/quill-guide.pdf) for full documentation.
Refer to the [user guide](docs/guide/quill-guide.pdf) for full documentation.

## Gallery

Expand Down Expand Up @@ -70,9 +70,11 @@ Some show-off examples, loosely replicating figures from [Quantum Computation an
- Swap order of row and column parameters in `annotate` to make it consistent with built-in Typst functions.
- Improvements:
- Improve layout (allow row/column spacing and min lengths to be specified in em-lenghts).
- Automatic bounds computation, even for labels.
- Improve meter (allow multi-qubit gate meters and respect global (per-circuit) gate padding).d
- Fixes:
- `lstick`/`rstick` braces broke with Typst 0.7.0.
- `lstick`/`rstick` bounds.
- Documentation
- Add section on creating custom gates.
- Add section on using labels.
Expand Down
5 changes: 3 additions & 2 deletions docs/guide/gallery.typ
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
[Control], quantum-circuit(1, ctrl(0), 1), raw("ctrl(0)"),
[Open control], quantum-circuit(1, ctrl(0, open: true), 1), raw("ctrl(0, open: true)"),
[Target], quantum-circuit(1, targ(), 1), raw("targ()"),
[Swap target], quantum-circuit(1, targX(), 1), raw("targX()"),
[Swap target], quantum-circuit(1, swap(0), 1), raw("swap(0)"),
[Permutation \ gate], quantum-circuit(1, permute(2,0,1), 1, [\ ], 3, [\ ], 3), raw("permute(2,0,1)"),
[Multiqubit \ gate], quantum-circuit(1, mqgate($U$, n: 3), 1, [\ ], 3, [\ ], 3), raw("mqgate($U$, 3)"),
[lstick], quantum-circuit(lstick($|psi〉$), 2), raw("lstick($|psi〉$)"),
Expand All @@ -33,7 +33,8 @@
[Swap \  gate], quantum-circuit(1, swap(1), 1, [\ ], 1, targX(), 1), [#raw("swap(1)") \ + \ #raw("targX()")],
[Controlled \ Hadamard], quantum-circuit(1, mqgate($H$, target: 1), 1, [\ ], 1, ctrl(0), 1), [#raw("mqgate($H$,target:1)") \ + \ #raw("ctrl(0)")],
[Plain\ vertical\ wire], quantum-circuit(1, ctrl(1, show-dot: false), 1, [\ ], 3), raw("ctrl(1, show-dot: false)"),
[Meter to \ classical], quantum-circuit(1, meter(target: 1), 1, [\ ], setwire(2), 1, ctrl(0), 1), [#raw("meter(target: 1)") \ + \ #raw("ctrl(0)")],
[Meter to \ classical], quantum-circuit(1, meter(target: 1), 1, [\ ], setwire(2), 1, ctrl(0), 1), [#raw("meter(target: 1)") \ + \ #raw("ctrl(0)")],
[Classical wire], quantum-circuit(setwire(2), 3), raw("setwire(2)"), [Styled wire], quantum-circuit(setwire(1, stroke: green), 3), raw("setwire(1, stroke: green)"),
[Labels],
quantum-circuit(scale: 100%,
1, gate($Q$, label: (
Expand Down
730 changes: 320 additions & 410 deletions docs/guide/quill-guide.typ

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions docs/guide/template.typ
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
title: "",
abstract: [],
authors: (),
url: none,
date: none,
version: none,
body,
) = {
// Set the document's basic properties.
Expand All @@ -15,11 +17,16 @@
set heading(numbering: "I.a")
show heading.where(level: 1): it => block(smallcaps(it), below: 1em)

v(4em)


// Title row.
align(center)[
#block(text(weight: 700, 1.75em, title))
#v(1em, weak: true)
#date
#v(4em, weak: true)
v#version #h(1.2cm) #date
#block(link(url))
#v(1.5em, weak: true)
]

// Author information.
Expand All @@ -32,18 +39,19 @@
..authors.map(author => align(center, strong(author))),
),
)
v(4em)

// Abstract.
pad(
x: 2em,
top: 1em,
bottom: 1.1em,
align(center)[
#heading(
outlined: false,
numbering: none,
text(0.85em, smallcaps[Abstract]),
)
// #heading(
// outlined: false,
// numbering: none,
// text(0.85em, smallcaps[Abstract]),
// )
#abstract
],
)
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/typst-doc.typ
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#let type-box(type) = {
let color = get-type-color(type)
h(2pt)
box(outset: 2pt, fill: color, radius: 2pt, raw(type))
box(outset: 2pt, fill: color, radius: 2pt, raw(type, lang: ""))
h(2pt)
}

Expand Down Expand Up @@ -160,7 +160,7 @@
#let process-function-references(text, label-prefix: none) = {
return text.replace(reference-matcher, info => {
let target = info.captures.at(0).trim(")").trim("(")
return "#link(label(\"" + label-prefix + target + "()\"))[`" + target + "()`]"
return "#link(label(\"" + label-prefix + target + "()\"))[#raw(\"" + target + "()\", lang: \"\")]"
})
}

Expand Down
542 changes: 351 additions & 191 deletions docs/images/gallery.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/gates.typ
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
/// - size-hint (function): Size hint function. This function should return a dictionary
/// containing the keys `width` and `height`. The result is used to determine
/// the gates position and cell sizes of the grid.
/// Signature: `(gate, draw-params).`
/// Signature: `(gate, draw-params) => {}`.
/// - draw-function (function): Drawing function that produces the displayed content.
/// Signature: `(gate, draw-params).`
/// Signature: `(gate, draw-params) => {}`.
/// - label (array, string, content, dictionary): One or more labels to add to the gate.
/// Usually, a label consists of a dictionary with entries for the keys
/// `content` (the label content), `pos` (2d alignment specifying the
Expand Down Expand Up @@ -200,13 +200,13 @@
gate(thecontent, box: false, fill: none)
}

/// Target element for controlled #smallcaps("x") operations (#sym.plus.circle).
/// Target element for controlled-X operations (#sym.plus.circle).
/// - fill (none, color, boolean): Fill color for the target circle. If set
/// to `true`, the target is filled with the circuits background color.
/// - size (length): Size of the target symbol.
#let targ(fill: none, size: 4.3pt, label: none) = gate(none, box: false, draw-function: draw-functions.draw-targ, fill: fill, data: (size: size), label: label)

/// Target element for controlled #smallcaps("z") operations (#sym.bullet).
/// Target element for controlled-Z operations (#sym.bullet).
///
/// - open (boolean): Whether to draw an open dot.
/// - fill (none, color): Fill color for the circle or stroke color if
Expand Down
19 changes: 10 additions & 9 deletions src/quill.typ
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@



/// Create a quantum circuit diagram. Content items may be
/// - Gates created by one of the many gate commands (@@gate,
/// @@mqgate, @@meter, ...)
/// - `[\ ]` for creating a new wire/row
/// - Commands like @@setwire or @@gategroup
/// - Integers for creating cells filled with the current wire setting
/// - Lengths for creating space between rows or columns
/// - Plain content or strings to be placed on the wire
/// - @@lstick, @@midstick or @@rstick for placement next to the wire
/// Create a quantum circuit diagram. Children may be
/// - gates created by one of the many gate commands (@@gate,
/// @@mqgate, @@meter, ...),
/// - `[\ ]` for creating a new wire/row,
/// - commands like @@setwire, @@slice or @@gategroup,
/// - integers for creating cells filled with the current wire setting,
/// - lengths for creating space between rows or columns,
/// - plain content or strings to be placed on the wire, and
/// - @@lstick, @@midstick or @@rstick for placement next to the wire.
///
///
/// - wire (stroke): Style for drawing the circuit wires. This can take anything
/// that is valid for the stroke of the builtin `line()` function.
Expand Down
13 changes: 13 additions & 0 deletions tests/perf.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import "../src/quill.typ": *


#{
let arr = ()
for i in range(1000) {
arr.push(gate($#i$))
if calc.rem(i, 10) == 0 { arr.push([\ ]) }
}
quantum-circuit(
1, $H$, 1, ..arr
)
}
4 changes: 3 additions & 1 deletion typst.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ entrypoint = "src/quill.typ"
authors = ["Mc-Zen"]
license = "MIT"
description = "A library for creating quantum circuit diagrams."
homepage = "https://github.com/Mc-Zen/quill"
homepage = "https://github.com/Mc-Zen/quill"
exclude = [ "/docs/*"]
keywords = ["quantum circuit diagram", "quantikz", "qcircuit"]

0 comments on commit 0ddb6f2

Please sign in to comment.