Skip to content

Commit

Permalink
Fix: Comments from Matthew's review
Browse files Browse the repository at this point in the history
- Mention duplication in docstring for rust Target.
- Use f"{*:g}" to avoid printing the floating point for 0 in `Target`'s repr method.
- Add note mentioning future unit-tests in rust.
  • Loading branch information
raynelfss committed Jul 23, 2024
1 parent d5392ea commit 367d711
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 11 additions & 0 deletions crates/accelerate/src/target_transpiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -54,6 +55,8 @@ type GateMap = IndexMap<String, PropsMap, RandomState>;
type PropsMap = NullableIndexMap<Qargs, Option<InstructionProperties>>;
type GateMapState = Vec<(String, Vec<(Option<Qargs>, Option<InstructionProperties>)>)>;

/// 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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1251,3 +1260,5 @@ pub fn target(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<Target>()?;
Ok(())
}

// TODO: Add rust-based unit testing.
10 changes: 3 additions & 7 deletions qiskit/transpiler/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 367d711

Please sign in to comment.