Skip to main content

quantrs2_ml/torchquantum/layer/
tqstrongentanglinglayer_traits.rs

1//! # TQStrongEntanglingLayer - Trait Implementations
2//!
3//! This module contains trait implementations for `TQStrongEntanglingLayer`.
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::TQStrongEntanglingLayer;
16
17impl TQModule for TQStrongEntanglingLayer {
18    fn forward(&mut self, qdev: &mut TQDevice) -> Result<()> {
19        for layer in &mut self.layers {
20            layer.forward(qdev)?;
21        }
22        Ok(())
23    }
24    fn parameters(&self) -> Vec<TQParameter> {
25        self.layers.iter().flat_map(|l| l.parameters()).collect()
26    }
27    fn n_wires(&self) -> Option<usize> {
28        Some(self.config.n_wires)
29    }
30    fn set_n_wires(&mut self, n_wires: usize) {
31        self.config.n_wires = n_wires;
32    }
33    fn is_static_mode(&self) -> bool {
34        self.static_mode
35    }
36    fn static_on(&mut self) {
37        self.static_mode = true;
38        for layer in &mut self.layers {
39            layer.static_on();
40        }
41    }
42    fn static_off(&mut self) {
43        self.static_mode = false;
44        for layer in &mut self.layers {
45            layer.static_off();
46        }
47    }
48    fn name(&self) -> &str {
49        "StrongEntanglingLayer"
50    }
51    fn zero_grad(&mut self) {
52        for layer in &mut self.layers {
53            layer.zero_grad();
54        }
55    }
56}