首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

Quantum computing in action: IBM's Q experience and the quantum shell game(1)

Quantum computing in action: IBM's Q experience and the quantum shell game(1)

Prerequisite knowledgeIf you have a little experience creating websites and some familiarity with                HTML and JavaScript, you’ll find this to be a very simple (and simplified)                experience. I won’t describe the details of the C#, HTML or JavaScript                code, as it’s somewhat irrelevant to how to use the Q experience platform.                As you’ll see, the tricky stuff is all happening in the backend.
It also helps if you have some understanding of the IBM Q experience's                Quantum Composer and the nature of the Quantum Assembler—but it’s not                required to follow this simple how-to.
System requirementsFirst, you’ll need an account on IBM’s Q experience. It’s free! How cool is                that? To sign up, .
You’ll want an integrated development editor (IDE) to write your code. For                my purposes, I used Microsoft Visual Studio 2015. If you are a die-hard,                you could use notepad, though I wouldn’t recommend it.
You can run your experiments locally on your system or a cloud platform of                your choice. I published my code to the IBM Cloud so I could share this with                you.
A                workaroundWhen thinking about how to use quantum computing to solve my puzzle, I                first envisioned this project as a fully JavaScript-browser-based task.                I’d write a little HTML 5, add some JS magic, and the shells would animate                across the screen. I could build the quantum assembler code (QASM) in                JavaScript and pass it all over to the IBM Q experience platform via a                simple web service call.
Unfortunately, IBM doesn’t permit cross-origin resource sharing (CORS) from                outside domains, so the browser prevented us from making any of the                service calls. Stymied!
Well, not quite. But back to the drawing board.
Another alternative is to make the request from server-side code, instead                of the browser, where CORS does not apply. This complicates matters a                little.
Now our con game must post the layout of the shell game to the server. The                server assembles the requests into QASM code and posts it to IBM’s                platform. The JSON returned from this web service request is then parsed                by the server and fed back to the web page, showing which shell was chosen                by the quantum computer. We basically insert a go-between to solve the                issue. And presto! The game works.
The quantum solutionThere are several ways to create, edit, and deploy an ASP.NET Core                application to IBM Cloud. I started by creating an ASP.NET Core 1.0                project in Visual Studio. After removing the default Contact and About                pages which come in the template, I modified the                Views\Shared\_Layout.cshtml file and the Views\Home\Index.cshtml to suit                my needs.
I then created a folder under the Controllers directory to store the class                files we’ll use to communicate with the IBM Q platform.
Figure 1. The ASP.NET Core solutionView image at full size
We’ll focus our attention on the IBMQ folder first, as it's the real heart                of this program.
The classes in this folder are responsible for logging into IBM’s Q                experience platform, assembling the Quantum Assembler Code (QASM), and                executing the code against IBM’s quantum processor and parsing the results                of the execution. Executing and parsing the code is done via the exposed                web interface.
  • The QProcessor class is the heart of this operation. It                    handles the login function and the execution of the QASM code, as well                    as a couple of utility and cleanup routines. It also persists the                    security information needed to make the various web service calls and                    wraps up the implementation. Note the function that’s used to delete                    experiments. IBM’s Q experience platform saves every execution as an                    experiment—over time, especially when testing out ideas, your account                    on the Q experience platform will literally be overrun with                    experiments. I found deleting them immediately after they have been                    run to be the best way to do the housekeeping.
  • The QResult class is a simple construct to pass the success                    of an operation back and forth between components.
  • QUser class is an object used to hold the results of logging                    into the Q experience platform. In this experiment, after logging in,                    you want to record the userId of the user, as this is later used as                    the access token granting you permission to perform operations against                    the account.
  • The QCode class will be used to assemble the QASM code. It                    also carried the number of shots (the number of times to perform the                    quantum execution). Remember, quantum qubits are returned as a                    probability of being a 1 or 0). For this application, I run the                    quantum code for 500 shots—which is more than enough to achieve a near                    100% probability of a 1 or a 0—thus removing some of the                    wishy-washiness of quantum processing.
  • QExecutionOutput is the most complicated class of these five                    classes. However, for the purposes of this application, we get to                    ignore most of it. The most important part is the P class lurking                    inside of the Data class. There are two properties, labels and values,                    that hold the result. The labels property tells us whether a given                    qubit resulted in a classical bit of 1 or 0, and the values property                    tell us what the probability of the result was. The class itself was                    generated from the JSON result of executing sample code against the                    IBM platform. I used an online converter — in this instance,  — to build                    the QExecutionOutput class. Admittedly, this class is probably not the                    perfect way to handle the resulting JSON, but it was faster than                    writing the class by hand.
So, let’s walk through the steps these classes are going to perform.
返回列表