Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions client/qiskit_serverless/core/clients/serverless_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__( # pylint: disable=too-many-positional-arguments
version: Optional[str] = None,
token: Optional[str] = None,
instance: Optional[str] = None,
channel: str = Channel.IBM_QUANTUM.value,
channel: str = Channel.IBM_QUANTUM_PLATFORM.value,
):
"""
Initializes the ServerlessClient instance.
Expand Down Expand Up @@ -133,7 +133,7 @@ def __init__( # pylint: disable=too-many-positional-arguments
except ValueError as error:
raise ValueError(
"Your channel value is not correct. Use one of the available channels: "
f"{Channel.LOCAL.value}, {Channel.IBM_QUANTUM.value}, "
f"{Channel.LOCAL.value}, "
f"{Channel.IBM_CLOUD.value}, {Channel.IBM_QUANTUM_PLATFORM.value}"
) from error

Expand Down Expand Up @@ -613,7 +613,7 @@ def __init__(
token: Optional[str] = None,
name: Optional[str] = None,
instance: Optional[str] = None,
channel: str = Channel.IBM_QUANTUM.value,
channel: str = Channel.IBM_QUANTUM_PLATFORM.value,
):
"""
Initialize a client with access to an IBMQ-provided remote cluster.
Expand Down Expand Up @@ -674,7 +674,7 @@ def _discover_account(
except ValueError as error:
raise ValueError(
"Your channel value is not correct. Use one of the available channels: "
f"{Channel.LOCAL.value}, {Channel.IBM_QUANTUM.value}, "
f"{Channel.LOCAL.value}, "
f"{Channel.IBM_CLOUD.value}, {Channel.IBM_QUANTUM_PLATFORM.value}"
) from error

Expand Down Expand Up @@ -714,7 +714,7 @@ def save_account(
name: Optional[str] = None,
overwrite: Optional[bool] = False,
instance: Optional[str] = None,
channel: str = Channel.IBM_QUANTUM.value,
channel: str = Channel.IBM_QUANTUM_PLATFORM.value,
) -> None:
"""
Save the account to disk for future use.
Expand Down
1 change: 0 additions & 1 deletion client/qiskit_serverless/core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ class Channel(str, Enum):
"""

LOCAL = "local"
IBM_QUANTUM = "ibm_quantum"
IBM_CLOUD = "ibm_cloud"
IBM_QUANTUM_PLATFORM = "ibm_quantum_platform"
2 changes: 1 addition & 1 deletion client/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ray[default]>=2.30, <3
requests>=2.32.2, <3
importlib-metadata>=5.2.0, <9
qiskit[qpy-compat]>=1.4, <3
qiskit-ibm-runtime~=0.40.1
qiskit-ibm-runtime>=0.40.1, <1
# Make sure ray node and notebook node have the same version of cloudpickle
cloudpickle==2.2.1
tqdm>=4.66.3, <5
Expand Down
42 changes: 5 additions & 37 deletions client/tests/core/test_ibm_serverless_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from qiskit_serverless import IBMServerlessClient
from qiskit_serverless.core.enums import Channel
from qiskit_serverless.exception import QiskitServerlessException


class TestIBMServerlessClient(unittest.TestCase):
Expand All @@ -39,7 +38,6 @@ def test_save_load_account(self, mock_file_path, mock_verify_credentials):
mock_file_path.return_value = temp_file.name

channels_to_test = [
Channel.IBM_QUANTUM.value,
Channel.IBM_CLOUD.value,
Channel.IBM_QUANTUM_PLATFORM.value,
]
Expand All @@ -64,44 +62,14 @@ def test_save_load_account(self, mock_file_path, mock_verify_credentials):
self.assertEqual(client.account.token, use_token)
self.assertEqual(client.account.instance, use_instance)

@patch("qiskit_ibm_runtime.accounts.management._DEFAULT_ACCOUNT_CONFIG_JSON_FILE")
def test_save_wrong_instance(self, mock_file_path):
"""Test saving with wrong instance format (ibm_quantum channel)."""

# Save config in a temporary file
with tempfile.NamedTemporaryFile() as temp_file:
mock_file_path.return_value = temp_file.name

use_channel = Channel.IBM_QUANTUM.value
use_instance = "wrong_ibm_quantum_instance"
use_token = "save_token"
use_name = f"test_save_account_{uuid.uuid4().hex}"

with self.assertRaisesRegex(
QiskitServerlessException,
r"Invalid format in account inputs - 'Invalid `instance` value\. "
"Expected hub/group/project format, got wrong_ibm_quantum_instance'",
):

IBMServerlessClient.save_account(
token=use_token,
name=use_name,
instance=use_instance,
channel=use_channel,
)

def test_init_wrong_instance(self):
"""Test initializing account with wrong instance format (ibm_quantum channel)."""
def test_ibm_quantum_channel(self):
"""Test error raised when initializing account with `ibm_quantum` channel."""

use_channel = Channel.IBM_QUANTUM.value
use_instance = "wrong_ibm_quantum_instance"
use_channel = "ibm_quantum"
use_instance = "h/g/p"
use_token = "save_token"

with self.assertRaisesRegex(
QiskitServerlessException,
r"Invalid format in account inputs - 'Invalid `instance` value\. "
"Expected hub/group/project format, got wrong_ibm_quantum_instance'",
):
with self.assertRaisesRegex(ValueError, r"Your channel value is not correct"):

IBMServerlessClient(
channel=use_channel, instance=use_instance, token=use_token
Expand Down
8 changes: 6 additions & 2 deletions client/tests/core/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def test_update_sub_status(self, job_env_variables):
@patch("requests.get", Mock(return_value=ResponseMock()))
def test_filtered_logs(self):
"""Tests job filtered log."""
client = ServerlessClient(host="host", token="token", version="version")
client = ServerlessClient(
host="host", token="token", instance="crn", version="version"
)
client.logs = MagicMock(
return_value="This is the line 1\nThis is the second line\nOK. This is the last line.\n", # pylint: disable=line-too-long
)
Expand All @@ -108,7 +110,9 @@ def test_filtered_logs(self):
@patch("requests.get", Mock(return_value=ResponseMock()))
def test_error_message(self):
"""Tests job filtered log."""
client = ServerlessClient(host="host", token="token", version="version")
client = ServerlessClient(
host="host", token="token", instance="crn", version="version"
)
client.status = MagicMock(
return_value="ERROR",
)
Expand Down
1 change: 1 addition & 0 deletions tests/basic/01_running_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
serverless = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", "http://localhost:8000"),
instance=os.environ.get("GATEWAY_INSTANCE", "an_awesome_crn"),
)
print(serverless)

Expand Down
1 change: 1 addition & 0 deletions tests/basic/02_arguments_and_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
serverless = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", "http://localhost:8000"),
instance=os.environ.get("GATEWAY_INSTANCE", "an_awesome_crn"),
)
print(serverless)

Expand Down
1 change: 1 addition & 0 deletions tests/basic/03_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
serverless = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", "http://localhost:8000"),
instance=os.environ.get("GATEWAY_INSTANCE", "an_awesome_crn"),
)
print(serverless)

Expand Down
1 change: 1 addition & 0 deletions tests/basic/04_distributed_workloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
serverless = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", "http://localhost:8000"),
instance=os.environ.get("GATEWAY_INSTANCE", "an_awesome_crn"),
)
print(serverless)

Expand Down
1 change: 1 addition & 0 deletions tests/basic/05_retrieving_past_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
serverless = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", "http://localhost:8000"),
instance=os.environ.get("GATEWAY_INSTANCE", "an_awesome_crn"),
)
print(serverless)

Expand Down
1 change: 1 addition & 0 deletions tests/basic/06_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
serverless = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", "http://localhost:8000"),
instance=os.environ.get("GATEWAY_INSTANCE", "an_awesome_crn"),
)

help = """
Expand Down
1 change: 1 addition & 0 deletions tests/docker/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def set_up_serverless_client():
serverless = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", connection_url),
instance=os.environ.get("GATEWAY_INSTANCE", "an_awesome_crn"),
)

# Initialize serverless folder for current user
Expand Down
1 change: 1 addition & 0 deletions tests/experimental/file_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
serverless = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", "http://localhost:8000"),
instance=os.environ.get("GATEWAY_INSTANCE", "an_awesome_crn"),
)
print(serverless)

Expand Down
1 change: 1 addition & 0 deletions tests/experimental/manage_data_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
serverless = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", "http://localhost:8000"),
instance=os.environ.get("GATEWAY_INSTANCE", "an_awesome_crn"),
)
print(serverless)

Expand Down
1 change: 1 addition & 0 deletions tests/experimental/running_programs_using_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
provider = ServerlessClient(
token=os.environ.get("GATEWAY_TOKEN", "awesome_token"),
host=os.environ.get("GATEWAY_HOST", "http://localhost:8000"),
instance=os.environ.get("GATEWAY_INSTANCE", "an_awesome_crn"),
)
print(provider)

Expand Down