From b637a7f3524d1e276cc130bd5fa7876cc8fe01c7 Mon Sep 17 00:00:00 2001 From: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com> Date: Tue, 23 Apr 2024 10:36:37 -0400 Subject: [PATCH] Fix: Move operations_from_name fully to rust --- crates/accelerate/src/target.rs | 14 +++++++++++++- qiskit/transpiler/target.py | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) 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