量子運算 簡單通俗例子
by YK Sugi
由YK Sugi
什么是量子計算機? 用一個簡單的例子解釋。 (What is a quantum computer? Explained with a simple example.)
Hi everyone!
嗨,大家好!
The other day, I visited D-Wave Systems in Vancouver, Canada. It’s a company that makes cutting-edge quantum computers.
前幾天,我參觀了加拿大溫哥華的D-Wave Systems 。 這是一家生產尖端量子計算機的公司。
I got to learn a lot about quantum computers there, so I’d like to share some of what I learned there with you in this article.
我在那里學習了很多有關量子計算機的知識,所以我想在本文中與大家分享一些我在這里學到的東西。
The goal of this article is to give you an accurate intuition of what a quantum computer is using a simple example.
本文的目的是讓您準確了解直覺量子計算機所使用的簡單示例。
This article will not require you to have prior knowledge of either quantum physics or computer science to be able to understand it.
本文將不要求您具有量子物理學或計算機科學的先驗知識才能理解。
Okay, let’s get started.
好的,讓我們開始吧。
Edit (Feb 26, 2019): I recently published a video about the same topic on my YouTube channel. I would recommend watching it (click here) before or after reading this article because I have added some additional, more nuanced arguments in the video.
編輯(2019年2月26日):我最近在我的YouTube頻道上發布了關于同一主題的視頻 。 我建議在閱讀本文之前或之后觀看它( 單擊此處 ),因為我在視頻中添加了一些其他的,更細微的參數。
什么是量子計算機? (What is a quantum computer?)
Here is a one-sentence summary of what a quantum computer is:
這是量子計算機的一句話摘要:
A quantum computer is a type of computer that uses quantum mechanics so that it can perform certain kinds of computation more efficiently than a regular computer can.
量子計算機是一種使用量子力學的計算機,因此它可以比常規計算機更有效地執行某些類型的計算。
There is a lot to unpack in this sentence, so let me walk you through what it is exactly using a simple example.
這句話有很多要解開的地方,所以讓我用一個簡單的例子向您介紹它的確切含義。
To explain what a quantum computer is, I’ll need to first explain a little bit about regular (non-quantum) computers.
為了解釋什么是量子計算機,我首先需要對常規(非量子)計算機進行一些解釋。
普通計算機如何存儲信息 (How a regular computer stores information)
Now, a regular computer stores information in a series of 0’s and 1’s.
現在,常規計算機以一系列0和1存儲信息。
Different kinds of information, such as numbers, text, and images can be represented this way.
可以用這種方式表示不同種類的信息,例如數字,文本和圖像。
Each unit in this series of 0’s and 1’s is called a bit. So, a bit can be set to either 0 or 1.
這個系列中的0和1的每個單位稱為一位。 因此,可以將某位設置為0或1。
現在,量子計算機呢? (Now, what about quantum computers?)
A quantum computer does not use bits to store information. Instead, it uses something called qubits.
量子計算機不使用位來存儲信息。 相反,它使用一種稱為qubits的東西。
Each qubit can not only be set to 1 or 0, but it can also be set to 1 and 0. But what does that mean exactly?
每個量子位不僅可以設置為1 或 0,還可以設置為1 和 0。但這到底意味著什么?
Let me explain this with a simple example. This is going to be a somewhat artificial example. But it’s still going to be helpful in understanding how quantum computers work.
讓我用一個簡單的例子對此進行解釋。 這將是一個人為的例子。 但這仍然有助于理解量子計算機的工作原理。
一個了解量子計算機如何工作的簡單示例 (A simple example for understanding how quantum computers work)
Now, suppose you’re running a travel agency, and you need to move a group of people from one location to another.
現在,假設您正在經營一家旅行社,并且需要將一群人從一個地點轉移到另一個地點。
To keep this simple, let’s say that you need to move only 3 people for now — Alice, Becky, and Chris.
為簡單起見,假設您現在只需要移動3個人-愛麗絲,貝基和克里斯。
And suppose that you have booked 2 taxis for this purpose, and you want to figure out who gets into which taxi.
并假設您已經為此預訂了2輛出租車,并且您想弄清楚誰乘坐哪輛出租車。
Also, suppose here that you’re given information about who’s friends with who, and who’s enemies with who.
此外,在這里假設您獲得有關誰與誰成為朋友以及誰與誰成為敵人的信息。
Here, let’s say that:
在這里,我們說:
- Alice and Becky are friends 愛麗絲和貝基是朋友
- Alice and Chris are enemies 愛麗絲和克里斯是敵人
- Becky and Chris are enemies 貝基和克里斯是敵人
And suppose that your goal here is to divide this group of 3 people into the two taxis to achieve the following two objectives:
并假設您的目標是將3人組成的團隊分為兩輛出租車,以實現以下兩個目標:
Maximize the number of friend pairs that share the same car
最大化共享同一輛車的朋友對的數量
Minimize the number of enemy pairs that share the same car
減少共享同一輛車的敵人對的數量
Okay, so this is the basic premise of this problem. Let’s first think about how we would solve this problem using a regular computer.
好的,這是此問題的基本前提。 首先考慮一下如何使用常規計算機解決此問題。
用常規計算機解決此問題 (Solving this problem with a regular computer)
To solve this problem with a regular, non-quantum computer, you’ll need first to figure out how to store the relevant information with bits.
為了使用常規的非量子計算機解決此問題,您首先需要弄清楚如何使用位存儲相關信息。
Let’s label the two taxis Taxi #1 and Taxi #0.
讓我們標記兩個出租車1號和0號出租車。
Then, you can represent who gets into which car with 3 bits.
然后,您可以用3位代表誰進入哪輛車。
For example, we can set the three bits to 0, 0, and 1 to represent:
例如,我們可以在三個位設置為0,0, 和1代表:
- Alice gets into Taxi #0 愛麗絲進入出租車0
- Becky gets into Taxi #0 貝基進入出租車0
- Chris gets into Taxi #1 克里斯進入出租車#1
Since there are two choices for each person, there are 2*2*2 = 8 ways to divide this group of people into two cars.
由于每個人都有兩個選擇,因此有2 * 2 * 2 = 8種方法可以將這一組人分為兩輛車。
Here’s a list of all possible configurations:
以下是所有可能配置的列表:
A | B | C0 | 0 | 00 | 0 | 10 | 1 | 00 | 1 | 11 | 0 | 01 | 0 | 11 | 1 | 01 | 1 | 1
A | B | C0 | 0 | 00 | 0 | 10 | 1 | 00 | 1 | 11 | 0 | 01 | 0 | 11 | 1 | 01 | 1 | 1個
Using 3 bits, you can represent any one of these combinations.
使用3位,您可以代表這些組合中的任何一種。
計算每種配置的分數 (Computing the score for each configuration)
Now, using a regular computer, how would we determine which configuration is the best solution?
現在,使用普通計算機,我們將如何確定哪種配置是最佳解決方案?
To do this, let’s define how we can compute the score for each configuration. This score will represent the extent to which each solution achieves the two objectives I mentioned earlier:
為此,讓我們定義如何計算每種配置的得分。 這個分數將代表每種解決方案在多大程度上實現了我之前提到的兩個目標:
Maximize the number of friend pairs that share the same car
最大化共享同一輛車的朋友對的數量
Minimize the number of enemy pairs that share the same car
減少共享同一輛車的敵人對的數量
Let’s simply define our score as follows:
讓我們簡單地定義得分如下:
(the score of a given configuration) = (# friend pairs sharing the same car) - (# enemy pairs sharing the same car)
(給定配置的分數)=(共享同一輛車的#個朋友對)-(共享同一輛車的#個敵人對)
For example, suppose that Alice, Becky, and Chris all get into Taxi #1. With three bits, this can be expressed as 111.
例如,假設Alice,Becky和Chris都進入了出租車1號。 使用三位,這可以表示為111 。
In this case, there is only one friend pair sharing the same car — Alice and Becky.
在這種情況下,只有一對朋友共享同一輛車-愛麗絲和貝基。
However, there are two enemy pairs sharing the same car — Alice and Chris, and Becky and Chris.
但是,有兩個敵對共享同一輛車-愛麗絲和克里斯,貝基和克里斯。
So, the total score of this configuration is 1-2 = -1.
因此,此配置的總分是1-2 = -1。
解決問題 (Solving the problem)
With all of this setup, we can finally go about solving this problem.
通過所有這些設置,我們終于可以解決這個問題了。
With a regular computer, to find the best configuration, you’ll need to essentially go through all configurations to see which one achieves the highest score.
對于常規計算機,要找到最佳配置,您實際上需要仔細檢查所有配置,以查看哪個配置得分最高。
So, you can think about constructing a table like this:
因此,您可以考慮構造一個像這樣的表:
A | B | C | Score0 | 0 | 0 | -10 | 0 | 1 | 1 <- one of the best solutions0 | 1 | 0 | -10 | 1 | 1 | -11 | 0 | 0 | -11 | 0 | 1 | -11 | 1 | 0 | 1 <- the other best solution1 | 1 | 1 | -1
A | B | C | 得分0 | 0 | 0 | -10 | 0 | 1 | 1 <-最佳解決方案之一 1 | 0 | -10 | 1 | 1 | -11 | 0 | 0 | -11 | 0 | 1 | -11 | 1 | 0 | 1 <-另一個最佳解決方案1 ??| 1 | 1 | -1
As you can see, there are two correct solutions here — 001 and 110, both achieving the score of 1.
如您所見,這里有兩個正確的解決方案-001和110,都達到了1分。
This problem is fairly simple. It quickly becomes too difficult to solve with a regular computer as we increase the number of people in this problem.
這個問題很簡單。 隨著我們增加處理此問題的人數,使用常規計算機很快變得難以解決。
We saw that with 3 people, we need to go through 8 possible configurations.
我們看到只有3個人,我們需要完成8種可能的配置。
What if there are 4 people? In that case, we’ll need to go through 2*2*2*2 = 16 configurations.
如果有四個人怎么辦? 在這種情況下,我們需要進行2 * 2 * 2 * 2 = 16個配置。
With n people, we’ll need to go through (2 to the power of n) configurations to find the best solution.
與n個人一起,我們將需要進行(2的n次方)個配置以找到最佳解決方案。
So, if there are 100 people, we’ll need to go through:
因此,如果有100個人,我們將需要完成以下工作:
- 21?? ~= 103? = one million million million million million configurations. 2 17 = 10 3 =一億億億億億個配置。
This is simply impossible to solve with a regular computer.
這是用常規計算機根本無法解決的。
用量子計算機解決這個問題 (Solving this problem with a quantum computer)
How would we go about solving this problem with a quantum computer?
我們將如何使用量子計算機解決這個問題?
To think about that, let’s go back to the case of dividing 3 people into two taxis.
考慮一下,讓我們回到將3個人分為兩輛出租車的情況。
As we saw earlier, there were 8 possible solutions to this problem:
正如我們之前看到的,有8種可能的解決方案:
A | B | C0 | 0 | 00 | 0 | 10 | 1 | 00 | 1 | 11 | 0 | 01 | 0 | 11 | 1 | 01 | 1 | 1
A | B | C0 | 0 | 00 | 0 | 10 | 1 | 00 | 1 | 11 | 0 | 01 | 0 | 11 | 1 | 01 | 1 | 1個
With a regular computer, using 3 bits, we were able to represent only one of these solutions at a time — for example, 001.
對于使用3位的常規計算機,我們一次只能代表這些解決方案之一,例如001。
However, with a quantum computer, using 3 qubits, we can represent all 8 of these solutions at the same time.
但是,使用一臺量子計算機,使用3個量子位 ,我們可以同時表示所有8個解決方案 。
There are debates as to what it means exactly, but here’s the way I think about it.
關于確切含義的爭論不休,但這是我對它的思考方式。
First, examine the first qubit out of these 3 qubits. When you set it to both 0 and 1, it’s sort of like creating two parallel worlds. (Yes, it’s strange, but just follow along here.)
首先,檢查這3個量子位中的第一個量子位。 當你將它設置為兩 0和1,有點像創建兩個平行的世界。 (是的,這很奇怪,但是請遵循此處。)
In one of those parallel worlds, the qubit is set to 0. In the other one, it’s set to 1.
在這些并行世界之一中,量子位設置為0。在另一個世界中,量子位設置為1。
Now, what if you set the second qubit to 0 and 1, too? Then, it’s sort of like creating 4 parallel worlds.
現在,如果您也將第二個量子比特設置為0 和 1,該怎么辦? 然后,就像創建四個平行世界。
In the first world, the two qubits are set to 00. In the second one, they are 01. In the third one, they are 10. In the fourth one, they are 11.
在第一個世界中,兩個量子位設置為00。在第二個世界中,它們設置為01。在第三個世界中,它們設置為10。在第四個世界中,它們設置為11。
Similarly, if you set all three qubits to both 0 and 1, you’d be creating 8 parallel worlds — 000, 001, 010, 011, 100, 101, 110, and 111.
同樣,如果將所有三個量子位都設置為0和1,則將創建8個并行世界-000、001、010、011、100、101、110和111。
This is a strange way to think, but it is one of the correct ways to interpret how the qubits behave in the real world.
這是一種奇怪的思考方式,但它是解釋量子位在現實世界中的行為的正確方法之一。
Now, when you apply some sort of computation on these three qubits, you are actually applying the same computation in all of those 8 parallel worlds at the same time.
現在,當您對這三個量子位應用某種計算時,實際上您實際上同時在所有這8個并行世界中應用了相同的計算。
So, instead of going through each of those potential solutions sequentially, we can compute the scores of all solutions at the same time.
因此,我們可以依次計算所有解決方案的得分,而不必依次檢查每個潛在解決方案。
With this particular example, in theory, your quantum computer would be able to find one of the best solutions in a few milliseconds. Again, that’s 001 or 110 as we saw earlier:
通過這個特定的例子,理論上,您的量子計算機將能夠在幾毫秒內找到最佳解決方案之一。 同樣,如我們先前所見,它是001或110:
A | B | C | Score0 | 0 | 0 | -10 | 0 | 1 | 1 <- one of the best solutions0 | 1 | 0 | -10 | 1 | 1 | -11 | 0 | 0 | -11 | 0 | 1 | -11 | 1 | 0 | 1 <- the other best solution1 | 1 | 1 | -1
A | B | C | 得分0 | 0 | 0 | -1 0 | 0 | 1 | 1 <-最佳解決方案之一| 1 | 0 | -10 | 1 | 1 | -11 | 0 | 0 | -11 | 0 | 1 | -1 1 | 1 | 0 | 1 <-其他最佳解決方案1 ??| 1 | 1 | -1
In reality, to solve this problem, you would need to give your quantum computer two things:
實際上,要解決此問題,您需要給量子計算機兩件事:
- All potential solutions represented with qubits 量子位表示所有可能的解決方案
- A function that turns each potential solution into a score. In this case, this is the function that counts the numbers of friend pairs and enemy pairs sharing the same car. 將每個潛在解決方案轉化為得分的功能。 在這種情況下,該功能可以計算共享同一輛汽車的朋友對和敵人對的數量。
Given these two things, your quantum computer will spit out one of the best solutions in a few milliseconds. In this case, that’s 001 or 110 with a score of 1.
鑒于這兩件事,您的量子計算機將在幾毫秒內吐出最佳解決方案之一。 在這種情況下,分數是1的001或110。
Now, in theory, a quantum computer is able to find one of the best solutions every time it runs.
現在,從理論上講,量子計算機能夠在每次運行時找到最佳解決方案之一。
However, in reality, there are errors when running a quantum computer. So, instead of finding the best solution, it might find the second-best solution, the third best solution, and so on.
但是,實際上,運行量子計算機時會出錯。 因此,與其找到最佳解決方案,不如尋找第二好解決方案,第三好解決方案,依此類推。
These errors become more prominent as the problem becomes more and more complex.
隨著問題變得越來越復雜,這些錯誤變得更加突出。
So, in practice, you will probably want to run the same operation on a quantum computer dozens of times or hundreds of times. Then pick the best result out of the many results you get.
因此,實際上,您可能希望在量子計算機上運行數十次或數百次相同的操作。 然后從獲得的許多結果中選擇最佳結果。
量子計算機如何擴展 (How a quantum computer scales)
Even with the errors I mentioned, the quantum computer does not have the same scaling issue a regular computer suffers from.
即使有我提到的錯誤,量子計算機也不會像普通計算機那樣遇到相同的縮放問題。
When there are 3 people we need to divide into two cars, the number of operations we need to perform on a quantum computer is 1. This is because a quantum computer computes the score of all configurations at the same time.
當我們需要將3個人分為兩輛車時,我們需要在量子計算機上執行的操作數為1。這是因為量子計算機同時計算所有配置的得分。
When there are 4 people, the number of operations is still 1.
當有4個人時,操作數仍為1。
When there are 100 people, the number of operations is still 1. With a single operation, a quantum computer computes the scores of all 21?? ~= 103? = one million million million million million configurations at the same time.
當有100個人時,操作數仍為1。通過一次操作,量子計算機將同時計算所有2 1? = 10 3 = 1億億億億億配置的分數。
As I mentioned earlier, in practice, it’s probably best to run your quantum computer dozens of times or hundreds of times and pick the best result out of the many results you get.
如前所述,在實踐中,最好是運行量子計算機數十次或數百次,然后從獲得的眾多結果中挑選出最佳結果。
However, it’s still much better than running the same problem on a regular computer and having to repeat the same type of computation one million million million million million times.
但是,它仍然比在常規計算機上運行相同的問題并且必須重復相同類型的計算1億億億億億次更好。
結語 (Wrapping up)
Special thanks to everyone at D-Wave Systems for patiently explaining all of this to me.
特別感謝D-Wave Systems的所有人耐心向我解釋了所有這些。
D-Wave recently launched a cloud environment for interacting with a quantum computer.
D-Wave最近推出了一種用于與量子計算機進行交互的云環境。
If you’re a developer and would like actually to try using a quantum computer, it’s probably the easiest way to do so.
如果您是開發人員,并且想實際嘗試使用量子計算機,那可能是最簡單的方法。
It’s called Leap, and it’s at https://cloud.dwavesys.com/leap. You can use it for free to solve thousands of problems, and they also have easy-to-follow tutorials on getting started with quantum computers once you sign up.
它稱為Leap,位于https://cloud.dwavesys.com/leap 。 您可以免費使用它來解決成千上萬的問題,并且一旦注冊,他們還將提供易于遵循的有關量子計算機入門的教程。
Footnote:
腳注:
- In this article, I used the term “regular computer” to refer to a non-quantum computer. However, in the quantum computing industry, non-quantum computers are usually referred to as classical computers. 在本文中,我使用術語“常規計算機”來指代非量子計算機。 然而,在量子計算工業中,非量子計算機通常被稱為經典計算機。
翻譯自: https://www.freecodecamp.org/news/what-is-a-quantum-computer-explained-with-a-simple-example-b8f602035365/
量子運算 簡單通俗例子