Skip to content

ppvm_vihaco::shots

shots

ppvm_vihaco::shots

Running a compiled program for many shots, optionally across threads.

Each shot runs on a fresh PPVM so shots are fully independent; the module is compiled once and cloned into each shot’s machine. With the `rayon` feature, run_shots parallelizes across shots when the global pool (sized once by set_global_threads) has more than one thread and there are enough shots to amortize the overhead.

classShotRecordsource

ppvm_vihaco::shots::ShotRecord

Bases: Debug, Clone, StructuralPartialEq, PartialEq, Default

Rust struct. One shot's full output: the measurement record and the trace-instruction record. Either may be empty depending on what the program emits.

pub struct ShotRecord

Fields

NameTypeDescription
measurementsVec<MeasurementResult>
tracesVec<f64>
source

propertyPARALLEL_SHOT_THRESHOLD

ppvm_vihaco::shots::PARALLEL_SHOT_THRESHOLD

pub const PARALLEL_SHOT_THRESHOLD: usize

Below this many shots, parallelism’s overhead outweighs its benefit and we always run serially. Provisional — tune with benchmarks.

functionrun_shotssource

ppvm_vihaco::shots::run_shots

Signature
pub fn run_shots(module: &PPVMModule, shots: usize, seed: Option<u64>) -> Result<Vec<ShotRecord>>

Parameters

NameTypeDescription
module&amp;PPVMModule
shotsusize
seedOption&lt;u64&gt;

Returns

Result<Vec<ShotRecord>>

Run `shots` shots, choosing serial or parallel execution. Goes parallel only when built with `rayon`, the global pool has more than one thread, and there are enough shots to be worth it; otherwise runs serially. The pool size is set once at startup by set_global_threads.

source

functionrun_shots_serialsource

ppvm_vihaco::shots::run_shots_serial

Signature
pub fn run_shots_serial(module: &PPVMModule, shots: usize, seed: Option<u64>) -> Result<Vec<ShotRecord>>

Parameters

NameTypeDescription
module&amp;PPVMModule
shotsusize
seedOption&lt;u64&gt;

Returns

Result<Vec<ShotRecord>>

Run `shots` shots serially. One entry per shot, in order.

source

functionset_global_threadssource

ppvm_vihaco::shots::set_global_threads

pub fn set_global_threads(threads: usize) -> Result<()>

Parameters

NameTypeDescription
threadsusize

Returns

Result<()>

Without the `rayon` feature there is no pool to size; anything but a single thread is meaningless, so reject it rather than silently run serially.

source