pub struct SparseStateVector {
pub n_qubits: usize,
/* private fields */
}Expand description
A sparse pure state: only nonzero basis amplitudes are stored.
Fields§
§n_qubits: usizeNumber of qubits.
Implementations§
Source§impl SparseStateVector
impl SparseStateVector
Sourcepub fn new_zero_state(n_qubits: usize) -> QuantumResult<Self>
pub fn new_zero_state(n_qubits: usize) -> QuantumResult<Self>
Construct the sparse |0…0⟩ state (a single populated key).
§Errors
Returns QuantumError::InvalidQubitCount for n_qubits == 0 or
n_qubits > 30.
Sourcepub fn from_dense(sv: &StateVector) -> Self
pub fn from_dense(sv: &StateVector) -> Self
Build a sparse representation from a dense state vector (drops zeros).
Sourcepub fn to_dense(&self) -> QuantumResult<StateVector>
pub fn to_dense(&self) -> QuantumResult<StateVector>
Expand back to a dense StateVector.
§Errors
Propagates the dense constructor’s qubit-count validation.
Sourcepub fn apply_1q(
&mut self,
qubit: usize,
gate: &[[Complex<f32>; 2]; 2],
) -> QuantumResult<()>
pub fn apply_1q( &mut self, qubit: usize, gate: &[[Complex<f32>; 2]; 2], ) -> QuantumResult<()>
Apply a single-qubit gate to qubit.
Iterates the current support, pairs each key with its qubit-flipped
partner, and writes the mixed amplitudes into a fresh map (so concurrent
reads of the old amplitudes are consistent).
§Errors
Returns QuantumError::QubitIndexOutOfRange if qubit >= n_qubits.
Sourcepub fn apply_cnot(&mut self, ctrl: usize, tgt: usize) -> QuantumResult<()>
pub fn apply_cnot(&mut self, ctrl: usize, tgt: usize) -> QuantumResult<()>
Apply a CNOT with the given control and target.
A CNOT only permutes basis indices (flips tgt when ctrl=1), so this is
a pure key remap that exactly preserves occupancy.
§Errors
Returns QuantumError::QubitIndexOutOfRange for an out-of-range index or
QuantumError::InvalidParameter if ctrl == tgt.
Trait Implementations§
Source§impl Clone for SparseStateVector
impl Clone for SparseStateVector
Source§fn clone(&self) -> SparseStateVector
fn clone(&self) -> SparseStateVector
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more