Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
27758fc
Make Optimize1qGatesDecomposition multithreaded
mtreinish Jan 13, 2026
b640d6a
Rework eager pre-initialization to be lazy again
mtreinish Jan 14, 2026
79c7076
Revert 100,000 crossover value and leave as TODO
mtreinish Jan 14, 2026
bc894d2
Fix initialization race condition with lazy state initalization
mtreinish Jan 14, 2026
417a094
Merge remote-tracking branch 'origin/main' into parallel-o1qgd
mtreinish Mar 10, 2026
2d52562
Merge remote-tracking branch 'origin/main' into parallel-o1qgd
mtreinish Mar 27, 2026
386024a
Fix rustfmt
mtreinish Mar 27, 2026
411463c
Merge remote-tracking branch 'origin/main' into parallel-o1qgd
mtreinish May 12, 2026
b5d1f3c
Update crate for getenv_use_multiple_threads
mtreinish May 12, 2026
d9a17d0
Fix rustfmt
mtreinish May 12, 2026
f193dfc
Document the pass is multithreaded now
mtreinish May 12, 2026
7e60481
Add a parallel threshold value
mtreinish May 12, 2026
8f03254
Remove parallel threshold
mtreinish May 13, 2026
d97a303
Merge remote-tracking branch 'origin/main' into parallel-o1qgd
mtreinish May 27, 2026
a79486f
Use try_for_each to propogate add_global_phase error
mtreinish May 27, 2026
fa636f8
Add release note
mtreinish Jun 3, 2026
97753e7
Update releasenotes/notes/optimize1qgatesdecomposition-is-parallel-in…
mtreinish Jun 3, 2026
b481553
Make typing of basis gates explicit
mtreinish Jun 3, 2026
73cc76b
Use target.is_some() for get_euler_basis global path check
mtreinish Jun 3, 2026
61496f9
Merge branch 'main' into parallel-o1qgd
mtreinish Jun 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions crates/accelerate/src/twirling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ use qiskit_circuit::packed_instruction::PackedInstruction;
use crate::QiskitError;

use qiskit_circuit::{BlocksMode, NoBlocks, VarsMode};
use qiskit_transpiler::passes::run_optimize_1q_gates_decomposition;
use qiskit_transpiler::passes::{
Optimize1qGatesDecompositionState, run_optimize_1q_gates_decomposition,
};
use qiskit_transpiler::target::Target;
use rand::prelude::*;
use rand::rngs::SysRng;
Expand Down Expand Up @@ -296,9 +298,12 @@ fn generate_twirled_circuit(
}
}
}
if optimizer_target.is_some() {
if let Some(optimizer_target) = optimizer_target {
let mut dag = DAGCircuit::from_circuit_data(&out_circ, false, None, None, None, None)?;
run_optimize_1q_gates_decomposition(&mut dag, optimizer_target, None, None)?;
let state = Optimize1qGatesDecompositionState::new(
optimizer_target.num_qubits.unwrap_or(0) as usize,
);
run_optimize_1q_gates_decomposition(&mut dag, &state, Some(optimizer_target), None, None)?;
Ok(CircuitData::from_dag_ref(&dag)?)
} else {
Ok(out_circ)
Expand Down
40 changes: 37 additions & 3 deletions crates/cext/src/transpiler/passes/optimize_1q_sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@

use crate::pointers::{const_ptr_as_ref, mut_ptr_as_ref};
use qiskit_circuit::{circuit_data::CircuitData, dag_circuit::DAGCircuit};
use qiskit_transpiler::{passes::run_optimize_1q_gates_decomposition, target::Target};
use qiskit_transpiler::{
passes::{Optimize1qGatesDecompositionState, run_optimize_1q_gates_decomposition},
target::Target,
};

/// @ingroup QkTranspilerPassesStandalone
/// Runs the Optimize1qGatesDecomposition pass in standalone mode on a circuit.
///
/// \qk_deprecated{2.4.0|use :c:func:`qk_transpiler_pass_standalone_optimize_1q_sequences` instead.}
///
/// This function is multithreaded and will potentially launch a thread pool
/// with threads equal to the number of CPUs by default. You can tune the
/// number of threads with the ``RAYON_NUM_THREADS`` environment variable.
/// For example, setting ``RAYON_NUM_THREADS=4`` would limit the thread pool
/// to 4 threads.
///
/// @param circuit A pointer to the ``QkCircuit`` object to transform.
/// @param target A pointer to the ``QkTarget`` object or a null pointer.
/// In the case a null pointer is provided and gate errors are unknown
Expand Down Expand Up @@ -48,6 +57,13 @@ pub unsafe extern "C" fn qk_transpiler_standalone_optimize_1q_sequences(
///
/// Refer to the ``qk_transpiler_pass_optimize_1q_sequences`` function for more details about the pass.
///
/// This function is multithreaded and will potentially launch a thread pool
/// with threads equal to the number of CPUs by default. You can tune the
/// number of threads with the ``RAYON_NUM_THREADS`` environment variable.
/// For example, setting ``RAYON_NUM_THREADS=4`` would limit the thread pool
/// to 4 threads.
///
///
/// @param circuit A pointer to the ``QkCircuit`` object to transform.
/// @param target A pointer to the ``QkTarget`` object or a null pointer.
/// In the case a null pointer is provided and gate errors are unknown
Expand Down Expand Up @@ -78,8 +94,11 @@ pub unsafe extern "C" fn qk_transpiler_pass_standalone_optimize_1q_sequences(
let mut circuit_as_dag = DAGCircuit::from_circuit_data(circuit, false, None, None, None, None)
.expect("Error while converting the circuit to a dag.");

let state = Optimize1qGatesDecompositionState::new(
target.map(|x| x.num_qubits.unwrap_or(0)).unwrap_or(0) as usize,
);
// Run the pass
run_optimize_1q_gates_decomposition(&mut circuit_as_dag, target, None, None)
run_optimize_1q_gates_decomposition(&mut circuit_as_dag, &state, target, None, None)
.expect("Error while running the pass.");

// Convert the DAGCircuit back to an instance of CircuitData
Expand All @@ -101,6 +120,12 @@ pub unsafe extern "C" fn qk_transpiler_pass_standalone_optimize_1q_sequences(
/// The error is the combined multiplication of the errors of individual gates on the
/// qubit it operates on.
///
/// This function is multithreaded and will potentially launch a thread pool
/// with threads equal to the number of CPUs by default. You can tune the
/// number of threads with the ``RAYON_NUM_THREADS`` environment variable.
/// For example, setting ``RAYON_NUM_THREADS=4`` would limit the thread pool
/// to 4 threads.
///
/// @param dag A pointer to the ``QkDag`` object to transform.
/// @param target A pointer to the ``QkTarget`` object or a null pointer.
/// In the case a null pointer is provided and gate errors are unknown
Expand Down Expand Up @@ -156,7 +181,16 @@ pub unsafe extern "C" fn qk_transpiler_pass_optimize_1q_sequences(
// SAFETY: Per documentation, the pointer is non-null and aligned.
let dag = unsafe { mut_ptr_as_ref(dag) };

let state = Optimize1qGatesDecompositionState::new(
target
.map(|x| {
x.num_qubits
.map(|num_qubits| num_qubits as usize)
.unwrap_or(0)
})
.unwrap_or(0),
);
// Run the pass
run_optimize_1q_gates_decomposition(dag, target, None, None)
run_optimize_1q_gates_decomposition(dag, &state, target, None, None)
.expect("Error while running the pass.");
}
3 changes: 2 additions & 1 deletion crates/transpiler/src/passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ pub use instruction_duration_check::{
pub use inverse_cancellation::{inverse_cancellation_mod, run_inverse_cancellation_standard_gates};
pub use litinski_transformation::{litinski_transformation_mod, run_litinski_transformation};
pub use optimize_1q_gates_decomposition::{
optimize_1q_gates_decomposition_mod, run_optimize_1q_gates_decomposition,
Optimize1qGatesDecompositionState, optimize_1q_gates_decomposition_mod,
run_optimize_1q_gates_decomposition,
};
pub use optimize_clifford_t::{optimize_clifford_t_mod, run_optimize_clifford_t};
pub use remove_diagonal_gates_before_measure::{
Expand Down
Loading
Loading