Quantum computing in action: IBM's Q experience and the quantum shell game(3)
- UID
- 1066743
|
Quantum computing in action: IBM's Q experience and the quantum shell game(3)
Phase 2. Execute the codeNow it’s time to submit the QASM code for execution. We’ll create an ExecuteCode function with the following information:
- A URL string with the following three parameters:
- Shots: the number of times to perform the experiment
- Seed
- deviceRunType: we use “simulator,” though if you’d prefer you can run this on the real quantum processor
- Other data including:
- the QASM code itself
- the codeType: for us, it’s QASM2
- a name to assign to the run
Below is the ExecuteCode function in all its glory:
Listing 4. ExecuteCode function1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| public QResult ExecuteCode(QCode code)
{
if (this.User == null) throw new Exception("Not logged in.");
QResult result = new QResult();
string url = string.Format("/codes/execute?shots={0}&seed={1}&deviceRunType={2}",
code.shots.ToString(),
code.seed.ToString(),
code.deviceRunType
);
string data = string.Format("qasm={0}&codeType={1}&name={2}",
code.qasm,
code.codeType,
code.name
);
var kvp = new List<KeyValuePair<string, string>>();
kvp.Add(new KeyValuePair<string, string>("qasm", code.qasm));
kvp.Add(new KeyValuePair<string, string>("codeType", code.codeType));
kvp.Add(new KeyValuePair<string, string>("name", code.name));
HttpContent content = new FormUrlEncodedContent(kvp);
result = FetchAPIData(url, HttpMethod.Post, content);
Debug.WriteLine("ExecuteCode received the following JSON from the API:");
Debug.WriteLine(result.Message);
return result;
}
|
We pack the data into a KeyValuePair which we then FormUrlEncoded so that it can be POSTed to the URL using our FetchAPIData call.
Good start. But now what? How does a quantum processor solve a shell game?
Grover’s algorithm and the amplitude amplification trick To understand how quantum computing works, you need to know about Grover’s algorithm and the amplitude amplification trick.
The IBM Q experience is an excellent deep-dive into the algorithm if you need a deeper explanation.
In physical reality, if you’re given a set of shells, you simply flip them over one at a time until you find the ball. In the world of computers, this shell game is nothing more than an unstructured search.
Unstructured search is the process in which N number of elements in a set are searched by applying a Boolean evaluation (a function specifically of the form, f(x)=1) to each element in the set.
Given N elements in a set X ={x1, x2,…xN} and given a function f: X=>{0,1}, find element x* in X where f(x*)=1.
In our case, we have a number of shells (let’s call that number N), and we want to find the shell with a ball under it. When we select a shell, if there is a ball under the shell, that becomes a result called “true” or “1.” If we find anything under the shell besides a ball, let the result be a value called “false” or “0”. In this way, we have a function denoted f(x) = 1 when there is a ball and f(x) = 0 when there is anything other than a ball.
In the world of classical computing and our shell game, we simply read each shell, apply the function, and stop when we find the ball. This is sometimes described as “consulting the oracle” since we treat the function as something like a black box. We don’t necessarily care what goes on inside the box, just that the result of the function is a 1 or a 0. Given N number of shells, the worst possible performance of the classical computers would be O(N) such evaluations (for example, the ball is under the last shell).
Using a quantum computer and the amplitude amplification trick, we can solve this problem in O(sqr(N)) evaluations. However, quantum computing is never straightforward. A quantum computation results in a probability less than 1—not an exact answer. That said, we can run the computation numerous times until the result is any arbitrarily selected high probability (say .99 or better). For our purposes, we will use 500 shots. This will almost always end up with a near 100 percent probability (or at least one that rounds up to 100%). |
|
|
|
|
|