Skip to content

Commit

Permalink
Fix: Move operations_from_name fully to rust
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss committed Apr 23, 2024
1 parent 9e30296 commit b637a7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion crates/accelerate/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,18 @@ impl Target {
.unbind())
}

#[pyo3(text_signature = "(/,)")]
fn operation_from_name(&self, instruction: String) -> PyResult<PyObject> {
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,
Expand Down Expand Up @@ -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<'_>,
Expand Down
2 changes: 1 addition & 1 deletion qiskit/transpiler/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b637a7f

Please sign in to comment.