pub struct TQDevice {
pub n_wires: usize,
pub device_name: String,
pub bsz: usize,
pub states: ArrayD<CType>,
pub record_op: bool,
pub op_history: Vec<OpHistoryEntry>,
}Expand description
Quantum device containing the quantum state vector
This struct mirrors TorchQuantum’s QuantumDevice class, providing:
- Multi-dimensional state tensor representation
- Batch support for parallel execution
- State reset and cloning operations
Fields§
§n_wires: usizeNumber of qubits
device_name: StringDevice name
bsz: usizeBatch size
states: ArrayD<CType>Quantum state vector (batched, multi-dimensional)
record_op: boolWhether to record operations
op_history: Vec<OpHistoryEntry>Operation history
Implementations§
Source§impl TQDevice
impl TQDevice
Sourcepub fn with_batch_size(n_wires: usize, bsz: usize) -> Self
pub fn with_batch_size(n_wires: usize, bsz: usize) -> Self
Create quantum device with batch size
Sourcepub fn reset_states(&mut self, bsz: usize)
pub fn reset_states(&mut self, bsz: usize)
Reset to |0…0> state
Sourcepub fn reset_identity_states(&mut self)
pub fn reset_identity_states(&mut self)
Reset to identity matrix (useful for computing unitaries)
Sourcepub fn reset_all_eq_states(&mut self, bsz: usize)
pub fn reset_all_eq_states(&mut self, bsz: usize)
Reset to equal superposition state
Sourcepub fn clone_states(&mut self, other: &TQDevice)
pub fn clone_states(&mut self, other: &TQDevice)
Clone states from another device
Sourcepub fn set_states(&mut self, states: ArrayD<CType>)
pub fn set_states(&mut self, states: ArrayD<CType>)
Set states directly
Sourcepub fn get_states_1d(&self) -> Array2<CType>
pub fn get_states_1d(&self) -> Array2<CType>
Get states as 1D vectors (shape: [bsz, 2^n_wires])
Sourcepub fn get_probs_1d(&self) -> Array2<f64>
pub fn get_probs_1d(&self) -> Array2<f64>
Get probabilities (|amplitude|^2) as 1D vectors
Sourcepub fn record_operation(&mut self, entry: OpHistoryEntry)
pub fn record_operation(&mut self, entry: OpHistoryEntry)
Record an operation in history
Sourcepub fn reset_op_history(&mut self)
pub fn reset_op_history(&mut self)
Clear operation history
Sourcepub fn apply_single_qubit_gate(
&mut self,
wire: usize,
matrix: &Array2<CType>,
) -> Result<()>
pub fn apply_single_qubit_gate( &mut self, wire: usize, matrix: &Array2<CType>, ) -> Result<()>
Apply a single-qubit gate matrix to specified wire
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TQDevice
impl RefUnwindSafe for TQDevice
impl Send for TQDevice
impl Sync for TQDevice
impl Unpin for TQDevice
impl UnwindSafe for TQDevice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.