diff --git a/qiskit_ibm_runtime/base_primitive.py b/qiskit_ibm_runtime/base_primitive.py index 113f5eca3..4dd596e2a 100644 --- a/qiskit_ibm_runtime/base_primitive.py +++ b/qiskit_ibm_runtime/base_primitive.py @@ -28,7 +28,6 @@ from .session import get_cm_session from .constants import DEFAULT_DECODERS from .qiskit_runtime_service import QiskitRuntimeService -from .utils.deprecation import issue_deprecation_msg # pylint: disable=unused-import,cyclic-import from .session import Session @@ -70,7 +69,6 @@ def __init__( # The base class, however, uses a `_run_options` which is an instance of # qiskit.providers.Options. We largely ignore this _run_options because we use # a nested dictionary to categorize options. - self._session: Optional[Session] = None self._service: QiskitRuntimeService = None self._backend: Optional[IBMBackend] = None @@ -90,39 +88,11 @@ def __init__( self._backend = self._service.backend( name=self._session.backend(), instance=self._session._instance ) - elif isinstance(session, IBMBackend): - issue_deprecation_msg( - msg="Passing a backend instance as the ``session`` parameter is deprecated", - version="0.10.0", - remedy="Please pass it as the ``backend`` parameter instead.", - ) - self._service = session.service - self._backend = session - elif isinstance(session, str): - issue_deprecation_msg( - msg="Passing a backend name as the ``session`` parameter is deprecated", - version="0.10.0", - remedy="Please pass it as the ``backend`` parameter instead.", - ) - self._service = ( - QiskitRuntimeService() - if QiskitRuntimeService.global_service is None - else QiskitRuntimeService.global_service - ) - self._backend = self._service.backend(session) - elif isinstance(backend, Session): - issue_deprecation_msg( - msg="``session`` is no longer the first parameter when initializing " - "a Qiskit Runtime primitive", - version="0.10.0", - remedy="Please use ``session=session`` instead.", - ) - self._session = backend - self._service = self._session.service - self._backend = self._service.backend( - name=self._session.backend(), instance=self._session._instance - ) - elif isinstance(backend, IBMBackend): + return + elif session is not None: + raise ValueError("session must be of type Session or None") + + if isinstance(backend, IBMBackend): self._service = backend.service self._backend = backend elif isinstance(backend, str): @@ -148,16 +118,6 @@ def __init__( raise ValueError( "A backend or session must be specified when not using ibm_cloud channel." ) - # self._first_run = True - # self._circuits_map = {} - # if self.circuits: - # for circuit in self.circuits: - # circuit_id = _hash( - # json.dumps(_circuit_key(circuit), cls=RuntimeEncoder) - # ) - # if circuit_id not in self._session._circuits_map: - # self._circuits_map[circuit_id] = circuit - # self._session._circuits_map[circuit_id] = circuit def _run_primitive(self, primitive_inputs: Dict, user_kwargs: Dict) -> RuntimeJob: """Run the primitive. diff --git a/test/unit/test_ibm_primitives.py b/test/unit/test_ibm_primitives.py index a96f39388..4044acd67 100644 --- a/test/unit/test_ibm_primitives.py +++ b/test/unit/test_ibm_primitives.py @@ -173,13 +173,11 @@ def test_init_with_session_backend_str(self): for cls in primitives: with self.subTest(primitive=cls), patch( "qiskit_ibm_runtime.base_primitive.QiskitRuntimeService" - ) as mock_service: - with self.assertWarns(DeprecationWarning): - mock_service.reset_mock() - mock_service.global_service = None + ): + with self.assertRaises(ValueError) as exc: inst = cls(session=backend_name) - mock_service.assert_called_once() self.assertIsNone(inst.session) + self.assertIn("session must be of type Session or None", str(exc.exception)) def test_init_with_backend_instance(self): """Test initializing a primitive with a backend instance.""" @@ -201,9 +199,10 @@ def test_init_with_backend_instance(self): runtime_options = service.run.call_args.kwargs["options"] self.assertEqual(runtime_options["backend"], backend.name) - with self.assertWarns(DeprecationWarning): + with self.assertRaises(ValueError) as exc: inst = cls(session=backend) self.assertIsNone(inst.session) + self.assertIn("session must be of type Session or None", str(exc.exception)) def test_init_with_backend_session(self): """Test initializing a primitive with both backend and session."""