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
impl CompiledSampler
Sourcepub fn with_gpu(self, context: Arc<GpuContext>) -> Self
Available on crate feature gpu only.
pub fn with_gpu(self, context: Arc<GpuContext>) -> Self
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.
pub fn num_measurements(&self) -> usize
pub fn sparse(&self) -> Option<&SparseParity>
pub fn parity_stats(&self) -> Option<ParityStats>
pub fn sample(&mut self) -> Vec<bool>
pub fn sample_bulk(&mut self, num_shots: usize) -> Vec<Vec<bool>>
Sourcepub fn sample_bulk_packed_device(
&mut self,
num_shots: usize,
) -> Result<DevicePackedShots>
Available on crate feature gpu only.
pub fn sample_bulk_packed_device( &mut self, num_shots: usize, ) -> Result<DevicePackedShots>
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.
Sourcepub fn sample_bulk_packed(&mut self, num_shots: usize) -> PackedShots
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.
pub fn try_sample_bulk_packed( &mut self, num_shots: usize, ) -> Result<PackedShots>
Sourcepub fn sample_chunked<A: ShotAccumulator>(
&mut self,
total_shots: usize,
acc: &mut A,
)
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.
pub fn sample_chunked_with_size<A: ShotAccumulator>( &mut self, total_shots: usize, chunk_size: usize, acc: &mut A, )
Sourcepub fn sample_counts(&mut self, total_shots: usize) -> HashMap<Vec<u64>, u64>
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.
pub fn try_sample_counts( &mut self, total_shots: usize, ) -> Result<HashMap<Vec<u64>, u64>>
Sourcepub fn sample_marginals(&mut self, total_shots: usize) -> Vec<f64>
pub fn sample_marginals(&mut self, total_shots: usize) -> Vec<f64>
Per-measurement frequency of reading 1 across total_shots sampled
shots.
pub fn try_sample_marginals(&mut self, total_shots: usize) -> Result<Vec<f64>>
Sourcepub fn sample_detection_events(
&mut self,
pairs: &[(usize, usize)],
num_shots: usize,
) -> PackedShots
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.
Sourcepub fn exact_counts(&self) -> Option<HashMap<Vec<u64>, u64>>
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.
pub fn parity_report(&self) -> String
Auto Trait Implementations§
impl Freeze for CompiledSampler
impl RefUnwindSafe for CompiledSampler
impl Send for CompiledSampler
impl Sync for CompiledSampler
impl Unpin for CompiledSampler
impl UnsafeUnpin for CompiledSampler
impl UnwindSafe for CompiledSampler
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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