qdk_chemistry.migrate package

Migrate serialized data files across serialization-schema versions.

Each qdk-chemistry data class versions its serialization schema independently, and its deserializer accepts only the version the installed library was built against. Loading a file written against an older version of that class’s schema raises an error; use this module to upgrade such a file to the version the library accepts.

Command line:

python -m qdk_chemistry.migrate OLD_FILE NEW_FILE

Python:

from qdk_chemistry import migrate
migrate.convert_file("old.hamiltonian.json", "new.hamiltonian.h5")

The data type is taken from the name.type.ext filename convention (orbitals / hamiltonian / wavefunction / ansatz) and the serialization format from the file extension (.json or .h5 / .hdf5). Input and output formats may differ.

Migration is keyed point-by-point on each data class’s serialization version, not on a library release: every migratable type exposes a STEPS table mapping a source version to a (next_version, transform) pair, and the chain is followed until it reaches the version the installed library accepts. To support a future serialization-version bump for a data class, register the next step in that type’s STEPS table (_orbitals/_hamiltonian/_wavefunction); the migrated document is validated against the live deserializer, so a missing step fails loudly.

This module lives outside the data classes so that no legacy-schema knowledge leaks into the core serialization.

exception qdk_chemistry.migrate.MigrationError[source]

Bases: RuntimeError

Raised when a file cannot be migrated to the current serialization version.

qdk_chemistry.migrate.convert_file(src, dst)[source]

Migrate a single data file to the serialization version the library accepts.

Return type:

Path

Parameters:
  • src (str | Path) – Path to the file to read (format inferred from its extension).

  • dst (str | Path) – Path to write the migrated file (format inferred from its extension).

Returns:

The dst path as a pathlib.Path.

Raises:

MigrationError – If the data type/format cannot be determined, the source and destination are the same file, the file is already at the current serialization version, or the migration fails.

Submodules