pub struct QuantumState {
pub amplitudes: Vec<Complex64>,
pub n_qubits: usize,
}Expand description
Represents a quantum state as a complex vector in Hilbert space
Fields§
§amplitudes: Vec<Complex64>State vector |ψ⟩ with 2^n complex amplitudes
n_qubits: usizeNumber of qubits
Implementations§
Source§impl QuantumState
impl QuantumState
Sourcepub fn superposition(n_qubits: usize) -> Self
pub fn superposition(n_qubits: usize) -> Self
Create equal superposition state |+⟩^⊗n
Sourcepub fn apply_single_qubit_gate(
&mut self,
gate: [[Complex64; 2]; 2],
qubit: usize,
)
pub fn apply_single_qubit_gate( &mut self, gate: [[Complex64; 2]; 2], qubit: usize, )
Apply single-qubit gate to a specific qubit
Sourcepub fn cnot(&mut self, control: usize, target: usize)
pub fn cnot(&mut self, control: usize, target: usize)
Apply CNOT gate between control and target qubits
Sourcepub fn measure(&mut self, qubit: usize, rng: &mut impl Rng) -> bool
pub fn measure(&mut self, qubit: usize, rng: &mut impl Rng) -> bool
Measure a qubit and collapse the state
Sourcepub fn measure_all(&mut self, rng: &mut impl Rng) -> u32
pub fn measure_all(&mut self, rng: &mut impl Rng) -> u32
Measure all qubits and return the classical state
Sourcepub fn entanglement_entropy(&self, partition_size: usize) -> f64
pub fn entanglement_entropy(&self, partition_size: usize) -> f64
Calculate von Neumann entropy for entanglement
Sourcepub fn bell_state(bell_type: u8) -> Self
pub fn bell_state(bell_type: u8) -> Self
Create Bell state |Φ+⟩ = (|00⟩ + |11⟩)/√2
Auto Trait Implementations§
impl Freeze for QuantumState
impl RefUnwindSafe for QuantumState
impl Send for QuantumState
impl Sync for QuantumState
impl Unpin for QuantumState
impl UnsafeUnpin for QuantumState
impl UnwindSafe for QuantumState
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> 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.