From bf723eb8ca1b5f9aabd380f8a342f026aabd1478 Mon Sep 17 00:00:00 2001 From: Naoki Kanazawa Date: Tue, 16 Jan 2024 02:20:54 +0900 Subject: [PATCH] Add user warning --- qiskit/pulse/calibration_entries.py | 7 +++++- test/python/pulse/test_calibration_entries.py | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/qiskit/pulse/calibration_entries.py b/qiskit/pulse/calibration_entries.py index baa1d4a6a228..8a5ba1b6e3d6 100644 --- a/qiskit/pulse/calibration_entries.py +++ b/qiskit/pulse/calibration_entries.py @@ -13,6 +13,7 @@ """Internal format of calibration data in target.""" from __future__ import annotations import inspect +import warnings from abc import ABCMeta, abstractmethod from collections.abc import Sequence, Callable from enum import IntEnum @@ -327,9 +328,13 @@ def _build_schedule(self): schedule.insert(qobj_inst.t0, qiskit_inst, inplace=True) self._definition = schedule self._parse_argument() - except QiskitError: + except QiskitError as ex: # When the play waveform data is missing in pulse_lib we cannot build schedule. # Instead of raising an error, get_schedule should return None. + warnings.warn( + f"Pulse calibration cannot be built and the entry is ignored: {ex.message}.", + UserWarning, + ) self._definition = IncompletePulseQobj def define( diff --git a/test/python/pulse/test_calibration_entries.py b/test/python/pulse/test_calibration_entries.py index f5cadd91cbf0..47d0793fc100 100644 --- a/test/python/pulse/test_calibration_entries.py +++ b/test/python/pulse/test_calibration_entries.py @@ -326,6 +326,30 @@ def test_add_qobj(self): ) self.assertEqual(schedule_to_test, schedule_ref) + def test_missing_waveform(self): + """Test incomplete Qobj should raise warning and calibration returns None.""" + serialized_program = [ + PulseQobjInstruction( + name="waveform_123456", + t0=20, + ch="d0", + ), + ] + entry = PulseQobjDef(converter=self.converter, name="my_gate") + entry.define(serialized_program) + + with self.assertWarns( + UserWarning, + msg=( + "Pulse calibration cannot be built and the entry is ignored: " + "Instruction waveform_123456 on channel d0 is not found in Qiskit namespace. " + "This instruction cannot be deserialized." + ), + ): + out = entry.get_schedule() + + self.assertIsNone(out) + def test_parameterized_qobj(self): """Test adding and managing parameterized qobj.