Skip to main content

CompiledSampler

Struct CompiledSampler 

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

Sampler for a compiled Clifford measurement circuit, built by compile_measurements or compile_forward. Shots XOR a random subset of rank flip rows into fixed reference bits; deterministic per seed. try_ methods propagate GPU errors; their plain twins fall back to the CPU path.

Implementations§

Source§

impl CompiledSampler

Source

pub fn rank(&self) -> usize

Number of independent random bits in the compiled parity system.

Source

pub fn with_gpu(self, context: Arc<GpuContext>) -> Self

Available on crate feature gpu only.

Opt in to GPU-accelerated BTS sampling. The sampler routes sample_bulk_packed through the GPU path when the circuit compiled to a flat sparse parity (no parity blocks) and the shot count crosses the GPU BTS threshold.

Source

pub fn num_measurements(&self) -> usize

Source

pub fn sparse(&self) -> Option<&SparseParity>

Source

pub fn parity_stats(&self) -> Option<ParityStats>

Source

pub fn sample(&mut self) -> Vec<bool>

Source

pub fn sample_bulk(&mut self, num_shots: usize) -> Vec<Vec<bool>>

Source

pub fn sample_bulk_packed_device( &mut self, num_shots: usize, ) -> Result<DevicePackedShots>

Available on crate feature gpu only.

Materialise packed shots directly on the GPU.

This is available only when the sampler has a GPU context and the compiled circuit routes through the flat sparse BTS path. Use DevicePackedShots::to_host to copy the full packed payload back, or DevicePackedShots::marginals / DevicePackedShots::counts to reduce on device first.

Source

pub fn sample_bulk_packed(&mut self, num_shots: usize) -> PackedShots

Draw num_shots shots as a packed bit matrix. The result layout depends on the sampling path taken; branch on PackedShots::layout.

Source

pub fn try_sample_bulk_packed( &mut self, num_shots: usize, ) -> Result<PackedShots>

Source

pub fn sample_chunked<A: ShotAccumulator>( &mut self, total_shots: usize, acc: &mut A, )

Stream total_shots through acc in default_chunk_size chunks, bounding peak memory.

Source

pub fn sample_chunked_with_size<A: ShotAccumulator>( &mut self, total_shots: usize, chunk_size: usize, acc: &mut A, )

Source

pub fn sample_counts(&mut self, total_shots: usize) -> HashMap<Vec<u64>, u64>

Histogram of total_shots outcomes keyed by packed measurement words. Ranks small relative to the shot count use a closed-form multinomial draw with no per-shot work.

A GPU failure falls back to the CPU sampler; Self::try_sample_counts surfaces it instead.

Source

pub fn try_sample_counts( &mut self, total_shots: usize, ) -> Result<HashMap<Vec<u64>, u64>>

Source

pub fn sample_marginals(&mut self, total_shots: usize) -> Vec<f64>

Per-measurement frequency of reading 1 across total_shots sampled shots.

Source

pub fn try_sample_marginals(&mut self, total_shots: usize) -> Result<Vec<f64>>

Source

pub fn sample_detection_events( &mut self, pairs: &[(usize, usize)], num_shots: usize, ) -> PackedShots

Sample packed detection events: output row e holds the XOR of measurement pair pairs[e] across shots.

§Panics

Panics if the sampler was compiled with no measurements.

Source

pub fn exact_counts(&self) -> Option<HashMap<Vec<u64>, u64>>

Exact outcome multiplicities over all 2^rank equally likely random-bit assignments; counts sum to 2^rank. None when rank exceeds 25 or no sparse parity is available.

Source

pub fn parity_report(&self) -> String

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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

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

Source§

fn vzip(self) -> V