Skip to content

ic3b3rger/qserver

Repository files navigation

qserver

Skills: JWT, Python

Files:

Qserver_Grovers1 : 4 bit Implmenetation of Grover's algorithm using unitary quantum gates on Qasm Simulator and 5 bit IBM QC ibmq_belem + ibmq_lima

Qserver_Grovers2 : 5 bit implementation of Grover's algorithm using diffuser, oracle on statevector simulator and IBM QC ibmq_lima

Qserver_Shors: Implmenets Shor's algorithm to decrypt a sample number

To run: Upload to IBMQ Jupyter Notebooks and run

AC folder contains a simple authentication server and API written using Flask and JWT. To run install the following Python packages: pip install --upgrade flask pyopenssl cryptography pyjwt

1.1 Qserver

The Qserver in this setup uses Quantum computing to Decrypt the token which is encrypted by classical RSA encryption algorithm by factorizing the public key value. The token in this case is a small number used for simplicity as factorizing large numbers would take a long time since I only have access to Shor being run on a simulator on a classical machine. This onviously isn't the case for a quantum machine.

(key, value) pairs can be stored using qubit registeres for example: for a 4 qubit system, 2 qubit registeres (2^2) can be used to store 4 keys and 2 registers to store 4 values.

An actual circuit designed using Quirk (2 qubits for key, 2 for value and 5th to mark whether the value was found/not found): Link to circuit!

https://github.com/JoelLeach/QuantumDatabaseSearch

1.2 Flowchart

Sample Token: tok_1IHe3yAf0FnMgOaca3bOjzky

Sample APIs: GET /get/<user_id> GET /check/<user_id>/ POST /store {user_id: <user_id>, token: }

3.1 IBM Qiskit Implmentation

Available IBM Quantum Machines (ALL): https://quantum-computing.ibm.com/services?skip=0&systems=all

Maximum Available qubits for free: 5 Max qubits on a Simulator: 5000

Development Specs: {'qiskit-terra': '0.16.4', 'qiskit-aer': '0.7.6', 'qiskit-ignis': '0.5.2', 'qiskit-ibmq-provider': '0.12.1', 'qiskit-aqua': '0.8.2', 'qiskit': '0.24.0'}

3.2 Grover's Algorithm

The Grover's Search algorithm is a quantum algorithm for searching an unsorted database with N entries in $O(\sqrt{N})$ time. Classically, it would take O(N) time where we would need to search all entries in order to find the desired one. While this is only a quadratic speedup, it is quite significant when $N$ is large.

Given an unsorted list of $N$ elements, Grover's algorithm allows us to find a target element (in our case, a state) with $O(\sqrt N)$ operations or iterations. The reason why Grover's algorithm works so well (at least in theory) is because of its amplitude amplification, meaning it will single out the desired element without us having to search all the elements of the list.

Assumption: 1. That the Oracle has access to the elements(token values) of the classical list. 2.That we can load with a superposition of addresses (token addresses) data from a RAM, also called QRAM.

Loading the values

"/>

And then

Firts apply the Hadamard gates on the address register and then apply the load operation on both registers. Then you will have a superposition of all values in the database an the value register.

Next, apply GA on the value register with any oracle (think of it as an optimization function and what constraints it has; like looking a for a prime or a specific value). After 𝑂(√𝑁) iterations the correct answer will be measured with high probability. Thus, the correct solution together with the register address 𝑥∗ of the correct solution will be very likely measured.

Steps for Grover's

Step 1: The amplitude amplification procedure starts out in the uniform superposition
|s⟩ , which is easily constructed from

Step 2: We apply the oracle reflection Uf to the state|s⟩.

Step 3: We now apply an additional reflection (Us) about the state U_s = 2|s\rangle\langle s| - \mathbb{1} This transformation maps the state to UsUf|s⟩and completes the transformation. After t steps we will be in the state|ψt⟩where: |ψt⟩=(UsUf)t|s⟩.

How many times do we need to apply the rotation? It turns out that roughly √N rotations suffice.

It is better to think of the quantum search algorithm as optimizing a function, instead of searching in a list/database. In an after thought, Grover's might not be the best algorithm for searching.

These are described by the following unitary evolution,

Here is used to represent a multi-qubit state consisting of two registers. The first register is in state
|x⟩, where x is is a binary representation of the input to our function. The number of qubits in this register is the number of bits required to represent the inputs.

Result FILE: Qserver_Grovers1.ipynb & FILE: Qserver_Grovers2.ipynb Outputs from IBM computers in /images

3.3 Shor's Algorithm

Note: this implementation of Shor’s algorithm uses 4𝑛+2 qubits, where 𝑛 is the number of bits representing the integer in binary. So in practice, for now, this implementation is restricted to factorizing small integers. Given the above value of N we compute 4𝑛+2 below and confirm the size from the actual circuit.

AWS Braket implementation: Tried but free tier is very limited (remove)

Other Resources Microsoft Q# Qunatum Development Kit https://github.com/Microsoft/Quantum/

Original paper for Grover's algorithm : https://arxiv.org/pdf/quant-ph/9706005.pdf

We acknowledge the use of IBM Quantum services for this work. The views expressed are those of the authors, and do not reflect the official policy or position of IBM or the IBM Quantum team.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published