Skip to main content

A small package to add two numbers together within quantum computing

Project description

QOSF ADDER CHALLENGE

Ricky's solution:

Hello, thank you for checking out my Draper adder solution! This problem seemed to be the most challenging tome and that was the chief reason why I chose it. As a bonus, I've generalized it to find the subset to sum for other lists of integers and outpus, assuming the integers are not negative.

Getting Started

Please create a conda environment for the module to run in if you do not have one: conda create -n draper python=3.9

pip install -r requirements.txt

Installation You can install from source by cloning this repository and running a pip install command in the root directory:

git clone url = https://github.com/rryoung98/QOSF.git
cd QOSF
python3 -m pip install -e .

Implementation

The problem requires checking all combinations of the list of integers to check if they sum. The subset_finder() defaults to find the subset for the problem statement, but this implementation has been generalized to take in other positive integers and outputs.

Here is an example adder circuit for 5+7. circuit

How it works

The algorithm first converts all the integers to binary and then uses the meet in the middle strategy to split the list into two and find all the combinations which add up to the desired value using the draper adder method.

The draper method is implemented using qiskit and applies a QFT without swap gates then a series of controlled phase gates.

Challenges

I faced a decent amount of challenges but all of them were very rewarding. From building the draper circuit to making sure that the python package was successfully deployed this was a pretty fun weekend. I think looking back at the problems I could have implemented this a lot faster if I paid closer attention to the various implementations of the draper circuit from several papers and the Microsoft tutorial. Some of them were for the modulo addition which I spent a good amount of time varifying. Big O considerations were also significant especially since the nature of arithmetic quantum circuit, the running of the circuit, as well as the combinations would slow the draper adder and would be an exciting topic to explore!

Tests

Some test were made to make sure that functions behave as expected. In the case that the pip install fails the requirements.txt is also available and a demo.

Conclusion

It was definitely fun doing this project. I'm happy with how relatively robust the solution and hope that this work can be considered for the mentorship!

Future improvements include running on allowing the ability to run on various simulators and hardware via kwargs and I would hope to add different methods of quantum arithmetic

QOSF PROBLEM 1:

For this problem, you want to find a positive integer that can be composed of the summation of a subset of the input vector, for example: [1,3,6,4,2], and we need to find the number 6

the possible solutions are:

  • [1,3,2],
  • [4,2],
  • [6] For this challenge, consider as input a vector of positive integers and a positive integer, generate a quantum circuit that indicates with higher probability the subset(s) that manage to obtain the number with their sum. Tip consider a QRAM to save the input vector and the encoding basis, using the before example that could be, we need n qubits for the length of the vector and m qubits for the length of the bits. Consider that we will use n = 5 qubits for the address, so the state |10000⟩ represents the index 1, the state |01000⟩ represents the index 2 and so on. And m = 3, because the number we need is 6 and in binary is 110, so we can use the bases encoding and the state result is |110⟩

In view of the above, the following should be carried out

|index of the vector⟩|value of the index⟩ Consider this format, we need 5 qubits for the index and 3 qubits of the values, i.e: 1 = > |10000001> 3 = > |01000011> 6 = > |00100110> 4 = > |00010100> 2 = > |00001010> And you want to find 6. The green part is the index state, and the red is the value. For this example you need to find an oracle where is the state six in the red qubits is a correct answer. The output could be

  • [1,3,2] = > |11001> ,
  • [4,2] = > |00011> ,
  • [6] = > |00100> Hint: For this task you can make use of the Adder by Draper, a general quantum circuit to make this proposal can be found here, but instead of adding 2 numbers find a way to accommodate the request.

Based on the diagram, the QFT and QFT-1 are used and U1 = . Then the values to be the binary number dep’ends on the U1 gates. Examples of this you can see in the images, consider the green cat as |0> and purple cat as |1>.

The challenge

Design a quantum circuit that finds the subsets where the sum is equal to the value 16 in the following vector [5,7,8,9,1]

References

Steven A. Cuccaro, Thomas G. Draper, Samuel A. Kutin, David Petrie Moulton (2004). A new quantum ripple-carry addition circuit. (https://arxiv.org/abs/quant-ph/0410184)

Thomas G. Draper (2000). Addition on a Quantum Computer (https://arxiv.org/abs/quant-ph/0008033)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

draperrry-0.0.1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

draperrry-0.0.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file draperrry-0.0.1.tar.gz.

File metadata

  • Download URL: draperrry-0.0.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for draperrry-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cdb473b34176acd076450462155cbb87c27936ca1716fe7682e8a937c06b99a5
MD5 ad00e1fcb42db2e0ae43b1eef93dfb62
BLAKE2b-256 dce2b8055193dac16a75e767f01442b6bdb065ee7d0c367a0cd81b3741de361b

See more details on using hashes here.

File details

Details for the file draperrry-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: draperrry-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for draperrry-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d00f3a1a312dcdbe2a52cba2cc6a1d9fca1b13eece067ed7b73194c582f9e92
MD5 670ce74e1011c488b99170ccc8e66850
BLAKE2b-256 de30f9f9387fcf3346e6ea2e3b6ca42b8c227f6877b3d45700efa68afbd10b7c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page