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_doc to the current serialization version by following steps.

steps maps a serialization version to a (next_version, transform) pair. The chain is walked from the document’s own _source_version until 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.

Return type:

dict

Parameters:
qdk_chemistry.migrate._io.detect_format(path)[source]

Return "json" or "hdf5" for a path, based on its suffix.

Return type:

str

Parameters:

path (Path)

qdk_chemistry.migrate._io.detect_type(path)[source]

Return the data type (‘orbitals’/’hamiltonian’/’wavefunction’/’ansatz’).

Uses the name.type.ext filename convention (e.g. foo.hamiltonian.h5).

Return type:

str

Parameters:

path (Path)

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.

Return type:

ndarray | None

Parameters:
  • group (h5py.Group)

  • name (str)

qdk_chemistry.migrate._io.read_vector(group, name)[source]

Read a 1-D dataset written by the C++ save_vector_to_group.

Return type:

ndarray | None

Parameters:
  • group (h5py.Group)

  • name (str)

qdk_chemistry.migrate._io.read_index_vector(group, name)[source]

Read a 1-D integer index dataset as a Python list.

Return type:

list | None

Parameters:
  • group (h5py.Group)

  • name (str)

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 group into 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.

Return type:

dict

Parameters:
  • group (h5py.Group)

  • type_token (str)

qdk_chemistry.migrate._io.write_object(obj, dst, fmt)[source]

Write a reconstructed data object to dst in the given format.

Return type:

None

Parameters: