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

Fix Target.instruction_supported when target.num_qubits == None (backport #13655) #13657

Merged
merged 1 commit into from
Jan 14, 2025
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
6 changes: 6 additions & 0 deletions crates/accelerate/src/target_transpiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,12 @@ impl Target {

/// Checks whether an instruction is supported by the Target based on instruction name and qargs.
pub fn instruction_supported(&self, operation_name: &str, qargs: Option<&Qargs>) -> bool {
// Handle case where num_qubits is None by checking globally supported operations
let qargs: Option<&Qargs> = if self.num_qubits.is_none() {
None
} else {
qargs
};
if self.gate_map.contains_key(operation_name) {
if let Some(_qargs) = qargs {
let qarg_set: HashSet<&PhysicalQubit> = _qargs.iter().collect();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fixed a bug in the :meth:`.Target.instruction_supported` method where
targets with ``self.num_qubits==None`` would always return ``false``
independently of the supported basis set.
8 changes: 8 additions & 0 deletions test/python/transpiler/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,14 @@ def test_instruction_supported_no_args(self):
def test_instruction_supported_no_operation(self):
self.assertFalse(self.ibm_target.instruction_supported(qargs=(0,), parameters=[math.pi]))

def test_instruction_supported_no_qubits(self):
"""Checks that instruction supported works when target.num_qubits is None."""
target = Target.from_configuration(["u", "cx", "rxx"])
self.assertTrue(target.instruction_supported("u", (0,)))
self.assertTrue(target.instruction_supported("cx", (0, 1)))
self.assertTrue(target.instruction_supported("cx", None))
self.assertTrue(target.instruction_supported("rxx", (2, 3)))

def test_target_serialization_preserve_variadic(self):
"""Checks that variadics are still seen as variadic after serialization"""

Expand Down
Loading