From 6fc8679d1868002c96ebcc0a67baf94475e33811 Mon Sep 17 00:00:00 2001 From: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:56:13 -0400 Subject: [PATCH] Fix: Bad compatibility with InstructionProperties - Make `InstructionProperties` "_calibration" attribute visible. - Removed attribute "calibration", treat as class property. - Other tweaks and fixes --- crates/accelerate/src/target.rs | 13 ++++++------- qiskit/transpiler/_target.py | 8 ++++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/accelerate/src/target.rs b/crates/accelerate/src/target.rs index 7e21d0982fe3..d9d08427fb8b 100644 --- a/crates/accelerate/src/target.rs +++ b/crates/accelerate/src/target.rs @@ -63,7 +63,8 @@ pub struct InstructionProperties { pub duration: Option, #[pyo3(get, set)] pub error: Option, - pub calibration: Option, + #[pyo3(get)] + _calibration: Option, } #[pymethods] @@ -74,15 +75,15 @@ impl InstructionProperties { calibration: Schedule | ScheduleBlock | CalibrationEntry | None = None,)")] pub fn new(duration: Option, error: Option, calibration: Option) -> Self { InstructionProperties { - calibration, error, duration, + _calibration: calibration, } } #[getter] pub fn get_calibration(&self, py: Python<'_>) -> Option { - match &self.calibration { + match &self._calibration { Some(calibration) => calibration.call_method0(py, "get_schedule").ok(), None => None, } @@ -90,7 +91,7 @@ impl InstructionProperties { #[setter] pub fn set_calibration(&mut self, py: Python<'_>, calibration: Bound) -> PyResult<()> { - self.calibration = Some(calibration.to_object(py)); + self._calibration = Some(calibration.to_object(py)); Ok(()) } @@ -98,9 +99,7 @@ impl InstructionProperties { if let Some(calibration) = self.get_calibration(py) { format!( "InstructionProperties(duration={:?}, error={:?}, calibration={:?})", - self.duration, - self.error, - calibration.call_method0(py, "__repr__") + self.duration, self.error, calibration ) } else { format!( diff --git a/qiskit/transpiler/_target.py b/qiskit/transpiler/_target.py index 7af7d2b09312..c43026ba47ae 100644 --- a/qiskit/transpiler/_target.py +++ b/qiskit/transpiler/_target.py @@ -91,6 +91,10 @@ def duration(self): def error(self): return self._InsrProp.error + @property + def _calibration(self): + return self._InsrProp._calibration + @error.setter def error(self, other): self._InsrProp.error = other @@ -332,7 +336,7 @@ def update_from_instruction_schedule_map(self, inst_map, inst_name_map=None, err props = None entry = get_calibration(inst_name, qargs) - if entry.user_provided and getattr(props, "calibration", None) != entry: + if entry.user_provided and getattr(props, "_calibration", None) != entry: # It only copies user-provided calibration from the inst map. # Backend defined entry must already exist in Target. if self.dt is not None: @@ -380,7 +384,7 @@ def update_from_instruction_schedule_map(self, inst_map, inst_name_map=None, err if isinstance(qargs, int): qargs = (qargs,) qlen.add(len(qargs)) - cal = getattr(out_props[tuple(qargs)], "calibration") + cal = getattr(out_props[tuple(qargs)], "_calibration") param_names.add(tuple(cal.get_signature().parameters.keys())) if len(qlen) > 1 or len(param_names) > 1: raise QiskitError(