0

i try to compare between the factorization time between : 1) classical algorithm function:

def is_prime1(n):

    if n<2:
        return False
    for i in range(2,n):
        if n % i ==0:
            return False
    return True



def output_prime_factors(num):

    num=round(num)
    p=0
    while p < num:
        p +=1
        if num % p==0 and is_prime1(p)==True:
            print (p)

Shor's algorithm on Qiskit (IBM) but the output is Unexpected that the quantum is slower how this happen )

N = 15

shor = Shor(N)

backend = BasicAer.get_backend('qasm_simulator')

quantum_instance = QuantumInstance(backend, shots=1024)

result = shor.run(quantum_instance)

print(f"The list of factors of {N} as computed by the Shor's algorithm is 
{result['factors'][0]}.")

the qiskit is slower than the classical function

  • 1
    It's normal! You need to compare the result for big `N` with big prime factors! – OmG Mar 30 '21 at 12:18
  • this IBM implementation limited for small number: – ammar ibrahim Mar 30 '21 at 14:55
  • Note: this implementation of Shor’s algorithm uses 4n+2 qubits, where n 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 4n+2 below and confirm the size from the actual circuit. – ammar ibrahim Mar 30 '21 at 14:55

1 Answers1

1

You are trying to factor on a simulation of a highly parallel system. This gives you all of the downsides of being a simulation and none of the upsides of parallelism that make quantum computing interesting.

Poor performance should come as no surprise.

btilly
  • 43,296
  • 3
  • 59
  • 88
  • can you explain this i don't understand – ammar ibrahim Mar 30 '21 at 17:52
  • @ammaribrahim See the line in your code that says `qasm_simulator`? That indicates you are trying to simulate quantum mechanics. Simulations tend to be slow. And the reason why quantum factoring should be fast on real quantum computers is that you are taking advantage of the parallelism of a quantum superposition. But you are simulating it on a computer without that parallelism, which makes it even slower. – btilly Mar 30 '21 at 20:10
  • thanks i got it know but if there any way to run it on quantum computer any where ? – ammar ibrahim Mar 31 '21 at 08:26
  • @ammaribrahim You could try https://www.ibm.com/quantum-computing/developers/ and create an account. I have no idea what it costs, but you're renting time on a machine that costs tens of millions of dollars. So I'd expect it to cost something. – btilly Mar 31 '21 at 15:15