1
$\begingroup$

I was trying to run this code on a quantum computer but I was getting an error can anyone suggest how to resolve this error?

enter preformatted text here
vector = [(159+625j), (3+71j)]
norm = np.linalg.norm(vector)
qc = QuantumCircuit(1)  # Create a quantum circuit with one qubit
initial_state = vector/np.linalg.norm(vector)
print('initial state is')
print(initial_state)
qc.initialize(initial_state, 0) 
qc.x(0) ###### for not gate
qc.h(0) ####### for hadamard gate
qc.snapshot('final', snapshot_type='statevector')
a = qc.draw() 
print(a)
IBMQ.load_account()
#provider = IBMQ.get_provider = ('ibm-q')
provider = IBMQ.load_account()
qcomp= provider.get_backend('ibmq_belem')
job = execute(qc,backend=qcomp)
from qiskit.tools.monitor import  job_monitor
job_monitor(job)
result = job.result()
plot_histogram(result.get_counts(qc))

When I ran this through the quantum computer I am getting this error:

Cannot unroll the circuit to the given basis, ['id', 'rz', 'sx', 'x', 'cx', 'reset']. 
No rule to expand instruction multiplex1_dg.
$\endgroup$
1
  • $\begingroup$ I was unable to reproduce the error. Which qiskit version are you using? $\endgroup$ – luciano Mar 5 at 8:31
2
$\begingroup$

As commented by @Luciano and @Patrick, it probably has to do with the qiskit version that you are using. Patrick pointed out in the comment that if you are using qiskit version 0.20.0 or later then you wouldn't have the unroll error.

However, there is also a problem with your circuit of not having measurement but then you tried to get the counts value of the experiment to plot the histogram... so I took what you did and fixed it. What you have should work now once you upgrade your qiskit to a later version.

from qiskit import QuantumCircuit, execute, QuantumRegister, ClassicalRegister, IBMQ
from qiskit.tools.monitor import  job_monitor
from qiskit.visualization import plot_histogram
%matplotlib inline
import numpy as np
provider = IBMQ.load_account()

vector = [(159+625j), (3+71j)]
norm = np.linalg.norm(vector)
qc = QuantumCircuit(1,1)  # Create a quantum circuit with one qubit
initial_state = vector/np.linalg.norm(vector)
print('initial state is')
print(initial_state)
qc.initialize(initial_state, 0) 
qc.x(0) ###### for not gate
qc.h(0) ####### for hadamard gate
qc.measure([0],[0])
qc.snapshot('final', snapshot_type='statevector')
print(qc)
job = execute(qc,backend=provider.get_backend('ibmq_belem'))
job_monitor(job)
result = job.result()
plot_histogram(result.get_counts(qc))

The output would be something like:

initial state is
[0.24506358+0.96330023j 0.00462384+0.10943091j]
     ┌────────────────────────────────────────────────┐┌───┐┌───┐┌─┐ ░ 
q_0: ┤ initialize(0.24506+0.9633j,0.0046238+0.10943j) ├┤ X ├┤ H ├┤M├─░─
     └────────────────────────────────────────────────┘└───┘└───┘└╥┘ ░ 
c: 1/═════════════════════════════════════════════════════════════╩════
                                                                  0    
Job Status: job has successfully run

enter image description here

$\endgroup$
4
  • $\begingroup$ I'm searching for the specific fix and I could not find it. Is it because the measurement? $\endgroup$ – luciano Mar 5 at 8:32
  • $\begingroup$ @luciano Hum... I guess the fix is to use a version of qiskit 0.20.0 and later .. using an old Qiskit version (0.19.2) i reproduced the unroll pb .... Using version 0.20.6 that works well .. :-) $\endgroup$ – Patrick Mensac Mar 5 at 15:38
  • $\begingroup$ @PatrickMensac You are right. Ha. I thought it was the measurement because the OP tried to plot the histogram of the results... but the would have given the 'No counts for experiment' error instead.... stupid me... $\endgroup$ – KAJ226 Mar 5 at 16:09
  • $\begingroup$ @luciano I thought it was but that would have given a different error... $\endgroup$ – KAJ226 Mar 5 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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