TRIQS / h5

A high-level C++ interface to the hdf5 library
https://triqs.github.io/h5
Other
3 stars 7 forks source link

Allow creation of softlinks #9

Closed hmenke closed 2 years ago

hmenke commented 2 years ago

This feature is quite useful for having a link in the output archive that always points to the last iteration of the calculation.

import h5

for it in range(5):
    # DMFT loop
    with h5.HDFArchive("/tmp/test.h5", "a") as A:
        iteration = "it-{:03d}".format(it)
        A.create_group(iteration)
        A[iteration]["test"] = it
        A.create_softlink(iteration, "it-last")
$ h5ls /tmp/test.h5 
it-000                   Group
it-001                   Group
it-002                   Group
it-003                   Group
it-004                   Group
it-last                  Soft Link {it-004}
$ h5ls -d /tmp/test.h5/it-last/test
test                     Dataset {SCALAR}
    Data:
        (0) 4
hmenke commented 2 years ago

The interface files have been updated by hand again, because there are some other weird c++2py generation errors.

$ c++2py h5py_io.hpp --members_read_only -N h5 -a _h5py -m _h5py -o _h5py --moduledoc="A lightweight hdf5 python interface" --cxxflags="-std=c++20" --includes=./../../c++ --only="object file group h5_read_bare h5_write_bare"
Welcome to C++2py
Parsing the C++ file (may take a few seconds) ...
... done. 

Analysing dependencies
====================
Error : The following types can not be converted: 

char * (char *)
Traceback (most recent call last):
  File "/home/og85ixak/Code/triqs/triqs_unstable/install/bin/c++2py", line 100, in <module>
    W.generate_desc_file(output_filename = (args.outputname or filename_1) + "_desc.py")
  File "/home/og85ixak/Code/triqs/triqs_unstable/install/lib/python3.8/site-packages/cpp2py/cpp2desc.py", line 288, in generate_desc_file
    import_list, converters_list = self.DE(self.get_all_params_ret_type(param_cls_list), types_being_wrapped_or_converted)
  File "/home/og85ixak/Code/triqs/triqs_unstable/install/lib/python3.8/site-packages/cpp2py/dependency_analyzer.py", line 75, in __call__
    raise TypeError("")
TypeError
Wentzell commented 2 years ago

The interface files have been updated by hand again, because there are some other weird c++2py generation errors.

Yes, I currently get the same error.

While the file header suggests differently this file was adjusted manually to avoid wrapping also the h5::object class.

A manual edit is the proper solution here, sorry for the confusion.

hmenke commented 2 years ago

I've introduced an additional parameter bool delete_if_exists = true (same as for create_group). Please review again, then I will squash and rebase.

Wentzell commented 2 years ago

Thank you @hmenke for the update! Could you possibly extend the test to check that you can successfully write over existing keys, and that you raise an exception for delete_if_exists = False ? C.f. assertRaises

hmenke commented 2 years ago

Squashed and rebased.