Skip to content

Commit 5d1bee1

Browse files
Ruff format and check
1 parent 1e1e1ab commit 5d1bee1

File tree

8 files changed

+31
-42
lines changed

8 files changed

+31
-42
lines changed

src/oqd_cloud/client.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
# limitations under the License.
1414

1515

16-
from typing import Literal, Optional, Sequence
16+
from typing import Optional, Sequence
1717
import urllib.request
1818

1919
import requests
20-
import json
2120
from oqd_core.backend.task import Task
2221
from pydantic import BaseModel, ConfigDict
2322

@@ -136,12 +135,7 @@ def connect(self, provider: Provider, username: str, password: str):
136135
# self.connect(self, self.provider)
137136
# pass
138137

139-
def submit_job(
140-
self,
141-
task: Task,
142-
backend: str,
143-
tags: str
144-
):
138+
def submit_job(self, task: Task, backend: str, tags: str):
145139
"""Submit a Task as an AnalogCircuit, DigitalCircuit, or AtomicCircuit to a backend."""
146140
response = requests.post(
147141
self.provider.job_submission_url(backend=backend),
@@ -170,8 +164,8 @@ def retrieve_job(self, job_id):
170164
if response.status_code == 200:
171165
# download result file from temporary link
172166
with urllib.request.urlopen(job.result) as f:
173-
job.result = f.read().decode('utf-8')
174-
167+
job.result = f.read().decode("utf-8")
168+
175169
self._jobs[job_id] = job
176170
return self.jobs[job_id]
177171

src/oqd_cloud/provider.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import requests
15+
import requests
1616
from oqd_cloud.server.model import Backends
1717

1818

@@ -28,17 +28,15 @@ def __init__(self, host: str = "http://localhost", port: int = 8000):
2828

2929
# get available backends
3030
self.backends = Backends(available=[])
31-
response = requests.get(
32-
self.url + "/available_backends"
33-
)
31+
response = requests.get(self.url + "/available_backends")
3432
backends = Backends.model_validate(response.json())
3533
if response.status_code == 200:
3634
self.backends = backends
3735

3836
@property
3937
def available_backends(self):
4038
return self.backends.available
41-
39+
4240
@property
4341
def registration_url(self):
4442
return self.url + "/auth/register"

src/oqd_cloud/server/jobqueue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ async def _report_success(job, connection, result, *args, **kwargs):
4141
async with asynccontextmanager(get_db)() as db:
4242
save_obj(job, result)
4343
url = get_temp_link(job)
44-
status_update = dict(status="finished", result=url)
45-
# status_update = dict(status="finished", result=result.model_dump_json())
44+
status_update = dict(status="finished", result=url)
45+
# status_update = dict(status="finished", result=result.model_dump_json())
4646
query = await db.execute(select(JobInDB).filter(JobInDB.job_id == job.id))
4747
job_in_db = query.scalars().first()
4848
for k, v in status_update.items():

src/oqd_cloud/server/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
if __name__ == "__main__":
1616
import uvicorn
1717

18-
uvicorn.run("app:app", host="0.0.0.0", port=8007, log_level='debug')
18+
uvicorn.run("app:app", host="0.0.0.0", port=8007, log_level="debug")

src/oqd_cloud/server/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Job(BaseModel):
4545
result: Optional[str] = None
4646
user_id: str
4747
tags: Optional[str] = None
48-
48+
4949

5050
class Backends(BaseModel):
51-
available: Sequence[str]
51+
available: Sequence[str]

src/oqd_cloud/server/route/job.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Literal, Sequence, Optional, Annotated
15+
from typing import Literal, Annotated
1616

1717
from fastapi import APIRouter, HTTPException, Body
1818
from fastapi import status as http_status
1919

2020
########################################################################################
21-
import oqd_analog_emulator #.qutip_backend import QutipBackend
21+
import oqd_analog_emulator # .qutip_backend import QutipBackend
2222
import oqd_trical
2323
from oqd_core.backend.task import Task
2424
from rq.job import Callback
@@ -51,8 +51,8 @@
5151
@job_router.get("/available_backends")
5252
async def available_backends():
5353
return backends
54-
55-
54+
55+
5656
@job_router.post("/submit/{backend}", tags=["Job"])
5757
async def submit_job(
5858
backend: Literal[tuple(backends.available)],

src/oqd_cloud/server/storage.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,20 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Literal
1615
from minio import Minio
1716
import os
1817
import io
1918
from datetime import timedelta
2019

21-
from oqd_cloud.server.database import JobInDB, get_db
20+
from oqd_cloud.server.database import JobInDB
2221

2322
########################################################################################
2423

2524
minio_client = Minio(
26-
f"localhost:9000",
25+
"localhost:9000",
2726
access_key=os.getenv("MINIO_ROOT_USER"),
2827
secret_key=os.getenv("MINIO_ROOT_PASSWORD"),
29-
secure=False
28+
secure=False,
3029
)
3130

3231
DEFAULT_MINIO_BUCKET = os.getenv("MINIO_DEFAULT_BUCKETS")
@@ -39,23 +38,22 @@
3938
print("Bucket", DEFAULT_MINIO_BUCKET, "already exists")
4039

4140

42-
4341
def save_obj(job: JobInDB, result):
4442
# if the file is already saved, fput can be used
4543
# minio_client.fput_object(
4644
# BUCKET, destination_file, source_file,
4745
# )
48-
49-
# here we dump to json, todo: future version should dump to HDF5
50-
json_bytes = result.model_dump_json().encode('utf-8')
46+
47+
# here we dump to json, todo: future version should dump to HDF5
48+
json_bytes = result.model_dump_json().encode("utf-8")
5149
buffer = io.BytesIO(json_bytes)
5250

5351
minio_client.put_object(
54-
DEFAULT_MINIO_BUCKET,
55-
f"{job.id}/{RESULT_FILENAME}",
56-
data=buffer,
57-
length=len(json_bytes),
58-
content_type='application/json'
52+
DEFAULT_MINIO_BUCKET,
53+
f"{job.id}/{RESULT_FILENAME}",
54+
data=buffer,
55+
length=len(json_bytes),
56+
content_type="application/json",
5957
)
6058

6159
return

tests/test_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
from oqd_core.interface.analog.operation import AnalogCircuit, AnalogGate
2424
from oqd_core.interface.analog.operator import PauliX, PauliZ
2525

26-
from oqd_core.interface.atomic.circuit import AtomicCircuit
2726

2827
from oqd_cloud.client import Client
2928
from oqd_cloud.provider import Provider
30-
from rich.pretty import pprint
29+
from rich.pretty import pprint
3130

3231
X = PauliX()
3332
Z = PauliZ()
@@ -67,19 +66,19 @@
6766
task.model_dump_json()
6867

6968

70-
#%%
69+
# %%
7170
client = Client()
7271
provider = Provider(port=8007)
7372
client.connect(provider=provider, username="ben", password="pwd")
7473
client.status_report
7574

76-
#%%
75+
# %%
7776
backends = provider.available_backends
7877
print(backends)
7978

8079
# %%
8180
print(client.jobs)
82-
job = client.submit_job(task=task, backend="oqd-analog-emulator-qutip", tags='a')
81+
job = client.submit_job(task=task, backend="oqd-analog-emulator-qutip", tags="a")
8382
pprint(job)
8483

8584
# %%

0 commit comments

Comments
 (0)