Skip to content

Commit

Permalink
[QI2-727] added name field to algorithms (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
NischalQuTech authored Jan 9, 2024
1 parent 6803acb commit bea0888
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 27 deletions.
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ python = "^3.8"
typer = {extras = ["all"], version = "^0.9.0"}
qutechopenql = "^0.11.1"
pydantic = "^2.5.2"
qi-compute-api-client = {git = "https://github.com/QuTech-Delft/compute-api-client.git", branch="0.9.0"}
qi-compute-api-client = {git = "https://github.com/QuTech-Delft/compute-api-client.git", branch="0.19.0"}
qxelarator = {version = "^0.6.2", optional = true}
pydantic-settings = "^2.1.0"

Expand Down
8 changes: 4 additions & 4 deletions quantuminspire/sdk/models/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def content(self) -> str:
return self._cqasm

@property
def content_type(self) -> str:
return str(AlgorithmType.QUANTUM)
def content_type(self) -> AlgorithmType:
return AlgorithmType.QUANTUM

@property
def compile_stage(self) -> str:
return str(CompileStage.NONE)
def compile_stage(self) -> CompileStage:
return CompileStage.NONE

def __enter__(self) -> "Circuit":
self.initialize()
Expand Down
8 changes: 4 additions & 4 deletions quantuminspire/sdk/models/hybrid_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def content(self) -> str:
return self._content

@property
def content_type(self) -> str:
return str(AlgorithmType.HYBRID)
def content_type(self) -> AlgorithmType:
return AlgorithmType.HYBRID

@property
def compile_stage(self) -> str:
return str(CompileStage.NONE)
def compile_stage(self) -> CompileStage:
return CompileStage.NONE

def read_file(self, file_pointer: Path) -> None:
"""Read the python file to the wrapper.
Expand Down
1 change: 1 addition & 0 deletions quantuminspire/util/api/remote_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ async def _create_algorithm(api_client: ApiClient, program: BaseAlgorithm, proje
project_id=project.id,
type=program.content_type,
shared=ShareType.PRIVATE,
name=program.program_name,
)
return await api_instance.create_algorithm_algorithms_post(obj)

Expand Down
5 changes: 3 additions & 2 deletions tests/sdk/test_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest.mock import MagicMock

import pytest
from compute_api_client import AlgorithmType, CompileStage
from pytest_mock import MockerFixture

from quantuminspire.sdk.models.circuit import Circuit
Expand Down Expand Up @@ -43,14 +44,14 @@ def test_get_content_type(openql: MagicMock, mock_file: None) -> None:
with Circuit(platform_name="platform", program_name="program") as c:
pass

assert c.content_type == "quantum"
assert c.content_type.value == "quantum"


def test_get_compile_stage(openql: MagicMock, mock_file: None) -> None:
with Circuit(platform_name="platform", program_name="program") as c:
pass

assert c.compile_stage == "none"
assert c.compile_stage.value == "none"


def test_create_empty_circuit(openql: MagicMock, mock_file: None) -> None:
Expand Down
5 changes: 3 additions & 2 deletions tests/sdk/test_hybrid_algorithm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import MagicMock

import pytest
from compute_api_client import AlgorithmType, CompileStage
from pytest_mock import MockerFixture

from quantuminspire.sdk.models.hybrid_algorithm import HybridAlgorithm
Expand All @@ -27,12 +28,12 @@ def test_get_program_name() -> None:

def test_get_content_type() -> None:
p = HybridAlgorithm(platform_name="platform", program_name="program")
assert p.content_type == "hybrid"
assert p.content_type.value == "hybrid"


def test_get_compile_stage() -> None:
p = HybridAlgorithm(platform_name="platform", program_name="program")
assert p.compile_stage == "none"
assert p.compile_stage.value == "none"


def test_read_algorithm(mock_file: MagicMock) -> None:
Expand Down
33 changes: 24 additions & 9 deletions tests/util/api/test_remote_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,37 @@ def test_run(api_client: MagicMock, compute_api_client: None, mocked_settings: M
def test_get_results(mocker: MockerFixture, api_client: MagicMock, mocked_settings: MagicMock) -> None:
backend = RemoteBackend()
jobs_api_instance = AsyncMock()
jobs = MagicMock()
jobs.status = JobStatus.COMPLETED
jobs_api_instance.read_job_jobs_id_get.return_value = jobs
job = MagicMock()
job.status = JobStatus.COMPLETED
job.id = 1
jobs_api_instance.read_job_jobs_id_get.return_value = job

results_api_instance = AsyncMock()
results = MagicMock()
results_api_instance.read_results_by_job_id_results_job_job_id_get.return_value = results

mocker.patch("quantuminspire.util.api.remote_backend.JobsApi", return_value=jobs_api_instance)
backend.get_results(1)
jobs_api_instance.read_job_jobs_id_get.assert_called_with(1)
mocker.patch("quantuminspire.util.api.remote_backend.ResultsApi", return_value=results_api_instance)
backend.get_results(job.id)
jobs_api_instance.read_job_jobs_id_get.assert_called_with(job.id)
results_api_instance.read_results_by_job_id_results_job_job_id_get.assert_called_with(job.id)


def test_get_results_not_completed(
mocker: MockerFixture, api_client: MagicMock, compute_api_client: None, mocked_settings: MagicMock
) -> None:
backend = RemoteBackend()
jobs_api_instance = AsyncMock()
jobs = MagicMock()
jobs.status = JobStatus.RUNNING
jobs_api_instance.read_job_jobs_id_get.return_value = jobs
job = MagicMock()
job.id = 1
job.status = JobStatus.RUNNING
jobs_api_instance.read_job_jobs_id_get.return_value = job

results_api_instance = AsyncMock()

mocker.patch("quantuminspire.util.api.remote_backend.JobsApi", return_value=jobs_api_instance)
backend.get_results(MagicMock())
mocker.patch("quantuminspire.util.api.remote_backend.ResultsApi", return_value=results_api_instance)
backend.get_results(job.id)
api_client.assert_has_calls([call().__aenter__(), call().__aexit__(None, None, None)])
jobs_api_instance.read_job_jobs_id_get.assert_called_with(job.id)
results_api_instance.read_results_by_job_id_results_job_job_id_get.assert_not_called()

0 comments on commit bea0888

Please sign in to comment.