Skip to content

Commit

Permalink
Added deprecation warning when using qiskitrc file (Qiskit#1219)
Browse files Browse the repository at this point in the history
* Added deprecation warning when using qiskitrc file

* Fixed bug whereby deprecation warnings cause failure for all 'qiskit*' modules. Changed warning to deprecation warning.

* Release note

* Small grammer fix

* black

---------

Co-authored-by: Kevin Tian <[email protected]>
  • Loading branch information
merav-aharoni and kt474 authored Nov 17, 2023
1 parent b778615 commit 0fe20cd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions qiskit_ibm_runtime/accounts/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import os
import ast
from typing import Optional, Dict

from qiskit_ibm_provider.proxies import ProxyConfiguration

from qiskit_ibm_runtime.utils.deprecation import issue_deprecation_msg
from .exceptions import AccountNotFoundError
from .account import Account, ChannelType
from .storage import save_config, read_config, delete_config, read_qiskitrc
Expand Down Expand Up @@ -195,6 +197,12 @@ def get(
return Account.from_saved_format(all_config[account_name])

if os.path.isfile(_QISKITRC_CONFIG_FILE):
issue_deprecation_msg(
msg="Use of the ~/.qiskit/qiskitrc.json file is deprecated.",
version="0.15.0",
remedy="Please use the ~/.qiskit/qiskit-ibm.json file instead.",
period="1 month",
)
return cls._from_qiskitrc_file()

raise AccountNotFoundError("Unable to find account.")
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/deprecate_qiskitrc-1fd8afc6d599fc0e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
deprecations:
- |
Usage of the ``~/.qiskit/qiskitrc.json`` file for account information has been
deprecated. Use ``~/.qiskit/qiskit-ibm.json`` instead.
2 changes: 1 addition & 1 deletion test/ibm_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def setUpClass(cls):
setup_test_logging(cls.log, filename)
cls._set_logging_level(logging.getLogger(QISKIT_IBM_RUNTIME_LOGGER_NAME))
# fail test on deprecation warnings from qiskit
warnings.filterwarnings("error", category=DeprecationWarning, module="qiskit")
warnings.filterwarnings("error", category=DeprecationWarning, module=r"^qiskit$")

@classmethod
def _set_logging_level(cls, logger: logging.Logger) -> None:
Expand Down
5 changes: 4 additions & 1 deletion test/unit/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import uuid
from typing import Any
from unittest import skipIf
import warnings

from qiskit_ibm_provider.proxies import ProxyConfiguration
from qiskit_ibm_runtime.accounts import (
Expand Down Expand Up @@ -859,7 +860,9 @@ def test_enable_account_by_qiskitrc(self):
"""
with custom_qiskitrc(contents=str.encode(str_contents)):
with temporary_account_config_file(contents={}):
service = FakeRuntimeService()
with warnings.catch_warnings(record=True) as warn:
service = FakeRuntimeService()
self.assertIn("Use of the ~/.qiskit/qiskitrc.json file is deprecated", str(warn[0].message))
self.assertTrue(service._account)
self.assertEqual(service._account.token, token)

Expand Down

0 comments on commit 0fe20cd

Please sign in to comment.