Learning Library

← Back to Library

Simple Qiskit Program: Superposition and Entanglement

Key Points

  • The video recaps quantum fundamentals: qubits can exist in superposition (0, 1, or any combination) and become entangled, with state changes effected by quantum gates followed by measurement.
  • To program quantum computers, developers use a quantum SDK; the tutorial focuses on Qiskit, a Python‑based and widely adopted framework.
  • A simple Qiskit program is built by creating a quantum circuit with two quantum registers (for the qubits) and two classical registers (to store measurement results), then applying a Hadamard gate to put the first qubit into superposition and a CNOT (control‑not) gate to entangle the two qubits.
  • After applying the gates, the circuit measures both qubits with a “measure all” call, allowing the quantum outcomes to be read back into the classical world, and repeated runs on an ideal quantum computer reveal the expected probabilistic results.

Full Transcript

# Simple Qiskit Program: Superposition and Entanglement **Source:** [https://www.youtube.com/watch?v=Jx7IuJMYtJM](https://www.youtube.com/watch?v=Jx7IuJMYtJM) **Duration:** 00:05:58 ## Summary - The video recaps quantum fundamentals: qubits can exist in superposition (0, 1, or any combination) and become entangled, with state changes effected by quantum gates followed by measurement. - To program quantum computers, developers use a quantum SDK; the tutorial focuses on Qiskit, a Python‑based and widely adopted framework. - A simple Qiskit program is built by creating a quantum circuit with two quantum registers (for the qubits) and two classical registers (to store measurement results), then applying a Hadamard gate to put the first qubit into superposition and a CNOT (control‑not) gate to entangle the two qubits. - After applying the gates, the circuit measures both qubits with a “measure all” call, allowing the quantum outcomes to be read back into the classical world, and repeated runs on an ideal quantum computer reveal the expected probabilistic results. ## Sections - [00:00:00](https://www.youtube.com/watch?v=Jx7IuJMYtJM&t=0s) **Getting Started with Qiskit** - The speaker briefly revisits qubits, superposition, and entanglement before demonstrating how to write a simple two‑qubit program in Python using the Qiskit quantum SDK. - [00:03:11](https://www.youtube.com/watch?v=Jx7IuJMYtJM&t=191s) **Understanding the CNOT Gate and Entanglement** - The passage explains how a control‑NOT gate entangles two qubits, yields only 00 or 11 measurement outcomes with equal probability, and demonstrates this using a simple Qiskit program. ## Full Transcript
0:00In my previous video, I talked about what quantum  computing is and what makes it special. But as 0:06a developer, I'm sure you want to know how to  actually write a piece of code that would run 0:10on a common computer. But before we dive into  that, let's just do a little bit of a quick 0:15recap. Instead of the classical bits of 0s and 1s,  quantum computers use qubits. A qubit can be a 0, 0:27a 1, or any linear combination of the two.  And that is what we called a superposition. 0:36We can also entangle multiple qubits. So their states become strongly correlated. In order 0:43to change the states of qubits, we apply  a series of gates, similar to the classical 0:48logic gates. And in the end, we want to measure  these qubits so we can get the results. 0:55So how do we take all these concepts into  code? And the answer is simple. We use a 1:02quantum software development kit. In  this video, we will be using Qiskit. 1:09Which is the most widely used quantum SDK today. 1:13Qiskit is based on Python, which is fairly simple  to learn, even if you've never used it before. 1:19So let's write a simple program in his Qiskit. In this program, we will use two qubits. 1:28We will put one into superposition, entangle it with the other, and then 1:34do a measurement of both of them. And  of course, all that is done using gates. 1:42So let's start by importing quantum circuit from  Qiskit. We then can create a quantum circuit 2:04with two quantum registers  and two classical registers. 2:09The quantum registers are used for quantum 2:13computation. One for each qubit. And the classical  registers are used to store the measured results. 2:25We need a classical registers because  even though the physical world is quantum, 2:29the majority of the classical  world is still classical. 2:33And the classical registers allow us to bring  quantum information back into the classical world. 2:40So the next thing we want to do is  apply some gates. And in this program, 2:44we're going to apply two gates. The  first one is the Hadamard gate 2:51on qubit 0. The Hadamard gate puts  the qubit into a superposition between 0 2:59and 1. That means it now has an equal  chance of being measured a 0 or 1. 3:06The next gate we need is the control  not gate, or "cx" for short. 3:15The control not gate is a conditional two qubits gate. It has a control qubit 3:24and the target qubit. 3:30Without superposition, the control  not gate is fairly simple to understand. 3:35That is, it is as if the state of the control qubit is  1, then you flip the state of the target qubit. 3:44And that's why it's called control not. 3:49And because the states of least two  qubits are now strongly correlated, 3:53we now say they are entangled. So the  last thing we want to do is actually do 3:58measurements so we can get the outputs. And we  do this by calling the measure all function. 4:06And there you have it. We just wrote a simple  quantum program using Qiskit. Now, if you take 4:13this program and run it a bunch of times on an  ideal quantum computer, you'll find out that 4:18there's a 50% chance of the outputs being 00 and  50% chance of it being 11. But you would never 4:26be a 01 or 10. The 50/50 of the first  qubit comes from the superposition. And while 4:36we didn't explicitly change the state of the  second qubit, it got changed anyway because 4:42it is entangled with the first qubit.  So it changes with the first qubit. 4:52So in this program, we created a quantum  circuit which operates at the same level 4:57as classical assembly language and allows you  to efficiently manipulate the qubits directly. 5:04However, if you're not fond of  playing with low level circuits, 5:07Qiskit also offers a number of higher  level algorithms. For example, Qiskit has 5:15a package focusing on machine learning that has  a number of pre-built classes. You can take a 5:22quantum kernel class, use it to train and test  data. You can then take this trained quantum 5:30kernel and pass it into a classical algorithm  such as the support vector classification 5:36from scikit-learn. Then you can then  accelerate your classical application. 5:44Thanks for watching. If you have any questions,  please leave them in the comments below. 5:49Also, please remember to Like this  video and Subscribe to our channel 5:53so we can continue to bring you  content that matters to you.