Skip to content

Commit

Permalink
Stop raising AttributeError when accessing missing calibration (Qiski…
Browse files Browse the repository at this point in the history
…t#9681)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and king-p3nguin committed May 22, 2023
1 parent c0049df commit 6c24f73
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions qiskit/transpiler/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def __init__(
@property
def calibration(self):
"""The pulse representation of the instruction."""
if self._calibration is None:
return None
return self._calibration.get_schedule()

@calibration.setter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Getting empty calibration from :class:`.InstructionProperties` raises
AttributeError has been fixed. Now it returns ``None``.
7 changes: 7 additions & 0 deletions test/python/transpiler/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,13 @@ def test_default_instmap_has_no_custom_gate(self):
inst_map = target.instruction_schedule_map()
self.assertFalse(inst_map.has_custom_gate())

def test_get_empty_target_calibration(self):
target = Target()
properties = {(0,): InstructionProperties(duration=100, error=0.1)}
target.add_instruction(XGate(), properties)

self.assertIsNone(target["x"][(0,)].calibration)


class TestGlobalVariableWidthOperations(QiskitTestCase):
def setUp(self):
Expand Down

0 comments on commit 6c24f73

Please sign in to comment.