quantrs2_ml/torchquantum/layer/
tqcxlayer_traits.rs1use crate::error::{MLError, Result};
12use crate::torchquantum::{
13 gates::{
14 TQHadamard, TQPauliX, TQPauliY, TQPauliZ, TQRx, TQRy, TQRz, TQCNOT, TQCRX, TQCRY, TQCRZ,
15 TQCZ, TQRXX, TQRYY, TQRZX, TQRZZ, TQS, TQSWAP, TQSX, TQT,
16 },
17 CType, TQDevice, TQModule, TQOperator, TQParameter,
18};
19
20use super::functions::{create_single_qubit_gate, create_two_qubit_gate};
21use super::types::TQCXLayer;
22
23impl TQModule for TQCXLayer {
24 fn forward(&mut self, qdev: &mut TQDevice) -> Result<()> {
25 let n_pairs = if self.circular {
26 self.n_wires
27 } else {
28 self.n_wires.saturating_sub(1)
29 };
30 for i in 0..n_pairs {
31 let wire0 = i;
32 let wire1 = (i + 1) % self.n_wires;
33 let mut gate = TQCNOT::new();
34 gate.apply(qdev, &[wire0, wire1])?;
35 }
36 Ok(())
37 }
38 fn parameters(&self) -> Vec<TQParameter> {
39 Vec::new()
40 }
41 fn n_wires(&self) -> Option<usize> {
42 Some(self.n_wires)
43 }
44 fn set_n_wires(&mut self, n_wires: usize) {
45 self.n_wires = n_wires;
46 }
47 fn is_static_mode(&self) -> bool {
48 self.static_mode
49 }
50 fn static_on(&mut self) {
51 self.static_mode = true;
52 }
53 fn static_off(&mut self) {
54 self.static_mode = false;
55 }
56 fn name(&self) -> &str {
57 "CXLayer"
58 }
59}