Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client does not hang #42

Merged
merged 34 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f1a4812
flag to choose if client does not hang
marcorossi5 Jun 10, 2024
a25bcfa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 10, 2024
a0a6171
removing try except causing errors
marcorossi5 Jun 10, 2024
cc15a58
Merge remote-tracking branch 'origin/feature/client-does-not-hang' in…
marcorossi5 Jun 10, 2024
99a02ad
version warning raised only if local version is behind server version
marcorossi5 Jul 2, 2024
4894a5e
Merge branch 'main' into feature/client-does-not-hang
marcorossi5 Jul 11, 2024
409b236
client does not hang by default
marcorossi5 Jul 11, 2024
83fe8f7
refactor qibo client to look like IBM Qiskit interface
marcorossi5 Jul 12, 2024
242d9fc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 12, 2024
41498d7
test utils module
marcorossi5 Jul 13, 2024
a523ae9
Merge remote-tracking branch 'origin/feature/client-does-not-hang' in…
marcorossi5 Jul 13, 2024
307b46f
fix exception message
marcorossi5 Jul 13, 2024
d96cd3d
small changes
marcorossi5 Jul 13, 2024
c6752df
add qibo_job module tests
marcorossi5 Jul 13, 2024
cad264a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 13, 2024
8c5965f
add trailing slashes to url paths
marcorossi5 Jul 14, 2024
8e7aea5
cover qibo client tests
marcorossi5 Jul 14, 2024
2498ed0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 14, 2024
7c4813c
add verbose logs
marcorossi5 Jul 14, 2024
6a39a83
Merge remote-tracking branch 'origin/feature/client-does-not-hang' in…
marcorossi5 Jul 14, 2024
79e78be
remove | syntax for linting
marcorossi5 Jul 14, 2024
f362135
fix test
marcorossi5 Jul 14, 2024
6c780a2
add responses to test dependencies
marcorossi5 Jul 14, 2024
f572162
read minimum qibo version allowed from server
marcorossi5 Jul 14, 2024
11130a4
remove deprecated endpoint
marcorossi5 Jul 18, 2024
b780fc8
use pathlib instead of open
marcorossi5 Jul 25, 2024
5fc6ec1
conform examples
marcorossi5 Jul 25, 2024
6a04a05
update readme to use new interface
marcorossi5 Jul 25, 2024
9c85b3f
requests made through utility function
marcorossi5 Jul 25, 2024
f9f82a2
complete coverage
marcorossi5 Jul 26, 2024
080a97c
fix tests
marcorossi5 Aug 1, 2024
2f5d563
fix tests
marcorossi5 Aug 1, 2024
55fd2cd
remove qijobresult class
marcorossi5 Aug 1, 2024
cfbdb01
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jobs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
22 changes: 19 additions & 3 deletions src/qibo_client/qibo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
check_response_has_keys(response, ["qibo_version"])
qibo_server_version = response.json()["qibo_version"]

if qibo_local_version != qibo_server_version:
if qibo_local_version < qibo_server_version:
logger.warning(
"Local Qibo package version does not match the server one, please "
"upgrade: %s -> %s",
Expand All @@ -144,7 +144,11 @@
)

def run_circuit(
self, circuit: qibo.Circuit, nshots: int = 1000, device: str = "sim"
self,
circuit: qibo.Circuit,
nshots: int = 1000,
device: str = "sim",
wait_for_results: bool = True,
) -> Optional[np.ndarray]:
"""Run circuit on the cluster.

Expand All @@ -154,6 +158,8 @@
:type nshots: int
:param device: the device to run the circuit on. Default device is `sim`
:type device: str
:param wait_for_results: wheter to let the client hang until server results are ready or not. Defaults to True.
:type wait_for_results: bool

:return:
the numpy array with the results of the computation. None if the job
Expand All @@ -169,8 +175,17 @@
logger.error(err.message)
return None

# retrieve results
logger.info("Job posted on server with pid %s", self.pid)

if not wait_for_results:
logger.info(

Check warning on line 181 in src/qibo_client/qibo_client.py

View check run for this annotation

Codecov / codecov/patch

src/qibo_client/qibo_client.py#L181

Added line #L181 was not covered by tests
"Check results availability for %s job in your reserved page at "
"https://cloud.qibo.science",
self.pid,
)
return None

Check warning on line 186 in src/qibo_client/qibo_client.py

View check run for this annotation

Codecov / codecov/patch

src/qibo_client/qibo_client.py#L186

Added line #L186 was not covered by tests

# retrieve results
logger.info(
"Check results every %d seconds ...", constants.SECONDS_BETWEEN_CHECKS
)
Expand Down Expand Up @@ -198,6 +213,7 @@

# checks
response.raise_for_status()

check_response_has_keys(response, ["pid", "message"])

# save the response
Expand Down
13 changes: 13 additions & 0 deletions tests/test_qibo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ def _new_side_effect(url, json, timeout):
assert return_value is None


def test__run_circuit_without_waiting_for_results(mock_request: Mock):
def _new_side_effect(url, json, timeout):
json_data = {"pid": None, "message": "post job to queue failed"}
return utils.MockedResponse(status_code=200, json_data=json_data)

mock_request.post.side_effect = _new_side_effect

client = _get_tii_client()
return_value = client.run_circuit(utils.MockedCircuit(), wait_for_results=False)

assert return_value is None


def test_wait_for_response_to_get_request(mock_request: Mock):
failed_attempts = 3
url = "http://example.url"
Expand Down