Repository navigation
Document how to retrieve TPB amplitudes, and the bitstring packing order (backport #55) - #57
Merged
Conversation
…der (#55) * Document how to retrieve TPB amplitudes, and the bitstring packing order Two things a user has to discover by reading upstream C++ or experimenting. TPB has two wavefunction output paths that write different formats, and nothing said so. `savename` -- the one named in `tpb_diag`'s signature -- goes to `SaveWavefunction`, which writes one file per b_comm position holding only that rank's block, behind a three-`size_t` header and the block's determinant words. `sbd_data.dump_matrix_form_wf` goes to `SaveMatrixFormWF`, which gathers the full adet x bdet subspace onto one rank and writes a bare row-major float64 array with no header at all, or, for a `.dat`/`.txt` path, a text table labelling each amplitude with its own alpha and beta bitstring. The second is what almost every caller wants, and is what this package's own SQD integration already uses (`sbd_solver.py` sets it and reads the result with a bare `np.fromfile`). It appeared only as a one-line pybind docstring and a CLI flag in `run_sbd_diag.py`, absent from the README's TPB section and from the `tpb_diag` docstring, both of which mention `savename` alone -- so following the signature led to parsing the wrong layout. Document both, side by side, and note that the text form is written with default stream formatting and so carries ~6 significant digits rather than full float64. `from_string` and `makestring` packed words with no stated convention. Bitstrings are packed from the right: the trailing `bit_length` characters become word 0, so the leading characters of a multi-word string land in the last word, not the first. Easy to get backwards, and a wrong guess yields a valid-looking but wrong subspace rather than an error. GDB needed no changes here: #46 documented its amplitude retrieval and file layout in examples/gdb/README.md. Assisted-by: Claude Opus 5 * Fit the amplitude and packing docs to the API surface #53 defined #53 curated the autodoc list and added field tables, which changes where this branch's documentation belongs. The packing convention moves from `from_string` to `from_strings`. #53 documents the bulk form and deliberately leaves the singular one out, so the convention was written on a function the rendered docs never show -- and `from_strings`, the form users are steered to, had no packing documentation of its own. `from_string` and `makestring` now point at it instead of restating it. The examples are shown as the `uint64` ndarray `from_strings` actually returns rather than as nested lists. `dump_matrix_form_wf` now appears in #53's `TPB_SBD` field table as well as the README's, so the README row defers to the format section instead of describing the field a second time. Also corrects a claim this branch made about `sbd_solver.py`: since #49 the wavefunction write is skipped when SBD selects the carryover itself (`carryover_type` 1 against an addon that accepts it), because the next subspace then comes back in `carryover_adet`/`carryover_bdet` and the amplitudes never reach Python. Saying it "uses" the dump without that qualification implied the write always happens. `tox -e docs` passes with no warnings, and the packing convention renders on the `from_strings` entry. Assisted-by: Claude Opus 5 (cherry picked from commit 90afb07)
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two things a user currently has to discover by reading the vendored C++ or by experimenting. Both came up in a user question about the Python bindings.
TPB has two wavefunction output paths, and they write different formats
tpb_diagreturns no amplitudes, and there are two ways to get them:sbd_data.dump_matrix_form_wfsavenameargumentlen(adet) × len(bdet)subspace, gathered onto one rankf"{savename}{rank_b:06d}.bin"size_t(adet_range,bdet_range,det_length), then that block's determinant wordsfloat64, row-major over α×βadet_range × bdet_rangefloat64loadnamedump_matrix_form_wfis what almost every caller wants, and is already what this package's own SQD integration uses —sbd_solver.pysets it and reads the result back with a barenp.fromfile. But it appeared only as a one-line pybind docstring and a CLI flag inexamples/tpb/run_sbd_diag.py; it was absent from the README's TPB section and from thetpb_diagdocstring, both of which mentionsavenamealone. Following the function signature therefore led to the per-rank restart layout, which is the wrong thing to parse for analysis.This adds the comparison to the README, a
Note:block ontpb_diag, a pointer ontpb_diag_from_files, a row in theTPB_SBDconfig table, and a fuller pybind docstring. It also records that the.dat/.txttext form is written with the stream's default formatting, so it carries roughly 6 significant digits rather than fullfloat64—restart.hsetsprecision(16)onstd::cout, not on the file stream.The word-packing convention was unstated
Bitstrings are packed from the right: the trailing
bit_lengthcharacters become word 0, so the leading characters of a string longer than one word land in the last word rather than the first.Worth stating explicitly because getting it backwards produces a valid-looking but wrong subspace rather than an error. It is documented on
from_strings, which #53 lists in the API reference, rather than on the singularfrom_string, which it deliberately leaves out; the singular forms point at it.Documentation only — no behavior change, hence an
otherrelease note.GDB needed no changes: #46 already documents its amplitude retrieval and per-shard file layout in
examples/gdb/README.md.Merged
mainafter #53#53 landed first and changed where this documentation belongs, so the merge commit is followed by a commit reconciling the two. No files overlapped — #53 is
docs/apidocs/*.rstonly — but three things needed fixing:from_string, which docs: list the API users call, and document the configuration fields #53's curated autodoc list omits, so it would never have rendered. It moves tofrom_strings, which had no packing documentation of its own despite being the form users are steered to.dump_matrix_form_wfis now in docs: list the API users call, and document the configuration fields #53'sTPB_SBDfield table, so the README row defers to the format section rather than describing the field twice.sbd_solver.pywas stale against Let SBD choose the SQD carryover (qiskit-addon-sqd#369) #49: the wavefunction write is skipped when SBD selects the carryover itself (carryover_type1, against an addon that accepts it), since the next subspace then arrives incarryover_adet/carryover_bdet. Saying it "uses" the dump implied the write always happens.tox -e docspasses with no warnings.This pull request was drafted by Claude Opus 5 under my guidance.
This is an automatic backport of pull request #55 done by [Mergify](https://mergify.com).