diff --git a/crates/accelerate/src/target_transpiler/mod.rs b/crates/accelerate/src/target_transpiler/mod.rs index e4afaa7357b0..906eea6d5db0 100644 --- a/crates/accelerate/src/target_transpiler/mod.rs +++ b/crates/accelerate/src/target_transpiler/mod.rs @@ -32,6 +32,7 @@ use pyo3::{ }; use qiskit_circuit::circuit_instruction::convert_py_to_operation_type; + use qiskit_circuit::operations::{Operation, OperationType, Param}; use smallvec::SmallVec; @@ -54,6 +55,8 @@ type GateMap = IndexMap; type PropsMap = NullableIndexMap>; type GateMapState = Vec<(String, Vec<(Option, Option)>)>; +/// Represents a Qiskit `Gate` object or a Variadic instruction. +/// Keeps a reference to its Python instance for caching purposes. #[derive(Debug, Clone, FromPyObject)] pub(crate) enum TargetOperation { Normal(NormalOperation), @@ -96,6 +99,8 @@ impl TargetOperation { } } +/// Represents a Qiskit `Gate` object, keeps a reference to its Python +/// instance for caching purposes. #[derive(Debug, Clone)] pub(crate) struct NormalOperation { pub operation: OperationType, @@ -133,6 +138,10 @@ constraints of a particular backend. The intent of this struct is to contain data that can be representable and accessible through both Rust and Python, so it can be used for rust-based transpiler processes. + +This structure contains duplicates of every element in the Python counterpart of +`gate_map`. Which improves access for Python while sacrificing a small amount of +memory. */ #[pyclass( mapping, @@ -1251,3 +1260,5 @@ pub fn target(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; Ok(()) } + +// TODO: Add rust-based unit testing. diff --git a/qiskit/transpiler/target.py b/qiskit/transpiler/target.py index 79de78bd246e..001e8020962b 100644 --- a/qiskit/transpiler/target.py +++ b/qiskit/transpiler/target.py @@ -746,9 +746,7 @@ def _build_coupling_graph(self): for qarg, properties in qarg_map.items(): if qarg is None: if self.operation_from_name(gate).num_qubits == 2: - self._coupling_graph = ( - None # pylint: disable=attribute-defined-outside-init - ) + self._coupling_graph = None return continue if len(qarg) == 1: @@ -893,12 +891,10 @@ def __str__(self): prop_str_pieces = [f"\t\t{qarg}:\n"] duration = getattr(props, "duration", None) if duration is not None: - prop_str_pieces.append( - f"\t\t\tDuration: {duration if duration > 0 else 0} sec.\n" - ) + prop_str_pieces.append(f"\t\t\tDuration: {duration:g} sec.\n") error = getattr(props, "error", None) if error is not None: - prop_str_pieces.append(f"\t\t\tError Rate: {error if error > 0 else 0}\n") + prop_str_pieces.append(f"\t\t\tError Rate: {error:g}\n") schedule = getattr(props, "_calibration", None) if schedule is not None: prop_str_pieces.append("\t\t\tWith pulse schedule calibration\n")