Skip to content

Commit

Permalink
Merge pull request #42 from qiboteam/feature/client-does-not-hang
Browse files Browse the repository at this point in the history
Client does not hang
  • Loading branch information
scarrazza authored Aug 2, 2024
2 parents 1566231 + cfbdb01 commit e090fea
Show file tree
Hide file tree
Showing 17 changed files with 1,177 additions and 557 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ token = "your-token"
client = qibo_client.Client(token)

# run the circuit
result = client.run_circuit(circuit, nshots=1000, device="sim")
job = client.run_circuit(circuit, nshots=1000, device="sim")
result = job.result()
print(result)
```
12 changes: 6 additions & 6 deletions examples/run_error_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
from qibo_client import Client

# create the circuit you want to run
circuit = qibo.models.QFT(11)
circuit = qibo.models.QFT(26)

# read the token from file
token_path = Path(__file__).parent / "token.txt"
with open(token_path) as f:
token = f.read()
token = token_path.read_text()

# authenticate to server through the client instance
client = Client(token)

# run the circuit
print(f"{'*'*20}\nPost first circuit")
result = client.run_circuit(circuit, nshots=100, device="sim")

print(result)
start = time.time()
job = client.run_circuit(circuit, nshots=100, device="sim")
print(job.result())
print(f"Program done in {time.time() - start:.4f}s")
3 changes: 1 addition & 2 deletions examples/run_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

# read the token from file
token_path = Path(__file__).parent / "token.txt"
with open(token_path) as f:
token = f.read()
token = token_path.read_text()

# authenticate to server through the client instance
start = time.time()
Expand Down
9 changes: 4 additions & 5 deletions examples/run_successful_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@

# read the token from file
token_path = Path(__file__).parent / "token.txt"
with open(token_path) as f:
token = f.read()
token = token_path.read_text()

# authenticate to server through the client instance
client = Client(token)

# run the circuit
print(f"{'*'*20}\nPost first circuit")
print(f"{'*'*20}\nPost circuit")
start = time.time()
result = client.run_circuit(circuit, nshots=100, device="sim")
print(result)
job = client.run_circuit(circuit, nshots=100, device="sim")
print(job.result())
print(f"Program done in {time.time() - start:.4f}s")
2 changes: 2 additions & 0 deletions jobs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
80 changes: 79 additions & 1 deletion poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pdbpp = "^0.10.3"
pytest = "^7.4.3"
pytest-cov = "^4.1.0"
pylint = "^3.0.3"
responses = "^0.25.3"

[tool.poetry.group.docs.dependencies]
sphinx = "^7.2.6"
Expand Down
1 change: 1 addition & 0 deletions src/qibo_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
__version__ = im.version(__package__)

from .qibo_client import Client
from .qibo_job import QiboJob, QiboJobStatus
3 changes: 1 addition & 2 deletions src/qibo_client/constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
from pathlib import Path

MINIMUM_QIBO_VERSION_ALLOWED = "0.2.4"

RESULTS_BASE_FOLDER = Path(os.environ.get("RESULTS_BASE_FOLDER", "/tmp/qibo_client"))
SECONDS_BETWEEN_CHECKS = os.environ.get("SECONDS_BETWEEN_CHECKS", 2)

BASE_URL = "https://cloud.qibo.science"
TIMEOUT = 60
8 changes: 8 additions & 0 deletions src/qibo_client/config.py → src/qibo_client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ class JobPostServerError(Exception):
def __init__(self, message="Server failed to post job to queue"):
self.message = message
super().__init__(self.message)


class JobApiError(Exception):
def __init__(self, status_code: int, message: str):
self.status_code = status_code
self.message = message
self.displayed_message = f"[{self.status_code} Error] {self.message}"
super().__init__(self.displayed_message)
Loading

0 comments on commit e090fea

Please sign in to comment.