Skip to content

Commit

Permalink
Fix:: Adapt to target changes (Qiskit#12288)
Browse files Browse the repository at this point in the history
- Fix lint stray imports.
  • Loading branch information
raynelfss committed May 12, 2024
1 parent 9702ddc commit 2d46d87
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
36 changes: 15 additions & 21 deletions crates/accelerate/src/target_transpiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,23 +1367,20 @@ impl Target {
*/
#[pyo3(text_signature = "(/, index: int)")]
fn instruction_properties(&self, py: Python<'_>, index: usize) -> PyResult<PyObject> {
let mut instruction_properties: Vec<Option<Py<InstructionProperties>>> = 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::<PropsMap>(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::<PropsMap>(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
)))
}

/**
Expand Down Expand Up @@ -1518,13 +1515,10 @@ impl Target {
// Get list of instructions.
let mut instruction_list: Vec<(PyObject, Option<Qargs>)> = 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::<PropsMap>(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::<PropsMap>(py)?.map.keys() {
let instruction_pair = (self.gate_name_map[op].clone_ref(py), qarg.clone());
instruction_list.push(instruction_pair);
}
}
// Return results.
Expand Down
8 changes: 3 additions & 5 deletions qiskit/transpiler/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,15 +58,15 @@ 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
calibration=None, # pylint: disable=keyword-arg-before-vararg
*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,
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2d46d87

Please sign in to comment.