Skip to content

Commit

Permalink
Add user warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nkanazawa1989 committed Jan 15, 2024
1 parent 4479e2b commit bf723eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion qiskit/pulse/calibration_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
24 changes: 24 additions & 0 deletions test/python/pulse/test_calibration_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit bf723eb

Please sign in to comment.