Skip to main content

quantrs2_core/circuit_synthesis/
hhltemplate_traits.rs

1//! # HHLTemplate - Trait Implementations
2//!
3//! This module contains trait implementations for `HHLTemplate`.
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, HHLTemplate, QAOATemplate, QuantumAlgorithmType, ResourceEstimates,
14    SynthesizedCircuit, TemplateInfo,
15};
16use crate::error::{QuantRS2Error, QuantRS2Result};
17use crate::QubitId;
18use std::collections::HashMap;
19use std::time::Duration;
20
21impl AlgorithmTemplate for HHLTemplate {
22    fn synthesize(&self, spec: &AlgorithmSpecification) -> QuantRS2Result<SynthesizedCircuit> {
23        QAOATemplate::new().create_circuit_from_gates(
24            vec![],
25            spec.parameters.num_qubits,
26            QuantumAlgorithmType::HHL,
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 * 10,
36            circuit_depth: n,
37            qubit_count: n,
38            gate_breakdown: HashMap::new(),
39            estimated_execution_time: Duration::from_micros((n * 500) as u64),
40            memory_requirements: 1 << n,
41            parallelization_factor: 0.5,
42        })
43    }
44    fn get_template_info(&self) -> TemplateInfo {
45        TemplateInfo {
46            name: "HHL".to_string(),
47            supported_parameters: vec!["num_qubits".to_string(), "linear_system".to_string()],
48            required_parameters: vec!["num_qubits".to_string()],
49            complexity_scaling: "O(log N)".to_string(),
50            hardware_compatibility: vec!["all".to_string()],
51        }
52    }
53    fn validate_specification(&self, spec: &AlgorithmSpecification) -> QuantRS2Result<()> {
54        if spec.parameters.num_qubits == 0 {
55            return Err(QuantRS2Error::InvalidParameter(
56                "num_qubits must be > 0".to_string(),
57            ));
58        }
59        Ok(())
60    }
61}