Commit 3c8b768
Validate probabilities in noise channel constructors (#132)
## Summary
The Pauli channel probability helpers (`error_probs`,
`pauli_channel_1_probs`, `pauli_channel_2_probs`,
`heralded_pauli_channel_1_probs`) accepted invalid inputs and produced
malformed distributions: `probs[0]` could come out negative when
individual entries were outside `[0, 1]` or their sum exceeded 1.
`ChannelSampler._precompute_sparse` then silently dropped those channels
because `p_fire = 1 - probs[0] > 1` doesn't trigger its `p_fire <=
1e-15` early-return — sampling proceeded as if the channel did nothing.
In the normal stim-driven pipeline this is unreachable (stim rejects bad
probabilities at parse time), but it bites anyone constructing a
`Channel` directly.
- Added `_validate_probabilities` to check each input is in `[0, 1]` and
the sum is ≤ 1.
- Wired it into all four Pauli helpers.
- `ChannelSampler._precompute_sparse` now raises `ValueError` when
`p_fire < 0` instead of silently skipping.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 988aab7 commit 3c8b768
2 files changed
Lines changed: 46 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
30 | 41 | | |
31 | 42 | | |
32 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
165 | 200 | | |
166 | 201 | | |
167 | 202 | | |
| |||
0 commit comments