量子比特纠缠_动手探索量子比特

量子比特纠缠

This post is part of the book: Hands-On Quantum Machine Learning With Python

这篇文章是这本书的一部分: Python的动手量子机器学习

The world of quantum mechanics is… different. A quantum system can be in a state of superposition. A popular notion of superposition is that the system is in different states concurrently unless you measure it.

量子力学的世界是……不同。 量子系统可以处于叠加状态。 流行的叠加概念是,除非进行测量,否则系统同时处于不同状态。

For instance, the spin of a particle is not up or down but it is up and down at the same time. But when you look at it, you find it either up or down.

例如,粒子的自旋不是向上向下,而是同时向上向下。 但是,当您查看它时,会发现它向上向下。

Or, let’s say you flip a quantum coin. In the air, it has both values heads and tails. If and only if you catch it and look at it, it decides for a value. Once landed, it is a normal coin with heads up or tails up.

或者,假设您掷出一枚量子硬币。 在空中,它同时具有正面反面的价值。 当且仅当您抓住它并查看它时,它才决定一个值。 一旦降落,它就是一头正常的硬币,头朝上尾巴朝上。

Another notion of superposition is that the system is truly random and therefore distinguishes from the systems we know. Tossing a (normal) coin, for instance, seems random, because whenever you do it, the conditions are slightly different. And even tiny differences can change the outcome from heads to tails. The coin has a sensitive dependence to initial conditions.

叠加的另一个概念是系统实际上是随机的,因此与我们已知的系统有所区别。 例如,投掷(普通)硬币似乎是随机的,因为每次进行投掷时,条件都会略有不同。 甚至微小的差异也可以将结果从头到尾改变。 硬币对初始条件敏感

If we were able to measure all conditions precisely, we could tell the outcome. In classic mechanics, there is no randomness. Things in our everyday world, such as the coin, seem random. But they are not. If measured with infinite precision, randomness would disappear. By contrast, a quantum system is truly random.

如果我们能够精确地测量所有条件,我们就能说出结果。 在经典力学中,没有随机性。 日常生活中的事物,例如硬币,似乎是随机的。 但事实并非如此。 如果以无限的精度进行测量,则随机性将消失。 相比之下,量子系统实际上是随机的。

Maybe you wonder: Ok, it’s random. Where’s the big deal?

也许你想知道:好吧,这是随机的。 有什么大不了的?

The big thing is the consequences. In a classic system, a system sensitive dependent to initial conditions, the answer to a question is already determined before we ask it.

最重要的是后果。 在经典系统中,一个对初始条件敏感的系统,在我们提出问题之前就已经确定了问题的答案。

Rather than watching the baseball match tonight, you spend the evening with your friends. When you return home, even though you don’t know the results, the match is over and there is a definite result. There could be different results, but you simply don’t know the result until you look at it.

与其今晚观看棒球比赛,不如和朋友们度过一个晚上。 当您返回家乡时,即使您不知道结果,比赛也结束了,并且有明确的结果。 可能会有不同的结果,但是您只是不知道结果,除非您查看它。

Contrarily, in a quantum system, the answer to a question is not determined up until the time you ask it. And since it is not determined yet, you still can change the probabilities of measuring distinct states.

相反,在量子系统中,直到提出问题时才确定问题的答案。 而且由于尚未确定,您仍然可以更改测量不同状态的概率。

If you have doubts, good! Not even Einstein liked this notion. It led him to his famous statement of God does not play dice.

如果您有疑问,那就好! 爱因斯坦甚至都不喜欢这个概念。 它导致他以他著名的上帝声明不玩骰子

Image for post
Image by author Frank Zickert
图片由作者Frank Zickert提供

Many physicists, including Einstein, proposed the quantum state, though hidden, to be a well-defined state. This is known as the hidden variable theory.

许多物理学家,包括爱因斯坦,都提出了量子状态,尽管它是隐藏的,但仍是定义明确的状态。 这就是所谓的隐藏变量理论

There are statistically distinct behaviors between a system following the hidden variable theory and a quantum system following the superposition principle. And experiments showed that the quantum mechanical predictions were correct.

在遵循隐变量理论的系统与遵循叠加原理的量子系统之间,在统计上存在不同的行为。 实验表明,量子力学的预测是正确的。

For now, let’s accept the quantum state is something different. Later in this book, we will have a closer look at it. And its consequences. But this requires a little more theory and math.

现在,让我们接受量子态的不同。 在本书的后面,我们将对其进行更仔细的研究。 及其后果。 但这需要更多的理论和数学知识。

We turn to the quantum computer. Let’s say you have a quantum bit. We call it qubit. Unless you observe its value, it is in a superposition state of 0 and 1. Once you observe its value, you'll get 0 or 1.

我们转向量子计算机。 假设您有一个量子位。 我们称它为qubit。 除非您观察其值,否则它处于01的叠加状态。 观察其值后,将得到01

The chances of a qubit to result in either one value don’t need to be 50:50. It can be 25:75, 67:33, or even 100:0. It can be any weighted probability distribution.

量子位产生任一值的机会不必为50:50。 它可以是25:75、67:33甚至100:0。 它可以是任何加权概率分布。

The probability distribution a qubit has when observed depends on its state. The quantum state.

观察时量子比特具有的概率分布取决于其状态。 量子态。

In quantum mechanics, we use vectors to describe the quantum state. A popular way of representing quantum state vectors is the Dirac notation’s “ket”-construct that looks like |ψ⟩|ψ⟩. In Python, we don’t have vectors. But we have arrays. Luckily, their structures are similar.

在量子力学中,我们使用向量来描述量子态。 表示量子态向量的一种流行方式是狄拉克符号的“ ket”构造,看起来像|ψ⟩|ψ⟩。 在Python中,我们没有向量。 但是我们有数组。 幸运的是,它们的结构相似。

Let’s have a look. We start with the simplest case. Let’s say, we have a qubit that, when observed, always has the value 0. If you argued this qubit must have the value 0 even before it is observed, you wouldn't be completely wrong. Yet, you'd be imprecise. Before it is observed, this qubit has the probability of 1 (=100%=100%) to have the value 0 when observed.

我们来看一下。 我们从最简单的情况开始。 比方说,我们有一个量子比特,当被观察时,它总是具有值0 。 如果您认为此qubit甚至在被观察之前就必须具有值0 ,那么您不会完全错误。 但是,您可能不准确。 在观察之前,当观察时,此量子位的概率为1(= 100%= 100%),值为0

These are the equivalent representations (ket, vector, array) of a qubit that always results in 0 when observed:

这些是量子位的等效表示形式(ket,向量,数组),在观察时始终为0

|0⟩=[1 0] and in Python [1, 0].

|0⟩= [1 0]和Python [1, 0]

Accordingly, the following representations depict a qubit that always results in 1 when observed:

因此,以下表示描述了一个在观察时始终为1的量子位:

|1⟩=[0 1] and in Python [0, 1].

|1⟩= [0 1]和Python [0, 1]

Ok, enough with the theory for now. Let’s have a look at the code of such a qubit.

好的,现在就足够理论了。 让我们来看看这样一个量子比特的代码。

You’ll need a Python environment. And I’ll recommend having a Jupyter Notebook running in a virtual environment. I’ve put together a brief explanation of how to set up such an environment.

您将需要一个Python环境。 并且我建议在虚拟环境中运行Jupyter Notebook。 我对如何设置这样的环境进行了简要说明

Besides the general setup, we’ll need two libraries: Qiskit and Matplotlib. Qiskit is IBM’s Python SDK for quantum programming. Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python

除了常规设置之外,我们还需要两个库: QiskitMatplotlib 。 Qiskit是IBM的用于量子编程的Python SDK。 Matplotlib是用于在Python中创建静态,动画和交互式可视化效果的综合库

You can install both with pip:

您可以使用pip安装两者:

pip install qiskit — user
pip install matplotlib

Install Qiskit in your home directory. Use --user to not depend on any special privileges (i.e. admin rights) during the installation.

在您的主目录中安装Qiskit。 使用--user在安装过程中不依赖任何特殊特权(即管理员权限)。

If you haven’t configured your workstation yet, have a look at the brief explanation of how to set up the working environment (section \ref{configuring-your-quantum-machine-learning-workstation}).

如果尚未配置工作站,请查看有关如何设置工作环境的简要说明(\ ref {configuring-your-quantum-machine-learning-workstation}部分)。

Now, open the Jupyter notebook and test whether Qiskit works.

现在,打开Jupyter笔记本并测试Qiskit是否有效。

import qiskit
qiskit.__qiskit_version__{'qiskit-terra': '0.15.1',
'qiskit-aer': '0.6.1',
'qiskit-ignis': '0.4.0',
'qiskit-ibmq-provider': '0.8.0',
'qiskit-aqua': '0.7.5',
'qiskit': '0.20.0'}

If you get a response like this, Qiskit works. Great! We’re ready to create our first qubit.

如果您收到这样的答复, Qiskit就会起作用。 大! 我们准备创建我们的第一个量子位。

from qiskit import QuantumCircuit


# Create a quantum circuit with one qubit
qc = QuantumCircuit(1)


# Define initial_state as |1>
initial_state = [0,1]


# Apply initialization operation to the qubit at position 0
qc.initialize(initial_state, 0)

The fundamental unit of Qiskit is the quantum circuit. A quantum circuit is a model for quantum computation. The program, if you will. Our circuit consists of a single one qubit (line 4).

Qiskit的基本单元是量子电路。 量子电路是用于量子计算的模型。 该程序,如果您愿意。 我们的电路由一个1 qubit(第4行)组成。

We define [0,1] as the initial_state of our qubit (line 7) and initialize the first and only qubit (at position 0 of the array) of our quantum circuit with it (line 10).

我们将[0,1]定义为量子位的initial_state (第7行),并使用它初始化量子电路的第一个也是唯一的量子位(在阵列的位置0 )(第10行)。

Remember [0,1]? This is the equivalent to |1⟩=[0 1]. And in plain English, it is a qubit resulting in the value 1 when observed.

还记得[0,1]吗? 这等于|1⟩= [0 1]。 用简单的英语来说,它是一个量子比特,当被观察时其值为1

This is it. It’s now time to boot our quantum computer. In case you don’t have one, no problem. We can simulate it. (In case you have one: “Cool, let me know”).

就是这个。 现在该启动我们的量子计算机了。 万一你没有,那就没问题。 我们可以模拟它。 (如果您有一个: “很酷,请告诉我” )。

from qiskit import execute, Aer


# Tell Qiskit how to simulate our circuit
backend = Aer.get_backend('statevector_simulator') 


# Do the simulation, returning the result
result = execute(qc,backend).result()

Qiskit provides the Aer package (that we import at line 1). It provides different backends for simulating quantum circuits. The most common backend is the statevector_simulator (line 4).

Qiskit提供了Aer程序包(我们在第1行导入)。 它提供了用于仿真量子电路的不同后端。 最常见的后端是statevector_simulator (第4行)。

The execute-function (that we import at line 1, too) runs our quantum circuit (qc) at the specified backend. It returns a job-object that has a useful method job.result(). This returns the result object once our program completes it.

execute function(也在第1行导入)在指定的backend运行量子电路( qc )。 它返回一个job ,有一个有用的方法-object job.result() 程序完成后,将返回result对象。

Let’s have a look at our qubit in action.

让我们来看看我们的量子比特。

Qiskit uses Matplotlib to provide useful visualizations. A simple histogram will do. The result object provides the get_counts method to obtain the histogram data of an executed circuit (line 5).

Qiskit使用Matplotlib提供有用的可视化。 一个简单的直方图就可以了。 result对象提供get_counts方法以获得已执行电路的直方图数据(第5行)。

The method plot_histogram returns a Matplotlib figure that Jupyter draws automatically (line 8).

plot_histogram方法返回Jupyter自动绘制的Matplotlib图形(第8行)。

We see we have a 100% chance of observing the value 1.

我们看到我们有100%的机会观察值1

from qiskit.visualization import plot_histogram
import matplotlib.pyplot as plt


# get the probability distribution
counts = result.get_counts()


# Show the histogram
plot_histogram(counts)
Image for post
Image by author Frank Zickert
图片由作者Frank Zickert提供

Now, let’s move on to a more advanced case. Say, we want our qubit to result in either 0 or 1 with the same probability (50:50).

现在,让我们继续一个更高级的案例。 假设我们希望我们的量子位以相同的概率(50:50)产生01

In quantum mechanics, there is the fundamental principle superposition. It says any two (or more) quantum states can be added together (“superposed”) and the result will be another valid quantum state.

在量子力学中,存在基本原理叠加。 它说可以将任何两个(或更多)量子态加在一起(“叠加”),结果将是另一个有效的量子态。

Wait! We already know two quantum states, |0⟩ and |1⟩. Why don’t we add them? |0⟩ and |1⟩ are vectors. Adding two vectors is straight forward.

等待! 我们已经知道两个量子态|0⟩和|1⟩。 我们为什么不添加它们? |0⟩和|1⟩是向量。 直接添加两个向量。

A vector is a geometric object that has a magnitude (or length) and a direction. Usually, they are represented by straight arrows, starting at one point on a coordinate axis and ending at a different point.

向量是具有大小(或长度)和方向的几何对象。 通常,它们用直箭头表示,从坐标轴上的一个点开始,到另一个点结束。

You can add two vectors by placing one vector with its tail at the other vector’s head. The straight line between the yet unconnected tail and the yet unconnected tail is the sum of both vectors. Have a look at the following figure.

您可以通过将一个向量的尾部放在另一个向量的头部来添加两个向量。 尚未连接的尾部和尚未连接的尾部之间的直线是两个向量的总和。 看下图。

Image for post
Image by author Frank Zickert
图片由作者Frank Zickert提供

Mathematically, it is as easy.

从数学上讲,这很容易。

Let u=[u1 u2] and v=[v1 v2] be two vectors.

令u = [u1 u2]和v = [v1 v2]是两个向量。

The sum of u and v is:

u和v的总和为:

Image for post

Accordingly, our superposed state should be ψ∗:∗ψ (“psi”) is a common symbol used for the state of a quantum system.

因此,我们的叠加态应为ψ∗: ∗ψ(“ psi”)是用于量子系统状态的常用符号。

Image for post

We have a computer in our hands. Why don’t we try it?

我们手里有一台电脑。 我们为什么不尝试呢?

# Define state |psi>
initial_state = [1, 1]


# Redefine the quantum circuit
qc = QuantumCircuit(1)


# Initialise the 0th qubit in the state `initial_state`
qc.initialize(initial_state, 0) 


# execute the qc
results = execute(qc,backend).result().get_counts()


# plot the results
plot_histogram(results)
QiskitError: 'Sum of amplitudes-squared does not equal one.'

It didn’t quite work. It tells us: QiskitError: 'Sum of amplitudes-squared does not equal one.'.

效果不佳。 它告诉我们: QiskitError: 'Sum of amplitudes-squared does not equal one.'

The amplitudes are the values in our array. They are proportional to probabilities. And all the probabilities should add up to exactly 1 (100%). We need to add weights to the quantum states |0⟩ and |1⟩. Let’s call them α and β.

振幅是我们数组中的值。 它们与概率成正比。 并且所有概率之和应恰好等于1(100%)。 我们需要给量子态| 0 |和|1⟩增加权重。 我们称它们为α和β。

We weight |0⟩ with α and |1⟩ with β. Like this:

我们用α加权|0⟩,用β加权|1⟩。 像这样:

Image for post

Amplitudes are proportional to probabilities. We need to normalize them so that:

幅度与概率成正比。 我们需要对其进行规范化,以便:

Image for post

If both states |0⟩ and |1⟩ should have the same weight, then α=β. And therefore, we can solve our equation to α:

如果|0⟩和|1⟩这两个状态应具有相同的权重,则α=β 。 因此,我们可以将方程式解为α:

Image for post

And we insert the value for both α and β (both are equal). Let’s try this quantum state:

然后我们插入α和β的值(两者相等)。 让我们尝试这种量子状态:

Image for post

The corresponding array in Python is: [1/sqrt(2), 1/sqrt(2)]. Don't forget to import sqrt.

Python中对应的数组是: [1/sqrt(2), 1/sqrt(2)] 。 不要忘记导入sqrt

from math import sqrt


# Define state |psi>
initial_state = [1/sqrt(2), 1/sqrt(2)] 


# Redefine the quantum circuit
qc = QuantumCircuit(1)


# Initialise the 0th qubit in the state `initial_state`
qc.initialize(initial_state, 0) 


# execute the qc
results = execute(qc,backend).result().get_counts()


# plot the results
plot_histogram(results)
Image for post
Image by author Frank Zickert
图片由作者Frank Zickert提供

Phew. In this post, we introduced quite a few terms and equations just to scratch on the surface of quantum mechanics. But the actual source code is pretty neat, isn’t it?

ew 在这篇文章中,我们介绍了许多术语和方程式只是为了介绍量子力学的表面。 但是实际的源代码很整洁,不是吗?

We introduced the notion of the quantum state. In particular, the state of a binary quantum system. The quantum bit or qubit.

我们介绍了量子态的概念。 特别是二元量子系统的状态。 量子位或量子位。

Until we observe a qubit, it is in superposition. Contrary to a classical bit that can be either 0 or 1, a qubit is in a superposition of both states. But once you observe it, there are distinct probabilities of measuring 0 or 1.

在我们观察到一个量子比特之前,它是叠加的。 与可以为01的经典位相反,量子位处于两个状态的叠加中。 但是一旦您观察到它,就有测量01不同概率。

This means that multiple measurements made on multiple qubits in identical states will not always give the same result. The equivalent representations of a quantum bit that, when observed, has the probability of α^2 to result in 0 and β^2 to result in 1 are:

这意味着对处于相同状态的多个量子位进行的多次测量将不会总是给出相同的结果。 当被观察时,具有a ^ 2产生0的概率和β^ 2产生1的概率的量子比特的等效表示是:

Image for post

In Python the array [alpha, beta] denotes this state.

在Python中,数组[alpha, beta]表示此状态。

This post is part of the book: Hands-On Quantum Machine Learning With Python.

这篇文章是这本书的一部分:动手使用Python进行量子机器学习。

Image for post

Get the first three chapters for free here.

此处免费获取前三章。

翻译自: https://towardsdatascience.com/hands-on-exploration-of-the-qubit-815bee3f30dd

量子比特纠缠

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值