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

Disconnect platform when job is interrupted #1110

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions src/qibolab/platform/platform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""A platform for executing quantum algorithms."""

import signal
from collections import defaultdict
from dataclasses import dataclass, field, replace
from typing import Dict, List, Optional, Tuple
Expand Down Expand Up @@ -117,6 +118,9 @@ class Platform:
"""Graph representing the qubit connectivity in the quantum chip."""

def __post_init__(self):
signal.signal(signal.SIGTERM, self.termination_handler)
signal.signal(signal.SIGINT, self.termination_handler)

log.info("Loading platform %s", self.name)
if self.resonator_type is None:
self.resonator_type = "3D" if self.nqubits == 1 else "2D"
Expand Down Expand Up @@ -168,6 +172,12 @@ def disconnect(self):
instrument.disconnect()
self.is_connected = False

def termination_handler(self, signum, frame):
self.disconnect()
raise RuntimeError(
f"Platform {self.name} disconnected because job was cancelled. Signal type: {signum}."
)

def _execute(self, sequence, options, **kwargs):
"""Executes sequence on the controllers."""
result = {}
Expand Down
Loading