Getting started with Development in Quantum Computing

Utkarsh Mehta
Dec 14, 2019 · 5 min read

There is lot of buzz about Quantum computing in the tech industry and the race to the Quantum supremacy is also making rapid innovation in the field.

So let’s dive in with the difference between Quantum and Classical computers to get the initial idea about Quantum Computers,


When Classical computer were just some registers on boards and scientists were performing basic functionality on them, that is the current state of Quantum computers right now.

So Quantum Researchers are working on developing new Circuits (these are Quantum Circuits made using gates which executes a particular operation) and Algorithms to find new use cases & applications for Quantum Computers.

Following companies are researching and developing Quantum computers:

IBM (https://www.ibm.com/quantum-computing/)

Microsoft (https://www.microsoft.com/en-in/quantum/)

Google (https://ai.google/research/teams/applied-science/quantum/)

D'Wave (https://www.dwavesys.com/quantum-computing)

Intel (https://www.intel.in/content/www/in/en/research/quantum-computing.html)

So we are focusing on IBM here, as they have plugged their Quantum Computer worth millions to the cloud and provided access to the whole world for free.

So in order to work on Quantum Computer you don’t need to be a Quantum Physicist.

You just need to understand basics of Maths, other things you can pick up as you move forward.

IBM provides jupyter notebook based environment on their website to code and test on their quantum computers or simulators. But it’s always better to work directly so from our system so let’s setup the working environment on our systems.

First Step, Download & Install Anaconda Python (make sure you download Python 3.7 version or more)

Second Step, Install Qiskit library using (terminal on Linux and Mac & Anaconda prompt on Windows) and following command,

pip install qiskit

Third Step, After qiskit installation type following command in the same terminal.

jupyter notebook

So now you can start coding in python3 for IBM Quantum Computers from here.

So Jupyter Notebook makes it really easy to use Python 3 environment and for continuous development and the main feature I feel is that you can just write a line of code and press shift enter and see the output of that code immediately or you can shift between lines of code or fix bugs and rerun a particular block of code basically it just makes it really easy to develop and debug applications.

So, let’s create a Quantum Circuit,

Line wise explanation,

  1. Import everything from qiskit.
  2. Get 2 quantum registers i.e. Qbits.
  3. Get 2 classical registers to measure the values in the quantum registers.
  4. Create a quantum circuit using registers.
  5. Matplotlib inline directive for graphics
  6. Draw the circuit which looks like following,

I know it looks confusing let draw it like we are not in 90's.

mpl stands for matplotlib

Now let’s add some gates. First up is H gate also known as Hadamard Gate (https://www.quantum-inspire.com/kbase/hadamard/). In short it sets the state of a single qubit in Superposition.

In superposition a quantum bit can be 0 and 1 at the same time.

So we added H gate on first qbit. Moving ahead we will add a Controlled Not (CX) gate from qbit 0 to qbit 1.

So basically whenever qbit-0 is 1 then it will flip the value of qbit-1

if qbit-0 == 1

qbit-1 =Flip(qbit-1)

if qbit-0 = 1 & qbit-1 = 0 then CX will set qbit-1 to 1

if qbit-0 = 1 & qbit-1 = 1 then CX will set qbit-1 to 0

Now as we have a very basic circuit ready let’s add some measurements to this.

Here what we are doing is measuring all the qbits in qr and saving the values in all the classical bits cr.

Basically qbit-0 -> cbit-0 & qbit-1 -> cbit-1.

Now let’s run this code on a qasm_simulator, provided in qiskit.

So here we got the simulator from Aer which is a part of qiskit. Then we passed the circuit and simulator to execute function again comes with qiskit.

Then in order to visualise the results we are using plot_histogram.

So you can see that we got almost 50/50 result for 00 && 11, and if you remember the way we designed the circuit, H gate will make the output of q0 as 0 and 1, after that the CX gate will set the output of q1 as 1 when q0 is 1 or 0. So the output we got is right.

So guys this is it for now, in the next post i will introduce you with some new algorithms to use with quantum circuits and we will execute our quantum circuit on IBM quantum computers.

Thanks!! ✌️

Tarka Labs Blog

Tarka Labs is a team of passionate hackers, designers and product managers. We believe in experimental methods to identify the best solutions to problems instead of working on technology du jour. Visit us at https://tarkalabs.com/

Utkarsh Mehta

Written by

Tarka Labs Blog

Tarka Labs is a team of passionate hackers, designers and product managers. We believe in experimental methods to identify the best solutions to problems instead of working on technology du jour. Visit us at https://tarkalabs.com/

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade