pub struct TwoQubitOptimization { /* private fields */ }
Expand description
Two-qubit gate optimization
Implementations§
Source§impl TwoQubitOptimization
impl TwoQubitOptimization
Sourcepub fn new(use_kak_decomposition: bool, optimize_cnots: bool) -> Self
pub fn new(use_kak_decomposition: bool, optimize_cnots: bool) -> Self
Examples found in repository?
examples/optimization_demo.rs (line 231)
219fn benchmark_optimization_passes(circuit: &Circuit<4>) {
220 println!("\nDemo 5: Pass Benchmarking");
221 println!("-------------------------");
222
223 // Benchmark individual passes
224 let passes: Vec<(&str, Box<dyn OptimizationPass>)> = vec![
225 ("Gate Cancellation", Box::new(GateCancellation::new(false))),
226 ("Rotation Merging", Box::new(RotationMerging::new(1e-10))),
227 ("Gate Commutation", Box::new(GateCommutation::new(5))),
228 ("Template Matching", Box::new(TemplateMatching::new())),
229 (
230 "Two-Qubit Opt",
231 Box::new(TwoQubitOptimization::new(false, true)),
232 ),
233 ];
234
235 let cost_model = AbstractCostModel::default();
236
237 for (name, pass) in passes {
238 let start = Instant::now();
239
240 match pass.apply(circuit, &cost_model) {
241 Ok(_) => {
242 let duration = start.elapsed();
243 println!(" {}: {:?}", name, duration);
244 }
245 Err(e) => {
246 println!(" {} failed: {:?}", name, e);
247 }
248 }
249 }
250
251 // Benchmark full optimization
252 println!("\nFull Optimization Benchmark:");
253 let start = Instant::now();
254 let mut optimizer = CircuitOptimizer2::<4>::with_level(OptimizationLevel::Heavy);
255
256 match optimizer.optimize(circuit) {
257 Ok(report) => {
258 let duration = start.elapsed();
259 println!(" Total time: {:?}", duration);
260 println!(
261 " Gates reduced: {} → {}",
262 report.initial_metrics.gate_count, report.final_metrics.gate_count
263 );
264
265 // Show detailed report
266 println!("\nDetailed Report:");
267 println!("{}", report.detailed_report());
268 }
269 Err(e) => {
270 println!(" Benchmark failed: {:?}", e);
271 }
272 }
273}
Trait Implementations§
Source§impl OptimizationPass for TwoQubitOptimization
impl OptimizationPass for TwoQubitOptimization
Source§fn apply_to_gates(
&self,
gates: Vec<Box<dyn GateOp>>,
_cost_model: &dyn CostModel,
) -> QuantRS2Result<Vec<Box<dyn GateOp>>>
fn apply_to_gates( &self, gates: Vec<Box<dyn GateOp>>, _cost_model: &dyn CostModel, ) -> QuantRS2Result<Vec<Box<dyn GateOp>>>
Apply the optimization pass to a gate list
Source§fn should_apply(&self) -> bool
fn should_apply(&self) -> bool
Check if this pass should be applied
Auto Trait Implementations§
impl Freeze for TwoQubitOptimization
impl RefUnwindSafe for TwoQubitOptimization
impl Send for TwoQubitOptimization
impl Sync for TwoQubitOptimization
impl Unpin for TwoQubitOptimization
impl UnwindSafe for TwoQubitOptimization
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T, const N: usize> OptimizationPassExt<N> for Twhere
T: OptimizationPass + ?Sized,
impl<T, const N: usize> OptimizationPassExt<N> for Twhere
T: OptimizationPass + ?Sized,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.