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
impl StateVector
Sourcepub fn basis(n: u8, k: usize) -> StateVector
pub fn basis(n: u8, k: usize) -> StateVector
The |k⟩ computational basis state on n qubits.
Sourcepub fn canonical_bytes(&self) -> Vec<u8> ⓘ
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.
Sourcepub fn statevector_hash(&self) -> [u8; 32]
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?
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}Sourcepub fn prob_weights(&self) -> Vec<i128>
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.
Sourcepub fn sample_shots(&self, seed: u64, shots: u64) -> Vec<u64>
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.
Sourcepub fn histogram_hash(&self, seed: u64, shots: u64) -> [u8; 32]
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).
Sourcepub fn fidelity_fx(&self, other: &StateVector) -> i64
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
impl Clone for StateVector
Source§fn clone(&self) -> StateVector
fn clone(&self) -> StateVector
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StateVector
impl Debug for StateVector
impl Eq for StateVector
Source§impl PartialEq for StateVector
impl PartialEq for StateVector
impl StructuralPartialEq for StateVector
Auto Trait Implementations§
impl Freeze for StateVector
impl RefUnwindSafe for StateVector
impl Send for StateVector
impl Sync for StateVector
impl Unpin for StateVector
impl UnsafeUnpin for StateVector
impl UnwindSafe for StateVector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.