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:
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 Q Experience
Accelerate your research and applications with the next generation of the leading quantum cloud services and software…
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)
Anaconda Python/R Distribution - Free Download
The open-source Anaconda Distribution is the easiest way to perform Python/R data science and machine learning on…
Second Step, Install Qiskit library using (terminal on Linux and Mac & Anaconda prompt on Windows) and following command,
Qiskit is an open source software development kit (SDK) for working with OpenQASM and the IBM Q quantum processors…
pip install qiskit
Third Step, After qiskit installation type following command in the same terminal.
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,
- Import everything from qiskit.
- Get 2 quantum registers i.e. Qbits.
- Get 2 classical registers to measure the values in the quantum registers.
- Create a quantum circuit using registers.
- Matplotlib inline directive for graphics
- 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.
Controlled NOT gate
In computing science, the controlled NOT gate (also C-NOT or CNOT) is a quantum logic gate that is an essential…
So basically whenever qbit-0 is 1 then it will flip the value of qbit-1
if qbit-0 == 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.