From 0444320113716b12d3c046dd6eae47d05baf1638 Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Tue, 22 Feb 2022 12:52:55 +0100 Subject: [PATCH] HDF5 Driver Update (#550) * refactor: basic HDF5Driver update * test: test both HDF5 type supports * Fix copyright * test: update new expected HDF5 file * ref: align new HDF5Driver with #554 * feat: add HDF5Driver.convert utility method * Add reno * Fix linters * refactor: do not replace by default * refactor: use `_new.hdf5` instead of `.hdf5.new` * refactor: update wording * fix: Python <3.9 compatibility * Update docstring Co-authored-by: Panagiotis Barkoutsos --- .../second_quantization/hdf5d/hdf5driver.py | 100 +++++++++++++++--- .../notes/hdf5-driver-bafbbd8e70ee15a6.yaml | 11 ++ .../hdf5d/test_driver_hdf5.hdf5 | Bin 15664 -> 48547 bytes .../hdf5d/test_driver_hdf5.py | 73 ++++++++++++- .../hdf5d/test_driver_hdf5_legacy.hdf5 | Bin 0 -> 15664 bytes .../hdf5d/test_driver_hdf5_save.py | 53 ---------- 6 files changed, 168 insertions(+), 69 deletions(-) create mode 100644 releasenotes/notes/hdf5-driver-bafbbd8e70ee15a6.yaml create mode 100644 test/drivers/second_quantization/hdf5d/test_driver_hdf5_legacy.hdf5 delete mode 100644 test/drivers/second_quantization/hdf5d/test_driver_hdf5_save.py diff --git a/qiskit_nature/drivers/second_quantization/hdf5d/hdf5driver.py b/qiskit_nature/drivers/second_quantization/hdf5d/hdf5driver.py index 53cf9ef76d..4b8ef77f1d 100644 --- a/qiskit_nature/drivers/second_quantization/hdf5d/hdf5driver.py +++ b/qiskit_nature/drivers/second_quantization/hdf5d/hdf5driver.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2021. +# (C) Copyright IBM 2018, 2022. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -12,20 +12,31 @@ """ HDF5 Driver """ -import os +import logging +import pathlib import warnings +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, +) from qiskit_nature.properties.second_quantization.electronic import ElectronicStructureDriverResult from ...qmolecule import QMolecule -from ..electronic_structure_driver import ElectronicStructureDriver +from ..base_driver import BaseDriver + +LOGGER = logging.getLogger(__name__) -class HDF5Driver(ElectronicStructureDriver): +class HDF5Driver(BaseDriver): """ Qiskit Nature driver for reading an HDF5 file. - The HDF5 file is one as saved from a :class:`~qiskit_nature.drivers.QMolecule` instance. + The HDF5 file is one constructed with :func:`~qiskit_nature.hdf5.save_to_hdf5` or a file + containing a legacy :class:`~qiskit_nature.drivers.QMolecule` instance. """ def __init__(self, hdf5_input: str = "molecule.hdf5") -> None: @@ -47,23 +58,82 @@ def work_path(self, new_work_path): """Sets work path.""" self._work_path = new_work_path - def run(self) -> ElectronicStructureDriverResult: - """ + def _get_path(self) -> pathlib.Path: + """Returns the absolute path to the HDF5 file. + Returns: - ElectronicStructureDriverResult re-constructed from the HDF5 file. + The absolute path to the HDF5 file. Raises: LookupError: file not found. """ - hdf5_file = self._hdf5_input - if self.work_path is not None and not os.path.isabs(hdf5_file): - hdf5_file = os.path.abspath(os.path.join(self.work_path, hdf5_file)) + hdf5_file = pathlib.Path(self._hdf5_input) + if self.work_path is not None and not hdf5_file.is_absolute(): + hdf5_file = pathlib.Path(self.work_path) / hdf5_file - if not os.path.isfile(hdf5_file): + if not hdf5_file.is_file(): raise LookupError(f"HDF5 file not found: {hdf5_file}") + return hdf5_file + + def convert(self, replace: bool = False) -> None: + """Converts a legacy QMolecule HDF5 file into the new Property-framework. + + Args: + replace: if True, will replace the original HDF5 file. Otherwise `_new.hdf5` will be + used as a suffix. + + Raises: + LookupError: file not found. + """ + hdf5_file = self._get_path() + warnings.filterwarnings("ignore", category=DeprecationWarning) - molecule = QMolecule(hdf5_file) + q_mol = QMolecule(hdf5_file) warnings.filterwarnings("default", category=DeprecationWarning) - molecule.load() - return ElectronicStructureDriverResult.from_legacy_driver_result(molecule) + q_mol.load() + + new_hdf5_file = hdf5_file + if not replace: + new_hdf5_file = hdf5_file.with_name(str(hdf5_file.stem) + "_new.hdf5") + + driver_result = ElectronicStructureDriverResult.from_legacy_driver_result(q_mol) + save_to_hdf5(driver_result, str(new_hdf5_file), replace=replace) + + def run(self) -> GroupedSecondQuantizedProperty: + """ + Returns: + GroupedSecondQuantizedProperty re-constructed from the HDF5 file. + + Raises: + LookupError: file not found. + QiskitNatureError: if the HDF5 file did not contain a GroupedSecondQuantizedProperty. + """ + hdf5_file = self._get_path() + + legacy_hdf5_file = False + + with h5py.File(hdf5_file, "r") as file: + if "origin_driver" in file.keys(): + legacy_hdf5_file = True + LOGGER.warning( + "Your HDF5 file contains the legacy QMolecule object! You should consider " + "converting it to the new property framework, see HDF5Driver.convert" + ) + + if legacy_hdf5_file: + warnings.filterwarnings("ignore", category=DeprecationWarning) + molecule = QMolecule(hdf5_file) + warnings.filterwarnings("default", category=DeprecationWarning) + molecule.load() + return ElectronicStructureDriverResult.from_legacy_driver_result(molecule) + + driver_result = load_from_hdf5(str(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 diff --git a/releasenotes/notes/hdf5-driver-bafbbd8e70ee15a6.yaml b/releasenotes/notes/hdf5-driver-bafbbd8e70ee15a6.yaml new file mode 100644 index 0000000000..38945bcbc8 --- /dev/null +++ b/releasenotes/notes/hdf5-driver-bafbbd8e70ee15a6.yaml @@ -0,0 +1,11 @@ +--- +features: + - | + The HDF5Driver has been refactored to leverage the new HDF5-integration + protocol of Qiskit Nature. The driver still supports loading legacy + QMolecule HDF5 files and also provides a conversion utility: + + .. code-block:: python + + driver = HDF5Driver("path_to_qmolecule.hdf5") + driver.convert(replace=True) diff --git a/test/drivers/second_quantization/hdf5d/test_driver_hdf5.hdf5 b/test/drivers/second_quantization/hdf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hq>uDCsCV#`2faR3yaFPU(f&UCOD1tVt=F;vA&5nHPF;RQv*#6tQQTy{66*XZb7jp`UIuKxaKZQK7Q*vX*=V1dkvVmpHXRZDA z3-nuxkT9^>Z)b!V)fc7sPqX&jWpS|{jUA%J@6z;jG1I}^`2t@y-qPEvb$f9}xNnhx%r;GiD8srCBs-3tBq zBu!yWL0Bi+8LiWQY_p#ptrKVOw&&|Xa^W6(K2#pd;W@Jvx0eX_Qekbu+S}ES4Q*Go z*T?yFrjH)ofE{p6!RUYt%qrZNzLJ5Lp}!IQ19xP`&&& zZ3bC73?iB3&l%|TLK4}yUrkLYnP4of%|XM1v1Bxe6VmVrIYTImtNxHGhr={qYzx_w zBI|upOaDJv|$PIvOhf?pHO3Z|2m$VK1PF4Jg0a?_0>YNJwqT8 z_vd(AT->h{Uj6=bKfYgzfFObS{YI-5t*UnA_IFoty3VS4Z#HUl4bc8>90dVyVXT1P z6_R{BKT#91>{k*Q-L*L`r<5XE%u9^cPpz$?no=T4!atc(rsNc7qsydgb0@8JL{{T+ zCPmjwjL$=kq%gVS^hqVjzmhBEMgrf~sM$wKc#jCfwH_`51H@q3M-NAefOxJ;wU9a{- z=M<-|W2k1+2GjtpSMxacD8l5Ut1FDzPr(AkeWjIuR_}+K;D5`QWDwBoholJu+o~br zeN*6|{ZKw6OOM&}Igxy^%>Nq|*PTK8{@^X~^U?$MeD$K%&#rc^NxQ0_K1LcuA7J@( zzf#Iu!Gf!gGhvjUJPZ0W$C+HcT*WYM&d+!Jex8M3LNYDj#{`_dOM^UtH;l`P4DT@| z^SmQ1Yur44@TZkXLLZ0DCA@}FD@V-s3=xj{Z)H7t?$pf}4y{f*&jy;4jU0MvbePwT Y9eqv%I>GvU=>)z%>RE5W*4q2~AI5V#_y7O^ diff --git a/test/drivers/second_quantization/hdf5d/test_driver_hdf5.py b/test/drivers/second_quantization/hdf5d/test_driver_hdf5.py index a7cd8f8058..2f1a27aec9 100644 --- a/test/drivers/second_quantization/hdf5d/test_driver_hdf5.py +++ b/test/drivers/second_quantization/hdf5d/test_driver_hdf5.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2021. +# (C) Copyright IBM 2018, 2022. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -12,7 +12,12 @@ """ Test Driver HDF5 """ +import os +import pathlib +import shutil +import tempfile import unittest + from test import QiskitNatureTestCase from test.drivers.second_quantization.test_driver import TestDriver from qiskit_nature.drivers.second_quantization import HDF5Driver @@ -30,6 +35,72 @@ def setUp(self): ) self.driver_result = driver.run() + def test_convert(self): + """Test the legacy-conversion method.""" + legacy_file_path = self.get_resource_path( + "test_driver_hdf5_legacy.hdf5", "drivers/second_quantization/hdf5d" + ) + + with self.subTest("replace=True"): + # pylint: disable=consider-using-with + tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".hdf5") + tmp_file.close() + os.unlink(tmp_file.name) + shutil.copy(legacy_file_path, tmp_file.name) + try: + driver = HDF5Driver(tmp_file.name) + driver.convert(replace=True) + with self.assertRaises(AssertionError): + # NOTE: we can use assertNoLogs once Python 3.10 is the default + with self.assertLogs( + logger="qiskit_nature.drivers.second_quantization.hdf5d.hdf5driver", + level="WARNING", + ): + driver.run() + finally: + os.unlink(tmp_file.name) + + with self.subTest("replace=False"): + # pylint: disable=consider-using-with + tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".hdf5") + tmp_file.close() + new_file_name = pathlib.Path(tmp_file.name).with_name( + str(pathlib.Path(tmp_file.name).stem) + "_new.hdf5" + ) + os.unlink(tmp_file.name) + shutil.copy(legacy_file_path, tmp_file.name) + try: + driver = HDF5Driver(tmp_file.name) + driver.convert(replace=False) + with self.assertLogs( + logger="qiskit_nature.drivers.second_quantization.hdf5d.hdf5driver", + level="WARNING", + ): + driver.run() + with self.assertRaises(AssertionError): + # NOTE: we can use assertNoLogs once Python 3.10 is the default + with self.assertLogs( + logger="qiskit_nature.drivers.second_quantization.hdf5d.hdf5driver", + level="WARNING", + ): + HDF5Driver(new_file_name).run() + finally: + os.unlink(tmp_file.name) + os.unlink(new_file_name) + + +class TestDriverHDF5Legacy(QiskitNatureTestCase, TestDriver): + """HDF5 Driver legacy file-support tests.""" + + def setUp(self): + super().setUp() + driver = HDF5Driver( + hdf5_input=self.get_resource_path( + "test_driver_hdf5_legacy.hdf5", "drivers/second_quantization/hdf5d" + ) + ) + self.driver_result = driver.run() + if __name__ == "__main__": unittest.main() diff --git a/test/drivers/second_quantization/hdf5d/test_driver_hdf5_legacy.hdf5 b/test/drivers/second_quantization/hdf5d/test_driver_hdf5_legacy.hdf5 new file mode 100644 index 0000000000000000000000000000000000000000..1f6b7af0cd8a6a56c1f6ede2b4f53a555094f86f GIT binary patch literal 15664 zcmeGjOKcle@HwC28jzCk3#HJdDkY(%geEO%0oj$3)F3`?6Ci?v?Ko?D!S-7IL{6a< z5)uUEQX~%C;J_i`LJlCx$vGeuRY(+s5C_y4RMHlT1OiGANa5|yjNN^!UB|8?$B8#e z=FOXVpP8MR_vXFL+uos(n_XL6OnaP8*2X&YBK=v$r|)s7A)M#|EI1I(Ae?J~f`e&4 zjCEsuC-yJ$jU62xW}K7yCy32hp&d$2s%XLur2+5oA)hAjJW4%|aPT20SlOAcALz+_ z*q}mS)vvb|I*OuQmb2dgx>eJDD|`X#gq`e{?3Uu;4B8KgnFz*ZtsGJlVI`tPM0h+1 zD+Qy^JUirIo0#rAyz!UCxC}js{z3B^L_?+VPjvzR54QsB1Hh!apg?>J+W{}^0O$e0 zyaL|`yMeH<2cU#}r*Hz)Ux6ls?a6;6^grSg{SmvX8PIg7kA(v|7|evmZ{@gFzJ>p3 zdQ>FK(rzwh7K@)Be3m56JwWEB@hJMoP^F%VZ{awr>< zrRZMiRhJ}5ebU1k@JfAq`si1zc%*-y>$uC6mNR;riC|huOX-aIV1IaB%U@{Ln}LME~1-!Hp(f^d0>La2Hq>uDCsCV#`2faR3yaFPU(f&UCOD1tVt=F;vA&5nHPF;RQv*#6tQQTy{66*XZb7jp`UIuKxaKZQK7Q*vX*=V1dkvVmpHXRZDA z3-nuxkT9^>Z)b!V)fc7sPqX&jWpS|{jUA%J@6z;jG1I}^`2t@y-qPEvb$f9}xNnhx%r;GiD8srCBs-3tBq zBu!yWL0Bi+8LiWQY_p#ptrKVOw&&|Xa^W6(K2#pd;W@Jvx0eX_Qekbu+S}ES4Q*Go z*T?yFrjH)ofE{p6!RUYt%qrZNzLJ5Lp}!IQ19xP`&&& zZ3bC73?iB3&l%|TLK4}yUrkLYnP4of%|XM1v1Bxe6VmVrIYTImtNxHGhr={qYzx_w zBI|upOaDJv|$PIvOhf?pHO3Z|2m$VK1PF4Jg0a?_0>YNJwqT8 z_vd(AT->h{Uj6=bKfYgzfFObS{YI-5t*UnA_IFoty3VS4Z#HUl4bc8>90dVyVXT1P z6_R{BKT#91>{k*Q-L*L`r<5XE%u9^cPpz$?no=T4!atc(rsNc7qsydgb0@8JL{{T+ zCPmjwjL$=kq%gVS^hqVjzmhBEMgrf~sM$wKc#jCfwH_`51H@q3M-NAefOxJ;wU9a{- z=M<-|W2k1+2GjtpSMxacD8l5Ut1FDzPr(AkeWjIuR_}+K;D5`QWDwBoholJu+o~br zeN*6|{ZKw6OOM&}Igxy^%>Nq|*PTK8{@^X~^U?$MeD$K%&#rc^NxQ0_K1LcuA7J@( zzf#Iu!Gf!gGhvjUJPZ0W$C+HcT*WYM&d+!Jex8M3LNYDj#{`_dOM^UtH;l`P4DT@| z^SmQ1Yur44@TZkXLLZ0DCA@}FD@V-s3=xj{Z)H7t?$pf}4y{f*&jy;4jU0MvbePwT Y9eqv%I>GvU=>)z%>RE5W*4q2~AI5V#_y7O^ literal 0 HcmV?d00001 diff --git a/test/drivers/second_quantization/hdf5d/test_driver_hdf5_save.py b/test/drivers/second_quantization/hdf5d/test_driver_hdf5_save.py deleted file mode 100644 index 304222ef16..0000000000 --- a/test/drivers/second_quantization/hdf5d/test_driver_hdf5_save.py +++ /dev/null @@ -1,53 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2020, 2021. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. - -""" Test Driver HDF5 via saved QMolecule on new HDF5 """ - -import unittest -import tempfile -import os - -from test import QiskitNatureTestCase -from test.drivers.second_quantization.test_driver import TestDriver -from qiskit_nature.drivers.second_quantization import HDF5Driver - - -@unittest.skip("Until the Property framework supports HDF5 storage") -class TestDriverHDF5Save(QiskitNatureTestCase, TestDriver): - """Use HDF5 Driver to test saved HDF5 from QMolecule""" - - def setUp(self): - super().setUp() - driver = HDF5Driver( - hdf5_input=self.get_resource_path( - "test_driver_hdf5.hdf5", "drivers/second_quantization/hdf5d" - ) - ) - temp_qmolecule = driver.run() - file, self.save_file = tempfile.mkstemp(suffix=".hdf5") - os.close(file) - # pylint: disable=no-member - temp_qmolecule.save(self.save_file) - # Tests are run on self.qmolecule which is from new saved HDF5 file - # so save is tested based on getting expected values as per original - driver = HDF5Driver(hdf5_input=self.save_file) - self.qmolecule = driver.run() - - def tearDown(self): - try: - os.remove(self.save_file) - except OSError: - pass - - -if __name__ == "__main__": - unittest.main()