Skip to content

Commit

Permalink
Issue 853 | Client: fix numpy serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
IceKhan13 committed Aug 7, 2023
1 parent 2d78f42 commit ac81c0c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/quantum_serverless/core/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def save_result(result: Dict[str, Any]):
)
return False

if not is_jsonable(result):
if not is_jsonable(result, cls=QiskitObjectsEncoder):
logging.warning("Object passed is not json serializable.")
return False

Expand Down
40 changes: 40 additions & 0 deletions client/tests/core/test_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Tests job."""
import os
from unittest import TestCase

import numpy as np
import requests_mock

from qiskit.circuit.random import random_circuit

from quantum_serverless.core.constants import (
ENV_JOB_GATEWAY_HOST,
ENV_JOB_ID_GATEWAY,
ENV_JOB_GATEWAY_TOKEN,
)
from quantum_serverless.core.job import save_result


class TestJob(TestCase):
"""TestJob."""

def test_save_result(self):
"""Tests job save result."""

os.environ[ENV_JOB_GATEWAY_HOST] = "https://awesome-tests.com/"
os.environ[ENV_JOB_ID_GATEWAY] = "42"
os.environ[ENV_JOB_GATEWAY_TOKEN] = "awesome-token"

url = (
f"{os.environ.get(ENV_JOB_GATEWAY_HOST)}/"
f"api/v1/jobs/{os.environ.get(ENV_JOB_ID_GATEWAY)}/result/"
)
with requests_mock.Mocker() as mocker:
mocker.post(url)
result = save_result(
{
"numpy_array": np.random.random((4, 2)),
"quantum_circuit": random_circuit(3, 2),
}
)
self.assertTrue(result)

0 comments on commit ac81c0c

Please sign in to comment.