Ket

Struct Ket 

Source
pub struct Ket<R: RealScalar> { /* private fields */ }
Expand description

Represents a quantum state vector as a Ket.

Implementations§

Source§

impl<R: RealScalar> Ket<R>

Source

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
Source

pub fn zero<T: Into<Radices>>(radices: T) -> Self

Create a zero state (all amplitudes zero).

§Arguments
  • radices - The radices of the qudit system.
§Example
use qudit_core::Ket;
let zero_state: Ket<f64> = Ket::zero([2, 2]);
Source

pub fn basis<T: Into<Radices>>(radices: T, index: usize) -> Self

Create a computational basis state |i⟩.

§Arguments
  • radices - The radices of the qudit system.
  • index - The computational basis index.
§Panics

Panics if the index is out of bounds for the given radices.

§Example
use qudit_core::Ket;
let state: Ket<f64> = Ket::basis([2, 2], 3); // |11⟩ state
Source

pub fn uniform<T: Into<Radices>>(radices: T) -> Self

Create a uniform superposition state (all amplitudes equal).

§Arguments
  • radices - The radices of the qudit system.
§Example
use qudit_core::Ket;
let uniform_state: Ket<f64> = Ket::uniform([2, 2]);
Source

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());
Source

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 states
Source

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 superposition
Source

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);
Source

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⟩

Trait Implementations§

Source§

impl<R: RealScalar, T: Into<R::C> + Copy> From<&[T]> for Ket<R>

Source§

fn from(value: &[T]) -> Self

Converts to this type from the input type.
Source§

impl<R: RealScalar, T: Into<R::C> + Copy, const N: usize> From<&[T; N]> for Ket<R>

Source§

fn from(value: &[T; N]) -> Self

Converts to this type from the input type.
Source§

impl<R: RealScalar, T: Into<R::C> + Copy, const N: usize> From<[T; N]> for Ket<R>

Source§

fn from(value: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl<C: ComplexScalar> From<Col<Own<C>>> for Ket<C::R>

Source§

fn from(value: Col<C>) -> Self

Converts to this type from the input type.
Source§

impl<R: RealScalar, T: Into<R::C> + Copy> From<Row<Own<T>>> for Ket<R>

Source§

fn from(value: Row<T>) -> Self

Converts to this type from the input type.
Source§

impl<R: RealScalar, T: Into<R::C> + Copy> From<Vec<T>> for Ket<R>

Source§

fn from(value: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<R: RealScalar, T: Into<R::C>> FromIterator<T> for Ket<R>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<R: RealScalar> Index<usize> for Ket<R>

Source§

type Output = <R as RealScalar>::C

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<R: RealScalar> QuditSystem for Ket<R>

Source§

fn radices(&self) -> Radices

Returns the radices of the qudits in the system. Read more
Source§

fn dimension(&self) -> usize

Returns the total dimension of the quantum system. Read more
Source§

fn num_qudits(&self) -> usize

Returns the number of qudits in the system. Read more
Source§

fn is_qubit_only(&self) -> bool

Checks if the system consists only of qubits (2-level systems). Read more
Source§

fn is_qutrit_only(&self) -> bool

Checks if the system consists only of qutrits (3-level systems). Read more
Source§

fn is_qudit_only<T: Into<Radix>>(&self, radix: T) -> bool

Checks if the system consists only of qudits with a specified radix. Read more
Source§

fn is_homogenous(&self) -> bool

Checks if the system is homogenous, i.e., all qudits have the same radix. Read more
Source§

impl<R: RealScalar, T: Into<R::C> + Copy> TryFrom<Mat<Own<T>>> for Ket<R>

Source§

type Error = String

The type returned in the event of a conversion error.
Source§

fn try_from(value: Mat<T>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<R> Freeze for Ket<R>

§

impl<R> RefUnwindSafe for Ket<R>
where <R as RealScalar>::C: RefUnwindSafe,

§

impl<R> Send for Ket<R>

§

impl<R> Sync for Ket<R>

§

impl<R> Unpin for Ket<R>
where <R as RealScalar>::C: Unpin,

§

impl<R> UnwindSafe for Ket<R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V