author | description | ms.author | ms.date | ms.service | ms.subservice | ms.topic | no-loc | title | uid | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
QuantumWriter |
Learn how to visually represent simple and complex quantum operations with quantum circuit diagrams. |
v-benbra |
02/01/2021 |
azure-quantum |
core |
conceptual |
|
Quantum circuit diagrams |
microsoft.quantum.concepts.circuits |
This article covers conventions for quantum circuit diagrams. Quantum operations are easier to understand in a diagram than in the equivalent written matrix once you understand the visual conventions.
Consider for a moment the unitary transformation
Operations with this or greater complexity are ubiquitous in quantum algorithms and quantum error correction. A quantum circuit diagram is a convenient tool for illustrating the operations.
The circuit diagram for preparing this maximally entangled quantum state is:
In a circuit diagram, each solid line depicts a qubit or more generally a qubit register.
By convention, the top line is qubit register
is a Hadamard operation acting on a single-qubit register.
Quantum gates are ordered in chronological order with the left-most gate as the gate first applied to the qubits. In other words, if you picture the wires as holding the quantum state, the wires bring the quantum state through each of the gates in the diagram from left to right. That is to say
is the unitary matrix
All previous examples given have had precisely the same number of wires (qubits) input to a quantum gate as the number of wires out from the quantum gate. It may at first seem reasonable that quantum circuits could have more, or fewer, outputs than inputs in general. This is impossible, however, because all quantum operations, save measurement, are unitary and hence reversible. If they did not have the same number of outputs as inputs they would not be reversible and hence not unitary, which is a contradiction. For this reason any box drawn in a circuit diagram must have precisely the same number of wires entering it as exiting it.
Multi-qubit circuit diagrams follow similar conventions to single-qubit ones.
As a clarifying example, we can define a two-qubit unitary operation
We can also view
The other construct that is built into multi-qubit quantum circuit diagrams is control.
The action of a quantum singly controlled gate, denoted
Here the black circle denotes the quantum bit on which the gate is controlled and a vertical wire denotes the unitary that is applied when the control qubit takes the value
Q# provides methods to automatically generate the controlled version of an operation, which saves the programmer from having to hand code these operations. An example of this is shown below:
operation PrepareSuperposition(qubit : Qubit) : Unit
is Ctl { // Auto-generate the controlled specialization of the operation
H(qubit);
}
The remaining operation to visualize in circuit diagrams is measurement. Measurement takes a qubit register, measures it, and outputs the result as classical information. A measurement operation is denoted by a meter symbol and always takes as input a qubit register (denoted by a solid line) and outputs classical information (denoted by a double line). Specifically, such a subcircuit looks like:
Q# implements a Measure operator for this purpose. See the section on measurements for more information.
Similarly, the subcircuit
gives a classically controlled gate, where
Quantum teleportation is perhaps the best quantum algorithm for illustrating these components. You can learn hands-on with the corresponding Quantum Kata Quantum teleportation is a method for moving data within a quantum computer (or even between distant quantum computers in a quantum network) through the use of entanglement and measurement. Interestingly, it is actually capable of moving a quantum state, say the value in a given qubit, from one qubit to another, without even knowing what the qubit's value is! This is necessary for the protocol to work according to the laws of quantum mechanics. The quantum teleportation circuit is given below; we also provide an annotated version of the circuit to illustrate how to read the quantum circuit.