1

I am trying to factor 15 with Shor's algorithm and want to find the period for $a^x$ mod $15$ on real quantum hardware with Qiskit. I took the code from the Qiskit Textbook and managed to run it on the Aer simulator which gave me the expected results, e.g. for $a=13$ and $a=11$. Then I adapted the code to run it on real quantum hardware according to this example.

However, when I run the code on quantum hardware I get really confusing results that have nothing in common with the expected values. I have also read the following post but increasing the optimization level did not help.

I was expecting some noise due to quantum errors but the "experiments" really have nothing in common with the theory or the simulation. You can find some of my results here. Unfortunately, I was redirected to different quantum hardware (ibm_kyoto and ibm_sherbrooke) depending on how busy the servers were but the quality of results seems not to be hardware dependent.

So, am I doing something wrong? Or do noise and quantum errors really explain the results? Will I have to implement quantum error correction codes on my own? Somehow I was expecting this to be done by the hardware automatically (and controlled by the optimization levels).

I do not know if it matters but I have the following setup:

  • python 3.12.3
  • Qiskit version 1.1.0
  • Qiskit IBM runtime version 0.24.0

As I have pointed out already I have copied the main parts of the code from the Qiskit textbook so I believe the circuit should be alright. Here is the relevant part that I have changed to run the circuit on real hardware:

# Run circuit in simulation mode
if mode == 'simulation':
    backend = Aer.get_backend('aer_simulator')
    t_qc = transpile(qc, backend)
    counts = backend.run(t_qc, shots=repetitions).result().get_counts()
    color = red
    title = 'a=' + str(a) + ' (Simulation, Repetitions=' + str(repetitions) + ')'
    id = 'simulation'

Run circuit on real hardware

elif mode == 'quantum_hardware': service = QiskitRuntimeService(channel="ibm_quantum", token=quiskit_token) backend = service.least_busy(operational=True, simulator=False, min_num_qubits=T_COUNT) pm = generate_preset_pass_manager(backend=backend, optimization_level=optimization_level) isa_circuit = pm.run(qc) sampler = Sampler(backend) job = sampler.run([isa_circuit], shots=repetitions) counts = job.result()[0].data.c.get_counts() color = blue title = 'a=' + str(a) + ' (Job: ' + job.job_id() + ', Repetitions=' + str(repetitions) + ')\n' + backend.name + " - Optimization level " + str(optimization_level)

Computation done -> populate missing data

for b in {'0000','0001','0010','0011','0100','0101','0110','0111','1000','1001','1010','1011','1100','1101','1110','1111'}: if b not in counts: counts[b] = 0

fig = plot_histogram(counts, color=color, title=title)

So, please give me a hint if I have a major bug and how to fix it or if my code is correct and how to explain the outcomes.

Thank you very much!

0 Answers0