Giter Site home page Giter Site logo

qoupang's Introduction

๐Ÿ’ฌ ย  If you want to ask me something, contact me!

Student Developer interested in Cloud and Quantum Computing


๐Ÿ’ป Programming with

Python Qiskit Github Notion Linux Windows

๐Ÿ“– Learning now

C React Quantum Computing Blockchain

๐ŸŒ Working on

Blog TIL Medium SlideShare Behance

  • โœ๏ธ Run my own blog in Github and write TIL
  • ๐ŸŽค Upload my presentations on SlideShare
  • ๐ŸŽจ Leave my art works on Behance

qoupang's People

Contributors

byc3230 avatar cym-2 avatar tula3and avatar woodowoon avatar wwhurin avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

qoupang's Issues

BUG: overflow in `hash8()` due incorrect modulo division

Environment

  • qiskit.version: 0.22.0
  • Python version: 3.8.0
  • Operating system: Ubuntu 18.04

What is happening?

The function hash8() in the file qrng.py has a bug in the modulo division % 63, which makes the program crash depending on whether the random number modulo 63 gives 62.

How can we reproduce the issue?

Just run the hash8() function multiple times (e.g. adding this at the end of the file):

for i in range(100):
    hash8()

Output:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Test.ipynb Cell 21 in 5
     51     return hash_result
     53 for i in range(100):
---> 54     hash8()

Test.ipynb Cell 21 in 5
     48     start += 6
     49     end += 6
---> 50     hash_result += table[rand]
     51 return hash_result

IndexError: string index out of range

The program fails when the random number modulo 63 is 62, since the table has only 62 characters and cannot get index 62.

What should happen?

The circuit should be measuring the qubits directly, without adding an extra register.

Any suggestions?

The correct value should be % 62, since the table has 62 characters.
Or even better % len(table), since the table can be changed in the future.

# ORIGINAL
# rand = int(bits[start:end], 2) % 63
# NEW
rand = int(bits[start:end], 2) % len(table)

BUG: consuming double of the space needed

Environment

  • qiskit.version: 0.22.0
  • Python version: 3.8.0
  • Operating system: Ubuntu 18.04

What is happening?

The instruction measure_all in the file qrng.py masures the qubits by adding an extra ClassicalRegister, making the circuit larger than it should be. At the same time, the existing ClassicalRegister, variable c, is not used at all.

How can we reproduce the issue?

Adding a print on the result measured in the circuit:

from qiskit import *
backend = Aer.get_backend('qasm_simulator')
q = QuantumRegister(48)
c = ClassicalRegister(48)
circuit = QuantumCircuit(q,c)
circuit.h(q)
for i in range(47):
    circuit.cx(q[i], q[47])
circuit.measure_all()
import string
table = string.ascii_uppercase + string.ascii_lowercase + string.digits
def hash8():
    hash_result = ''
    result = execute(circuit, backend, shots=1).result()
    count = result.get_counts(circuit)
    print(count)
    bits = max(count, key=lambda i: count[i])[:48]
    start = 0
    end = 6
    while (end <= 48):
        rand = int(bits[start:end], 2) % 63
        start += 6
        end += 6
        hash_result += table[rand]
    return hash_result
hash8()

Output:

{'101011111101100100111001000010110010010000111110 000000000000000000000000000000000000000000000000': 1}

Which shows how the program is running a program which is twice as large as it should be.

What should happen?

The circuit should be measuring the qubits directly, without adding an extra register.

Any suggestions?

Following the documentation of the measure_all method, it is possible to measure the qubits directly, without adding an extra register. The code should be changed to:

circuit.measure_all(add_bits=False)

or with the measure method:

circuit.measure(q, c)

This produces the following:

{'101011111101100100111001000010110010010000111110': 1}

As a consequence the slicing can be removed from the hash8 function.

# ORIGINAL
# bits = max(count, key=lambda i: count[i])[:48]
# NEW
bits = max(count, key=lambda i: count[i])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.