Skip to content

Commit f6e7dff

Browse files
authored
Missing private key in update in database (#243)
* Most likely fix the bug * Move the coverage to the right dependency group
1 parent 3506a11 commit f6e7dff

File tree

8 files changed

+279
-91
lines changed

8 files changed

+279
-91
lines changed

.github/workflows/spooler_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
poetry install
4545
- name: Run Tests
4646
run: |
47-
poetry run pytest tests
47+
poetry run pytest --cov=src tests
4848
lint:
4949

5050
runs-on: ubuntu-latest

poetry.lock

Lines changed: 91 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mypy = "^1.8.0"
2828
python-decouple = "^3.6"
2929
ipykernel = "^6.28.0"
3030
icecream = "^2.1.3"
31+
pytest-cov = "^5.0.0"
3132

3233
[tool.poetry.group.docs]
3334
optional = true

src/sqooler/spoolers.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,7 @@ def add_job(
410410
result_dict: The dictionary with the results of the job.
411411
status_msg_dict: The status dictionary of the job.
412412
"""
413-
414413
result_dict, status_msg_dict, clean_dict = self._prep_job(json_dict, job_id)
415-
416414
if status_msg_dict.status == "ERROR":
417415
return result_dict, status_msg_dict
418416
# now we can generate the circuit for each experiment
@@ -615,15 +613,15 @@ def gen_circuit(
615613
with open(exp_script, "a", encoding="UTF-8") as script_file:
616614
script_file.write(code)
617615
except:
618-
print("Something wrong. Does file path exists?")
616+
logging.error("Something wrong. Does file path exists?")
619617

620618
code = "Experiment.final_action()" + "\n" + "stop(Experiment.t+0.1)"
621619
# pylint: disable=bare-except
622620
try:
623621
with open(exp_script, "a", encoding="UTF-8") as script_file:
624622
script_file.write(code)
625623
except:
626-
print("Something wrong. Does file path exists?")
624+
logging.error("Something wrong. Does file path exists?")
627625
self.remote_client.set_labscript_file(
628626
exp_script
629627
) # CAUTION !! This command only selects the file. It does not generate it!
@@ -661,7 +659,7 @@ def gen_circuit(
661659
shots_array.append(this_run.get_results("/measure", "nat"))
662660
got_nat = True
663661
except Exception as exc:
664-
print(exc)
662+
logging.exception(exc)
665663
sleep(self.labscript_params.t_wait)
666664
n_tries += 1
667665
exp_sub_dict = create_memory_data(shots_array, exp_name, n_shots, ins_list)

src/sqooler/utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def main(
7979
will run forever.
8080
"""
8181
backends_list = list(backends.keys())
82-
8382
# set the appropiate display names for all the back-ends
8483
for requested_backend, spooler in backends.items():
8584
# the content
@@ -114,6 +113,7 @@ def main(
114113
if job_dict.job_json_path == "None":
115114
counter += 1
116115
continue
116+
logging.debug("Got a job in %s", requested_backend)
117117
job_json_dict = storage_provider.get_job_content(
118118
storage_path=job_dict.job_json_path, job_id=job_dict.job_id
119119
)
@@ -146,8 +146,14 @@ def main(
146146
status_msg_dict.error_message += "; " + slimmed_tb
147147
logging.exception("Error in add_job for %s .", requested_backend)
148148

149+
logging.debug("Updating in database.")
150+
spooler.get_private_jwk()
149151
storage_provider.update_in_database(
150-
result_dict, status_msg_dict, job_dict.job_id, requested_backend
152+
result_dict,
153+
status_msg_dict,
154+
job_dict.job_id,
155+
requested_backend,
156+
private_jwk,
151157
)
152158

153159
counter += 1
@@ -169,6 +175,5 @@ def run_json_circuit(json_dict: dict, job_id: str, spooler: Spooler) -> dict:
169175
result_dict, status_msg_dict = spooler.add_job(json_dict, job_id)
170176
if not status_msg_dict.status == "DONE":
171177
logging.error(status_msg_dict.error_message)
172-
print(status_msg_dict.error_message)
173178
raise AssertionError("Job failed")
174179
return result_dict.model_dump()

tests/sqooler_test_utils.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"""
2+
In this file, we define some utility functions that are used in the
3+
tests that invole the sqooler and the utils.
4+
"""
5+
6+
from typing import Literal, Optional
7+
8+
from typing_extensions import Annotated
9+
from pydantic import Field
10+
from sqooler.schemes import (
11+
ExperimentDict,
12+
ExperimentalInputDict,
13+
GateInstruction,
14+
)
15+
16+
from sqooler.spoolers import (
17+
create_memory_data,
18+
)
19+
20+
21+
class DummyInstruction(GateInstruction):
22+
"""
23+
The test instruction for testing the whole system.
24+
25+
Attributes:
26+
name: The string to identify the instruction
27+
wires: The wire on which the instruction should be applied
28+
so the indices should be between 0 and N_MAX_WIRES-1
29+
params: has to be empty
30+
"""
31+
32+
name: Literal["test"]
33+
wires: Annotated[
34+
list[Annotated[int, Field(ge=0, le=0)]], Field(min_length=0, max_length=1)
35+
]
36+
params: Annotated[
37+
list[Annotated[int, Field(ge=1, le=10)]],
38+
Field(min_length=1, max_length=1),
39+
]
40+
parameters: str = "omega, delta, phi"
41+
description: str = "Apply the Rydberg and Rabi coupling over the whole array."
42+
# TODO: This should become most likely a type that is then used for the enforcement of the wires.
43+
coupling_map: list = [[0], [1], [2], [0, 1, 2, 3, 4]]
44+
qasm_def: str = "gate rydberg_full(omega, delta, phi) {}"
45+
46+
47+
class DummyFullInstruction(GateInstruction):
48+
"""
49+
The time evolution under the global Hamiltonian. It does not allow for any local control.
50+
51+
Attributes:
52+
name: The string to identify the instruction
53+
wires: The wire on which the instruction should be applied
54+
so the indices should be between 0 and N_MAX_WIRES-1
55+
params: Define the paramert for `RX`, `RZ`and `RydbergBlock` in this order
56+
"""
57+
58+
name: Literal["test"] = "test"
59+
wires: Annotated[
60+
list[Annotated[int, Field(ge=0, le=5)]],
61+
Field(min_length=2, max_length=5),
62+
]
63+
params: Annotated[
64+
list[Annotated[float, Field(ge=0, le=5)]],
65+
Field(min_length=3, max_length=3),
66+
]
67+
68+
# a string that is sent over to the config dict and that is necessary for compatibility with QISKIT.
69+
parameters: str = "omega, delta, phi"
70+
description: str = "Apply the Rydberg and Rabi coupling over the whole array."
71+
# TODO: This should become most likely a type that is then used for the enforcement of the wires.
72+
coupling_map: list = [[0], [0, 1, 2, 3, 4]]
73+
qasm_def: str = "gate rydberg_full(omega, delta, phi) {}"
74+
75+
76+
def dummy_gen_circuit(
77+
exp_name: str,
78+
json_dict: ExperimentalInputDict,
79+
job_id: Optional[str] = None, # pylint: disable=unused-argument
80+
) -> ExperimentDict:
81+
"""
82+
A dummy function to generate a circuit from the experiment dict.
83+
"""
84+
n_shots = json_dict.shots
85+
ins_list = json_dict.instructions
86+
_ = json_dict.seed
87+
shots_array = [1, 2, 3]
88+
exp_sub_dict = create_memory_data(shots_array, exp_name, n_shots, ins_list)
89+
return exp_sub_dict

0 commit comments

Comments
 (0)