diff --git a/crates/accelerate/src/target.rs b/crates/accelerate/src/target.rs index 85ee4c5b2c2b..f90d4c128703 100644 --- a/crates/accelerate/src/target.rs +++ b/crates/accelerate/src/target.rs @@ -678,6 +678,36 @@ impl Target { } Ok(false) } + + #[pyo3(text_signature = "( /, operation_name: str, qargs: tuple[int, ...],)")] + fn has_calibration( + &self, + py: Python<'_>, + operation_name: String, + qargs: HashableVec, + ) -> PyResult { + /* + Return whether the instruction (operation + qubits) defines a calibration. + + Args: + operation_name: The name of the operation for the instruction. + qargs: The tuple of qubit indices for the instruction. + + Returns: + Returns ``True`` if the calibration is supported and ``False`` if it isn't. + */ + if !self.gate_map.contains_key(&operation_name) { + return Ok(false); + } + if let Some(gate_map_qarg) = self.gate_map[&operation_name].as_ref() { + if let Some(oper_qarg) = &gate_map_qarg[&Some(qargs)] { + return Ok(!oper_qarg.getattr(py, "_calibration")?.is_none(py)); + } else { + return Ok(false); + } + } + Ok(false) + } } #[pymodule] diff --git a/qiskit/transpiler/_target.py b/qiskit/transpiler/_target.py index a435a2b90098..c0826bfccb4d 100644 --- a/qiskit/transpiler/_target.py +++ b/qiskit/transpiler/_target.py @@ -586,3 +586,19 @@ def check_obj_params(parameters, obj): operation_class, parameters, ) + + def has_calibration( + self, + operation_name: str, + qargs: tuple[int, ...], + ) -> bool: + """Return whether the instruction (operation + qubits) defines a calibration. + + Args: + operation_name: The name of the operation for the instruction. + qargs: The tuple of qubit indices for the instruction. + + Returns: + Returns ``True`` if the calibration is supported and ``False`` if it isn't. + """ + return self._Target.has_calibration(operation_name, qargs)