Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid exception in Target.has_calibration for instruction without properties #12526

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qiskit/transpiler/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ def has_calibration(
return False
if qargs not in self._gate_map[operation_name]:
return False
return getattr(self._gate_map[operation_name][qargs], "_calibration") is not None
return getattr(self._gate_map[operation_name][qargs], "_calibration", None) is not None

def get_calibration(
self,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
:meth:`.Target.has_calibration` has been updated so that it does not raise
an exception for an instruction that has been added to the target with
``None`` for its instruction properties. Fixes
`#12525 <https://github.com/Qiskit/qiskit/issues/12525>`__.
25 changes: 25 additions & 0 deletions test/python/transpiler/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,31 @@ def test_get_empty_target_calibration(self):

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

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

# Test false for properties with no calibration
self.assertFalse(target.has_calibration("x", (0,)))
# Test false for no properties
self.assertFalse(target.has_calibration("x", (1,)))

properties = {
(0,): InstructionProperties(
duration=self.custom_sx_q0.duration,
error=None,
calibration=self.custom_sx_q0,
)
}
target.add_instruction(SXGate(), properties)

# Test true for properties with calibration
self.assertTrue(target.has_calibration("sx", (0,)))

def test_loading_legacy_ugate_instmap(self):
# This is typical IBM backend situation.
# IBM provider used to have u1, u2, u3 in the basis gates and
Expand Down
Loading