Skip to content

Commit 76b4d6d

Browse files
committed
Fixes bad session management logic. Adds deduplication_id default management. Minor fixes to tests, as well as added coolname dependency.
1 parent eb3abc7 commit 76b4d6d

File tree

9 files changed

+15
-8
lines changed

9 files changed

+15
-8
lines changed

pennylane_scaleway/aer_device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def execute(
199199
) -> List:
200200

201201
if not self._session_id:
202-
self.start()
202+
raise RuntimeError("No active session. Please instanciate the device using a context manager, or call start() first. You can also attach to an existing deduplication_id.")
203203

204204
if isinstance(circuits, QuantumScript):
205205
circuits = [circuits]

pennylane_scaleway/aqt_device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def execute(
242242
execution_config: ExecutionConfig | None = None,
243243
) -> List:
244244
if not self._session_id:
245-
self.start()
245+
raise RuntimeError("No active session. Please instanciate the device using a context manager, or call start() first. You can also attach to an existing deduplication_id.")
246246

247247
if isinstance(circuits, QuantumScript):
248248
circuits = [circuits]

pennylane_scaleway/scw_device.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,14 @@ def start(self) -> str:
126126
"""
127127
if not self._session_id:
128128
self._session_id = self._platform.start_session(**self._session_options)
129+
129130
return self._session_id
130131

131132
def stop(self):
132133
"""
133134
Stops the currently running session on the Scaleway platform. Raises an error if no session is running.
134135
"""
136+
135137
if self._session_id:
136138
self._platform.stop_session(self._session_id)
137139
self.tracker.reset()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
coolname
12
pennylane
23
tenacity

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
setup(
3434
name="pennylane-scaleway",
35-
version="0.2.4",
35+
version="0.2.5",
3636
project_urls={
3737
"Documentation": "https://www.scaleway.com/en/quantum-as-a-service/",
3838
"Source": "https://github.com/scaleway/pennylane-scaleway",

tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ install-pennylane-scaleway: install-dependencies
77
.PHONY: install-dependencies
88
install-dependencies:
99
pip install --upgrade pip
10-
pip install -r ../requirements.txt
10+
pip install -Ur ../requirements.txt
1111

1212
.PHONY: install-tests-dependencies
1313
install-tests-dependencies:

tests/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pytest
22
pytest-progress
3-
scipy==1.16.2
4-
scipy-openblas32==0.3.30.0.4
3+
scipy

tests/test_aer_device.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
# Credentials
2323
SCW_PROJECT_ID = os.environ["SCW_PROJECT_ID"]
2424
SCW_SECRET_KEY = os.environ["SCW_SECRET_KEY"]
25-
SCW_BACKEND_NAME = os.getenv("SCW_BACKEND_NAME", "EMU-AER-16C-128M")
2625
SCW_API_URL = os.getenv("SCW_API_URL")
2726

27+
if SCW_SECRET_KEY in ["fake-token", ""]:
28+
SCW_BACKEND_NAME = "EMU-AER-LOCAL"
29+
else:
30+
SCW_BACKEND_NAME = "EMU-AER-16C-128M"
31+
2832
SHOTS = 4096
2933
EPSILON = 0.2 # High because we test noisy devices too.
3034

tests/test_scaleway_devices.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def circuit_probs():
171171
qml.CNOT(wires=[0, 1])
172172
return qml.probs(wires=[0, 1])
173173

174-
probs = circuit_probs()
174+
probs = circuit_probs()
175175

176176
# Result should be |00> and |11>
177177
assert isinstance(probs, np.ndarray)
@@ -305,3 +305,4 @@ def objective_fn(x: np.ndarray) -> float:
305305
assert np.allclose(
306306
final_prob_1, 1.0, atol=0.2
307307
), f"Expected P(|1>) ~ 1.0, got {final_prob_1}"
308+

0 commit comments

Comments
 (0)