pub struct Ket<R: RealScalar> { /* private fields */ }Expand description
Represents a quantum state vector as a Ket.
Implementations§
Source§impl<R: RealScalar> Ket<R>
impl<R: RealScalar> Ket<R>
Sourcepub fn new<T: Into<Radices>, V: Into<Self>>(radices: T, vector: V) -> Self
pub fn new<T: Into<Radices>, V: Into<Self>>(radices: T, vector: V) -> Self
Create a new Ket.
§Arguments
radices- The radices of the qudit system.vector- The vector to wrap.
§Panics
Panics if the vector is not a pure state.
§Example
use faer::Col;
use qudit_core::Ket;
use qudit_core::c64;
let zero_state: Ket<f64> = Ket::new([2, 2], vec![
c64::ONE, c64::ZERO, c64::ZERO, c64::ZERO
]);§See Also
Sourcepub fn is_pure_state(&self) -> bool
pub fn is_pure_state(&self) -> bool
Check if this is a valid normalized pure quantum state.
A pure state must have norm² ≈ 1.0 (normalized).
§Arguments
tolerance- Optional tolerance for normalization check (default: 1e-10)
§Example
use qudit_core::Ket;
let basis_state: Ket<f64> = Ket::basis([2, 2], 0);
assert!(basis_state.is_pure_state());Sourcepub fn get_distance_from(&self, other: &Self) -> R
pub fn get_distance_from(&self, other: &Self) -> R
Get the distance from another quantum state.
This computes 1 - |⟨ψ|φ⟩|² where |⟨ψ|φ⟩|² is the fidelity. Distance of 0 means identical states, distance of 1 means orthogonal states.
§Arguments
other- The other quantum state to compare with
§Panics
Panics if the states have different dimensions.
§Example
use qudit_core::Ket;
let state1: Ket<f64> = Ket::basis([2], 0);
let state2: Ket<f64> = Ket::basis([2], 1);
let distance = state1.get_distance_from(&state2);
assert!((distance - 1.0).abs() < 1e-10); // Orthogonal statesSourcepub fn probabilities(&self) -> Vec<R>
pub fn probabilities(&self) -> Vec<R>
Get the probabilities for all computational basis states.
Returns a vector where each element is |amplitude|² for the corresponding basis state.
§Example
use qudit_core::Ket;
let uniform_state: Ket<f64> = Ket::uniform([2, 2]);
let probs = uniform_state.probabilities();
// Each probability should be 0.25 for uniform superpositionSourcepub fn probability_at(&self, index: usize) -> R
pub fn probability_at(&self, index: usize) -> R
Get the probability of measuring the state in a specific computational basis state.
§Arguments
index- The computational basis index
§Panics
Panics if the index is out of bounds.
§Example
use qudit_core::Ket;
let basis_state: Ket<f64> = Ket::basis([2, 2], 1);
assert!((basis_state.probability_at(1) - 1.0).abs() < 1e-10);
assert!(basis_state.probability_at(0).abs() < 1e-10);Sourcepub fn tensor_product(&self, other: &Self) -> Self
pub fn tensor_product(&self, other: &Self) -> Self
Compute the tensor product with another quantum state.
Creates a new state |ψ⟩ ⊗ |φ⟩ representing a composite quantum system.
§Arguments
other- The other quantum state to tensor with
§Example
use qudit_core::Ket;
let qubit1: Ket<f64> = Ket::basis([2], 0); // |0⟩
let qubit2: Ket<f64> = Ket::basis([2], 1); // |1⟩
let combined = qubit1.tensor_product(&qubit2); // |01⟩