Skip to content

Commit

Permalink
Merge pull request #1110 from qiboteam/cancel-disconnect
Browse files Browse the repository at this point in the history
Disconnect platform when job is interrupted
  • Loading branch information
stavros11 authored Dec 5, 2024
2 parents bdf1adc + 3025a0a commit ac5157b
Showing 1 changed file with 10 additions and 0 deletions.
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

0 comments on commit ac5157b

Please sign in to comment.