Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
feat: polish error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
miwurster committed Apr 21, 2022
1 parent 7776f66 commit b2fa003
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
16 changes: 11 additions & 5 deletions planqk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def base_url():
return os.environ.get('PLANQK_QUANTUM_BASE_URL', 'http://127.0.0.1:8000')
return os.environ.get('PLANQK_QUANTUM_BASE_URL', 'http://quantum-engine.34.107.19.77.nip.io')


class PlanqkClient(object):
Expand All @@ -19,28 +19,34 @@ def get_backends(self) -> list[str]:
headers = self._get_default_headers()
response = requests.get(f'{base_url()}/backends', headers=headers)
if not response:
raise PlanqkClientError(f'Error requesting available quantum backends (status: {response.status_code})')
raise PlanqkClientError(
f'Error requesting available quantum backends (HTTP {response.status_code}: {response.text})'
)
return response.json()

def submit_job(self, payload: dict) -> dict:
headers = self._get_default_headers()
response = requests.post(f'{base_url()}/jobs', json=payload, headers=headers)
if not response:
raise PlanqkClientError(f'Error submitting job (status: {response.status_code})')
raise PlanqkClientError(f'Error submitting job (HTTP {response.status_code}: {response.text})')
return response.json()

def get_job(self, job_id: str) -> dict:
headers = self._get_default_headers()
response = requests.get(f'{base_url()}/jobs/{job_id}', headers=headers)
if not response:
raise PlanqkClientError(f'Error requesting details of job "{job_id}" (status: {response.status_code})')
raise PlanqkClientError(
f'Error requesting details of job "{job_id}" (HTTP {response.status_code}: {response.text})'
)
return response.json()

def get_job_result(self, job_id: str) -> dict:
headers = self._get_default_headers()
response = requests.get(f'{base_url()}/jobs/{job_id}/result', headers=headers)
if not response:
raise PlanqkClientError(f'Error requesting result of job "{job_id}" (status: {response.status_code})')
raise PlanqkClientError(
f'Error requesting result of job "{job_id}" (HTTP {response.status_code}: {response.text})'
)
return response.json()

def _get_default_headers(self):
Expand Down
7 changes: 4 additions & 3 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
import unittest

import pytest
Expand All @@ -11,11 +12,11 @@

logging.basicConfig(level=logging.DEBUG)


# overwrite base url
# os.environ['PLANQK_QUANTUM_BASE_URL'] = 'http://engine.34.107.19.77.nip.io'
os.environ['PLANQK_QUANTUM_BASE_URL'] = 'http://127.0.0.1:8000'
# set access token
# os.environ['PLANQK_QUANTUM_ACCESS_TOKEN'] = 'todo'
os.environ['PLANQK_QUANTUM_ACCESS_TOKEN'] \
= '7439cead03a3429bd4f49dbf832fa181b0ffc01cb4435a19e6ae736aa1126055aa64da0faada22c8'


class BasicTestSuite(unittest.TestCase):
Expand Down

0 comments on commit b2fa003

Please sign in to comment.