1
$\begingroup$

I created the following code to run a simple circuit through a quantum device twice. My purpose was to show the effects of noise with different arrangements of qubits when using ibmq_belem.

#Run circuit with two different qubit layouts
from qiskit import IBMQ, execute
#Load account
provider=IBMQ.load_account()
#Choose device
backend=provider.get_backend('ibmq_belem')
C=[]
for initial_layout in [[0,3],[2,4]]:
    job=execute(circuit, backend, initial_layout=initial_layout).result()
    c=result.get_counts()
    C.append(c)

followed by plot_histogram([C[0],C[1]],title="Comparing Noise") to create the histogram which give me ... enter image description here

Which does not reflect any of the noise that I see in my results taken directly from IBMQ which shows the first and second runthroughs respectivly as ... enter image description here

enter image description here

These are clearly not the identically perfect versions that my C set seems to have created. This makes my question; What have I done wrong in coding this that C is not accurately reflecting my counts?

Edit: I note that it has somehow decided to take the counts from when I ran this circuit on a simulator in a prior cell using the following code.

simulator=Aer.get_backend('aer_simulator')
result=execute(circuit,backend=simulator).result()
plot_histogram(result.get_counts(circuit)) 

This code had been run before I ever created the set C, so I did not expect it to interfere, but now I'm not sure how to work around this.

$\endgroup$
2
  • 1
    $\begingroup$ You have a typo inside the for loop. Change this row: c=result.get_counts() to this: c = job.result().get_counts(). $\endgroup$
    – Ohad
    Commented Oct 26, 2022 at 21:09
  • 1
    $\begingroup$ @Ohad You found that just as I did! Thank you for taking a look! $\endgroup$
    – PGibbon
    Commented Oct 26, 2022 at 21:27

1 Answer 1

1
$\begingroup$

Figured it out! It was using my result label from the initial coding when I used the simulator and appending that twice to my set C. So in my code I have now changed c=result.get_counts() to c=job.get_counts() as that was the 'job' I wanted the results from! And now all is beautiful and full of noise!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.