Skip to main content

QuantumRegister

Struct QuantumRegister 

Source
pub struct QuantumRegister { /* private fields */ }
Expand description

An n-qubit quantum register holding 2^n complex amplitudes.

This is a higher-level wrapper around QuantumStatevector that tracks qubit count explicitly and provides convenience initializers.

Implementations§

Source§

impl QuantumRegister

Source

pub fn new(n_qubits: usize) -> Self

Create a new register in the |0…0⟩ state.

Source

pub fn n_qubits(&self) -> usize

Number of qubits.

Source

pub fn size(&self) -> usize

Number of basis states (2^n).

Source

pub fn amplitude(&self, i: usize) -> Complex

Read amplitude at index i.

Source

pub fn prob(&self, i: usize) -> f64

Probability of basis state i.

Source

pub fn apply_gate(&mut self, gate: &Gate2x2, qubit: usize)

Apply a single-qubit gate to qubit q.

Source

pub fn apply_cnot(&mut self, control: usize, target: usize)

Apply CNOT with given control and target qubits.

Source

pub fn prepare_uniform_superposition(&mut self)

Prepare the uniform superposition state H^⊗n |0⟩.

Source

pub fn measure_qubit(&self, qubit: usize, seed: u64) -> u8

Measure qubit q (deterministic via seed).

Source

pub fn is_normalized(&self) -> bool

Check normalisation.

Source

pub fn amplitudes(&self) -> &[Complex]

Amplitudes as a slice.

Trait Implementations§

Source§

impl Debug for QuantumRegister

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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.