Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Support session #588

Closed
jyu00 opened this issue Apr 20, 2023 · 7 comments · Fixed by #699
Closed

Support session #588

jyu00 opened this issue Apr 20, 2023 · 7 comments · Fixed by #699
Assignees
Labels
priority: high type: enhancement Existing functionality improvement
Milestone

Comments

@jyu00
Copy link
Collaborator

jyu00 commented Apr 20, 2023

What is the expected enhancement?

Support Qiskit Runtime session. Probably easier to wait for Qiskit/qiskit-ibm-runtime#548 to finish first though.

@jyu00 jyu00 added the type: enhancement Existing functionality improvement label Apr 20, 2023
@merav-aharoni
Copy link
Collaborator

@kt474 - can you elaborate on the intent of this issue?

  1. Do we want to be able to write something like:
with Session(service=service, backend=backend_name) as session:
    job = backend.run(circuits, session=session)
  1. Will provider use Session from qiskit-ibm-runtime?

@kt474
Copy link
Member

kt474 commented Jul 11, 2023

  1. I don't know the exact details (@jyu00 maybe you can elaborate) but yes, I think we would want to same format as qiskit-ibm-runtime. The snippet you posted makes sense to me.

  2. For now, to keep things more simple, we can use Session from qiskit-ibm-runtime but ideally we copy over the necessary code to this repo and then remove the duplication.

@jyu00
Copy link
Collaborator Author

jyu00 commented Aug 1, 2023

Yeah we want the user interface to be as similar as possible. In qiskit-ibm-runtime Session can be used both as a context manager and passed in as a parameter to the primitives (because context manager is not always possible/easy). So we should support both here as well.

@merav-aharoni
Copy link
Collaborator

@jyu00 , if I understand you correctly, then we would also like to support passing Session as a parameter to either IBMBackend() or to IBMBackend.run(), like it is an (optional) parameter to Sampler or Estimator. I don't think it is a good idea to change the interface to IBMBackend, although that would be more similar to what is done in the primitives. I would prefer to pass Session as a parameter to IBMBackend.run(). Do you agree?

@jyu00
Copy link
Collaborator Author

jyu00 commented Aug 4, 2023

I don't think it is a good idea to change the interface to IBMBackend

I agree, since people don't instantiate IBMBackend directly.

Unfortunately it's a bit difficult to retro-fit Session into backend.run and keep the interface consistent. After thinking about this some more, how about

  1. With a context manager
provider = IBMProvider()
backend = provider.get_backend("ibm_gotham")

with Session() as session:
    job1 = backend.run(circuits)
    job2 = backend.run(circuits)  # <--- we'll need to check/raise this is not the same backend
  1. Without context manager
provider = IBMProvider()
backend = provider.get_backend("ibm_gotham")
backend.set_options(session=Session())
job1 = backend.run(circuits)
job2 = backend.run(circuits)

Now Session in qiskit-ibm-provider will continue to accept max_time in its constructor. Unlike its counterpart in qiskit-ibm-runtime, it obviously won't accept service. I don't think it's necessary to pass a backend either, since the backend to be used can be inferred.

How does this sound?

@merav-aharoni
Copy link
Collaborator

My approach was that Session should be a member of the IBMProvider and not of IBMBackend. I view the backend as a physical being and having a Session would not be in line with that. I also wanted to keep IBMBackend similar to that in qiskit-ibm-runtime, and that one does not own a Session.
I am also not sure about passing session as an option to the backend. All the other options are of type configuration/run options.
Please have a look at what I did in the PR #675 and tell me if you agree with this direction or if you still think the Session should be passed to the backend.

@jyu00
Copy link
Collaborator Author

jyu00 commented Aug 8, 2023

@merav-aharoni after some feedback from internal users, we settled on

# without context manager
backend = provider.get_backend("ibmq_manila")
backend.open_session()
backend.run(...)
backend.close_session()

# with context manager
with backend.open_session():
    backend.run(...)

The main reasons behind this are

  1. Easy to open a new session without having to create a new object
  2. We can still pass backend around to methods that take a Backend object (like in qiskit-experiments)
  3. No need to specify the session parameter at each run

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
priority: high type: enhancement Existing functionality improvement
Projects
None yet
3 participants