Skip to content

Commit 14f340f

Browse files
committed
chore: updated tests for additional job parameters
1 parent e27d70e commit 14f340f

File tree

8 files changed

+71
-10
lines changed

8 files changed

+71
-10
lines changed

integration/test_gpu_decoder_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def test_gpu_decoder_config_flow(
8585
programs=[qir_program_ref],
8686
name=f"qir gpu decoder config execute job for {test_case_name}",
8787
n_shots=[100],
88+
max_cost=[10.0],
8889
backend_config=qnx.QuantinuumConfig(
8990
device_name="H1-1E",
90-
max_cost=10,
9191
),
9292
gpu_decoder_config=gpu_decoder_config_ref,
9393
project=proj_ref,

integration/test_qir.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ def test_execution_on_NG_devices(
197197
job_ref = qnx.start_execute_job(
198198
programs=[qir_ref],
199199
n_shots=[10],
200+
max_cost=[10.0],
200201
backend_config=qnx.QuantinuumConfig(
201-
device_name="Helios-1E", max_cost=10, compiler_options={"max-qubits": 5}
202+
device_name="Helios-1E", compiler_options={"max-qubits": 5}
202203
),
203204
project=project_ref,
204205
name=f"qir job for {test_case_name}",

integration/test_qsys_jobs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@
2525
@pytest.mark.parametrize(
2626
"backend_config",
2727
[
28-
SeleneConfig(
29-
n_qubits=5,
30-
),
28+
SeleneConfig(),
3129
HeliosConfig(
3230
system_name="Helios-1E-lite",
33-
emulator_config=HeliosEmulatorConfig(n_qubits=5),
31+
emulator_config=HeliosEmulatorConfig(),
3432
),
3533
],
3634
)
@@ -58,6 +56,7 @@ def test_guppy_execution(
5856
backend_config=backend_config,
5957
project=project_ref,
6058
name=f"selene job for {test_case_name}",
59+
n_qubits=[5],
6160
)
6261

6362
qnx.jobs.wait_for(job_ref)

qnexus/client/hugr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
uploaded to Nexus before stability is achieved might not work in the future.
55
"""
66

7-
import warnings
87
import base64
8+
import warnings
99
from datetime import datetime
1010
from typing import Any, Literal, Union, cast
1111
from uuid import UUID

qnexus/client/jobs/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
SystemRef,
6161
WasmModuleRef,
6262
)
63-
6463
from qnexus.models.scope import ScopeFilterEnum
6564
from qnexus.models.utils import assert_never
6665

@@ -613,6 +612,8 @@ def execute(
613612
credential_name: str | None = None,
614613
user_group: str | None = None,
615614
timeout: float | None = 300.0,
615+
max_cost: float | list[float] | list[None] = list(),
616+
n_qubits: int | list[int] | list[None] = list(),
616617
) -> list[ExecutionResult]:
617618
"""
618619
Utility method to run an execute job and return the results. Blocks until
@@ -635,6 +636,8 @@ def execute(
635636
language=language,
636637
credential_name=credential_name,
637638
user_group=user_group,
639+
max_cost=max_cost,
640+
n_qubits=n_qubits,
638641
)
639642

640643
wait_for(job=execute_job_ref, timeout=timeout)

qnexus/client/jobs/_execute.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def start_execute_job(
5858
wasm_module: WasmModuleRef | None = None,
5959
gpu_decoder_config: GpuDecoderConfigRef | None = None,
6060
user_group: str | None = None,
61-
max_cost: float | list[float] | list[None] = list(),
61+
max_cost: float | list[float] | list[None] = list(),
6262
n_qubits: int | list[int] | list[None] = list(),
6363
) -> ExecuteJobRef:
6464
"""
@@ -88,6 +88,10 @@ def start_execute_job(
8888

8989
if len(n_shots) != len(program_ids):
9090
raise ValueError("Number of programs must equal number of n_shots.")
91+
if len(max_cost) != len(program_ids):
92+
raise ValueError("Number of programs must equal number of max_cost.")
93+
if len(n_qubits) != len(program_ids):
94+
raise ValueError("Number of programs must equal number of n_qubits.")
9195

9296
attributes_dict = CreateAnnotations(
9397
name=name,

qnexus/client/qir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Client API for QIR in Nexus."""
22

3-
import warnings
43
import base64
4+
import warnings
55
from datetime import datetime
66
from typing import Any, Literal, Union, cast
77
from uuid import UUID

tests/test_jobs.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Tests related to running jobs."""
2+
3+
import uuid
4+
from datetime import datetime
5+
6+
import pytest
7+
from quantinuum_schemas.models.backend_config import SeleneConfig
8+
9+
import qnexus as qnx
10+
from qnexus.models.annotations import Annotations
11+
from qnexus.models.references import (
12+
HUGRRef,
13+
ProjectRef,
14+
)
15+
16+
17+
@pytest.mark.parametrize(
18+
"n_shots, max_cost, n_qubits, error_param",
19+
[
20+
([10], [10, 20], [5, 10], "n_shots"),
21+
([10, 20], [10], [5, 10], "max_cost"),
22+
([10, 20], [10, 20], [5], "n_qubits"),
23+
],
24+
)
25+
def test_job_parameterization(
26+
n_shots: list[int],
27+
max_cost: list[float],
28+
n_qubits: list[int],
29+
error_param: str,
30+
) -> None:
31+
"""Test that we can parameterize max_cost and n_qubits for a Hugr program submission."""
32+
33+
my_proj = ProjectRef(
34+
id=uuid.uuid4(), annotations=Annotations(), contents_modified=datetime.now()
35+
)
36+
37+
hugr_ref = HUGRRef(
38+
id=uuid.uuid4(),
39+
annotations=Annotations(),
40+
project=my_proj,
41+
)
42+
43+
with pytest.raises(
44+
ValueError, match=f"Number of programs must equal number of {error_param}."
45+
):
46+
qnx.start_execute_job(
47+
programs=[hugr_ref, hugr_ref],
48+
n_shots=n_shots,
49+
backend_config=SeleneConfig(),
50+
project=my_proj,
51+
name="This job will never run",
52+
max_cost=max_cost,
53+
n_qubits=n_qubits,
54+
)

0 commit comments

Comments
 (0)