Commit de20370
authored
Fix bit_length=64 undefined behavior, make it configurable, and lower --samples/--max_nb defaults (#12)
* Fix undefined behavior from hardcoded bit_length=64; make it configurable
SBD packs determinant bitstrings into std::vector<size_t> with
`bit_length` bits per word. The Python wrapper hardcoded 64 in four
places, but bitadvance() in framework/bit_manipulation.h computes
size_t d = (((size_t) 1) << bit_length) - 1;
Shifting a 64-bit size_t by 64 is undefined behavior. In practice the
shift count is masked to 0, so the mask collapses to d == 0 (checked on
aarch64 and x86-64). bitadvance() is reached from mpi_redistribution()
and mpi_sort_bitarray(), the multi-rank determinant distribution paths.
RIKEN documents the default as 20 (see --bit_length in
apps/chemistry_tpb_selected_basis_diagonalization/README.md), which is
also what run_sbd_diag.py already defaults to; only run_sqd_sbd.py was
passing 64.
Changes:
- Add SBD_DEFAULT_BIT_LENGTH = 20 in sbd_solver.py and use it for the
_create_sbd_config default.
- Thread the effective value through. _ci_strings_to_sbd_dets() and
_sbd_dets_to_ci_strings() now take bit_length, and _solve_sci_core()
builds the config before packing so determinants are packed with the
same value the C++ engine uses to interpret them. Previously a
caller-supplied bit_length reached the engine but not the packing,
which would silently corrupt the determinants.
- Add --bit_length to run_sqd_sbd.py (default 20) instead of hardcoding.
Validated on GB200 (NVHPC 25.5, cc100, 4 GPUs, CUDA-aware MPICH 5.0.1):
- H2O 1e-5 subspace, dim 303,601: -76.2437350421 at bit_length 20, both
at np=1 and 2x2, matching the pre-change value and run_sbd_diag.py's
independent file-based path (-76.2437349413).
- bit_length 20 / 48 / 63 give bit-identical energies, confirming that
packing, unpacking and the engine now agree. norb=24 at bit_length=20
spans two size_t words, so this also exercises the multi-word path.
* Lower --samples default to 3000 and --max_nb default to 10
--max_nb sets the Davidson block size, and davidson_thrust.h allocates
2 * num_block vectors of length dim on the device, so GPU memory scales
as dim * (2 * max_nb + ~4) * 8 bytes. 10 matches the upstream default in
chemistry/tpb/sbdiag.h and cuts that workspace by ~4x versus 50.
* Update example notebook to bit_length 20
The notebook's sbd_config hardcoded 64, the value this PR removes as
undefined behavior. Its 'max_nb': 10 already matches the new CLI default.1 parent 7c7cc09 commit de20370
3 files changed
Lines changed: 36 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | | - | |
| 202 | + | |
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
95 | 99 | | |
96 | 100 | | |
97 | 101 | | |
| |||
223 | 227 | | |
224 | 228 | | |
225 | 229 | | |
226 | | - | |
| 230 | + | |
227 | 231 | | |
228 | 232 | | |
229 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
32 | 43 | | |
33 | 44 | | |
34 | 45 | | |
| |||
154 | 165 | | |
155 | 166 | | |
156 | 167 | | |
157 | | - | |
158 | | - | |
159 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
160 | 172 | | |
161 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
162 | 177 | | |
163 | 178 | | |
164 | 179 | | |
| |||
199 | 214 | | |
200 | 215 | | |
201 | 216 | | |
202 | | - | |
203 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
204 | 223 | | |
205 | 224 | | |
206 | 225 | | |
| |||
411 | 430 | | |
412 | 431 | | |
413 | 432 | | |
414 | | - | |
| 433 | + | |
| 434 | + | |
415 | 435 | | |
416 | 436 | | |
417 | 437 | | |
418 | 438 | | |
419 | 439 | | |
420 | 440 | | |
421 | | - | |
422 | 441 | | |
423 | 442 | | |
424 | 443 | | |
| |||
428 | 447 | | |
429 | 448 | | |
430 | 449 | | |
431 | | - | |
| 450 | + | |
| 451 | + | |
432 | 452 | | |
433 | 453 | | |
434 | | - | |
435 | 454 | | |
436 | 455 | | |
437 | 456 | | |
| |||
459 | 478 | | |
460 | 479 | | |
461 | 480 | | |
462 | | - | |
| 481 | + | |
463 | 482 | | |
464 | 483 | | |
465 | 484 | | |
| |||
0 commit comments