Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDF5 Driver Update #550

Merged
merged 14 commits into from
Feb 22, 2022
Merged

Conversation

mrossinek
Copy link
Member

Summary

Refactors the HDF5Driver to be aligned with #461.
It will also support loading legacy QMolecule files stored in HDF5 files.

Details and comments

@mrossinek mrossinek mentioned this pull request Feb 10, 2022
10 tasks
@coveralls
Copy link

coveralls commented Feb 10, 2022

Pull Request Test Coverage Report for Build 1881110027

  • 39 of 41 (95.12%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 83.095%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit_nature/drivers/second_quantization/hdf5d/hdf5driver.py 39 41 95.12%
Files with Coverage Reduction New Missed Lines %
qiskit_nature/drivers/second_quantization/psi4d/psi4driver.py 1 84.43%
Totals Coverage Status
Change from base Build 1863627392: 0.03%
Covered Lines: 8764
Relevant Lines: 10547

💛 - Coveralls

@mrossinek mrossinek marked this pull request as ready for review February 11, 2022 07:59
@mrossinek mrossinek self-assigned this Feb 11, 2022
@mrossinek
Copy link
Member Author

I rebased this PR on #554, blocking it until that is merged.

@mrossinek mrossinek added the on hold Can not fix yet label Feb 14, 2022
dlasecki
dlasecki previously approved these changes Feb 15, 2022
@@ -62,8 +74,64 @@ def run(self) -> ElectronicStructureDriverResult:
if not os.path.isfile(hdf5_file):
raise LookupError(f"HDF5 file not found: {hdf5_file}")

return hdf5_file

def convert(self, replace: bool = True) -> None:
Copy link
Member

@woodsp-ibm woodsp-ibm Feb 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering about this being an instance method, but more so the default behavior of it overwriting of the same file is destructive if anything goes wrong or not what the user might have wanted. Something safer by default I think.

Now would this be better as a static method or function in this same module that takes the input file name, an optional output file name and replace False by default. So it becomes more of a conversion function that can be used that is not done as really an extension of driver functionality. By default the output file name could be the input file name part with _new appended. E.g I give it "h2_631g.hdf5" which is a legacy hdf5 and it would create, by default, "h2_631g_new.hdf5", unless I give it an explicit name. If the output already exists, for whatever, it would require them to set replace to True. Buyer beware I guess if you give the output file the same name as the input and replace True. But at least it would not be the default behavior where they may lose their input file with it being overwritten and intended to keep it. If the input is not a legacy hdf5 file the raise an error indicating that etc.

If you prefer to keep this as an instance method, supplying the source file to be converted via the constructor I the behavior could still be the same as described for the function above - just that the source name would not need to be provided.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the default value of replace and the HDF5 suffix handling.

However, I kept convert() as an instance method. My reasoning is that a user may encounter the warning of using a legacy file at runtime where they already instantiated the driver object. They can then simply run driver.convert() to update the legacy file.

Copy link
Contributor

@pbark pbark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @mrossinek!

@mrossinek mrossinek merged commit 937cf0e into qiskit-community:main Feb 22, 2022
@mrossinek mrossinek deleted the hdf5_driver_update branch February 22, 2022 11:52
Anthony-Gandon pushed a commit to Anthony-Gandon/qiskit-nature that referenced this pull request May 25, 2023
* refactor: basic HDF5Driver update

* test: test both HDF5 type supports

* Fix copyright

* test: update new expected HDF5 file

* ref: align new HDF5Driver with qiskit-community#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 <bpa@zurich.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants