Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qiskit Runtime Sampler , sampler not taking the argument "backend" #1033

Closed
sirgeorgesawcon opened this issue Aug 24, 2023 · 7 comments
Closed
Labels
bug Something isn't working

Comments

@sirgeorgesawcon
Copy link

Environment

  • Qiskit Terra version: 0.22.2
  • Python version: 3.8.1
  • Operating system: Win10

What is happening?

Following the Qiskit tutorial on sampler : https://qiskit.org/ecosystem/ibm-runtime/tutorials/how-to-getting-started-with-sampler.html

while invoking the Qiskit runtime sampler, with any backend (backend = ibmq_qasm_simulator) and then running the

sampler = Sampler(backend=backend)

gives the error: TypeError: Sampler.init() got an unexpected keyword argument 'backend'

It should not happen, since the sampler function in qiskit takes in the following input
screenshot_2023-08-22_at_15-25-46_qiskit_ibm_runtime sampler_____qiskit_runtime_ibm_client_0 11 4_documentation

but here it's flagging backend as unexpected keyword

How can we reproduce the issue?


service = QiskitRuntimeService(channel="ibm_quantum")
backend = service.backend("ibmq_qasm_simulator")

from qiskit_ibm_runtime import Sampler

sampler = Sampler(backend=backend)

What should happen?

Sampler should take in the backend and then when executed with a quantum circuit qc should return the job results.

Any suggestions?

No response

@sirgeorgesawcon sirgeorgesawcon added the bug Something isn't working label Aug 24, 2023
@1ucian0 1ucian0 transferred this issue from Qiskit/qiskit Aug 24, 2023
@1ucian0
Copy link
Member

1ucian0 commented Aug 24, 2023

It seems to be a problem related with an out-of-sync version of qiskit-ibm-runtime. What's your qiskit-ibm-runtime version?

from qiskit_ibm_runtime import __version__
print(__version__)

If lower than 0.11, consider updating your package pip install -U qiskit-ibm-runtime

@sirgeorgesawcon
Copy link
Author

It's again giving the same issue:
Screenshot 2023-08-25 151349

@jyu00
Copy link
Collaborator

jyu00 commented Aug 25, 2023

@sirgeorgesawcon Where did you import that Sampler from? The tutorial first shows how to use Sampler from Qiskit (terra) by first doing from qiskit.primitives import Sampler. Then later it shows using Qiskit Runtime Sampler by first doing from qiskit_ibm_runtime import Sampler.

qiskit.primitives.Sampler doesn't accept backend as an input argument.

@sirgeorgesawcon
Copy link
Author

Screenshot 2023-08-28 114946
This is how I'm importing Sampler

@kt474
Copy link
Member

kt474 commented Aug 28, 2023

@sirgeorgesawcon if you're using the latest version of qiskit-ibm-runtime, the following code snippet should work - as mentioned in the comment above, I believe you're not actually using the Sampler imported from qiskit_ibm_runtime but using the Sampler imported from qiskit.primitives.

from qiskit_ibm_runtime import QiskitRuntimeService, Sampler

service = QiskitRuntimeService(channel="ibm_quantum")
backend = service.backend("ibmq_qasm_simulator")

sampler = Sampler(backend=backend)

@sirgeorgesawcon
Copy link
Author

Hi, Yes, It is running perfectly now, thanks, The issue was that in the big file of imports, I was importing sampler twice, first from runtime and second from aer. Now it's working fine. But the sampler from aer gives a different result than sampler from runtime.

I understand that sampler from aer is running on my local machine, and sampler from runtime is running on IBM cloud and specifically ibm_qasm_simulator, given the Qasm Simulator is noise free simulator, both the results should be the same, But the aer sampler gives the result that matches with the classical and runtime sampler gives different result than that.

@kt474
Copy link
Member

kt474 commented Aug 29, 2023

Closing for now, following up discussion in #1043

@kt474 kt474 closed this as completed Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants