pub trait TQModule: Send + Sync {
Show 13 methods
// Required methods
fn forward(&mut self, qdev: &mut TQDevice) -> Result<()>;
fn parameters(&self) -> Vec<TQParameter>;
fn n_wires(&self) -> Option<usize>;
fn set_n_wires(&mut self, n_wires: usize);
fn is_static_mode(&self) -> bool;
fn static_on(&mut self);
fn static_off(&mut self);
fn name(&self) -> &str;
// Provided methods
fn forward_with_input(
&mut self,
qdev: &mut TQDevice,
_x: Option<&Array2<f64>>,
) -> Result<()> { ... }
fn get_unitary(&self) -> Option<Array2<CType>> { ... }
fn zero_grad(&mut self) { ... }
fn train(&mut self, _mode: bool) { ... }
fn training(&self) -> bool { ... }
}Expand description
Base trait for all TorchQuantum-compatible quantum modules
This trait mirrors TorchQuantum’s QuantumModule class, providing:
- Forward pass execution
- Parameter management
- Static/dynamic mode switching
- Noise model support
Required Methods§
Sourcefn forward(&mut self, qdev: &mut TQDevice) -> Result<()>
fn forward(&mut self, qdev: &mut TQDevice) -> Result<()>
Execute the forward pass on the quantum device
Sourcefn parameters(&self) -> Vec<TQParameter>
fn parameters(&self) -> Vec<TQParameter>
Get all trainable parameters
Sourcefn set_n_wires(&mut self, n_wires: usize)
fn set_n_wires(&mut self, n_wires: usize)
Set number of wires
Sourcefn is_static_mode(&self) -> bool
fn is_static_mode(&self) -> bool
Check if module is in static mode
Sourcefn static_off(&mut self)
fn static_off(&mut self)
Disable static mode
Provided Methods§
Sourcefn forward_with_input(
&mut self,
qdev: &mut TQDevice,
_x: Option<&Array2<f64>>,
) -> Result<()>
fn forward_with_input( &mut self, qdev: &mut TQDevice, _x: Option<&Array2<f64>>, ) -> Result<()>
Execute forward pass with optional input data (for encoders)
Sourcefn get_unitary(&self) -> Option<Array2<CType>>
fn get_unitary(&self) -> Option<Array2<CType>>
Get the unitary matrix representation (if available)