kazawai / shor_qiskit

Very simple shor's algorithm simulated in Qiskit version 1.0.x
Apache License 2.0
3 stars 1 forks source link

Quantum Part of Shor not being executed in rsa_compare.py? #2

Open stubbi opened 6 months ago

stubbi commented 6 months ago

@kazawai the plot for python3 rsa_compare.py looks good:

Figure_1

Though I added a debug print and found the quantum part of shor's algorithm to be never executed. How is that? 🤔 And when I comment out the

# Check if N is a perfect power
    for a in range(2, N):
        if N % a == 0:
            if pow(a, N - 1, N) == 1:
                continue
            else:
                return a, N // a

I receive error

Traceback (most recent call last):
  File "/rsa_compare.py", line 14, in <module>
    shor(value)
  File "/rsa_shor.py", line 143, in shor
    counts = qpe_period_finding()
             ^^^^^^^^^^^^^^^^^^^^
  File "/rsa_shor.py", line 116, in qpe_period_finding
    qc.append(c_amod15(a, 2**q), [q] + [i + 4 for i in range(n_count)])
  File "/opt/homebrew/lib/python3.11/site-packages/qiskit/circuit/quantumcircuit.py", line 1276, in append
    operation.broadcast_arguments(expanded_qargs, expanded_cargs)
  File "/opt/homebrew/lib/python3.11/site-packages/qiskit/circuit/gate.py", line 207, in broadcast_arguments
    raise CircuitError(
qiskit.circuit.exceptions.CircuitError: 'The amount of qubit(9)/clbit(0) arguments does not match the gate expectation (5).'

So I assume the algorithm would work quantumly only for specific numbers?

kazawai commented 6 months ago

Thanks for pointing this out ! I noticed this error for myself already before but I still haven't figured out how I could work around it just yet. I am working on it ^^ !