Skip to content

Commit

Permalink
Update stable/0.15 (#1231)
Browse files Browse the repository at this point in the history
* Update main branch 0.16.0 (#1227)

* Revert `Session.from_id 0.15.0` changes   (#1229)

* Revert "Update session.from_id() (#1163)"

This reverts commit 8fa0472.

* add reno

* Prepare release 0.15.1 (#1230)
  • Loading branch information
kt474 authored Nov 17, 2023
1 parent 5271642 commit 577fb52
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '0.15.0'
release = '0.15.1'

docs_url_prefix = "ecosystem/ibm-runtime"

Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.15.0
0.15.1
29 changes: 6 additions & 23 deletions qiskit_ibm_runtime/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
from .runtime_program import ParameterNamespace
from .program.result_decoder import ResultDecoder
from .ibm_backend import IBMBackend
from .exceptions import IBMInputValueError
from .utils.deprecation import deprecate_arguments
from .utils.default_session import set_cm_session
from .utils.deprecation import deprecate_arguments


def _active_session(func): # type: ignore
Expand Down Expand Up @@ -284,7 +283,7 @@ def service(self) -> QiskitRuntimeService:
def from_id(
cls,
session_id: str,
service: QiskitRuntimeService,
service: Optional[QiskitRuntimeService] = None,
backend: Optional[Union[str, IBMBackend]] = None,
) -> "Session":
"""Construct a Session object with a given session_id
Expand All @@ -296,32 +295,16 @@ def from_id(
backend: instance of :class:`qiskit_ibm_runtime.IBMBackend` class or
string name of backend.
Raises:
IBMInputValueError: If given `session_id` does not exist. or the backend passed in does
not match the original session backend.
Returns:
A new Session with the given ``session_id``
"""
"""
if backend:
deprecate_arguments("backend", "0.15.0", "Sessions do not support multiple backends.")
if isinstance(backend, IBMBackend):
backend = backend.name

response = service._api_client.session_details(session_id)
if response:
session_backend = response.get("backend_name")
if backend and backend != session_backend:
raise IBMInputValueError(
f"The session_id {session_id} was created with backend {session_backend}, "
f"but backend {backend} was given."
)
session = cls(service, session_backend)
session._session_id = session_id
return session

raise IBMInputValueError(f"The session_id {session_id} does not exist.")
session = cls(service, backend)
session._session_id = session_id
return session

def __enter__(self) -> "Session":
set_cm_session(self)
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/0.15/revert-from-id-9b87ea2d948251d6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Reverting `0.15.0` changes to :meth:`~qiskit_ibm_runtime.Session.from_id` because it was
a breaking change without proper deprecation.
17 changes: 8 additions & 9 deletions test/integration/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from qiskit.result import Result

from qiskit_ibm_runtime import Estimator, Session, Sampler, Options
from qiskit_ibm_runtime.exceptions import IBMInputValueError

from ..decorators import run_integration_test, quantum_only
from ..ibm_test_case import IBMIntegrationTestCase
Expand Down Expand Up @@ -91,16 +90,16 @@ def test_using_correct_instance(self, service):

@run_integration_test
def test_session_from_id(self, service):
"""Test creating a session with from_id with simulator."""
"""Test creating a session from a given id"""
backend = service.backend("ibmq_qasm_simulator")
session = Session(service=service, backend=backend)

sampler = Sampler(session=session)
with Session(service, backend=backend) as session:
sampler = Sampler(session=session)
job = sampler.run(ReferenceCircuits.bell(), shots=400)
session_id = job.session_id
new_session = Session.from_id(backend=backend, session_id=session_id)
sampler = Sampler(session=new_session)
job = sampler.run(ReferenceCircuits.bell(), shots=400)
session_id = job.session_id

with self.assertRaises(IBMInputValueError):
_ = Session.from_id(session_id=session_id, service=service)
self.assertEqual(session_id, job.session_id)


class TestBackendRunInSession(IBMIntegrationTestCase):
Expand Down

0 comments on commit 577fb52

Please sign in to comment.