Skip to content

Commit

Permalink
mypy support
Browse files Browse the repository at this point in the history
  • Loading branch information
kukushechkin committed Aug 29, 2022
1 parent 249ee70 commit 64861d7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy-mockito.*]
ignore_missing_imports = True
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

Version 6.2
===========

* Add mypy support. `#41 <https://github.com/iqm-finland/iqm-client/pull/41>`_

Version 6.1
===========

Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ testing =
jsons==1.6.1
jsonschema==4.4.0
mockito==1.3.0
types-requests == 2.28.9
types-jsonschema == 4.14.0
cicd =
twine >= 3.3.0, < 4.0
wheel >= 0.36.2, < 1.0
26 changes: 14 additions & 12 deletions src/iqm_client/iqm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ def __del__(self):
except Exception: # pylint: disable=broad-except
pass

# pylint: disable=too-many-locals
def submit_circuits(
self,
circuits: list[Circuit],
Expand All @@ -523,6 +524,7 @@ def submit_circuits(
Returns:
ID for the created task. This ID is needed to query the status and the execution results.
"""
serialized_qubit_mapping: Optional[list[SingleQubitMapping]] = None
if qubit_mapping is not None:
# check if qubit mapping is injective
target_qubits = set(qubit_mapping.values())
Expand All @@ -543,13 +545,13 @@ def submit_circuits(
if diff:
raise ValueError(f'The physical qubits {diff} in the qubit mapping are not defined in settings.')

qubit_mapping = serialize_qubit_mapping(qubit_mapping)
serialized_qubit_mapping = serialize_qubit_mapping(qubit_mapping)

# ``bearer_token`` can be ``None`` if cocos we're connecting does not use authentication
bearer_token = self._get_bearer_token()

data = RunRequest(
qubit_mapping=qubit_mapping,
qubit_mapping=serialized_qubit_mapping,
circuits=circuits,
settings=settings,
calibration_set_id=calibration_set_id,
Expand Down Expand Up @@ -593,13 +595,13 @@ def get_run(self, job_id: UUID) -> RunResult:
timeout = 10
)
result.raise_for_status()
result = RunResult.from_dict(result.json())
if result.warnings:
for warning in result.warnings:
run_result = RunResult.from_dict(result.json())
if run_result.warnings:
for warning in run_result.warnings:
warnings.warn(warning)
if result.status == Status.FAILED:
raise CircuitExecutionError(result.message)
return result
if run_result.status == Status.FAILED:
raise CircuitExecutionError(run_result.message)
return run_result

def get_run_status(self, job_id: UUID) -> RunStatus:
"""Query the status of the running task.
Expand All @@ -621,11 +623,11 @@ def get_run_status(self, job_id: UUID) -> RunStatus:
timeout=REQUESTS_TIMEOUT
)
result.raise_for_status()
result = RunStatus.from_dict(result.json())
if result.warnings:
for warning in result.warnings:
run_result = RunStatus.from_dict(result.json())
if run_result.warnings:
for warning in run_result.warnings:
warnings.warn(warning)
return result
return run_result

def wait_for_results(self, job_id: UUID, timeout_secs: float = DEFAULT_TIMEOUT_SECONDS) -> RunResult:
"""Poll results until run is ready, failed, or timed out.
Expand Down
Empty file added src/iqm_client/py.typed
Empty file.
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ extras =
testing
commands =
pytest tests --verbose --cov --cov-report term-missing --junitxml=test_report.xml --doctest-modules src
pytest --pylint src/
pytest --pylint tests/ --pylint-rcfile=tests/.pylintrc
pytest --mypy --pylint src/
pytest --mypy --pylint tests/ --pylint-rcfile=tests/.pylintrc
pytest --isort tests/ src/ --verbose

[testenv:docs]
Expand Down

0 comments on commit 64861d7

Please sign in to comment.