行翻转和列翻转_用量子计算机翻转硬币

行翻转和列翻转

Amazon recently announced its latest AWS offering: Quantum computing as a service. It’s called Amazon Braket (pronounced “bracket”). Last week it moved from a closed beta to general availability.

亚马逊最近宣布了其最新的AWS产品:量子计算即服务。 它被称为Amazon Braket (发音为“括号”)。 上周,它从一个封闭的Beta转变为全面上市。

Here’s how you can run your first quantum program in just a few minutes.

这是您在短短几分钟内即可运行第一个量子程序的方式。

第1步:设置您的帐户 (Step 1: Set Up Your Account)

The first thing you need to do is create an AWS account if you don’t have one already. Go to https://aws.amazon.com and follow the instructions.

您需要做的第一件事是创建一个AWS账户(如果您还没有账户)。 转到https://aws.amazon.com并按照说明进行操作。

Next, you’ll need to activate Amazon Braket by going to https://aws.amazon.com/braket/ and clicking “Get Started with Amazon Braket.”

接下来,您需要通过转到https://aws.amazon.com/braket/并单击“ Amazon Braket入门”来激活Amazon Braket。

This will walk you through some terms and conditions, which you’ll need to agree with to proceed. You’ll also be prompted to create an S3 bucket for storing the results of quantum programs. You’ll also have to set up access rules for the account. Fortunately, there are default settings filled in for you already. I just left every option alone. Make a note of the name of the S3 bucket for later.

这将引导您完成一些条款和条件,您需要同意这些条款和条件才能继续进行。 系统还会提示您创建一个S3存储桶,用于存储量子程序的结果。 您还必须为该帐户设置访问规则。 幸运的是,已经为您填写了默认设置。 我只留下了每个选项。 记下S3存储桶的名称,以备后用。

Image for post

Next, click “notebooks” on the left and create a new notebook instance to run your code. Name it something meaningful and select the “ml.t3.medium” instance type. Keep in mind that this costs money to run. It is included in the AWS free tier, so you may be eligible to run up to 250 hours for free.

接下来,单击左侧的“笔记本”,然后创建一个新的笔记本实例来运行您的代码。 将其命名为有意义的名称,然后选择“ ml.t3.medium”实例类型。 请记住,这需要花钱才能运行。 它包含在AWS免费套餐中,因此您可能有资格免费运行250小时。

There are some other settings for permissions and networking. Again, I just left the defaults.

权限和网络还有其他一些设置。 同样,我只是保留了默认值。

第2步:编写一些代码 (Step 2: Write Some Code)

Click the notebook URL shown on the notebook instance list. The URL will look something like: amazon-braket-[name].notebook.[region].sagemaker.aws

单击笔记本实例列表上显示的笔记本URL。 该URL类似于: amazon-braket-[name].notebook.[region].sagemaker.aws

This opens up a Jupyter Notebook environment. Click “New” on the top right then choose conda_braket. (This is the name of the Python virtual environment with all the needed dependencies pre-installed).

这将打开Jupyter Notebook环境。 单击右上角的“新建”,然后选择conda_braket 。 (这是预安装所有必需依赖项的Python虚拟环境的名称)。

Copy and run this code:

复制并运行以下代码:

If all goes well, you will see a result like:

如果一切顺利,您将看到类似以下结果:

Counter({'0': 505, '1': 495})

We performed a simulation of running a single-qubit Hadamard gate and then measured the result 1,000 times. The counter shows the number of times the qubit was measured in the ground state ‘0’ and the excited state ‘1’.

我们对运行单量子位Hadamard门进行了仿真,然后对结果进行了1000次测量。 计数器显示在基态“ 0”和激发态“ 1”下测量量子比特的次数。

The Hadamard gate puts the qubit in a superposition where it will have an equal probability of being measured in either state. This is exactly what we want: a coin flip with a 50/50 chance.

哈达玛门将量子比特置于一个叠加中,在任一状态下它都有相等的概率被测量。 这正是我们想要的:机会为50/50的硬币翻转。

But this example was just simulating a quantum computer. We want to use the real thing!

但是这个例子只是在模拟一台量子计算机。 我们要使用真实的东西!

步骤3:选择一台Quantum计算机 (Step 3: Choose a Quantum Computer)

Amazon offers three different quantum computing devices to choose from:

亚马逊提供三种不同的量子计算设备供您选择:

  1. Gate-based superconducting qubits from Rigetti Computing

    来自Rigetti Computing的基于门的超导量子比特
  2. Gate-based ion traps from IonQ

    来自IonQ的基于门的离子阱
  3. Quantum annealing from D-Wave

    D波的量子退火

The third option, quantum annealing from D-Wave, is a different paradigm of quantum computing that won’t work with the above code. So our choice is between using superconducting qubits or ion traps.

第三种选择是D-Wave的量子退火,它是量子计算的另一范式,不适用于以上代码。 因此,我们的选择是在使用超导量子位或离子阱之间。

I’m going to choose the superconducting qubits from Rigetti since they have a cheaper per-shot rate than IonQ… and because I used to work at Rigetti.

我要从Rigetti选择超导量子比特,因为它们的单次发射速率比IonQ便宜……并且因为我曾经在Rigetti工作。

In a new cell, copy the following. Here is where you’ll need the S3 folder from earlier because, unlike the free simulator, you don’t want to lose any results from real hardware. If you forgot the name of the S3 folder, you can look it up back in the AWS console under the S3 header.

在新的单元格中,复制以下内容。 在这里,您将需要较早版本的S3文件夹,因为与免费的模拟器不同,您不想丢失任何来自实际硬件的结果。 如果您忘记了S3文件夹的名称,则可以在AWS控制台中的S3标头下查找它。

We’re reusing the coin_flip_circuit we created in the last step.

我们将重用在上一步中创建的coin_flip_circuit

If all goes well it should respond with:

如果一切顺利,它应该以以下方式回应:

'CREATED'

Now in a new cell (do not rerun the previous cell since that will enqueue another task!) keep running task.state() to see the status change to 'QUEUED'.

现在在新的单元格中(不要重新运行前一个单元格,因为这将使另一个任务入队!)继续运行task.state()以查看状态更改为'QUEUED'

What’s happened? Your task hasn’t run on the quantum computer yet because it is waiting in line. Also, some of the quantum computers are only accessible during certain times of the day. It takes a lot of work to maintain properly calibrated quantum computing hardware, so it will only be available sparingly. Check the Devices tab on the Amazon Braket AWS console page to see the schedule for each device.

发生了什么? 您的任务尚未在量子计算机上运行,​​因为它正在排队。 同样,某些量子计算机仅在一天中的特定时间可用。 维护正确校准的量子计算硬件需要花费大量工作,因此只能少量使用。 在Amazon Braket AWS控制台页面上查看设备选项卡,以查看每个设备的时间表。

In my case, I was scheduled to wait several hours for the next available slot. If you don’t want to keep my notebook server running for that amount of time, then you can run task.id and make a note of the returned value.

就我而言,我计划等待几个小时才能获得下一个可用的广告位。 如果您不想让我的笔记本服务器在这段时间内运行,则可以运行task.id并记下返回值。

Later, you can run the following in a new cell (or even a new notebook) to recover the task:

以后,您可以在新的单元格(甚至新的笔记本)中运行以下命令以恢复任务:

Once task.state() returns 'COMPLETED' then you can access the results just like in the local simulator:

一旦task.state()返回'COMPLETED'您就可以像在本地模拟器中那样访问结果:

Again if all goes well, you’ll see a result like this:

同样,如果一切顺利,您将看到如下结果:

Counter({'0': 593, '1': 407})

If you have the patience to repeat this a few times, you’ll likely notice that the ‘0’s seem to dominate the results. This is not a mistake, but more a reflection that today’s quantum computers aren’t perfectly accurate. In our example circuit, this results in more ‘0’s than ‘1’s.

如果您有耐心重复几次,您可能会注意到“ 0”似乎主导了结果。 这不是一个错误,而是更多地反映出当今的量子计算机并不十分准确。 在我们的示例电路中,这导致比“ 1”更多的“ 0”。

By the way: To run on the ion traps instead replace device/qpu/rigetti/Aspen-8 with device/qpu/ionq/ionQdevice in the code above. It would be a good idea to reduce the number of shots since running 1000 shots costs 35 cents on Rigetti but 10 dollars on IonQ.

顺便说一句:要在离子阱上运行, device/qpu/ionq/ionQdevice 在上面的代码 device/qpu/rigetti/Aspen-8 替换为 device/qpu/ionq/ionQdevice 减少拍摄数量是一个好主意,因为在Rigetti上运行1000张照片要花费35美分,在IonQ上要花费10美元。

步骤4:放在一起 (Step 4: Put It All Together)

A complete coin flip example could look something like this:

一个完整的硬币翻转示例可能看起来像这样:

Note: there is a minimum of 10 shots in Braket for some reason, but we only need one coin flip, so we ignore the other 9 shots.

注意:出于某些原因,Braket中至少有10张照片,但是我们只需要掷一次硬币,因此我们忽略了另外9张照片。

This will (eventually) print either HEADS! or TAILS! depending on the measured state of the qubit.

(最终)这将打印两个头HEADS!TAILS! 取决于量子位的测量状态。

Make sure to stop your notebook instance once you’re done!

完成后,请确保停止笔记本实例!

与经典的硬币翻转比较 (Comparing with a classical coin flip)

Here’s my review of the experience using a quantum computer to flip a coin vs. just flipping a physical coin.

这是我对使用量子计算机抛硬币与仅抛硬币的经验的评论。

Flipping a coin with a quantum computer:

用量子计算机翻转硬币:

  • 🚫 biased towards tails (although there are ways to work around this)

    ed偏于尾巴(尽管有解决此问题的方法)
  • 🚫 costs money each flip

    flip每次翻转都要花钱
  • 🚫 only available during business hours

    🚫仅在工作时间提供
  • ✅ cool and quantum

    ✅酷而量子

Flipping a physical coin:

翻转实物硬币:

  • ✅ fair coin

    ✅公平硬币
  • ✅ you need a coin, but you get to keep it afterward

    need你需要一枚硬币,但是以后要保留它
  • ✅ available any time

    any随时可用
  • 🚫 boring and classical

    classical无聊而古典

Overall, flipping a coin with a quantum computer is neat but not a very good way to decide who goes first in a football game. Nevertheless, quantum computers can still be a good source of randomness through the use of a randomness extractor. Some companies will go to great lengths to get a reliable source of truly random bits.

总的来说,用量子计算机掷硬币是很整洁的,但不是决定谁在足球比赛中首屈一指的好方法。 尽管如此,通过使用随机性提取器 ,量子计算机仍然可以成为良好的随机性来源。 一些公司将竭尽全力以获取可靠的真正随机位的来源。

There are many other uses for a quantum computer, some of which you can find in the “Braket examples” folder on the notebook server. For instance, one notebook shows how to simulate molecule binding energies using the Variational Quantum Eigensolver (VQE) algorithm. There are other examples as well for basic quantum algorithms, quantum teleportation, and quantum optimization. As a next step, you can look through these and run the code there as well against real quantum devices.

量子计算机还有许多其他用途,其中一些可以在笔记本服务器的“ Braket示例”文件夹中找到。 例如,一个笔记本显示了如何使用变分量子本征求解器(VQE)算法来模拟分子结合能。 基本量子算法,量子隐形传态和量子优化也有其他示例。 下一步,您可以浏览这些代码,并针对真正的量子设备在其中运行代码。

Happy quantum computing!

快乐的量子计算!

翻译自: https://medium.com/better-programming/flipping-a-coin-with-a-quantum-computer-4c8aec93fa27

行翻转和列翻转

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,业涵盖各高科技业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值