Skip to main content

StateVector

Struct StateVector 

Source
pub struct StateVector {
    pub n_qubits: u8,
    pub amps: Vec<Amp>,
}
Expand description

A reconstructed fixed-point state vector — the hashed quantity.

Fields§

§n_qubits: u8§amps: Vec<Amp>

Implementations§

Source§

impl StateVector

Source

pub fn basis(n: u8, k: usize) -> StateVector

The |k⟩ computational basis state on n qubits.

Source

pub fn canonical_bytes(&self) -> Vec<u8> ⓘ

Canonical serialization of the amplitudes: re_le(i64) ‖ im_le(i64) per amplitude, in index order — the bytes the statevector hash covers.

Source

pub fn statevector_hash(&self) -> [u8; 32]

statevector-equivalence — the portable BLAKE3 identity of the whole reconstructed vector. Two conforming sinks agree on this iff every amplitude is byte-identical, on every machine, with no tolerance parameter.

Examples found in repository?
examples/bell.rs (line 28)
9fn main() {
10    let mut c = Circuit::new(2);
11    c.h(0).cx(0, 1); // a Bell pair
12
13    let sv = c.simulate().expect("simulate");
14
15    println!("circuit    {} qubits, {} gates", c.n_qubits, c.ops.len());
16    let (backend, why) = qt::recommend_backend(&c);
17    println!("backend    {backend:?} — {why}");
18
19    println!("outcomes");
20    for (state, p) in qt::top_outcomes(&sv, 4) {
21        if p > 0.0 {
22            println!("  |{state:02b}>  {p:.6}");
23        }
24    }
25
26    // Not "a hash of this run" — the reconstruction is byte-exact, so this is the
27    // same value natively, in a browser, and in a WASI component at the edge.
28    let h = sv.statevector_hash();
29    print!("state-hash ");
30    for b in h {
31        print!("{b:02x}");
32    }
33    println!();
34}
Source

pub fn prob_weights(&self) -> Vec<i128>

Per-basis-state probability weights |amp|^2 at scale 2^(2·FRAC), i128 (un-normalized; summing gives ≈ 2^(2·FRAC)). No divide — the sampler walks these directly.

Source

pub fn sample_shots(&self, seed: u64, shots: u64) -> Vec<u64>

Sample shots computational-basis measurements with the pinned splitmix64 seeded by seed; returns a per-basis-state count vector. Deterministic on every machine.

Source

pub fn histogram_hash(&self, seed: u64, shots: u64) -> [u8; 32]

shot-histogram-equivalence — the portable BLAKE3 identity of a shot histogram at a pinned (seed, shots).

Source

pub fn fidelity_fx(&self, other: &StateVector) -> i64

State fidelity |⟨self|other⟩|^2 in the fixed-point floor (result at 2^FRAC) — the quantum-information-theoretic similarity metric. For two exactly-reconstructed vectors it is a diagnostic (identical states give ≈ ONE); it is the metric a future float/behavioral quantum prior — which cannot back intent=replicate — would conform against. i128 accumulation so the overlap sum never overflows.

Trait Implementations§

Source§

impl Clone for StateVector

Source§

fn clone(&self) -> StateVector

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StateVector

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for StateVector

Source§

impl PartialEq for StateVector

Source§

fn eq(&self, other: &StateVector) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for StateVector

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.