Skip to content

Commit

Permalink
Avoid unnecessary matrix construction in Split2qUnitaries (#13378)
Browse files Browse the repository at this point in the history
During the transition of this pass to Rust, the matrix creation was
accidentally moved before the check of whether the pass would operate on
the node.  This wastes time and allocations on creating matrices that
will not be further examined.
  • Loading branch information
jakelishman authored Oct 29, 2024
1 parent e89cb47 commit e7fc5a7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crates/accelerate/src/split_2q_unitaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ pub fn split_2q_unitaries(
for node in nodes {
if let NodeType::Operation(inst) = &dag.dag()[node] {
let qubits = dag.get_qargs(inst.qubits).to_vec();
let matrix = inst.op.matrix(inst.params_view());
// We only attempt to split UnitaryGate objects, but this could be extended in future
// -- however we need to ensure that we can compile the resulting single-qubit unitaries
// to the supported basis gate set.
if qubits.len() != 2 || inst.op.name() != "unitary" {
continue;
}
let matrix = inst
.op
.matrix(inst.params_view())
.expect("'unitary' gates should always have a matrix form");
let decomp = TwoQubitWeylDecomposition::new_inner(
matrix.unwrap().view(),
matrix.view(),
Some(requested_fidelity),
None,
)?;
Expand Down

0 comments on commit e7fc5a7

Please sign in to comment.