日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

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

發(fā)布時(shí)間:2023/12/2 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 行翻转和列翻转_用量子计算机翻转硬币 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

行翻轉(zhuǎn)和列翻轉(zhuǎn)

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產(chǎn)品:量子計(jì)算即服務(wù)。 它被稱為Amazon Braket (發(fā)音為“括號(hào)”)。 上周,它從一個(gè)封閉的Beta轉(zhuǎn)變?yōu)槿嫔鲜小?

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

這是您在短短幾分鐘內(nèi)即可運(yùn)行第一個(gè)量子程序的方式。

第1步:設(shè)置您的帳戶 (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.

您需要做的第一件事是創(chuàng)建一個(gè)AWS賬戶(如果您還沒(méi)有賬戶)。 轉(zhuǎn)到https://aws.amazon.com并按照說(shuō)明進(jìn)行操作。

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

接下來(lái),您需要通過(guò)轉(zhuǎn)到https://aws.amazon.com/braket/并單擊“ Amazon Braket入門(mén)”來(lái)激活A(yù)mazon 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.

這將引導(dǎo)您完成一些條款和條件,您需要同意這些條款和條件才能繼續(xù)進(jìn)行。 系統(tǒng)還會(huì)提示您創(chuàng)建一個(gè)S3存儲(chǔ)桶,用于存儲(chǔ)量子程序的結(jié)果。 您還必須為該帳戶設(shè)置訪問(wèn)規(guī)則。 幸運(yùn)的是,已經(jīng)為您填寫(xiě)了默認(rèn)設(shè)置。 我只留下了每個(gè)選項(xiàng)。 記下S3存儲(chǔ)桶的名稱,以備后用。

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.

接下來(lái),單擊左側(cè)的“筆記本”,然后創(chuàng)建一個(gè)新的筆記本實(shí)例來(lái)運(yùn)行您的代碼。 將其命名為有意義的名稱,然后選擇“ ml.t3.medium”實(shí)例類型。 請(qǐng)記住,這需要花錢(qián)才能運(yùn)行。 它包含在AWS免費(fèi)套餐中,因此您可能有資格免費(fèi)運(yùn)行250小時(shí)。

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

權(quán)限和網(wǎng)絡(luò)還有其他一些設(shè)置。 同樣,我只是保留了默認(rèn)值。

第2步:編寫(xiě)一些代碼 (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

單擊筆記本實(shí)例列表上顯示的筆記本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).

這將打開(kāi)Jupyter Notebook環(huán)境。 單擊右上角的“新建”,然后選擇conda_braket 。 (這是預(yù)安裝所有必需依賴項(xiàng)的Python虛擬環(huán)境的名稱)。

Copy and run this code:

復(fù)制并運(yùn)行以下代碼:

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

如果一切順利,您將看到類似以下結(jié)果:

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’.

我們對(duì)運(yùn)行單量子位Hadamard門(mén)進(jìn)行了仿真,然后對(duì)結(jié)果進(jìn)行了1000次測(cè)量。 計(jì)數(shù)器顯示在基態(tài)“ 0”和激發(fā)態(tài)“ 1”下測(cè)量量子比特的次數(shù)。

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.

哈達(dá)瑪門(mén)將量子比特置于一個(gè)疊加中,在任一狀態(tài)下它都有相等的概率被測(cè)量。 這正是我們想要的:機(jī)會(huì)為50/50的硬幣翻轉(zhuǎn)。

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

但是這個(gè)例子只是在模擬一臺(tái)量子計(jì)算機(jī)。 我們要使用真實(shí)的東西!

步驟3:選擇一臺(tái)Quantum計(jì)算機(jī) (Step 3: Choose a Quantum Computer)

https://aws.amazon.com/braket/.https://aws.amazon.com/braket/ 。

Amazon offers three different quantum computing devices to choose from:

亞馬遜提供三種不同的量子計(jì)算設(shè)備供您選擇:

  • Gate-based superconducting qubits from Rigetti Computing

    來(lái)自Rigetti Computing的基于門(mén)的超導(dǎo)量子比特
  • Gate-based ion traps from IonQ

    來(lái)自IonQ的基于門(mén)的離子阱
  • 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的量子退火,它是量子計(jì)算的另一范式,不適用于以上代碼。 因此,我們的選擇是在使用超導(dǎo)量子位或離子阱之間。

    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選擇超導(dǎo)量子比特,因?yàn)樗鼈兊膯未伟l(fā)射速率比IonQ便宜……并且因?yàn)槲以?jīng)在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.

    在新的單元格中,復(fù)制以下內(nèi)容。 在這里,您將需要較早版本的S3文件夾,因?yàn)榕c免費(fèi)的模擬器不同,您不想丟失任何來(lái)自實(shí)際硬件的結(jié)果。 如果您忘記了S3文件夾的名稱,則可以在AWS控制臺(tái)中的S3標(biāo)頭下查找它。

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

    我們將重用在上一步中創(chuàng)建的coin_flip_circuit 。

    If all goes well it should respond with:

    如果一切順利,它應(yīng)該以以下方式回應(yīng):

    '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'.

    現(xiàn)在在新的單元格中(不要重新運(yùn)行前一個(gè)單元格,因?yàn)檫@將使另一個(gè)任務(wù)入隊(duì)!)繼續(xù)運(yùn)行task.state()以查看狀態(tài)更改為'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.

    發(fā)生了什么? 您的任務(wù)尚未在量子計(jì)算機(jī)上運(yùn)行,??因?yàn)樗谂抨?duì)。 同樣,某些量子計(jì)算機(jī)僅在一天中的特定時(shí)間可用。 維護(hù)正確校準(zhǔn)的量子計(jì)算硬件需要花費(fèi)大量工作,因此只能少量使用。 在Amazon Braket AWS控制臺(tái)頁(yè)面上查看設(shè)備選項(xiàng)卡,以查看每個(gè)設(shè)備的時(shí)間表。

    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.

    就我而言,我計(jì)劃等待幾個(gè)小時(shí)才能獲得下一個(gè)可用的廣告位。 如果您不想讓我的筆記本服務(wù)器在這段時(shí)間內(nèi)運(yùn)行,則可以運(yùn)行task.id并記下返回值。

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

    以后,您可以在新的單元格(甚至新的筆記本)中運(yùn)行以下命令以恢復(fù)任務(wù):

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

    一旦task.state()返回'COMPLETED'您就可以像在本地模擬器中那樣訪問(wèn)結(jié)果:

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

    同樣,如果一切順利,您將看到如下結(jié)果:

    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.

    如果您有耐心重復(fù)幾次,您可能會(huì)注意到“ 0”似乎主導(dǎo)了結(jié)果。 這不是一個(gè)錯(cuò)誤,而是更多地反映出當(dāng)今的量子計(jì)算機(jī)并不十分準(zhǔn)確。 在我們的示例電路中,這導(dǎo)致比“ 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.

    順便說(shuō)一句:要在離子阱上運(yùn)行, device/qpu/ionq/ionQdevice 在上面的代碼 device/qpu/rigetti/Aspen-8 替換為 device/qpu/ionq/ionQdevice 。 減少拍攝數(shù)量是一個(gè)好主意,因?yàn)樵赗igetti上運(yùn)行1000張照片要花費(fèi)35美分,在IonQ上要花費(fèi)10美元。

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

    A complete coin flip example could look something like this:

    一個(gè)完整的硬幣翻轉(zhuǎn)示例可能看起來(lái)像這樣:

    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.

    (最終)這將打印兩個(gè)頭HEADS! 或TAILS! 取決于量子位的測(cè)量狀態(tài)。

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

    完成后,請(qǐng)確保停止筆記本實(shí)例!

    與經(jīng)典的硬幣翻轉(zhuǎn)比較 (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.

    這是我對(duì)使用量子計(jì)算機(jī)拋硬幣與僅拋硬幣的經(jīng)驗(yàn)的評(píng)論。

    Flipping a coin with a quantum computer:

    用量子計(jì)算機(jī)翻轉(zhuǎn)硬幣:

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

      ed偏于尾巴(盡管有解決此問(wèn)題的方法)
    • 🚫 costs money each flip

      flip每次翻轉(zhuǎn)都要花錢(qián)
    • 🚫 only available during business hours

      🚫僅在工作時(shí)間提供
    • ? cool and quantum

      ?酷而量子

    Flipping a physical coin:

    翻轉(zhuǎn)實(shí)物硬幣:

    • ? fair coin

      ?公平硬幣
    • ? you need a coin, but you get to keep it afterward

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

      any隨時(shí)可用
    • 🚫 boring and classical

      classical無(wú)聊而古典

    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.

    總的來(lái)說(shuō),用量子計(jì)算機(jī)擲硬幣是很整潔的,但不是決定誰(shuí)在足球比賽中首屈一指的好方法。 盡管如此,通過(guò)使用隨機(jī)性提取器 ,量子計(jì)算機(jī)仍然可以成為良好的隨機(jī)性來(lái)源。 一些公司將竭盡全力以獲取可靠的真正隨機(jī)位的來(lái)源。

    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.

    量子計(jì)算機(jī)還有許多其他用途,其中一些可以在筆記本服務(wù)器的“ Braket示例”文件夾中找到。 例如,一個(gè)筆記本顯示了如何使用變分量子本征求解器(VQE)算法來(lái)模擬分子結(jié)合能。 基本量子算法,量子隱形傳態(tài)和量子優(yōu)化也有其他示例。 下一步,您可以瀏覽這些代碼,并針對(duì)真正的量子設(shè)備在其中運(yùn)行代碼。

    Happy quantum computing!

    快樂(lè)的量子計(jì)算!

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

    行翻轉(zhuǎn)和列翻轉(zhuǎn)

    總結(jié)

    以上是生活随笔為你收集整理的行翻转和列翻转_用量子计算机翻转硬币的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。