Qiskit / qiskit-ibm-runtime

IBM Client for Qiskit Runtime
https://docs.quantum.ibm.com/api/qiskit-ibm-runtime
Apache License 2.0
144 stars 153 forks source link

`QiskitRuntimeService.backend` ignores the `instance` parameter (ibm_quantum channel) #630

Closed LenaPer closed 1 year ago

LenaPer commented 1 year ago

Describe the bug When I want to specify which instance to use when loading a backend before using it in a session (available through multiple providers with my account), I noticed on the job page in iqx that it completely ignores which instance is specified. Also noticed that when I don't specify anything, it will choose the same premium provider by default each time.

Steps to reproduce This doesn't work :

# doesn't work
from qiskit.test.reference_circuits import ReferenceCircuits
from qiskit_ibm_runtime import QiskitRuntimeService, Session, Sampler

service = QiskitRuntimeService(channel="ibm_quantum")
bell = ReferenceCircuits.bell()

backend=service.backend(name='ibmq_quito', instance='ibm-q/open/main')

with Session(service=service, backend=backend) as session:
    sampler = Sampler(session=session)

    job = sampler.run(bell, shots=1024)
    print(f"Job ID: {job.job_id()}")

This does :

# works
from qiskit.test.reference_circuits import ReferenceCircuits
from qiskit_ibm_runtime import QiskitRuntimeService, Session, Sampler

service = QiskitRuntimeService(channel="ibm_quantum", instance='ibm-q/open/main')
bell = ReferenceCircuits.bell()

backend=service.backend('ibmq_quito')

with Session(service=service, backend=backend) as session:
    sampler = Sampler(session=session)

    job = sampler.run(bell, shots=1024)
    print(f"Job ID: {job.job_id()}")

Expected behavior When I load backend=service.backend(name='ibmq_quito', instance='ibm-q/open/main') , the session should run through the right specified provider.

Suggested solutions

Additional Information

kt474 commented 1 year ago

I don't think this is actually a bug. The backend() method just selects a backend given some parameters - it does not select an instance. To select an instance within a session, it would be done through options

backend = service.backend(name='ibmq_qasm_simulator')

options = Options(instance='ibm-q/open/main')

with Session(service=service, backend=backend) as session:
    sampler = Sampler(session=session, options=options)

    job = sampler.run(bell, shots=1024)
    print(f"Job ID: {job.job_id()}")

@jyu00 thoughts on this?

jyu00 commented 1 year ago

I think we should honor the h/g/p selection because that's what most users would expect. @kt474 I think you had code to fix a similar issue in qiskit-ibm-provider (by attaching h/g/p to the backend instance).