Skip to content

Commit

Permalink
[feature] Support token-based authentication (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Oct 3, 2023
1 parent 63b6894 commit 0ad7454
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Unreleased
* Update pytket version requirement to 1.20.
* Update iqm-client version requirement to 14.0.
* Fix job status checks.
* Add support for token-based authentication.

0.6.0 (March 2023)
------------------
Expand Down
33 changes: 21 additions & 12 deletions pytket/extensions/iqm/backends/iqm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import json
import os
from typing import cast, Dict, List, Optional, Sequence, Tuple, Union
from uuid import UUID
from iqm.iqm_client.iqm_client import Circuit as IQMCircuit
Expand Down Expand Up @@ -91,9 +92,15 @@ def __init__(
"""
Construct a new IQM backend.
Requires a valid username and API key. These can either be provided as
parameters or set in config using
:py:meth:`pytket.extensions.iqm.set_iqm_config`.
Requires _either_ a valid auth server URL, username and password, _or_ a tokens
file.
Auth server URL, username and password can either be provided as parameters or
set in config using :py:meth:`pytket.extensions.iqm.set_iqm_config`.
Path to the tokens file is read from the environmment variable
``IQM_TOKENS_FILE``. If set, this overrides any other credentials provided as
arguments.
:param url: base URL for requests
:param arch: Optional list of couplings between the qubits defined, if
Expand All @@ -108,21 +115,23 @@ def __init__(

if auth_server_url is None:
auth_server_url = config.auth_server_url # type: ignore
tokens_file = os.getenv("IQM_TOKENS_FILE")
if username is None:
username = config.username # type: ignore
if username is None:
raise IqmAuthenticationError()
if password is None:
password = config.password # type: ignore
if password is None:
if (username is None or password is None) and tokens_file is None:
raise IqmAuthenticationError()

self._client = IQMClient(
self._url,
auth_server_url=auth_server_url,
username=username,
password=password,
)
if tokens_file is None:
self._client = IQMClient(
self._url,
auth_server_url=auth_server_url,
username=username,
password=password,
)
else:
self._client = IQMClient(self._url, tokens_file=tokens_file)
_iqmqa = self._client.get_quantum_architecture()
self._operations = [_IQM_PYTKET_OP_MAP[op] for op in _iqmqa.operations]
self._qubits = [_as_node(qb) for qb in _iqmqa.qubits]
Expand Down

0 comments on commit 0ad7454

Please sign in to comment.