Skip to content

Commit

Permalink
feat: disconnect platform when job is interrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros11 committed Dec 1, 2024
1 parent cc64ee1 commit 1ee3778
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 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,10 @@ 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("signals registered")

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 +173,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

0 comments on commit 1ee3778

Please sign in to comment.