Qiskit: Creating a Quantum Circuit

Creating a Quantum Circuit is the basic requirement to getting started with working on Quantum Computing. Creating a Quantum Circuit with Qiskit is as easy as it can get. In this chapter of the Qiskit Tutorial, you will learn about creating Quantum Circuit and vizualizing it using Qiskit.


Quantum Register

A Quantum Register is a system of many Qubits. A Quantum Register can be created in Qiskit by using the QuantumRegister class and passing it the number of Qubits required in the Quantum Register.

# Creating a Quantum Register qr with 2 Qubits
qr = QuantumRegister(2)

Classical Register

A Classical Register is a system of many bits. Bits in classical registers are used for storing the measured values of Qubits in Quantum Registers. A Classical Register can be created in Qiskit by using the ClassicalRegister class and passing it the number of bits required in the Classical Register.

# Creating a Classical Register cr with 2 bits
cr = ClassicalRegister(2)

Quantum Circuit

A Quantum Circuit consists of Quantum Register and Classical Registers which are used for measuring the states of Quantum Register. Once the Quantum Circuit is created, it is possible to perform various operations on the Qubits as well as measuring them. A Quantum Register can be created in Qiskit by using the QuantumCircuit class and passing it the Quantum Register and Classical Register.

# Creating a Quantum Circuit qc using Quantum Register qr and Classical Register cr
qc = QuantumCircuit(qr, cr)

Alternatively, the Quantum Circuits can be created by passing the QuantumCircuit class the number of Qubits and bits required in the Quantum Circuit instead of passing instances of QuantumRegister and ClassicalRegister class.

# Creating a Quantum Circuit qc 2 Qubits and 2 bits
qc = QuantumCircuit(2, 2)

Visualizing Quantum Circuits

Qiskit allows you to visualize your Quantum Circuits. This is especially needed after performing various operations on your Quantum Circuit. Visualizing a Quantum Circuit can be done by calling the draw() method on the Quantum Circuit.

qc.draw()

The draw() method draws the Quantum Circuit. In this particular example, we have not performed any operation on any Qubit or bit, and therefore, the Quantum Circuit vizualization shows just the Qubits and bits.

qiskit quantum circuit

Note– Notice that all the Qubits are shown separately(as q_0, q_1), whereas all the bits are clubbed together(as c) into a Classical Register and the number shown next to it representing the number of bits.