We have reached in an era where we can now implement basic AND, OR and XOR logics on quantum circuits similar to the classical computing and we call this era as Quantum Era.
This article is a simple introduction to Applied Quantum Computing (AQC) where we will code a Hello World program on real quantum chip š .
But waitĀ ā¦ I donāt have a quantum computer so how can I even do thatĀ ???
And there is a very simple solution for this, with companies like IBM and Google actually making quantum devices we can leverage them to build and test stuffs on real devices with ZERO setup of whatsoever.
So here is our tech stackĀ :
So letās get our hands entangled. š
Quantum computers are based on quantum bits, also known as qubits. They have two possible values (states) as 0
and 1
, similar to the one we have in the classical computer. But the laws of quantum mechanics also allow other possibilities, which we call superposition states.
A Quantum Computer created by IBM combining the quantum registers.
Quantum computing could enable exponential speedups for certain classes of problems by exploiting superposition and entanglement in the manipulation of quantum bits (qubits). One such example is using quantum computing in Artificial Intelligence space, we can implement an optimisation algorithm(s) which can use the properties of superposition and help in speeding up the optimisation problem which can eventually lead to better and faster learning algorithm(s).
Quantum Annealing OptimizerĀ : Computing multiple local and global minima at aĀ time.
Using quantum annealing in classical Boltzmann machine, the weight discovery process can be made quantum mechanical, which can help us to find pattern which we couldn't find using classical annealing process (SGD).
Which can be a key towards Artificial General Intelligence (AGI).
There have been lots of development made recently in the space of QC and all the major player in market are trying to make revolutionary break thru. Some of them are listed below:
Image SourceĀ : www.qilimanjaro.io
Letās implement our first Hello World program using quantum registers.
Colab linkĀ : https://colab.research.google.com/drive/1gVet-CcDbsCgOjhtNg9gCvlE7PHIYuQP
Github link: https://github.com/goodrahstar/hello-quantum-world
To start with quantum programming we will use Open Source Quantum Information Science Kit (QISKit). Itās a rapidly growing open source community making efforts to bring quantum computing easily accessible for larger audience.
For more: https://github.com/QISKit
pip install qiskit
Now that we have the package setupāed lets get familiar with the programming paradigm in quantum world. There are 4 major components for quantum programming.
We will initialize the quantum program, create a quantum register with 2 qubits and a classical register with 2 bits and set them into the circuit using below scripts:
from qiskit import QuantumProgram
**# Create a QuantumProgram object instance.**qp = QuantumProgram()
# Create a Quantum Register called "qr" with 2 qubits.qr = qp.create_quantum_register('qr',2)
# Create a Classical Register called "cr" with 2 bits.cr = qp.create_classical_register('cr',2)
**# Create a Quantum Circuit called "qc" involving qr and cr.**qc = qp.create_circuit('HelloWorldCircuit', [qr],[cr])
Once we have our circuit ready, we need to run it on a quantum computer. And here comes the real fun. š
We will connect to a real quantum chipset and execute quantum operations on our HelloWorldCircuit. Here I am using IBM-Q deployed chipsets which has various options like:
They are still in development phase and by the time you are reading this article they may get deprecated. So to get updated list look here.
To access these chipsets you will need an account on IBM Quantum Experience. And generate the token from here.
Set the backend as ibmqx5, provide your token and setup the connection. If the token is valid and the backend is configured then you are all set to access the quantum power.
backend = 'ibmqx5'
token = 'a7dbfb3cfc1252c4a7555020c32808cff17102a467c595801371f7b7f1f7c3a3355d565469aa4a37564df269f3710f33d7d13ba3c900ca947c1513598b64c5e7'
qp.set_api(token,url='https://quantumexperience.ng.bluemix.net/api')
Now its time to compose our circuit and execute the experiment.
Steps to create our Hello World circuit:
Our Hello WorldĀ circuit.
# Add the H gate in the Qubit 1, putting this qubit in superposition.qc.h(qr[1])
# Add the CX gate on control qubit 1 and target qubit 0, putting the qubits in a Bell state i.e entanglementqc.cx(qr[1], qr[0])
# Add a Measure gate to see the state.qc.measure(qr[0],cr[0])qc.measure(qr[1],cr[1])
# Compile and execute the Quantum Program in the ibmqx5results = qp.execute(['HelloWorldCircuit'] ,backend ,timeout=2400)print(results.get_counts('HelloWorldCircuit'))
Now when we examine the results you will see 4 quantum states 0000, 0001, 0010,0011 each having some probabilities associated with it.
So this depicts that all the four states co-exists at a givenĀ time.
{ā00ā: 488, ā01ā: 90, ā10ā: 58, ā11ā: 388}
CongratulationsĀ !!! š š You just experienced the 2 basic properties of quantum world i.e Superposition and Entanglement.
In this article we just touched the surface of quantum computing and there are lot more happening around. Here are some great links to keep up with the domain.