Skip to content

HDF5 Hamiltonian generation and loading errors #495

@awoodwa

Description

@awoodwa

A Hamiltonian saved to HDF5 on one environment cannot be loaded in another using Hamiltonian.from_hdf5_file. The load fails with:

ValueError: Tried to generate invalid Hamiltonian object.

Expected behavior

The Hamiltonian should load successfully across environments when using Hamiltonian.from_hdf5_file.

To Reproduce

Steps to reproduce the behavior:

  1. Generate hdf5 file in one environment (envA) using qdk_chemistry version 2.0.0 (branch: feature/agamshayit/x2c0 ):
from qdk_chemistry.algorithms import create
from qdk_chemistry.data import Structure
from qdk_chemistry.utils import compute_valence_space_parameters
xyz = """3
Water molecule
O    0.000000    0.000000    0.000000
H    0.758602    0.000000    0.504284
H   -0.758602    0.000000    0.504284
"""
structure = Structure.from_xyz(xyz)
scf = create("scf_solver")
scf.settings().set("scf_type", "restricted")
e_scf, scf_wfn = scf.run(
    structure,
    charge=0,
    spin_multiplicity=1,
    basis_or_guess="def2-svp",
)
num_val_e, num_val_o = compute_valence_space_parameters(scf_wfn, charge=0)
selector = create("active_space_selector", "qdk_valence")
selector.settings().set("num_active_electrons", num_val_e)
selector.settings().set("num_active_orbitals", num_val_o)
active_wfn = selector.run(scf_wfn)
ham_constructor = create("hamiltonian_constructor", "qdk_cholesky")
ham_constructor.settings().set("cholesky_tolerance", 1e-6)
ham = ham_constructor.run(active_wfn.get_orbitals())
ham.to_hdf5_file("water.hamiltonian.h5")
print(f"SCF energy: {e_scf:.10f} Ha")
print(f"Valence active space: {num_val_e}e, {num_val_o}o")
print(f"Saved Hamiltonian: water.hamiltonian.h5")
  1. Load hdf5 file in new environment (envB) where qdk_chemistry version 1.1.0 is used:
>>> from qdk_chemistry.data import Hamiltonian
>>> h = Hamiltonian.from_hdf5_file("water.hamiltonian.h5")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    h = Hamiltonian.from_hdf5_file("water.hamiltonian.h5")
ValueError: Tried to generate invalid Hamiltonian object.

Environments

Environment A (generation)

Field Value
Machine Intel Xeon Platinum 8180M
OS Ubuntu
Python 3.12.3
qdk_chemistry 2.0.0 (feature/agamshayit/x2c0)

Environment B (loading)

Field Value
Machine AMD EPYC 7V12
OS Azure Linux 3.0
Python 3.13.1
qdk_chemistry 1.0.0

Additional Notes:

  • This error is not observed when generating the Hamiltonian via code provided in step 1 using envB, then reading on envA following the code provided in step 3
  • hdf5 files generated in envA using qdk_chemistry version 2.0.0 can be properly loaded in another virtual environment on envA using qdk_chemistry version 1.1.0

Perhaps this is a python version discrepancy?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requestedtriageAn issue yet to be triaged with respect to its priority

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions