Skip to content

Commit 4e8a099

Browse files
committed
feat(client): wip models
1 parent 53d64b6 commit 4e8a099

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
dataclasses-json==0.6.4
2+
dataclasses==0.6
13
randomname==0.2.1
24
httpx==0.27.0
35
pytimeparse==1.1.8

scaleway_qaas_client/models.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright 2025 Scaleway
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from enum import Enum
15+
from typing import List
16+
17+
from dataclasses import dataclass
18+
from dataclasses_json import dataclass_json
19+
20+
21+
class SerializationType(Enum):
22+
UNKOWN = 0
23+
QASM_V1 = 1
24+
QASM_V2 = 2
25+
QASM_V3 = 3
26+
JSON = 4
27+
28+
29+
@dataclass_json
30+
@dataclass
31+
class CircuitPayload:
32+
serialization_type: SerializationType
33+
circuit_serialization: str
34+
35+
36+
@dataclass_json
37+
@dataclass
38+
class RunPayload:
39+
circuits: List[CircuitPayload]
40+
options: dict
41+
42+
43+
@dataclass_json
44+
@dataclass
45+
class BackendPayload:
46+
name: str
47+
version: str
48+
options: dict
49+
50+
51+
@dataclass_json
52+
@dataclass
53+
class ClientPayload:
54+
user_agent: str
55+
56+
57+
@dataclass_json
58+
@dataclass
59+
class JobPayload:
60+
client: ClientPayload
61+
backend: BackendPayload
62+
run: RunPayload

tests/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pytest
2+
pytest-dependency
3+
pytest-progress
4+
pytest-httpx

tests/test_api.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright 2025 Scaleway
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import os
15+
import numpy as np
16+
import random
17+
18+
from qiskit import QuantumCircuit
19+
from qiskit_scaleway import ScalewayProvider
20+
21+
22+
def _random_qiskit_circuit(size: int) -> QuantumCircuit:
23+
num_qubits = size
24+
num_gate = size
25+
26+
qc = QuantumCircuit(num_qubits)
27+
28+
for _ in range(num_gate):
29+
random_gate = np.random.choice(["unitary", "cx", "cy", "cz"])
30+
31+
if random_gate == "cx" or random_gate == "cy" or random_gate == "cz":
32+
control_qubit = np.random.randint(0, num_qubits)
33+
target_qubit = np.random.randint(0, num_qubits)
34+
35+
while target_qubit == control_qubit:
36+
target_qubit = np.random.randint(0, num_qubits)
37+
38+
getattr(qc, random_gate)(control_qubit, target_qubit)
39+
else:
40+
for q in range(num_qubits):
41+
random_gate = np.random.choice(["h", "x", "y", "z"])
42+
getattr(qc, random_gate)(q)
43+
44+
qc.measure_all()
45+
46+
return qc
47+
48+
49+
def test_aer_multiple_circuits():
50+
provider = ScalewayProvider(
51+
project_id=os.environ["QISKIT_SCALEWAY_PROJECT_ID"],
52+
secret_key=os.environ["QISKIT_SCALEWAY_API_TOKEN"],
53+
url=os.environ["QISKIT_SCALEWAY_API_URL"],
54+
)
55+
56+
backend = provider.get_backend("aer_simulation_pop_c16m128")
57+
58+
assert backend is not None
59+
60+
session_id = backend.start_session(
61+
name="my-aer-session-autotest",
62+
deduplication_id=f"my-aer-session-autotest-{random.randint(1, 1000)}",
63+
max_duration="15m",
64+
)
65+
66+
assert session_id is not None
67+
68+
try:
69+
qc1 = _random_qiskit_circuit(20)
70+
qc2 = _random_qiskit_circuit(15)
71+
qc3 = _random_qiskit_circuit(21)
72+
qc4 = _random_qiskit_circuit(17)
73+
74+
run_result = backend.run(
75+
[qc1, qc2, qc3, qc4],
76+
shots=1000,
77+
max_parallel_experiments=0,
78+
session_id=session_id,
79+
).result()
80+
81+
results = run_result.results
82+
83+
assert len(results) == 4
84+
85+
for result in results:
86+
assert result.success
87+
finally:
88+
backend.delete_session(session_id)

0 commit comments

Comments
 (0)