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

Support token-based authentication #62

Merged
merged 3 commits into from
Oct 3, 2023
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
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