Skip to main content

Hello World! in Quantum Computing


 “Hello World!” will be everyone’s first program. In the context of quantum computing, this is very different. In quantum computing, implementing superposition and entanglement is akin to writing a hello world program. This blog discusses the implementation of several fundamental quantum gates used in quantum computing. For implementation, I’m utilizing IBM’s Qiskit open-source package and the Python programming language.

Please review my earlier blogs on superposition and entanglement, as well as quantum gates and qiskit, before delving into the implementation, assuming you are familiar with or at least have a basic understanding of the Python programming language.

Qiskit is an open-source software development kit for working with quantum computers at the level of circuits, pulses, and algorithms. It provides tools for creating and manipulating quantum programs and running them on prototype quantum devices on IBM Quantum Platform or on simulators on a local computer. Before starting complete initial setup by installing qiskit, refer more here.

Quantum Gate’s

While quantum gates are conceptually similar to traditional logic gates, their reversibility is their defining feature. The number of quantum gates is vast, but I’m going to restrict myself to the minimum necessary for this blog. For further information on quantum gates, take a look here.

Pauli X or Quantum Not gate


The Pauli X gate is exactly similar to the NOT gate. Given an input X, the gate will flip the bit.



When we measure Qubit q[0], we will get the desired output.X∣0⟩ → ∣1⟩
X∣1⟩ → ∣0⟩

Hadamard Gate

This is one of the most important gates in quantum mechanics since it helps us realize the superposition of qubits. The below shows how Hadamard Gate transforms ∣0⟩ and ∣1⟩ into their respective superposition states.


H∣0⟩ → ∣+⟩

H∣1⟩ → ∣-⟩


where ∣+⟩=1/√2[∣0⟩+∣1⟩] and ∣-⟩=1/√2[∣0⟩-∣1⟩]. To understand this better, please look below at the probability distribution from IBM simulator.

∣0⟩ and ∣1⟩ were equally distributed here.

C-NOT gate 

After Hadamard, C-NOT is the other most important gate, as it helps us generate entanglement states from superposition. C-NOT is a bassically two-qubit gate. One qubit has to act as control, and the other has to act as target. The way it works is that whenever the control qubit is ∣0⟩, it does nothing to the target qubit; on the other hand, when the control qubit is ∣1⟩, it flips the bit of the target qubit; basically, it applies the “X gate to the target qubit". In general, CNOT helps us implement and realize various quantum circuits, starting from entanglement to algorithms and much more. Refer to the to the below images from IBM Composer for more understanding.


C-NOT applied together with Hadamard to generate entanglement.



Equal probability distribution of ∣00⟩ and ∣11⟩, however ∣10⟩ and ∣01⟩ will be vanished eventually.

We have learned enough about quantum computing to write the code for our Hello World application. I indicated before that creating an entangled state is often thought of as the “hello world” of quantum computing. The source code for one of the Bell states is going to be shared in this blog. Next question: What does the bell mean?

Bell state 

The states that are maximally entangled in two qubits are referred to as Bell states. To be more specific, there are a total of four bell states, which are collectively referred to as bell states or bell pairs. Please see the image below
Image credit to quantum computing stock exchange.

We can simulate the bell state using above mentioned X and Hadamard gate. I have included the circuit below, and I suggest you try implementing these circuits at IBM quantum computing composer.
Circuit diagram for Bell states. Image credit ResearchGate


But our aim is to generate these states using python code. Ok let’s dive into the code.

Step 1 : Import required packages

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister

Step 2 : Initialize quantum and classical registers and define quantum circuit.

qubit = QuantumRegister(2)
bit = ClassicalRegister(1)
circuit = QuantumCircuit(qubit, bit)

Step 3 : Apply Hadamard gate on qubit q0 and CNOT gate as control on q0 and target at q1.

circuit.h(q0)
circuit.cx(q0,q1)

Our two qubit entanglement, or one of the four bell states, has been successfully established. That is conclusive. Congratulations on successfully completing your quantum computing “hello world” project. It may appear to be a little challenging for novices, but believe me when I say that this is nothing more than the equivalent of “print(“Hello World!”)” in Python. Furthermore, if you would like to view the circuit, utilize the piece of code that is provided below.

circuit.draw(‘mpl’)

1/√2[∣00⟩+∣11⟩] bell state

For the above code, I would appreciate it if you could test it out on your own for additional bell states, and if you have any questions, please don’t hesitate to get in touch with me. Please leave a comment with your thoughts on this blog, and feel free to make suggestions for blogs that will be published in the future.

See Yaa,

Thirumalai Manimaran

Comments

Popular posts from this blog

One Brave Qubit Refusing DeCoherence

Hey there,  I'm wrapping up my year long exploration around quantum tech in 2025, yes this is my second of its kind next to "Kutty Story on Quantum -  Wrap of my Quantum Odyssey 2024". To be honest I was so active by last year, yet I started my career in Quantum in 2025, a transition phase from academic to industry. Ok whatever let's wrap it up, FYI you may not expect any scientific details in quantum, its all about personal journey in Quantum tech. I was in huge disappointment by dec 2024, so I did planned lot of things as expected I'm not able to execute many. I spend very less amount of time in my thesis compared 2024, and yes it has been submitted successfully. Graduated from IIT Jodhpur - Masters in Quantum Technology. Really so thankful to QIC department, IIT Jodhpur, especially inspiring Professors such as Prof Atul Kumar, Prof V Narayanan, Prof Kirankumar Hiremath and others. I really made lot friends and all my batchmates are in very good place now, I wis...

Kutty Story on Quantum - Wrap of my Quantum Odyssey 2024

 First of all if you have made to this page, thanks for making. Just a note the following will be a personal blog about my journey on Quantum tech in 2024. If at all you know me in person you might like the story and if you are someone who is working in Quantum Tech you might have some key takeaways. Again this going to be completely about Me and Quantum, so I’ll be bragging myself here and there. Ok Let’s dive… What you Seek is Seeking you ! I personally believe that Quantum is the one opted me and I’m just dancing through it, anyway I have to dance carefully hereafter. This year started with Bangg!! As a batch we have started Quantum Club at IIT Jodhpur and the whole batch elected me as Secretary, that moment I decided that it going to be a huge responsibility, since I was completely new to this field at that time and there are lot of Scholars in campus are already working extensively in Quantum tech for years. Anyways I knew that I can handle this, however most places I have str...

Once Upon a time in Physics: The Birth of Quantum Physics

  I was first introduced to the world of quantum mechanics through popular media like Marvel movies and online videos. As I advanced in my higher education, I found myself increasingly fascinated by the fundamental principles of quantum physics. What I realized is that the actual facts and phenomena, like quantum tunneling, quantum teleportation, quantum algorithms, quantum machine learning, quantum communication, etc., within the realm of quantum mechanics are often more astonishing and mind-boggling than the speculations and mysteries that occasionally surround them. One captivating example of this is the intriguing concept of quantum teleportation. The concept of quantum mechanics has generated a significant amount of excitement among people from various backgrounds. Quantum is no longer confined to the realms of science fiction or specialised scientific knowledge. This article aims to introduce the origins of quantum mechanics in simpler terms without delving too deeply into co...

Overview of Quantum Machine Learning (QML)

QML — It’s a complete new domain of research area which combines Principle of Quantum Computing and Machine Learning together. This is one of sub-group of Quantum computing. There will be series of blogs on QML starting from encoding mechanism to optimization. Not just limited to theory, there will be python code implementation as well. Qiskit will be the predominant library and here and there we will touch upon Pennylane and Cirq. So before continuing Quantum Computing, Machine learning and Deep Learning Algorithms, Qiskit, Pennylane will be considered as pre requisite. Image generated by napkin.ai One big question arises Why someone need QML ? There are some problems which cannot be solved classically, where quantum computing helps to achieve it with better performance. In some cases QML has given good results than classical machine learning. However QML is not as easy as ML, the difficulty starts with data encoding itself. One has to encode classical dataset into respective quantum ...

Spooky Action at a Distance - The EPR Paradox

 Einstein’s paper with his two postdoctoral research companions, Boris Podolsky and Nathan Rosen, was the great EPR paradox .”Can Quantum Mechanical Description of Physical Reality Be Considered Complete?” asks the paper.(1935). You might be surprised to learn that Einstein was the one who laid the groundwork for quantum mechanics in its early stages, only to propose that quantum physics is incomplete. Some refer to this as Einstein’s great mistake, which led to a tremendous quantum discovery. In this blog, I will discuss EPR briefly. However, it takes a fundamental understanding of quantum characteristics, which I am here to simplify. Even now, this study is regarded as one of the top ten most influential publications ever published in the field of physics. The argument over EPR continues to this day. One common misconception is that quantum communications are faster than or close to the speed of light, which is not true. EPR proposes something similar. This contradiction is argue...

Superposition and Entanglement

  The two notable terms that attract people to quantum physics are superposition and entanglement. These two characteristics really have a significant impact on quantum computing. Superposition and entanglement will be utilized in quantum communications and information storage, respectively, in the future. Computers were typically controlled in bits, which are represented as 0 or 1. On the other hand, quantum computing makes use of quantum bits, or qubits, which exist in a condition known as the superposition state, which is a combination of 0 and 1. Let’s imagine that we can anticipate both a head and a tail result when a coin is thrown. However, a coin can exist in both the head and tail states in a quantum world. In physics, you may have studied the dual nature of light. We discovered that light behaves as both a wave and a particle in Young’s Double Slit Experiment with Interference Pattern. The method of experimentation determines the character of light. demonstrated how light...