How to program a quantum computer using Qiskit

IBM Technology
2 Jun 202205:59

Summary

TLDRThis video offers an introduction to quantum computing and coding with Qiskit, a popular quantum software development kit based on Python. The presenter explains the basics of qubits, superposition, and entanglement, then demonstrates how to write a simple quantum program using Qiskit. The program involves creating a quantum circuit with two qubits, applying a Hadamard gate for superposition and a control not gate for entanglement, followed by measurements. The video highlights the 50/50 probability outcomes of 00 or 11 due to entanglement. It also mentions higher-level Qiskit features, such as machine learning packages, to integrate quantum capabilities into classical applications.

Takeaways

  • 🔍 In the previous video, quantum computing and its unique features were discussed.
  • 💻 Developers are interested in how to write code for quantum computers on common computers.
  • 🔄 Quantum computers use qubits, which can represent 0, 1, or any linear combination of both, known as superposition.
  • 🌀 Multiple qubits can be entangled, meaning their states become strongly correlated.
  • ⚙️ To manipulate qubit states, quantum gates are applied, similar to classical logic gates.
  • 🛠️ Qiskit is a widely used quantum software development kit (SDK) based on Python.
  • 📐 A simple Qiskit program involves creating a quantum circuit with quantum and classical registers.
  • ⚡ Gates like the Hadamard gate (for superposition) and the CNOT gate (for entanglement) are applied to qubits.
  • 📏 Measurements are done using the 'measure all' function to get the results.
  • 📊 Running the program multiple times shows a 50% chance of outputs being 00 or 11, due to superposition and entanglement.
  • 🔬 Qiskit also offers higher-level algorithms and packages for tasks like machine learning, which can integrate with classical algorithms.
  • 📈 The quantum kernel class in Qiskit can be used for training and testing data, enhancing classical applications.

Q & A

  • What is the main focus of the video script?

    -The video script focuses on explaining quantum computing concepts and how to write a simple quantum program using Qiskit, a quantum software development kit based on Python.

  • What are the key differences between classical bits and qubits?

    -Classical bits can be either 0 or 1, while qubits can be 0, 1, or any linear combination of the two, which is known as superposition. Additionally, qubits can be entangled, meaning the state of one qubit can be strongly correlated with another.

  • How does the Hadamard gate affect a qubit?

    -The Hadamard gate puts a qubit into a superposition state, giving it an equal probability of being measured as 0 or 1.

  • What is the purpose of the control not gate (cx) in quantum computing?

    -The control not gate is a conditional two-qubit gate that flips the state of the target qubit if the control qubit is in state 1. It is used to create entanglement between qubits.

  • Why are classical registers used in quantum circuits?

    -Classical registers are used to store the measured results of qubits. They allow quantum information to be brought back into the classical world for further processing or analysis.

  • What is the significance of entanglement in quantum computing?

    -Entanglement is significant because it allows the states of multiple qubits to be strongly correlated. This property is fundamental for quantum algorithms and quantum information processing.

  • How does the 'measure all' function work in Qiskit?

    -The 'measure all' function in Qiskit is used to perform measurements on all qubits in a quantum circuit, which collapses their superposition states and gives classical output results.

  • What is the expected output when running the simple quantum program described in the script multiple times on an ideal quantum computer?

    -The expected output is a 50% chance of the results being 00 and a 50% chance of it being 11. The program will never output 01 or 10 due to the entanglement of the qubits.

  • How does Qiskit's higher-level algorithms package for machine learning work?

    -Qiskit's higher-level algorithms package for machine learning includes pre-built classes like a quantum kernel class. This class can be used to train and test data, and then the trained quantum kernel can be passed into a classical algorithm like support vector classification from scikit-learn to accelerate classical applications.

  • What is the relationship between Qiskit and Python?

    -Qiskit is a quantum software development kit based on Python, making it accessible for developers who are familiar with Python or are willing to learn it.

  • Why is it important to bring quantum information back into the classical world?

    -It is important because most of the applications and systems we interact with are classical. Bringing quantum information back into the classical world allows for the integration of quantum computing with existing technologies and systems.

Outlines

00:00

🚀 Introduction to Quantum Computing and Qiskit

This paragraph introduces the concept of quantum computing and its fundamental principles. It explains how qubits can exist in a superposition of states, allowing for computation that is fundamentally different from classical computing. The speaker also discusses the concept of entanglement, where qubits become correlated in such a way that the state of one qubit can depend on another, no matter the distance between them. To demonstrate these concepts, the speaker introduces Qiskit, a quantum software development kit based on Python, and outlines the process of writing a simple quantum program using it. The program involves creating a quantum circuit with two qubits, putting one into superposition, entangling it with the other, and then measuring both to obtain results. The process involves the application of quantum gates, specifically the Hadamard gate to create superposition and the control-not gate to achieve entanglement. The speaker also touches on the importance of classical registers for storing the results of quantum computations.

05:04

🌟 Exploring Higher-Level Quantum Algorithms with Qiskit

In the second paragraph, the speaker shifts focus from the basic quantum circuit to higher-level applications of quantum computing, specifically within the realm of machine learning. Qiskit offers a package that includes pre-built classes for quantum machine learning, such as a quantum kernel class. This class can be utilized to train and test data, leveraging the unique capabilities of quantum computing to potentially enhance performance. The trained quantum kernel can then be integrated with classical algorithms, such as support vector classification from scikit-learn, to create a hybrid system that combines the strengths of both quantum and classical computing. The speaker concludes the video by inviting viewers to ask questions in the comments, and encourages them to like and subscribe to the channel for more relevant content.

Mindmap

Keywords

💡Quantum Computing

Quantum computing refers to a type of computing that uses quantum-mechanical phenomena, such as superposition and entanglement, to perform operations on data. This concept is central to the video's theme as it contrasts with classical computing and forms the foundation for understanding quantum software development.

💡Qubit

A qubit is the fundamental unit of quantum information, analogous to a bit in classical computing. Unlike a classical bit, which can be either 0 or 1, a qubit can be in a superposition of both states simultaneously. The video introduces qubits to explain the basics of quantum computation and how they differ from classical bits.

💡Superposition

Superposition is a principle of quantum mechanics where a quantum system can exist in multiple states at once. In the video, it is explained that qubits can be 0, 1, or both simultaneously, which is crucial for understanding how quantum computers process information differently from classical computers.

💡Entanglement

Entanglement is a quantum phenomenon where multiple particles become interconnected such that the state of one particle instantly influences the state of another, no matter the distance between them. The video uses entanglement to demonstrate how qubits can be strongly correlated, enhancing the power of quantum computations.

💡Quantum Gates

Quantum gates are the building blocks of quantum circuits, similar to classical logic gates. They manipulate qubits' states through operations like superposition and entanglement. The video introduces Hadamard and control not (CX) gates as examples to show how quantum states are altered during computation.

💡Hadamard Gate

The Hadamard gate is a specific quantum gate that puts a qubit into a superposition state. The video explains its role in creating equal probabilities for a qubit to be 0 or 1, illustrating a fundamental operation in quantum algorithms.

💡Control Not Gate

The control not (CX) gate is a quantum gate that flips the state of a target qubit if the control qubit is in state 1. This gate is essential for creating entanglement between qubits, as explained in the video when demonstrating how qubits interact conditionally.

💡Quantum Circuit

A quantum circuit is a model for quantum computation where a sequence of quantum gates is applied to qubits. The video guides viewers through creating a simple quantum circuit using Qiskit, highlighting its importance in structuring quantum algorithms.

💡Qiskit

Qiskit is an open-source quantum software development kit (SDK) for working with quantum circuits and algorithms using Python. The video emphasizes Qiskit's accessibility for developers new to quantum computing and demonstrates how to write a basic program using this SDK.

💡Classical Register

A classical register is used to store the results of quantum measurements, converting quantum information into a classical format. The video explains the necessity of classical registers in quantum computing for bridging quantum computations with classical data processing.

Highlights

Introduction to quantum computing and its special features.

Recap of quantum computing basics: qubits and superposition.

Explanation of qubit entanglement and its significance.

Introduction to quantum gates and their role in quantum computing.

Discussion on quantum software development kits, specifically Qiskit.

Qiskit is based on Python, making it accessible for developers.

Outline of a simple quantum program using Qiskit with two qubits.

Steps to create a quantum circuit with quantum and classical registers.

Importance of classical registers in quantum computing.

Application of the Hadamard gate to put a qubit in superposition.

Use of the control not gate (CX gate) to entangle qubits.

Measurement of qubits to obtain results in quantum computing.

Expected outputs from the quantum program: 50% chance of 00 or 11.

Explanation of why 01 or 10 outputs are not possible.

High-level quantum algorithms available in Qiskit, including machine learning packages.

Example of using a quantum kernel with classical algorithms for enhanced performance.

Encouragement to like and subscribe to the channel for more content.

Transcripts

play00:00

In my previous video, I talked about what quantum  computing is and what makes it special. But as  

play00:06

a developer, I'm sure you want to know how to  actually write a piece of code that would run  

play00:10

on a common computer. But before we dive into  that, let's just do a little bit of a quick  

play00:15

recap. Instead of the classical bits of 0s and 1s,  quantum computers use qubits. A qubit can be a 0,  

play00:27

a 1, or any linear combination of the two.  And that is what we called a superposition.  

play00:36

We can also entangle multiple qubits. So their states become strongly correlated. In order  

play00:43

to change the states of qubits, we apply  a series of gates, similar to the classical  

play00:48

logic gates. And in the end, we want to measure  these qubits so we can get the results.  

play00:55

So how do we take all these concepts into  code? And the answer is simple. We use a  

play01:02

quantum software development kit. In  this video, we will be using Qiskit.  

play01:09

Which is the most widely used quantum SDK today.  

play01:13

Qiskit is based on Python, which is fairly simple  to learn, even if you've never used it before.  

play01:19

So let's write a simple program in his Qiskit. In this program, we will use two qubits.  

play01:28

We will put one into superposition, entangle it with the other, and then  

play01:34

do a measurement of both of them. And  of course, all that is done using gates.  

play01:42

So let's start by importing quantum circuit from  Qiskit. We then can create a quantum circuit 

play02:04

with two quantum registers  and two classical registers.  

play02:09

The quantum registers are used for quantum  

play02:13

computation. One for each qubit. And the classical  registers are used to store the measured results.  

play02:25

We need a classical registers because  even though the physical world is quantum,  

play02:29

the majority of the classical  world is still classical.  

play02:33

And the classical registers allow us to bring  quantum information back into the classical world.  

play02:40

So the next thing we want to do is  apply some gates. And in this program,  

play02:44

we're going to apply two gates. The  first one is the Hadamard gate 

play02:51

on qubit 0. The Hadamard gate puts  the qubit into a superposition between 0  

play02:59

and 1. That means it now has an equal  chance of being measured a 0 or 1.  

play03:06

The next gate we need is the control  not gate, or "cx" for short.  

play03:15

The control not gate is a conditional two qubits gate. It has a control qubit

play03:24

and the target qubit.

play03:30

Without superposition, the control  not gate is fairly simple to understand.  

play03:35

That is, it is as if the state of the control qubit is  1, then you flip the state of the target qubit.  

play03:44

And that's why it's called control not.  

play03:49

And because the states of least two  qubits are now strongly correlated,  

play03:53

we now say they are entangled. So the  last thing we want to do is actually do  

play03:58

measurements so we can get the outputs. And we  do this by calling the measure all function.  

play04:06

And there you have it. We just wrote a simple  quantum program using Qiskit. Now, if you take  

play04:13

this program and run it a bunch of times on an  ideal quantum computer, you'll find out that  

play04:18

there's a 50% chance of the outputs being 00 and  50% chance of it being 11. But you would never  

play04:26

be a 01 or 10. The 50/50 of the first  qubit comes from the superposition. And while  

play04:36

we didn't explicitly change the state of the  second qubit, it got changed anyway because  

play04:42

it is entangled with the first qubit.  So it changes with the first qubit.  

play04:52

So in this program, we created a quantum  circuit which operates at the same level  

play04:57

as classical assembly language and allows you  to efficiently manipulate the qubits directly.  

play05:04

However, if you're not fond of  playing with low level circuits,  

play05:07

Qiskit also offers a number of higher  level algorithms. For example, Qiskit has  

play05:15

a package focusing on machine learning that has  a number of pre-built classes. You can take a  

play05:22

quantum kernel class, use it to train and test  data. You can then take this trained quantum  

play05:30

kernel and pass it into a classical algorithm  such as the support vector classification  

play05:36

from scikit-learn. Then you can then  accelerate your classical application.  

play05:44

Thanks for watching. If you have any questions,  please leave them in the comments below.  

play05:49

Also, please remember to Like this  video and Subscribe to our channel  

play05:53

so we can continue to bring you  content that matters to you.

Rate This

5.0 / 5 (0 votes)

Related Tags
Quantum ComputingQiskit SDKPython ProgrammingQuantum BitsSuperpositionEntanglementQuantum GatesHadamard GateControl Not GateMachine LearningScikit-learn