Skip to content

Commit

Permalink
edits (#916)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Tian <kevin.tian@ibm.com>
  • Loading branch information
beckykd and kt474 authored Jun 15, 2023
1 parent 28b17ac commit 274d868
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions docs/tutorials/grover_with_sampler.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "db78a668",
"metadata": {},
Expand All @@ -9,25 +10,27 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "e57d1e6b",
"metadata": {},
"source": [
"## Background\n",
"\n",
"Amplitude amplification is a general purpose quantum algorithm, or subroutine, that can be used to obtain a quadratic speedup over a handful of classical algorithms. [Grover’s algorithm](https://arxiv.org/abs/quant-ph/9605043) was the first to demonstrate this speed up on unstructured search problems. Formulating a Grover's search problem requires an oracle function that marks one or more computational basis states as the states we are interested in finding, and an amplification circuit that increases the amplitude of marked states, consequently suppressing the remaining states. \n",
"Amplitude amplification is a general purpose quantum algorithm, or subroutine, that can be used to obtain a quadratic speedup over a handful of classical algorithms. [Grover’s algorithm](https://arxiv.org/abs/quant-ph/9605043) was the first to demonstrate this speedup on unstructured search problems. Formulating a Grover's search problem requires an oracle function that marks one or more computational basis states as the states we are interested in finding, and an amplification circuit that increases the amplitude of marked states, consequently suppressing the remaining states. \n",
"\n",
"Here we demonstrate how to construct Grover oracles and make use of the `GroverOperator` from the Qiskit circuit library, to easily setup a Grover's search instance. The runtime `Sampler` allows for seamless execution of Grover circuits, including automatic compilation, error suppression, and readout error mitigation techniques."
"Here we demonstrate how to construct Grover oracles and make use of the `GroverOperator` from the Qiskit circuit library to easily setup a Grover's search instance. The runtime `Sampler` primitive allows for seamless execution of Grover circuits, including automatic compilation, error suppression, and readout error mitigation techniques."
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "54602708",
"metadata": {},
"source": [
"## Setup\n",
"\n",
"Here we import the small number tools we need for this tutorial."
"Here we import the small number of tools we need for this tutorial."
]
},
{
Expand All @@ -50,13 +53,14 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "f71e0999",
"metadata": {},
"source": [
"## Initialize Runtime service and select backends\n",
"\n",
"Here we instantiate the Runtime service that gives access to the quantum devices and simulator that we use in this tutorial. Here we make use of a simulator to validate our circuit, and then turn to execution on a real quantum system."
"Here we instantiate the Runtime service that gives access to the quantum devices and the simulator that we use in this tutorial. We will first use a simulator to validate our circuit, then execute it on a real quantum system."
]
},
{
Expand All @@ -81,13 +85,14 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "d4845f4d",
"metadata": {},
"source": [
"## Define a Grover experiment\n",
"\n",
"Grover's algorithm requires an [oracle](https://quantum-computing.ibm.com/admin/docs/admin/guide/grovers-algorithm#the-oracle) that specifies one or more marked computational basis states, where \"marked\" means a state with a phase of -1. A controlled-Z gate, or its multi-controlled generalization over $N$ qubits, marks the $2^{N}-1$ state (`'1'`*$N$ bit-string). Marking basis states with one or more `'0'` in the binary representation requires applying X-gates on the corresponding qubits before and after the controlled-Z gate; equivalent to having an open-control on that qubit. In the following, we define an oracle that does just that, marking one or more input basis states defined through their bit-string representation. The `MCMT` gate is used to implement the multi-controlled Z-gate."
"Grover's algorithm requires an [oracle](https://quantum-computing.ibm.com/admin/docs/admin/guide/grovers-algorithm#the-oracle) that specifies one or more marked computational basis states, where \"marked\" means a state with a phase of -1. A controlled-Z gate, or its multi-controlled generalization over $N$ qubits, marks the $2^{N}-1$ state (`'1'`*$N$ bit-string). Marking basis states with one or more `'0'` in the binary representation requires applying X-gates on the corresponding qubits before and after the controlled-Z gate; equivalent to having an open-control on that qubit. In the following code, we define an oracle that does just that, marking one or more input basis states defined through their bit-string representation. The `MCMT` gate is used to implement the multi-controlled Z-gate."
]
},
{
Expand Down Expand Up @@ -131,13 +136,14 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "bca14740",
"metadata": {},
"source": [
"### Specific Grover's instance\n",
"\n",
"With the oracle function in hand, we can now define a specific instance of Grover search. In this example we will mark two computational states out of the 8 available in a 3-qubit computational space:"
"Now that we have the oracle function, we can define a specific instance of Grover search. In this example we will mark two computational states out of the eight available in a three-qubit computational space:"
]
},
{
Expand Down Expand Up @@ -166,13 +172,14 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "25487b93",
"metadata": {},
"source": [
"### The `GroverOperator`\n",
"\n",
"The built-in Qiskit `GroverOperator` takes an oracle circuit, and returns a circuit that is composed of the oracle circuit itself, and a circuit that amplifies the states marked by the oracle. Here we `decompose` the circuit to see the gates within the operator:"
"The built-in Qiskit `GroverOperator` takes an oracle circuit and returns a circuit that is composed of the oracle circuit itself and a circuit that amplifies the states marked by the oracle. Here, we `decompose` the circuit to see the gates within the operator:"
]
},
{
Expand All @@ -199,6 +206,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "83c34dc9",
"metadata": {},
Expand All @@ -219,6 +227,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "e06c8238",
"metadata": {},
Expand Down Expand Up @@ -258,13 +267,14 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "c5edec73",
"metadata": {},
"source": [
"## Execution with the Sampler primitive\n",
"\n",
"Amplitude amplification is a sampling problem that is suitable for execution with the `Sampler` runtime primitive. Because we have a single-circuit, we instantiate a `Sampler` using the target backend. To begin, this is the simulator:"
"Amplitude amplification is a sampling problem that is suitable for execution with the `Sampler` runtime primitive. Because we have a single circuit, we instantiate a `Sampler` using the target backend. To begin, this is the simulator:"
]
},
{
Expand All @@ -278,11 +288,12 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "618d25bc",
"metadata": {},
"source": [
"and execute the circuit using `sim_sampler.run`. The result is obtained in the returned quasi-probability distribution:"
"Now we execute the circuit by using `sim_sampler.run`. The result is obtained in the returned quasi-probability distribution:"
]
},
{
Expand All @@ -296,6 +307,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "0413c16d",
"metadata": {},
Expand Down Expand Up @@ -331,6 +343,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "1f53f619",
"metadata": {},
Expand Down

0 comments on commit 274d868

Please sign in to comment.