Skip to content

Commit

Permalink
Add: has_calibration method to Target
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss committed Apr 15, 2024
1 parent 3063856 commit 7006e88
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
30 changes: 30 additions & 0 deletions crates/accelerate/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
) -> PyResult<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.
*/
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]
Expand Down
16 changes: 16 additions & 0 deletions qiskit/transpiler/_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 7006e88

Please sign in to comment.