Skip to content

Commit

Permalink
Quantum counting English fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnePicus authored and TaliCohn committed Feb 13, 2025
1 parent dddaa15 commit b0f7ab5
Showing 1 changed file with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
"id": "456a591a-6383-45cf-ac3e-cca3014edf6b",
"metadata": {},
"source": [
"# Quantum Counting using the Iterative Quantum Amplitude Estimation Algorithm\n",
"# Quantum Counting Using the Iterative Quantum Amplitude Estimation Algorithm\n",
"\n",
"Quantum Counting algorithm [[1](#QCWiki)] is an algorithm for efficiently estimating the number of valid solutions to a search problem, based on the amplitude estimation algorithm. It demonstrates a quadratic improvement with regards to a classical algorithm with black-box oracle access to the function $f$.\n",
"The quantum counting algorithm [[1](#QCWiki)] efficiently estimates the number of valid solutions to a search problem, based on the amplitude estimation algorithm. It demonstrates a quadratic improvement with regard to a classical algorithm with black box oracle access to the function $f$.\n",
"\n",
"More precisely, the counting problem is, given a boolean function $f :\\{0, 1\\}^n\\rightarrow\\{0,1\\}$, estimate the number of inputs $x$ to $f$ such that $f(x)=1$.\n",
"More precisely, given a Boolean function $f :\\{0, 1\\}^n\\rightarrow\\{0,1\\}$, the counting problem estimates the number of inputs $x$ to $f$ such that $f(x)=1$.\n",
"\n",
"In this tutorial we will deomstrate how to estimate the Couting problem using a specific variant of the Amplitude Estimation algorithm - the Iterative Quantum Amplitude Estimation (IQAE) [[2](#IQAE)].\n",
"This tutorial demonstrates how to estimate the counting problem using a specific variant of the amplitude estimation algorithm: the Iterative Quantum Amplitude Estimation (IQAE) [[2](#IQAE)].\n",
"\n",
"The IQAE does not rely on the Quantum Phase Estimation algoritm [[3](#AE)], but purely on applications of the grover operator:\n",
"The IQAE does not rely on the Quantum Phase Estimation algorithm [[3](#AE)], but purely on applications of the grover operator:\n",
"$$\n",
"Q\\equiv - A S_0 A^{\\dagger} S_{\\psi_1} ,\n",
"Q\\equiv - A S_0 A^{\\dagger} S_{\\psi_1},\n",
"$$\n",
"Hence reducing the required amount of qubits and gates of the circuit, at the expense of additional multiplicative factor poly-logarithmic in the error $\\epsilon$.\n"
"thereby reducing the required number of qubits and gates of the circuit, at the expense of additional multiplicative factor polylogarithmic in the error $\\epsilon$.\n"
]
},
{
"cell_type": "markdown",
"id": "38184f42-a77b-4370-8e42-0224e711c5e0",
"metadata": {},
"source": [
"## Setting the problem\n",
"## Setting Up the Problem\n",
"\n",
"We will choose the equation:\n",
"We choose this equation:\n",
"$$\n",
"(a + b) <= 2\n",
"$$\n",
"where $a$, $b$ are 2-bit unsigned integers. This equation has 6 solutions. The goal is to estimate the number of valid solutions out of the 16 possible inputs, with precision $0.5$.\n",
"where $a$, $b$ are 2-bit unsigned integers. This equation has six solutions. The goal is to estimate the number of valid solutions out of the 16 possible inputs, with precision $0.5$.\n",
"\n",
"\n"
]
Expand All @@ -41,15 +41,15 @@
"id": "d69d5803-107a-4083-aa25-9c3d5dc092f3",
"metadata": {},
"source": [
"## Amplitude Estimation using Phase Estimation"
"## Amplitude Estimation Using Phase Estimation"
]
},
{
"cell_type": "markdown",
"id": "58a44d55-97ee-4463-8d38-d3c64151f76a",
"metadata": {},
"source": [
"We first show how to use Quantum Phase Estimation algorithm for the Quantum Counting [[3](#AE)], then move to solve it using the IQAE method."
"We first show how to use quantum phase estimation algorithm for quantum counting [[3](#AE)], then solve it using the IQAE method."
]
},
{
Expand All @@ -58,40 +58,40 @@
"metadata": {},
"source": [
"Given a state $|\\psi\\rangle$ such that $|\\psi\\rangle=\\sqrt{a}|\\psi_1\\rangle+\\sqrt{1-a}|\\psi_0\\rangle$ we can measure $a$ up to arbitrary precision, given the following building blocks:\n",
"1) State Preperation: \n",
"A unitary $A$ such that: $A|0\\rangle = |\\psi\\rangle = \\sqrt{a}|\\psi_1\\rangle+\\sqrt{1-a}|\\psi_0\\rangle$\n",
"1) State preparation: \n",
"A unitary $A$ such that: $A|0\\rangle = |\\psi\\rangle = \\sqrt{a}|\\psi_1\\rangle+\\sqrt{1-a}|\\psi_0\\rangle$.\n",
"\n",
"\n",
"2) Oracle:\n",
"A unitary $S_{\\psi_1}$ such that $S_{\\psi_1}=I-2|\\psi_1\\rangle\\langle\\psi_1|$, which adds a $(-1)$ phase to $|\\psi_1|\\psi\\rangle\\rangle$ and does nothing to any orthognal states to $|\\psi_1\\rangle$.\n",
"This is effectively a reflection around the \"good\" state $|\\psi_1\\rangle$.\n",
"\n",
"Given this 2 functions, we can construct the grover operator:\n",
"Given these two functions, we can construct the Grover operator:\n",
"$$\n",
"Q\\equiv - A S_0 A^{\\dagger} S_{\\psi_1} ,\n",
"$$\n",
"Which is exactly the same operator as the one for the grover's search algorithm. \n",
"which is exactly the same operator as for the Grover's search algorithm. \n",
"\n",
"\n",
"In the subspace spanned by $|\\psi_1\\rangle$ and $|\\psi_0\\rangle$, $Q$ has 2 eigenvalues: \n",
"In the subspace spanned by $|\\psi_1\\rangle$ and $|\\psi_0\\rangle$, $Q$ has two eigenvalues: \n",
"$$\n",
"\\lambda_{\\pm}=\\exp\\left(\\pm i2\\pi \\theta \\right), \\qquad \\sin^2 \\left(\\pi \\theta\\right)\\equiv a.\n",
"$$\n",
"\n",
"Therefore, if we apply a QPE on $A|0\\rangle$ we will have these two eigenvalues encoded in the QPE register, however, both give the value of $a$, so there is no ambiguity here."
"Therefore, if we apply a QPE on $A|0\\rangle$ we have these two eigenvalues encoded in the QPE register; however, both give the value of $a$, so there is no ambiguity."
]
},
{
"cell_type": "markdown",
"id": "16100fce-c9ad-4eba-a4a2-deb14a610b43",
"metadata": {},
"source": [
"### Arithmetic oracle\n",
"### Arithmetic Oracle\n",
"\n",
"Here we define the $S_{\\psi_1}$ oracle:\n",
"We define the $S_{\\psi_1}$ oracle:\n",
"\n",
"$$\n",
"S_{\\psi_1}|a\\rangle|b\\rangle= (-1)^{f(a,b)}|a\\rangle|b\\rangle\n",
"S_{\\psi_1}|a\\rangle|b\\rangle= (-1)^{f(a,b)}|a\\rangle|b\\rangle.\n",
"$$"
]
},
Expand Down Expand Up @@ -136,9 +136,9 @@
"source": [
"### Diffuser\n",
"\n",
"The diffuser consists of the reflection around the $|0\\rangle$ state, and a state-preparation function.\n",
"The diffuser consists of the reflection around the $|0\\rangle$ state and a state-preparation function.\n",
"\n",
"The state preparation function $A$ reflects knowledge about the solution space, and can be used to eliminate invalid assignments. Here we assume no knowledge on the solution space, hence we use the uniform superposition state preparation."
"The state preparation function $A$ reflects knowledge about the solution space and can be used to eliminate invalid assignments. Here we assume no knowledge of the solution space; hence, we use the uniform superposition state preparation."
]
},
{
Expand Down Expand Up @@ -181,7 +181,7 @@
"id": "26ccb4d1-030e-48dc-a883-908d0cd9359c",
"metadata": {},
"source": [
"### Complete Grover operator definition"
"### Defining a Complete Grover Operator"
]
},
{
Expand All @@ -207,15 +207,15 @@
"id": "75227dd9-12f9-4933-909d-795c9bdeff2d",
"metadata": {},
"source": [
"### Wrap all to the Phase Estimation"
"### Wrapping All to the Phase Estimation"
]
},
{
"cell_type": "markdown",
"id": "372e2c83-9cc3-45fc-bdb4-ccd1db54a2c3",
"metadata": {},
"source": [
"We will acheive the desired precision only in the IQAE phase. Here we compute the worst-case precision for 5 phase qubits:"
"We will achieve the desired precision only in the IQAE phase. Here, we compute the worst-case precision for five phase qubits:"
]
},
{
Expand Down Expand Up @@ -276,7 +276,7 @@
"id": "23e1bba3-1958-4de1-aa5b-ea36842541c0",
"metadata": {},
"source": [
"### Synthesize the model to a quantum program"
"### Synthesizing the Model to a Quantum Program"
]
},
{
Expand All @@ -303,7 +303,7 @@
"id": "5fe6073e-4ebe-438c-b8bb-12d658c4eece",
"metadata": {},
"source": [
"### Quantum Program execution"
"### Executing the Quantum Program"
]
},
{
Expand All @@ -321,7 +321,7 @@
"id": "9cc9df6d-2968-4d3d-9ed8-5303336a1365",
"metadata": {},
"source": [
"Plotting the resulting histogram we see two phase values with high probability (however, both corresponds to the same amplitude). Note that `phase_reg` is already coded as fixed QNum in the range [0,1]."
"Upon plotting the resulting histogram, we see two phase values with high probability (however, both correspond to the same amplitude). Note that `phase_reg` is already coded as fixed QNum in the range [0,1]."
]
},
{
Expand Down Expand Up @@ -367,7 +367,7 @@
"id": "08319831-bf54-4892-a623-b7ce1c9b8488",
"metadata": {},
"source": [
"From the phase we can extract the number of solutions:"
"From the phase, we can extract the number of solutions:"
]
},
{
Expand Down Expand Up @@ -399,23 +399,23 @@
"id": "e8efaff8-3114-429b-ab20-fdff96246ea7",
"metadata": {},
"source": [
"## Amplitude Estimation using Iterative Quantum Amplitude Estimation"
"## Amplitude Estimation Using Iterative Quantum Amplitude Estimation"
]
},
{
"cell_type": "markdown",
"id": "f6518bf7-acec-4fde-8612-35c2fe73c02f",
"metadata": {},
"source": [
"Now we are ready for the iterative method! \n",
"Now we are ready for the iterative method. \n",
"\n",
"Instead of QPE, the algorithm applies the unitary:\n",
"Instead of QPE, the algorithm applies the unitary\n",
"$$\n",
"(Q)^mA\n",
"$$\n",
"where $m$, the number of repetitions is changed between iterations of the algorithm.\n",
"where $m$, the number of repetitions, changes between iterations of the algorithm.\n",
"\n",
"There is one subtlety that will change the way we work with the Grover operator. The classical algorithm expects additional indicator qubit that marks the \"good\" states, i.e.:\n",
"There is one subtlety that changes the way we work with the Grover operator. The classical algorithm expects an additional indicator qubit that marks the \"good\" states, i.e.:\n",
"$$\n",
"|a\\rangle|b\\rangle|f(a,b)\\rangle\n",
"$$"
Expand All @@ -426,7 +426,7 @@
"id": "16c1a7bf-77d4-4e13-9b9b-249a78b750f1",
"metadata": {},
"source": [
"So now, most of our logic will go into the state preparation oracle ($A$). It will combine both the loading of the solution space, and the setting of the indicator qubit."
"So now, most of our logic goes into the state preparation oracle ($A$). It combines the loading of the solution space with setting the indicator qubit."
]
},
{
Expand All @@ -452,7 +452,7 @@
"id": "d4afdfd8-507c-43e1-9440-ae94df4dbf22",
"metadata": {},
"source": [
"Now, as we use the indicator qubit, the oracle is very simple - it is just a $Z$ gate on the indicator qubit!"
"Now, as we use the indicator qubit, the oracle is simple: it is just a $Z$ gate on the indicator qubit!"
]
},
{
Expand All @@ -474,7 +474,7 @@
"tags": []
},
"source": [
"### Wrapping all to the Iterative Quantum Amplitude Estimation Algorithm"
"### Wrapping All to the Iterative Quantum Amplitude Estimation Algorithm"
]
},
{
Expand All @@ -484,7 +484,7 @@
"source": [
"The circuit starts with the state $A|0\\rangle$, then applies iterations of the Grover operator. \n",
"\n",
"Notice that the algorithm applies varied number of grover iterations on each execution. The number of iterations is chosen dynamically based on previous execution results, using statistical inference methods."
"Note that the algorithm applies a varied number of Grover iterations on each execution. The number of iterations is chosen dynamically based on previous execution results, using statistical inference methods."
]
},
{
Expand All @@ -511,7 +511,7 @@
"metadata": {},
"source": [
"We use the built-in `iqae` classical execution code. It assumes only one output to the circuit, which is the indicator qubit.\n",
"We set $\\epsilon = 1/{2^4} \\cdot 0.5 = 1/32$. `alpha` is the tail probability of esimtating the result with accuracy $\\epsilon$."
"We set $\\epsilon = 1/{2^4} \\cdot 0.5 = 1/32$. `alpha` is the tail probability of estimating the result with accuracy $\\epsilon$."
]
},
{
Expand Down Expand Up @@ -552,7 +552,7 @@
"id": "2fe2254c-5fe2-48e3-b2cd-825d71dbcbf6",
"metadata": {},
"source": [
"### Synthesize the model to a quantum program"
"### Synthesizing the Model to a Quantum Program"
]
},
{
Expand Down Expand Up @@ -584,7 +584,7 @@
"id": "a468ad77-ace5-4ee5-a8fe-5cb5bfe4342f",
"metadata": {},
"source": [
"### Quantum Program execution"
"### Executing the Quantum Program"
]
},
{
Expand Down Expand Up @@ -681,9 +681,9 @@
"source": [
"## References\n",
"\n",
"<a name='QCWiki'>[1]</a>: [Quantum Counting Algorithm Wikipedia](https://en.wikipedia.org/wiki/Quantum_counting_algorithm)\n",
"<a name='QCWiki'>[1]</a>: [Quantum Counting Algorithm, Wikipedia](https://en.wikipedia.org/wiki/Quantum_counting_algorithm).\n",
"\n",
"<a name='IQAE'>[2]</a>: [Grinko, D., Gacon, J., Zoufal, C. et al. Iterative quantum amplitude estimation. npj Quantum Inf 7, 52 (2021)](https://doi.org/10.1038/s41534-021-00379-1)\n",
"<a name='IQAE'>[2]</a>: [Grinko, D., Gacon, J., Zoufal, C. et al. Iterative quantum amplitude estimation. npj Quantum Inf 7, 52 (2021)](https://doi.org/10.1038/s41534-021-00379-1).\n",
"\n",
"<a name='AE'>[3]</a>: [Brassard, G., Hoyer, P., Mosca, M., & Tapp, A. (2002). Quantum Amplitude Amplification and Estimation. Contemporary Mathematics, 305, 53-74.](https://arxiv.org/abs/quant-ph/0005055)\n"
]
Expand Down

0 comments on commit b0f7ab5

Please sign in to comment.