Quantum Computing, Programming

Introduction to Quantum Computing with Python and Qiskit

First steps into the realm of quantum computing

Bala Priya C
Oct 16 · 6 min read
Image for post
Image for post
Photo by Michael Dziedzic on Unsplash

What is Quantum Computing?

What is a Qubit ?

Superposition and Schrodinger’s cat

Image for post
Image for post
Schrodinger’s cat (Image credits: https://betterexplained.com/articles/gotcha-shrodingers-cat/)

Entanglement

Getting started with the Qiskit Library

!pip install qiskit
!pip install matplotlib
from qiskit import QuantumRegister,ClassicalRegister,Aer,execute
import Our_Qiskit_Functions as oq
# Initializing backend simulators to visualize circuits
S_simulator = Aer.backends(name='statevector_simulator')[0]
Q_simulator = Aer.backends(name='qasm_simulator')[0]
# Creating quantum registers to hold quibits
q = QuantumRegister(2)
# Creating classical registers to hold bits
c = ClassicalRegister(2)
# Create a quantum circuit with these registers
qc=quantumCircuit(q,c)

Understanding Quantum Gates

Image for post
Image for post
Identity Gate (Image Source)
# Identity Gate
qc.iden(q[0])
print(oq.Wavefunction(qc))
qc.draw(output = “mpl”)
Image for post
Image for post
NOT Gate (Image Source)
# NOT gate
qc.x(q[0])
print(oq.Wavefunction(qc))
qc.draw(output = "mpl")
Image for post
Image for post
Controlled NOT Gate (Image Source)
# Controlled-NOT gate
qc.cx(q[0],q[1])
print(oq.Wavefunction(qc))
qc.draw(output = "mpl")
Image for post
Image for post
Hadamard Gate (H) (Image source:https://www.picuki.com/media/2242281885485368924)

Quantum Circuit Simulators

Our First Quantum Circuit

Image for post
Image for post
Example State: | 1011 ⟩
Image for post
Image for post
Putting together the Quantum Circuit in Circuit Composer
# Create the circuit and add the gates
q = QuantumRegister(5)
c = ClassicalRegister(4)
qc = QuantumCircuit(q,c)
qc.x(q[0])
qc.x(q[2])
qc.x(q[3])
qc.cx(q[3],q[4])
qc.cx(q[4],q[3])
qc.draw(output = "mpl")
Image for post
Image for post
FinalCircuit
# Execute the circuit
ex = execute(qc, Q_simulator, shots = 1024)
res = ex.result()
M = res.get_counts(qc)

# Plot the results
plot_histogram(M, bar_labels=False)
Image for post
Image for post
The output is 1010

Towards AI

The Best of Tech, Science, and Engineering.

Sign up for Towards AI Newsletter

By Towards AI

Towards AI publishes the best of tech, science, and engineering. Subscribe with us to receive our newsletter right on your inbox. For sponsorship opportunities, please email us at pub@towardsai.net Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Thanks to Towards AI Team

Bala Priya C

Written by

Math,Signal Processing & Machine Learning Enthusiast| Passionate about Women in Tech and Diversity & Inclusion

Towards AI

Towards AI is a world’s leading multidisciplinary science publication. Towards AI publishes the best of tech, science, and engineering. Read by thought-leaders and decision-makers around the world.

Bala Priya C

Written by

Math,Signal Processing & Machine Learning Enthusiast| Passionate about Women in Tech and Diversity & Inclusion

Towards AI

Towards AI is a world’s leading multidisciplinary science publication. Towards AI publishes the best of tech, science, and engineering. Read by thought-leaders and decision-makers around the world.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface.

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox.

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic.

Get the Medium app