Skip to content

Commit

Permalink
Merge branch 'main' into qpy/13
Browse files Browse the repository at this point in the history
  • Loading branch information
1ucian0 authored Jan 9, 2025
2 parents fbdc01e + 4c3684a commit 504ecba
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 55 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
python-version: [3.9, '3.10', '3.11', '3.12']
os: [ "macos-latest", "ubuntu-latest", "windows-latest" ]
exclude:
- os: "macos-latest"
python-version: 3.8
- os: "macos-latest"
python-version: 3.9
env:
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[tool.black]
line-length = 100
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']
target-version = ['py39', 'py310', 'py311', 'py312']

[tool.towncrier]
single_file = false
Expand Down Expand Up @@ -68,7 +68,6 @@ classifiers=[
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand All @@ -78,7 +77,7 @@ classifiers=[

keywords = ["qiskit", "sdk", "quantum", "api", "runtime", "ibm"]

requires-python=">=3.8"
requires-python=">=3.9"

dependencies = [
"requests>=2.19",
Expand Down
1 change: 1 addition & 0 deletions release-notes/unreleased/2097.upgrade.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Python 3.8 reached end-of-life on Oct 7th, 2024. Qiskit SDK dropped support for 3.8 in `qiskit 1.3`. In the same vein, `qiskit-ibm-runtime` does not support Python 3.8 anymore.
5 changes: 3 additions & 2 deletions test/integration/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def test_resolve_crn_for_invalid_service_instance_name(self):
self._skip_on_ibm_quantum()

service_instance_name = "-non-existing-service-name-"
with self.subTest(instance="-non-existing-service-name-"), self.assertRaises(
CloudResourceNameResolutionError
with (
self.subTest(instance="-non-existing-service-name-"),
self.assertRaises(CloudResourceNameResolutionError),
):
QiskitRuntimeService(
channel="ibm_cloud",
Expand Down
120 changes: 74 additions & 46 deletions test/unit/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,30 +275,36 @@ def test_save_get(self):
def test_list(self):
"""Test list."""

with temporary_account_config_file(
contents={
"key1": _TEST_IBM_CLOUD_ACCOUNT.to_saved_format(),
"key2": _TEST_IBM_QUANTUM_ACCOUNT.to_saved_format(),
}
), self.subTest("non-empty list of accounts"):
with (
temporary_account_config_file(
contents={
"key1": _TEST_IBM_CLOUD_ACCOUNT.to_saved_format(),
"key2": _TEST_IBM_QUANTUM_ACCOUNT.to_saved_format(),
}
),
self.subTest("non-empty list of accounts"),
):
accounts = AccountManager.list()

self.assertEqual(len(accounts), 2)
self.assertEqual(accounts["key1"], _TEST_IBM_CLOUD_ACCOUNT)
self.assertTrue(accounts["key2"], _TEST_IBM_QUANTUM_ACCOUNT)

with temporary_account_config_file(
contents={
"key1": _TEST_IBM_CLOUD_ACCOUNT.to_saved_format(),
"key2": _TEST_IBM_QUANTUM_ACCOUNT.to_saved_format(),
_DEFAULT_ACCOUNT_NAME_IBM_CLOUD: Account.create_account(
channel="ibm_cloud", token="token-ibm-cloud", instance="crn:123"
).to_saved_format(),
_DEFAULT_ACCOUNT_NAME_IBM_QUANTUM: Account.create_account(
channel="ibm_quantum", token="token-ibm-quantum"
).to_saved_format(),
}
), self.subTest("filtered list of accounts"):
with (
temporary_account_config_file(
contents={
"key1": _TEST_IBM_CLOUD_ACCOUNT.to_saved_format(),
"key2": _TEST_IBM_QUANTUM_ACCOUNT.to_saved_format(),
_DEFAULT_ACCOUNT_NAME_IBM_CLOUD: Account.create_account(
channel="ibm_cloud", token="token-ibm-cloud", instance="crn:123"
).to_saved_format(),
_DEFAULT_ACCOUNT_NAME_IBM_QUANTUM: Account.create_account(
channel="ibm_quantum", token="token-ibm-quantum"
).to_saved_format(),
}
),
self.subTest("filtered list of accounts"),
):
accounts = list(AccountManager.list(channel="ibm_cloud").keys())
self.assertEqual(len(accounts), 2)
self.assertListEqual(accounts, ["key1", _DEFAULT_ACCOUNT_NAME_IBM_CLOUD])
Expand Down Expand Up @@ -383,8 +389,9 @@ def test_default_env_channel(self):
subtests = ["ibm_quantum", "ibm_cloud"]
for channel in subtests:
channel_env = {"QISKIT_IBM_CHANNEL": channel}
with temporary_account_config_file(channel=channel, token=token), custom_envs(
channel_env
with (
temporary_account_config_file(channel=channel, token=token),
custom_envs(channel_env),
):
service = FakeRuntimeService()
self.assertEqual(service.channel, channel)
Expand Down Expand Up @@ -481,34 +488,42 @@ def test_set_channel_precedence(self):
}

# 'name' parameter
with temporary_account_config_file(contents=contents), custom_envs(channel_env), no_envs(
"QISKIT_IBM_TOKEN"
with (
temporary_account_config_file(contents=contents),
custom_envs(channel_env),
no_envs("QISKIT_IBM_TOKEN"),
):
service = FakeRuntimeService(name="any-quantum")
self.assertEqual(service.channel, "ibm_quantum")
self.assertEqual(service._account.token, any_token)

# No name or channel params, no env vars, get the account specified as "is_default_account"
with temporary_account_config_file(contents=contents), no_envs(
"QISKIT_IBM_CHANNEL"
), no_envs("QISKIT_IBM_TOKEN"):
with (
temporary_account_config_file(contents=contents),
no_envs("QISKIT_IBM_CHANNEL"),
no_envs("QISKIT_IBM_TOKEN"),
):
service = FakeRuntimeService()
self.assertEqual(service.channel, "ibm_quantum")
self.assertEqual(service._account.token, preferred_token)

# parameter 'channel' is specified, it overrides channel in env
# account specified as "is_default_account"
with temporary_account_config_file(contents=contents), custom_envs(channel_env), no_envs(
"QISKIT_IBM_TOKEN"
with (
temporary_account_config_file(contents=contents),
custom_envs(channel_env),
no_envs("QISKIT_IBM_TOKEN"),
):
service = FakeRuntimeService(channel="ibm_quantum")
self.assertEqual(service.channel, "ibm_quantum")
self.assertEqual(service._account.token, preferred_token)

# account with default name for the channel
contents["preferred-ibm-quantum"]["is_default_account"] = False
with temporary_account_config_file(contents=contents), custom_envs(channel_env), no_envs(
"QISKIT_IBM_TOKEN"
with (
temporary_account_config_file(contents=contents),
custom_envs(channel_env),
no_envs("QISKIT_IBM_TOKEN"),
):
service = FakeRuntimeService(channel="ibm_quantum")
self.assertEqual(service.channel, "ibm_quantum")
Expand All @@ -517,8 +532,10 @@ def test_set_channel_precedence(self):
# any account for this channel
del contents["default-ibm-quantum"]
# channel_env = {"QISKIT_IBM_CHANNEL": "ibm_quantum"}
with temporary_account_config_file(contents=contents), custom_envs(channel_env), no_envs(
"QISKIT_IBM_TOKEN"
with (
temporary_account_config_file(contents=contents),
custom_envs(channel_env),
no_envs("QISKIT_IBM_TOKEN"),
):
service = FakeRuntimeService(channel="ibm_quantum")
self.assertEqual(service.channel, "ibm_quantum")
Expand All @@ -527,8 +544,10 @@ def test_set_channel_precedence(self):
# no channel param, get account that is specified as "is_default_account"
# for channel from env
contents["preferred-ibm-quantum"]["is_default_account"] = True
with temporary_account_config_file(contents=contents), custom_envs(channel_env), no_envs(
"QISKIT_IBM_TOKEN"
with (
temporary_account_config_file(contents=contents),
custom_envs(channel_env),
no_envs("QISKIT_IBM_TOKEN"),
):
service = FakeRuntimeService()
self.assertEqual(service.channel, "ibm_quantum")
Expand All @@ -541,17 +560,21 @@ def test_set_channel_precedence(self):
"token": default_token,
}
channel_env = {"QISKIT_IBM_CHANNEL": "ibm_quantum"}
with temporary_account_config_file(contents=contents), custom_envs(channel_env), no_envs(
"QISKIT_IBM_TOKEN"
with (
temporary_account_config_file(contents=contents),
custom_envs(channel_env),
no_envs("QISKIT_IBM_TOKEN"),
):
service = FakeRuntimeService()
self.assertEqual(service.channel, "ibm_quantum")
self.assertEqual(service._account.token, default_token)

# no channel param, any account for the channel from env
del contents["default-ibm-quantum"]
with temporary_account_config_file(contents=contents), custom_envs(channel_env), no_envs(
"QISKIT_IBM_TOKEN"
with (
temporary_account_config_file(contents=contents),
custom_envs(channel_env),
no_envs("QISKIT_IBM_TOKEN"),
):
service = FakeRuntimeService()
self.assertEqual(service.channel, "ibm_quantum")
Expand Down Expand Up @@ -657,8 +680,9 @@ def test_enable_account_by_channel_url(self):
for channel in subtests:
with self.subTest(channel=channel):
token = uuid.uuid4().hex
with temporary_account_config_file(channel=channel, token=token), no_envs(
["QISKIT_IBM_TOKEN"]
with (
temporary_account_config_file(channel=channel, token=token),
no_envs(["QISKIT_IBM_TOKEN"]),
):
with self.assertLogs("qiskit_ibm_runtime", logging.WARNING) as logged:
service = FakeRuntimeService(channel=channel, url="some_url")
Expand All @@ -675,8 +699,9 @@ def test_enable_account_by_only_channel(self):
for channel in subtests:
with self.subTest(channel=channel):
token = uuid.uuid4().hex
with temporary_account_config_file(channel=channel, token=token), no_envs(
["QISKIT_IBM_TOKEN"]
with (
temporary_account_config_file(channel=channel, token=token),
no_envs(["QISKIT_IBM_TOKEN"]),
):
service = FakeRuntimeService()
self.assertTrue(service._account)
Expand All @@ -691,8 +716,9 @@ def test_enable_account_both_channel(self):
contents = get_account_config_contents(channel="ibm_cloud", token=token)
contents.update(get_account_config_contents(channel="ibm_quantum", token=uuid.uuid4().hex))

with temporary_account_config_file(contents=contents), no_envs(
["QISKIT_IBM_TOKEN", "QISKIT_IBM_CHANNEL"]
with (
temporary_account_config_file(contents=contents),
no_envs(["QISKIT_IBM_TOKEN", "QISKIT_IBM_CHANNEL"]),
):
service = FakeRuntimeService()
self.assertTrue(service._account)
Expand Down Expand Up @@ -794,9 +820,11 @@ def test_enable_account_by_channel_pref(self):
]
for channel in ["ibm_cloud", "ibm_quantum"]:
for extra in subtests:
with self.subTest(channel=channel, extra=extra), temporary_account_config_file(
channel=channel, verify=True, proxies={}
), no_envs(["QISKIT_IBM_TOKEN"]):
with (
self.subTest(channel=channel, extra=extra),
temporary_account_config_file(channel=channel, verify=True, proxies={}),
no_envs(["QISKIT_IBM_TOKEN"]),
):
service = FakeRuntimeService(channel=channel, **extra)
self.assertTrue(service._account)
self._verify_prefs(extra, service._account)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
minversion = 3.15
envlist = py38, py39, py310, py311, py312, lint, docs
envlist = py39, py310, py311, py312, lint, docs
isolated_build = True

[testenv]
Expand Down

0 comments on commit 504ecba

Please sign in to comment.