qdk_chemistry.migrate._io module
Low-level helpers shared across the schema-migration converters.
Handles serialization-format and data-type detection, the per-object
serialization-version step chain (migrate_doc()), reading dense arrays out
of the legacy HDF5 layout (which stores Eigen column-major matrices in
[rows, cols] datasets), and writing a reconstructed object back out in the
requested format.
- qdk_chemistry.migrate._io.migrate_doc(steps, read_doc, label)[source]
Upgrade
read_docto the current serialization version by followingsteps.stepsmaps a serialization version to a(next_version, transform)pair. The chain is walked from the document’s own_source_versionuntil no further step applies. A version with no registered step is rejected rather than silently reinterpreted, so an already-current (or otherwise unsupported) file fails fast.
- qdk_chemistry.migrate._io.detect_format(path)[source]
Return
"json"or"hdf5"for a path, based on its suffix.
- qdk_chemistry.migrate._io.detect_type(path)[source]
Return the data type (‘orbitals’/’hamiltonian’/’wavefunction’/’ansatz’).
Uses the
name.type.extfilename convention (e.g.foo.hamiltonian.h5).
- qdk_chemistry.migrate._io.read_matrix(group, name)[source]
Read a dense matrix written by the C++
save_matrix_to_group.The C++ side writes Eigen column-major data into a
[rows, cols]dataset, so the row-major bytes h5py returns are the transpose of the logical matrix.
- qdk_chemistry.migrate._io.read_vector(group, name)[source]
Read a 1-D dataset written by the C++
save_vector_to_group.
- qdk_chemistry.migrate._io.read_index_vector(group, name)[source]
Read a 1-D integer index dataset as a Python list.
- qdk_chemistry.migrate._io.read_attr(obj, name, default=None)[source]
Read an HDF5 attribute, decoding bytes to str.
- Parameters:
name (str)
- qdk_chemistry.migrate._io.subgroup_to_json(group, data_class, type_token)[source]
Serialize an embedded, schema-unchanged sub-object to JSON.
Copies
groupinto a standalone temporary HDF5 file and loads it with the given data class’ (current, unchanged-schema)from_hdf5_file, then emits JSON. Used for nested objects whose serialization schema is unchanged across the migrated versions (e.g.BasisSet), so the migration need not know their internal layout.