Skip to main content

quantrs2_core/circuit_synthesis/
shortemplate_traits.rs

1//! # ShorTemplate - Trait Implementations
2//!
3//! This module contains trait implementations for `ShorTemplate`.
4//!
5//! ## Implemented Traits
6//!
7//! - `AlgorithmTemplate`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use super::functions::AlgorithmTemplate;
12use super::types::{
13    AlgorithmSpecification, QAOATemplate, QuantumAlgorithmType, ResourceEstimates, ShorTemplate,
14    SynthesizedCircuit, TemplateInfo,
15};
16use crate::error::{QuantRS2Error, QuantRS2Result};
17use crate::QubitId;
18use std::collections::HashMap;
19use std::time::Duration;
20
21impl AlgorithmTemplate for ShorTemplate {
22    fn synthesize(&self, spec: &AlgorithmSpecification) -> QuantRS2Result<SynthesizedCircuit> {
23        QAOATemplate::new().create_circuit_from_gates(
24            vec![],
25            spec.parameters.num_qubits,
26            QuantumAlgorithmType::Shor,
27        )
28    }
29    fn estimate_resources(
30        &self,
31        spec: &AlgorithmSpecification,
32    ) -> QuantRS2Result<ResourceEstimates> {
33        let n = spec.parameters.num_qubits;
34        Ok(ResourceEstimates {
35            gate_count: n.pow(3),
36            circuit_depth: n.pow(2),
37            qubit_count: n,
38            gate_breakdown: HashMap::new(),
39            estimated_execution_time: Duration::from_millis((n.pow(3) / 1000) as u64),
40            memory_requirements: 1 << n,
41            parallelization_factor: 0.6,
42        })
43    }
44    fn get_template_info(&self) -> TemplateInfo {
45        TemplateInfo {
46            name: "Shor".to_string(),
47            supported_parameters: vec![
48                "num_qubits".to_string(),
49                "factorization_target".to_string(),
50            ],
51            required_parameters: vec!["num_qubits".to_string()],
52            complexity_scaling: "O((log N)^3)".to_string(),
53            hardware_compatibility: vec!["all".to_string()],
54        }
55    }
56    fn validate_specification(&self, spec: &AlgorithmSpecification) -> QuantRS2Result<()> {
57        if spec.parameters.num_qubits == 0 {
58            return Err(QuantRS2Error::InvalidParameter(
59                "num_qubits must be > 0".to_string(),
60            ));
61        }
62        Ok(())
63    }
64}