quantrs2_sim/automatic_parallelization/
autoparallelengine_select_hardware_strategy_group.rs1use quantrs2_circuit::builder::{Circuit, Simulator};
8use quantrs2_core::{
9 error::{QuantRS2Error, QuantRS2Result},
10 gate::GateOp,
11 qubit::QubitId,
12};
13use std::sync::{Arc, Barrier, Mutex, RwLock};
14
15use super::types::{DependencyGraph, HardwareCharacteristics, HardwareStrategy};
16
17use super::autoparallelengine_type::AutoParallelEngine;
18
19impl AutoParallelEngine {
20 pub(super) fn select_hardware_strategy<const N: usize>(
22 &self,
23 hw_char: &HardwareCharacteristics,
24 circuit: &Circuit<N>,
25 graph: &DependencyGraph,
26 ) -> QuantRS2Result<HardwareStrategy> {
27 let gates = circuit.gates();
28 let num_gates = gates.len();
29 if hw_char.has_gpu && num_gates > 1000 {
30 return Ok(HardwareStrategy::GPUOffload);
31 }
32 if hw_char.num_numa_nodes > 1 && N > 20 {
33 return Ok(HardwareStrategy::NUMAAware);
34 }
35 let has_many_rotation_gates = self.count_rotation_gates(gates) > num_gates / 2;
36 if has_many_rotation_gates && hw_char.simd_width >= 256 {
37 return Ok(HardwareStrategy::SIMDOptimized);
38 }
39 if num_gates < 500 && N < 15 {
40 return Ok(HardwareStrategy::CacheOptimized);
41 }
42 Ok(HardwareStrategy::Hybrid)
43 }
44 pub(super) fn count_rotation_gates(&self, gates: &[Arc<dyn GateOp + Send + Sync>]) -> usize {
46 gates
47 .iter()
48 .filter(|g| Self::is_rotation_gate(g.as_ref()))
49 .count()
50 }
51}