Programming Your Quantum Computer

A Programmable Stovepipe

The prospect of greater computing power in quantum systems is intriguing, but it comes with some awkward constraints. To begin with, every function computed by a quantum system must be fully reversible. If the machine grinds up input A to produce output B, then it must have a way to reconstruct A when given B. A corollary is that every function must have the same number of inputs and outputs. In one stroke, this rule outlaws most of arithmetic as conventionally practiced. The usual addition algorithm, for example, is not reversible. You can add 3 and 4 to get 7, but you can’t “unadd” 7 to recover the original inputs 3 and 4. To add reversibly, you must avoid erasures, preserving enough information to retrace your steps. Reversible methods exist for all computable functions, but they require some mental adjustments in one’s approach to problem solving.

Another no-no in quantum computing is copying a qubit. (This principle is called the no-cloning theorem.) Nor can you arbitrarily set or reset qubits in the middle of a computation. Attempting to do so would destroy the quantum superposition.

Taken together, the restrictions on qubit operations imply that any quantum program must have a stovepipe architecture. Reversible quantum logic gates are lined up in sequence, and information flows straight through them from one end to the other. Of particular importance, the program structure can have no loops, where control is transferred backward to an earlier point so that a sequence of instructions is traversed multiple times.

Taken together, the restrictions on qubit operations imply that any quantum program must have a stovepipe architecture. Reversible quantum logic gates are lined up in sequence, and information flows straight through them from one end to the other. Of particular importance, the program structure can have no loops, where control is transferred backward to an earlier point so that a sequence of instructions is traversed multiple times.

Loops and conditional branching are indispensable tools in classical computer programming. How can we possibly get along without them? Anyone building a pure quantum computer will have to confront this difficult question. As a practical matter, however, the answer is: Don’t build a pure quantum computer. Build a classical computer with a quantum subsystem, then create appropriate software for each part. The quantum programming languages QCL and Quipper both acknowledge this reality, though in different ways.