diff --git a/qiskit_nature/drivers/second_quantization/hdf5d/hdf5driver.py b/qiskit_nature/drivers/second_quantization/hdf5d/hdf5driver.py index d50c4737c8..33e8c6b789 100644 --- a/qiskit_nature/drivers/second_quantization/hdf5d/hdf5driver.py +++ b/qiskit_nature/drivers/second_quantization/hdf5d/hdf5driver.py @@ -18,6 +18,7 @@ import h5py +from qiskit_nature import QiskitNatureError from qiskit_nature.hdf5 import load_from_hdf5, save_to_hdf5 from qiskit_nature.properties.second_quantization.second_quantized_property import ( GroupedSecondQuantizedProperty, @@ -60,8 +61,11 @@ def work_path(self, new_work_path): def _get_path(self) -> str: """Returns the absolute path to the HDF5 file. + Returns: + The absolute path to the HDF5 file. + Raises: - LoopupError: file not found. + LookupError: file not found. """ hdf5_file = self._hdf5_input if self.work_path is not None and not os.path.isabs(hdf5_file): @@ -101,6 +105,7 @@ def run(self) -> GroupedSecondQuantizedProperty: Raises: LookupError: file not found. + QiskitNatureError: if the HDF5 file did not contain a GroupedSecondQuantizedProperty. """ hdf5_file = self._get_path() @@ -122,4 +127,11 @@ def run(self) -> GroupedSecondQuantizedProperty: return ElectronicStructureDriverResult.from_legacy_driver_result(molecule) driver_result = load_from_hdf5(hdf5_file) + + if not isinstance(driver_result, GroupedSecondQuantizedProperty): + raise QiskitNatureError( + f"Expected a GroupedSecondQuantizedProperty but found a {type(driver_result)} " + "object instead." + ) + return driver_result