From 2d46d87b8d764c43d1b09a61a97da58997d0a92c Mon Sep 17 00:00:00 2001 From: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com> Date: Sat, 11 May 2024 23:27:36 -0400 Subject: [PATCH] Fix:: Adapt to target changes (#12288) - Fix lint stray imports. --- .../accelerate/src/target_transpiler/mod.rs | 36 ++++++++----------- qiskit/transpiler/target.py | 8 ++--- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/crates/accelerate/src/target_transpiler/mod.rs b/crates/accelerate/src/target_transpiler/mod.rs index 8fd2f89fc07f..f08eba917547 100644 --- a/crates/accelerate/src/target_transpiler/mod.rs +++ b/crates/accelerate/src/target_transpiler/mod.rs @@ -1367,23 +1367,20 @@ impl Target { */ #[pyo3(text_signature = "(/, index: int)")] fn instruction_properties(&self, py: Python<'_>, index: usize) -> PyResult { - let mut instruction_properties: Vec>> = vec![]; - for operation in self.gate_map.map.keys() { - if self.gate_map.map.contains_key(operation) { - let gate_map_oper = &self.gate_map.map[operation]; - let gate_map_oper = gate_map_oper.extract::(py)?; - for (_, inst_props) in gate_map_oper.map.iter() { - instruction_properties.push(inst_props.clone()) + let mut index_counter = 0; + for (_operation, props_map) in self.gate_map.map.iter() { + let gate_map_oper = props_map.extract::(py)?; + for (_, inst_props) in gate_map_oper.map.iter() { + if index_counter == index { + return Ok(inst_props.to_object(py)); } + index_counter += 1; } } - if !((0..instruction_properties.len()).contains(&index)) { - return Err(PyIndexError::new_err(format!( - "Index: {:?} is out of range.", - index - ))); - } - Ok(instruction_properties[index].to_object(py)) + Err(PyIndexError::new_err(format!( + "Index: {:?} is out of range.", + index + ))) } /** @@ -1518,13 +1515,10 @@ impl Target { // Get list of instructions. let mut instruction_list: Vec<(PyObject, Option)> = vec![]; // Add all operations and dehash qargs. - for op in self.gate_map.map.keys() { - if self.gate_map.map.contains_key(op) { - let gate_map_op = &self.gate_map.map[op]; - for qarg in gate_map_op.extract::(py)?.map.keys() { - let instruction_pair = (self.gate_name_map[op].clone(), qarg.clone()); - instruction_list.push(instruction_pair); - } + for (op, props_map) in self.gate_map.map.iter() { + for qarg in props_map.extract::(py)?.map.keys() { + let instruction_pair = (self.gate_name_map[op].clone_ref(py), qarg.clone()); + instruction_list.push(instruction_pair); } } // Return results. diff --git a/qiskit/transpiler/target.py b/qiskit/transpiler/target.py index e841a33f7097..20354f4c56ed 100644 --- a/qiskit/transpiler/target.py +++ b/qiskit/transpiler/target.py @@ -38,8 +38,6 @@ # full target from qiskit.providers.backend import QubitProperties # pylint: disable=unused-import from qiskit.providers.models.backendproperties import BackendProperties -from qiskit.pulse.calibration_entries import CalibrationEntry, ScheduleDef -from qiskit.pulse.schedule import Schedule, ScheduleBlock # import target class from the rust side from qiskit._accelerate.target import ( # pylint: disable=unused-import @@ -60,7 +58,7 @@ class InstructionProperties(InstructionProperties2): custom attributes for those custom/additional properties by the backend. """ - def __new__( + def __new__( # pylint: disable=keyword-arg-before-vararg cls, duration=None, # pylint: disable=keyword-arg-before-vararg error=None, # pylint: disable=keyword-arg-before-vararg @@ -68,7 +66,7 @@ def __new__( *args, # pylint: disable=unused-argument **kwargs, # pylint: disable=unused-argument ): - return super().__new__(cls, duration, error, calibration) + return super().__new__(cls, duration=duration, error=error, calibration=calibration) def __init__( self, @@ -286,7 +284,7 @@ def _build_coupling_graph(self): self.coupling_graph.add_edge(*qarg, {gate: properties}) qargs = self.qargs if self.coupling_graph.num_edges() == 0 and ( - qargs == None or any(x is None for x in qargs) + qargs is None or any(x is None for x in qargs) ): self.coupling_graph = None # pylint: disable=attribute-defined-outside-init