diff --git a/_posts/2020-06-23-Durr_Hoyer_Post_1.md b/_posts/2020-06-23-Durr_Hoyer_Post_1.md new file mode 100644 index 0000000..3683fdb --- /dev/null +++ b/_posts/2020-06-23-Durr_Hoyer_Post_1.md @@ -0,0 +1,139 @@ +--- +title: "Building a Q# library to find table minima: Part 1" +date: 2020-06-22 +categories: + - Blog +tags: + - library + - algorithm + - in-development +--- + +> TL;DR +> The Dürr-Høyer algorithm takes an unsorted table of integers of length N and finds the minima in O(sqrt(N)). +> I started a project that implements this algorithm here : [https://github.com/mridulsar/DurrHoyerLibrary](https://github.com/mridulsar/DurrHoyerLibrary), contributions welcome! + +## Introduction + +Hello all! My name is Mridul Sarkar, and I am an undergraduate at University of California Davis studying Mathematics and Scientific Computation. I wanted to share with the community my experiences in learning about the Dürr–Høyer algorithm and creating a library for Q# implementing it. This project has pushed me and is still pushing me outside of my comfort zone, but learning Q# while slowly refining my quantum intuition has been a rewarding experience. I would like to pass on what I have seen and understood in that time, as well as ask the community for feedback. I will likely be posting about this algorithm and library more as the library and my understanding continues developing. +https://github.com/mridulsar/DurrHoyerLibrary. + +## The Dürr–Høyer Algorithm + +Say we have a table with N unsorted items where you want to find the minimum value stored in this table. The Dürr–Høyer Algorithm helps us solve this problem. It was originally proposed in "A quantum algorithm for finding the minimum'' (1), where it was called the 'Quantum Minimum Searching Algorithm'. I'll summarize the main ideas below in case you don't have time to read the paper in all of its glory. + +## QMSA + +#### 1. Choose an integer (y) uniformly at random between 0...N-1, where N = flattened table length. +#### 2. Repeat the following steps until you find an answer. + #### 2(a) Initialize the memory as a uniform superposition of qubits. Each qubit represents an index. After initializing the memory, grab the y-th qubit and entangle the state of your register with this y-th qubit according to the Oracle that marks all T[j]) = |->, so don't neet to reset, but the phase kickback will remain. + (ControlledOnInt(0, X))(register!, aux); + } + } +``` +From here we apply the inverse of the Hadmard, this is just the conjugate transpose since Hadamard is unitary. This can be implemented be calling the Adjunct of Hadamard. +``` + // Apply Adjunct Hadamard to register + ApplyToEachA(H,Register); +``` +The last step is another conditional phase shift, though it is applied if the qubit is 1. This can be done by using the Z gate. The Z gate takes our qubit in and checks if it is |0> or |1>. If |0> leave it be. If |1> map to |0>. + +``` + ApplyToEach(Z, Register); //Reflect qubits that are 1s +``` +For further information on how this was derived take a look at 'Tight bounds on quantum searching' [2]. It is important to note the above algorithm only works for a table with an even number of entries. + +The algorithm breaks down when applying the Hadamard gate as the Hadamard is layed across the diagonal of an identity matrix which is equal in dimensions to the number of qubits we have. With a bit of math, if we try to lay a 2x2 matrix along an odd dimensioned identity matrix the transformation is not retained. To circumvent this we introduce the following implementation, utilizing QFT. + +Now we refer back to our QMSA outline to observe that the Algorithm(TableLength,RandomIndex) is iterated on until we find a suitable y' or we simply hit our time limit. The true stars of this algorithm are the time limit, which guarantees O(sqrt(N)), the generalized Grover's algorithm given in QESA, which provides for easy implementation and has O(1) for each iteration, and lastly, the oracle function which marks our states, which along with our initialization of qubits, has O(log(n)). +The full script for QESA can be found here: https://github.com/mertall/DurrHoyerLibrary/blob/master/library/Library.qs. + + + +### Measuring register + +At the moment we are measuring our register by using MeasureInteger(), though this is decoding LittleEndian into an integer as is represented by some binary string. We will have to develop a different way to measure our qubits to get probabilistic results on each qubit. + +## Motivation + +The motivation behind this project is to provide open source functionality. The efficiency that is proposed by this algorithm is much better than a typical algorithm for finding the minimum of an unsorted table. On a classical computer it will take as many time steps as there are items to find a minimum. This means the Big-O is N. The Dürr-Høyer algorithm takes this problem and solves it in sqrt(N) time steps. For example assume there are 9 items in a table, on a classical computer this would take 9 time steps. The Dürr-Høyer algorithm would find the minimum in 3 steps. We can understand this efficiency as the Big-O. The Big-O essentially means the run time of the program will increase as the table size grows. Dürr and Høyer propose a quantum algorithm in order to find the minimum of an unsorted table with a 50% success rate. + +In order for this library to be used properly it must meet some guidelines. At the moment I am referencing the amazing template given by Dr. Sarah Kaiser https://github.com/crazy4pi314/qsharp-library-template in order to make this library usable in Q#. +https://github.com/mridulsar/DurrHoyerLibrary + +### My Backgroud + +I began my journey from math to computers through my passion for ML algorithms, where I stumbled upon quantum computing. I was instantly pulled in by the elegant algorithms and proposed efficiency. About a year ago, I started looking into a model that treats nodes of neural networks as qubits. I took a deep dive into the research papers and found myself amazed by what was out there. Realizing I had hunger to learn more I looked for online courses in quantum computing. I began with a Coursera course from St. Petersburg University on quantum computing with detail on quantum algorithm design and quantum computer architecture. From here I tinkered with Q# and developed basic algorithms that I previously learned. I found Dürr and Høyer's paper and saw it as a fusion of Duestch's, Shor's, and Grover's Algorithm; a perfect next step for me. + +## Conclusion + +So far I have been greatly enjoying throwing myself into this new and exciting world of quantum computing. I have seen some awesome principles translate across quantum algorithms that are keeping me engaged. In specific, I mentioned I felt Dürr and Høyer used principles from Duestch's, Grover's, and Shor's algorithm. Duestsch's Algorithm famously simplifies a classical problem into an non intuitive oracle function as done in Dürr and Høyer's algorithm to mark all states that satisfy T[j]