1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Caller-supplied Rayon pool, for embedding PRISM-Q in an application that
//! owns the process-wide pool.
use crate;
/// A bounded Rayon pool that PRISM-Q runs inside, leaving the process-wide pool
/// untouched.
///
/// Simulation entry points otherwise size the global Rayon pool on first use. Work run
/// through [`ThreadPool::install`] uses this pool, and the global pool is neither built
/// nor resized.
///
/// Pool width can change results. Dense unitary evolution, seeded terminal sampling,
/// and the stabilizer tableau are bitwise at any width; parallel reductions move by
/// about 1e-12; compiled (BTS) shot payloads differ because the batched sampler splits
/// shots by pool width. The threading architecture page has the per-path contract.
///
/// # Examples
///
/// ```
/// use prism_q::{ThreadPool, run_qasm};
///
/// let qasm = r#"
/// OPENQASM 3.0;
/// include "stdgates.inc";
/// qubit[2] q;
/// h q[0];
/// cx q[0], q[1];
/// "#;
///
/// let pool = ThreadPool::with_threads(2).expect("build pool");
/// let result = pool.install(|| run_qasm(qasm, 42)).expect("simulation");
/// let probs = result.probabilities.expect("no probabilities").to_vec();
/// assert!((probs[0] - 0.5).abs() < 1e-10);
/// ```