Introduction to Quantum Circuits
Quantum circuits are essentially a sequence of quantum logic gates and measurements representing a quantum program. They form the most basic unit for describing and reasoning about quantum algorithms, much like classical circuits compose the fundamental building block of traditional computing.
By operating a series of quantum gates on qubits initialized to certain states, we can manipulate their superposition and entanglement to achieve desired computational transformations. The output is then read by measuring qubits to collapse their state onto classical bits for retrieval.
Mastering the composition and visualization of quantum circuit diagrams is an indispensable skill for quantum programming. Quantum circuits require whole new intuitions around manipulating mutable quantum states versus static classical data. In this chapter, we take a comprehensive look at the structure and essential components involved in modelling quantum state evolutions as circuits within Qiskit.
Table of Contents
Components of a Quantum Circuit
The schema of a quantum circuit consists of:
- Quantum Registers: To represent and contain qubit states
- Classical Registers: To store measurements
- Quantum Gates: Unitary operators manipulating qubit states
- Wires: Connecting qubits and classical bit flows
- Measurement: Collapsing quantum state into classical values
This quantum circuit repetitively applies gates to qubits in superposition and entangles them into joint states before finally measuring the transformed result. Now let’s delve deeper into what each of these components entails.
Quantum Registers for Qubit State Encoding
A quantum register represents an allocated array of qubits available to manipulate within a quantum program. For instance:
qr1 = QuantumRegister(5, 'q1') # Allocate 5 qubits with label q1
Here we have reserved 5 qubits tagged q1. Multiple registers can exist:
qr2 = QuantumRegister(3, 'q2') # Another register with 3 qubits
Registers are containers for qubits we apply operations on.
Classical Registers for Measurement Values
Classical registers store the bit values output when qubits are measured. For example:
cr = ClassicalRegister(8, 'c') # 8 bits labelled c
These classical bits can interface with external classical programs.
Composing Quantum Circuits
Registers are now combined to form a quantum circuit:
qc = QuantumCircuit(qr1, qr2, cr)
This circuit can manipulate qs’s 8 qubits storing outputs in cr. We are now ready to start adding quantum gates and operations.
Quantum Gates: Unitary Operators
Quantum gates manipulate qubit states. Some common single-qubit gates include:
- Pauli-X: Bit-flip or NOT gate, toggles between |0> and |1> states
- Hadamard (H): Puts qubit into equal superposition of basis states
- PhaseShift: Rotates the relative phase between |0> and |1>
Two-qubit gates like CNOT entangle multiple qubits. Gates are unitary operators preserving vector length.
For example, applying a Hadamard transform:
qc.h(qr1) # Apply H gate to the 3rd qubit
Rotations can be customized by specifying rotation angles. Multiple gates compose into the desired sequence.
Measuring Qubits onto Classical Bits
Once in the intended states, qubits are measured out onto classical bits:
qc.measure(qr1, cr[0:5]) # Measure qubits onto first 5 classical bits
The circuit’s manipulative power emerges from interfacing quantum parallelism with robust classical states through measurement. We can visualize the circuit diagram via the draw() method.
Assembling Quantum Circuits Modularly
Constructing valid gate sequences transforming input states into target output forms the basis of quantum circuit design. Common patterns like interference of alternative paths emerge. These low-level circuits are composed of larger modules building up complex algorithms.
In this section, we took a deep look into modelling quantum state evolutions as manipulatable circuits within Qiskit – comprising elements like registers, gates and measurements. Next, we will compile and execute these circuits on simulators and real hardware to understand their manipulated qubit behaviour. Being able to assemble quantum circuits modularly is critical to unlocking quantum computing’s potential through Qiskit.