diff --git a/crates/accelerate/src/target.rs b/crates/accelerate/src/target.rs index 238c6438ef0c..85cb43b38a5e 100644 --- a/crates/accelerate/src/target.rs +++ b/crates/accelerate/src/target.rs @@ -746,6 +746,18 @@ impl Target { .unbind()) } + #[pyo3(text_signature = "(/,)")] + fn operation_from_name(&self, instruction: String) -> PyResult { + if self.gate_name_map.contains_key(&instruction) { + Ok(self.gate_name_map[&instruction].to_owned()) + } else { + Err(PyKeyError::new_err(format!( + "Instruction {:?} not in target", + instruction + ))) + } + } + #[pyo3(text_signature = "(/, qargs)")] fn operations_for_qargs( &self, @@ -794,7 +806,7 @@ impl Target { Ok(res.into()) } - #[pyo3(text_signature = "(/, qargs)")] + #[pyo3(text_signature = "(/, qargs=None)")] fn operation_names_for_qargs( &self, py: Python<'_>, diff --git a/qiskit/transpiler/target.py b/qiskit/transpiler/target.py index 1eef51c8a6b4..5532bccc4660 100644 --- a/qiskit/transpiler/target.py +++ b/qiskit/transpiler/target.py @@ -301,7 +301,7 @@ def operation_from_name(self, instruction): name. This also can also be the class for globally defined variable with operations. """ - return super().gate_name_map[instruction] + return super().operation_from_name(instruction) def operations_for_qargs(self, qargs): """Get the operation class object for a specified qargs tuple