Quill:0.4.0 ⚛ Enhanced quantum circuit diagrams

Quill is a package for creating quantum circuit diagrams in Typst.

Here you can find the repository, the user guide and more information.

As of the new update, there are two alternative models for building circuits - and they can be combined!

  1. The original grid-based model.
#import "@preview/quill:0.4.0": *

#quantum-circuit(
  lstick($|0〉$), $H$, ctrl(1), rstick($(|00〉+|11〉)/√2$, n: 2), [\ ],
  lstick($|0〉$), 1, targ(), 1
)

bell state preparation circuit

  • The circuit is layed out manually.
  • Gates are created via the gate() function or math elements as a short-hand.
  • Advancing to a different column without placing a gate can be achieved with integer elements, e.g., 1.
  • A new wire is started via the [\ ] element.

  1. The new version quill:0.4.0 now adds the submodule Tequila which enables building and composing circuits sequentially.
#import "@preview/quill:0.4.0": *
#import tequila as tq

#quantum-circuit(
  ..tq.build(
    tq.h(0),
    tq.cx(0, 1),
    tq.cx(0, 2),
  ),
  gategroup(x: 2, y: 0, 3, 2)
)

GHZ preparation circuit

  • Similar to how QASM and Qiskit work: gates are successively applied to the circuit which is then layed out automatically by packing gates as tightly as possible.
  • We start by calling the tq.build() function and filling it with quantum operations. This returns a collection of gates which we expand into the circuit with the .. syntax.
  • Now, we still have the option to add annotations, groups, slices, or even more gates via manual placement, i.e., gate($H$, x: 4, y: 2) and similar.

With Tequila, it is easy to build templates for quantum circuits and to compose circuits of various building blocks. For this purpose, tq.build() and the built-in templates all feature optional x and y arguments to allow placing a subcircuit at an arbitrary position of the circuit. As an example, Tequila provides a tq.graph-state() template for quickly drawing graph state preparation circuits.

#import tequila as tq

#quantum-circuit(
  ..tq.graph-state((0, 1), (1, 2)),
  ..tq.build(y: 3, 
      tq.p($pi$, 0), 
      tq.cx(0, (1, 2)), 
    ),
  ..tq.graph-state(x: 6, y: 2, invert: true, (0, 1), (0, 2)),
  // Mark the individual subcircuits
  gategroup(x: 1, 3, 3),       
  gategroup(x: 1, y: 3, 3, 3),
  gategroup(x: 6, y: 2, 3, 3),
  slice(x: 5)
)

image

Have fun designing the most beautiful quantum circuit diagrams :atom_symbol: :typstguy_science:

13 Likes

This looks really cool! Thanks a lot for the effort :slight_smile: :rocket:

1 Like