Skip to main content

quantrs2_ml/torchquantum/layer/
tqrandomlayer_traits.rs

1//! # TQRandomLayer - Trait Implementations
2//!
3//! This module contains trait implementations for `TQRandomLayer`.
4//!
5//! ## Implemented Traits
6//!
7//! - `TQModule`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use crate::error::{MLError, Result};
12use crate::torchquantum::{TQDevice, TQModule, TQOperator, TQParameter};
13
14use super::functions::{create_single_qubit_gate, create_two_qubit_gate};
15use super::types::TQRandomLayer;
16
17impl TQModule for TQRandomLayer {
18    fn forward(&mut self, qdev: &mut TQDevice) -> Result<()> {
19        for (op_name, wires) in &self.gate_sequence {
20            if wires.len() == 1 {
21                let mut gate = create_single_qubit_gate(op_name, true, false);
22                gate.apply(qdev, wires)?;
23            } else {
24                let mut gate = create_two_qubit_gate(op_name, false, false);
25                gate.apply(qdev, wires)?;
26            }
27        }
28        Ok(())
29    }
30    fn parameters(&self) -> Vec<TQParameter> {
31        Vec::new()
32    }
33    fn n_wires(&self) -> Option<usize> {
34        Some(self.n_wires)
35    }
36    fn set_n_wires(&mut self, n_wires: usize) {
37        self.n_wires = n_wires;
38        self.regenerate();
39    }
40    fn is_static_mode(&self) -> bool {
41        self.static_mode
42    }
43    fn static_on(&mut self) {
44        self.static_mode = true;
45    }
46    fn static_off(&mut self) {
47        self.static_mode = false;
48    }
49    fn name(&self) -> &str {
50        "RandomLayer"
51    }
52}