An Introduction to Quantum Programming in Quipper
Quipper is a recently developed programming language for expressing quantum computations. This paper gives a brief tutorial introduction to the language, through a demonstration of how to make use of some of its key features. We illustrate many of Quipper’s language features by developing a few well known examples of Quantum computation, including quantum teleportation, the quantum Fourier transform, and a quantum circuit for addition.
💡 Research Summary
The paper “An Introduction to Quantum Programming in Quipper” serves as a tutorial‑style guide to the functional quantum programming language Quipper, which is embedded in Haskell. It begins by positioning Quipper within the IARP‑funded QCS project, whose goal is to accurately estimate the resources required for realistic quantum algorithms. The authors stress that Quipper is not merely a circuit description language but a full‑featured DSL that leverages Haskell’s expressive power while introducing its own abstractions to keep quantum‑specific constraints visible to the programmer.
A central theme is the explicit separation of three kinds of data: Bool (compile‑time parameters), Bit (classical inputs known only at execution time), and Qubit (quantum inputs). This tri‑type system mirrors the three phases of execution—compile time, circuit generation time, and circuit execution time—allowing the language to reason about ancilla allocation, measurement, and classical control in a disciplined way. The paper explains how Quipper’s extended circuit model supports both quantum and classical wires, controlled operations (quantum‑controlled by classical bits are forbidden), and scoped ancillae via explicit qinit and termination.
The tutorial proceeds through three representative quantum algorithms. First, quantum teleportation is built from the ground up. Primitive gates (hadamard, qnot ‘controlled‘ a) are wrapped in monadic Circ functions such as plus_minus and share. The authors illustrate how to compose these building blocks into higher‑level functions (alice, bob, bell00) and finally into a complete teleportation circuit (teleport). The example demonstrates Quipper’s linear‑use discipline (each qubit is written once and read once) and its generic measure operator, which can act on any data structure containing qubits.
Next, the paper introduces generic programming via the QShape type class. By declaring that three related types—Boolean, classical, and quantum—share the same shape, users can write functions that automatically lift to any composite data type (tuples, lists, etc.). Functions such as mapUnary, mapBinary, and mapBinary_c are used to apply unary or binary quantum operations across entire structures. The authors rewrite the teleportation example in a fully generic form (teleport_generic), showing that the same code can teleport a pair of qubits, a list of three qubits, or any other shape without modification. The generic version also requires a more flexible printing primitive (print_generic) that takes an explicit shape argument to select a concrete instance for visualization.
The third major example covers the quantum Fourier transform (QFT) and a quantum addition circuit. Here recursion over a list of qubits is employed to express the QFT succinctly. Base cases handle empty and singleton lists; the recursive case applies a controlled rotation followed by a recursive call on the tail, mirroring the textbook textbook definition. The authors also demonstrate “boxing” sub‑circuits to encapsulate reusable components and discuss how Quipper can simulate the generated circuits, providing gate‑count and depth statistics useful for resource estimation.
Throughout the paper, the authors emphasize practical tooling: print_simple and print_generic for exporting circuits to PDF or other formats, comment_with_label for annotating large diagrams, and the ability to lazily generate circuits so that even very large constructions need not be held entirely in memory. They also note pitfalls of the embedded approach, such as cryptic error messages that refer to Haskell types and the temptation to “escape” into host‑language code, which can break abstraction barriers.
In summary, the paper showcases Quipper’s blend of high‑level functional abstraction (monads, type classes, generic programming) with low‑level quantum gate control. By walking through teleportation, generic teleportation, QFT, and addition, it demonstrates that Quipper can express non‑trivial quantum algorithms concisely, support modular design, enable systematic resource analysis, and produce human‑readable circuit diagrams. This makes Quipper a valuable platform for both quantum algorithm researchers and developers preparing code for near‑term quantum hardware.
Comments & Academic Discussion
Loading comments...
Leave a Comment