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

Add local channel #1793

Merged
merged 29 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f6b94aa
add local channel type
ptristan3 Jul 5, 2024
c92016b
return QiskitRuntimeLocalService for local channel
ptristan3 Jul 5, 2024
20fabba
Merge branch 'main' into add-local-channel
ptristan3 Jul 5, 2024
7cb28c4
style fixes
ptristan3 Jul 5, 2024
ef036d3
pylint disable
ptristan3 Jul 8, 2024
7619edb
pylint disable
ptristan3 Jul 8, 2024
700c67b
Merge branch 'main' into add-local-channel
ptristan3 Jul 8, 2024
16543b4
add test case for QiskitRuntimeLocalService
ptristan3 Jul 10, 2024
034a91a
Merge branch 'main' into add-local-channel
ptristan3 Jul 10, 2024
656bd77
ignore[no-untyped-def]
ptristan3 Jul 10, 2024
f4b5219
fix type
ptristan3 Jul 10, 2024
c1ce3a2
update FakeRuntimeService
ptristan3 Jul 10, 2024
418dfd8
Merge branch 'main' into add-local-channel
ptristan3 Jul 10, 2024
66ca7dc
updated test
ptristan3 Jul 10, 2024
5aa8067
Merge branch 'main' into add-local-channel
ptristan3 Jul 10, 2024
d81fc08
release note
ptristan3 Jul 10, 2024
bfa3f70
Merge branch 'main' into add-local-channel
kt474 Jul 11, 2024
bcb29fe
Update release-notes/unreleased/1793.feat.rst
ptristan3 Jul 11, 2024
6ff893f
back the import
ptristan3 Jul 11, 2024
388a428
replace by args and kwargs
ptristan3 Jul 11, 2024
a334168
Merge branch 'main' into add-local-channel
ptristan3 Jul 16, 2024
4aa3434
Merge branch 'main' into add-local-channel
ptristan3 Jul 18, 2024
a3b6dcf
updated docstring
ptristan3 Jul 18, 2024
ea76183
add check to the refresh method
ptristan3 Jul 18, 2024
2422c1f
Merge branch 'main' into add-local-channel
ptristan3 Jul 18, 2024
7b59c20
Use private _run
kt474 Jul 22, 2024
c49a67d
Merge branch 'main' into add-local-channel
kt474 Jul 22, 2024
cd8b405
update unit tests
kt474 Jul 22, 2024
d5389b0
Merge branch 'add-local-channel' of https://github.com/ptristan3/qisk…
kt474 Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/accounts/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from ..utils import resolve_crn

AccountType = Optional[Literal["cloud", "legacy"]]
ChannelType = Optional[Literal["ibm_cloud", "ibm_quantum"]]
ChannelType = Optional[Literal["ibm_cloud", "ibm_quantum", "local"]]

IBM_QUANTUM_API_URL = "https://auth.quantum-computing.ibm.com/api"
IBM_CLOUD_API_URL = "https://cloud.ibm.com"
Expand Down
14 changes: 12 additions & 2 deletions qiskit_ibm_runtime/qiskit_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ class QiskitRuntimeService:

global_service = None

def __new__(cls, *args, **kwargs): # type: ignore[no-untyped-def]
channel = kwargs.get("channel", None)
if channel == "local":
# pylint: disable=import-outside-toplevel
from .fake_provider.local_service import QiskitRuntimeLocalService

return super().__new__(QiskitRuntimeLocalService)
else:
return super().__new__(cls)

def __init__(
self,
channel: Optional[ChannelType] = None,
Expand Down Expand Up @@ -85,7 +95,7 @@ def __init__(
values in the loaded account.

Args:
channel: Channel type. ``ibm_cloud`` or ``ibm_quantum``.
channel: Channel type. ``ibm_cloud``, ``ibm_quantum`` or ``local``.
ptristan3 marked this conversation as resolved.
Show resolved Hide resolved
token: IBM Cloud API key or IBM Quantum API token.
url: The API URL.
Defaults to https://cloud.ibm.com (ibm_cloud) or
Expand All @@ -106,7 +116,7 @@ def __init__(
private_endpoint: Connect to private API URL.

Returns:
An instance of QiskitRuntimeService.
An instance of QiskitRuntimeService or QiskitRuntimeLocalService for local channel.

Raises:
IBMInputValueError: If an input is invalid.
Expand Down
8 changes: 8 additions & 0 deletions release-notes/unreleased/1793.feat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The :class:`QiskitRuntimeLocalService` was created to support a local
testing mode. To avoid having to initialize a separate class, "local"
has been added to the valid :class:`QiskitRuntimeService` channel.

.. code:: python
service=QiskitRuntimeService(channel="local")

a :class:`QiskitRuntimeLocalService` instance will be returned.
16 changes: 16 additions & 0 deletions test/integration/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime.accounts import CloudResourceNameResolutionError
from qiskit_ibm_runtime.fake_provider.local_service import QiskitRuntimeLocalService
from qiskit_ibm_runtime.utils.utils import (
get_resource_controller_api_url,
get_iam_api_url,
Expand Down Expand Up @@ -74,6 +75,21 @@ def test_channel_strategy(self):
)
self.assertTrue(service)

def test_local_channel(self):
"""Test local channel mode"""
local_service = QiskitRuntimeService(
channel="local",
)
local_service1 = QiskitRuntimeService(
channel="local",
url=self.dependencies.url,
token=self.dependencies.token,
instance=self.dependencies.instance,
channel_strategy="default",
)
self.assertIsInstance(local_service, QiskitRuntimeLocalService)
self.assertIsInstance(local_service1, QiskitRuntimeLocalService)

def test_resolve_crn_for_valid_service_instance_name(self):
"""Verify if CRN is transparently resolved based for an existing service instance name."""
self._skip_on_ibm_quantum()
Expand Down
3 changes: 3 additions & 0 deletions test/unit/mock/fake_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class FakeRuntimeService(QiskitRuntimeService):
DEFAULT_COMMON_BACKEND = "common_backend"
DEFAULT_UNIQUE_BACKEND_PREFIX = "unique_backend_"

def __new__(cls, *args, num_hgps=2, runtime_client=None, backend_specs=None, **kwargs):
return super().__new__(cls, *args, **kwargs)

def __init__(self, *args, num_hgps=2, runtime_client=None, backend_specs=None, **kwargs):
self._test_num_hgps = num_hgps
self._fake_runtime_client = runtime_client
Expand Down