1
$\begingroup$

I am trying to run the quantum communication algorithm from qiskit textbook "Entangled States" using my IBM API key, however, it throws the error RuntimeError: IBMBackend.run() is not supported in the Qiskit Runtime environment.. What am I doing wrong? This is my code:

service = QiskitRuntimeService(channel="ibm_quantum", token=[REDACTED API KEY])
backend = service.least_busy(simulator=False, operational=True)
print(f'Running on {backend}')

qc_charlie = QuantumCircuit(2,2)

qc_charlie.h(1)
qc_charlie.cx(1,0)


MESSAGE = '01'

qc_alice = QuantumCircuit(2,2)

if MESSAGE[-2]=='1':
    qc_alice.z(1)
if MESSAGE[-1]=='1':
    qc_alice.x(1)

qc_bob = QuantumCircuit(2,2)
# Bob disentangles
qc_bob.cx(1,0)
qc_bob.h(1)
# Then measures
qc_bob.measure([0,1],[0,1])


complete_qc = qc_charlie.compose(qc_alice.compose(qc_bob))
backend.run(complete_qc).result().get_counts()

I know the API works since I get Running on <IBMBackend('ibmq_belem')> and the circuit is ok as i can see it using qc_charlie.draw(), qc_alice.draw() and qc_bob.draw().

$\endgroup$

2 Answers 2

1
$\begingroup$

When done through the Qiskit Runtime environment the run is done on an Estimator or Sampler object rather than on the backend object itself as would be done on an AerSimulator as in the Qiskit textbook's original treatment. The backend is instead given as either an argument of the Estimator/Sampler object or an option on the specific run. For this case, simply replace backend.run(complete_qc).result().get_counts() with:

sampler = Sampler(session=backend) 
sampler.run(complete_qc).result().quasi_dists
$\endgroup$
0
$\begingroup$

You need to use a Session object and the Sampler

import qiskit
from qiskit import QuantumCircuit
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import QiskitRuntimeService, Session, Sampler
service = QiskitRuntimeService(channel="ibm_quantum", token=[REDACTED API KEY])
backend = service.least_busy(simulator=False, operational=True)
print(f'Running on {backend.name}')

qc_charlie = QuantumCircuit(2,2)

qc_charlie.h(1)
qc_charlie.cx(1,0)


MESSAGE = '01'

qc_alice = QuantumCircuit(2,2)

if MESSAGE[-2]=='1':
    qc_alice.z(1)
if MESSAGE[-1]=='1':
    qc_alice.x(1)

qc_bob = QuantumCircuit(2,2)
# Bob disentangles
qc_bob.cx(1,0)
qc_bob.h(1)
# Then measures
qc_bob.measure([0,1],[0,1])


complete_qc = qc_charlie.compose(qc_alice.compose(qc_bob))
with Session(backend=backend):
    sampler = Sampler()
    result = sampler.run(complete_qc).result()
print(result.quasi_dists)
$\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.