Skip to content

Commit

Permalink
Perform BarrierBeforeFinalMeasurements analysis in paralle
Browse files Browse the repository at this point in the history
With #13410 removing the non-threadsafe structure from our circuit
representation we're now able to read and iterate over a DAGCircuit from
multiple threads. This commit is the first small piece doing this, it
moves the analysis portion of the BarrierBeforeFinalMeasurements pass to
execure in parallel. The pass checks every node to ensure all it's
decendents are either a measure or a barrier before reaching the end of
the circuit. This commit iterates over all the nodes and does the check
in parallel.
  • Loading branch information
mtreinish committed Nov 8, 2024
1 parent 33ef7eb commit 6481eab
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/accelerate/src/barrier_before_final_measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use hashbrown::HashSet;
use pyo3::prelude::*;
use rayon::prelude::*;
use rustworkx_core::petgraph::stable_graph::NodeIndex;

use qiskit_circuit::circuit_instruction::ExtraInstructionAttributes;
Expand All @@ -30,8 +31,8 @@ pub fn barrier_before_final_measurements(
dag: &mut DAGCircuit,
label: Option<String>,
) -> PyResult<()> {
let final_ops: HashSet<NodeIndex> = dag
.op_nodes(true)
let node_indices: Vec<NodeIndex> = dag.op_nodes(true).collect();
let final_ops: HashSet<NodeIndex> = node_indices.into_par_iter()
.filter(|node| {
let NodeType::Operation(ref inst) = dag.dag()[*node] else {
unreachable!();
Expand Down

0 comments on commit 6481eab

Please sign in to comment.