-
Notifications
You must be signed in to change notification settings - Fork 127
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
Support for h5read
#637
Comments
Good catch that this doesn't work. I had in fact been wanting to move to a system where you don't have to specify the type at all, but instead when we write types to HDF5 it includes a string saying what the type is. This string would be eval'd when we read the data back in to generate an actual Julia type, at which point we call the type-specific version of h5read internally. But you've definitely hit upon an issue that I was coming across, namely that we might want to write data of various closely related types such as Index{T} for various values of T. But then in a lot of cases it's not a priori clear how specific of a type we should put, and whether it should be a common abstract type like Index, or the exact type etc. Probably it should be the "exact enough" type, meaning enough to represent the data stored. So it's something we should discuss. |
Yeah, in that case it seems like it could be a minimal amount of type information to reconstruct the original object. In general it isn't necessary to store The issues I was more focusing on were:
Also see the discussion here, a safer alternative to using |
Glad you agree, and a related thought about which type to store is that the more abstract or general information that we put into the file, the more "forward compatible" or "future proof" it will be. So like e.g. if we decide to change some detail about whether the QN's are stored in a tuple or a vector (just making this up) and if that reflects in the type, not to have that break all previously written HDF5 files. But even if we do break compatibility, I had been thinking of and already implementing a versioning system where we put a version number and keep older reading-in code around if we detect older versions. It won't work perfectly but may allow some smooth upgrading across many versions. To your point #2, you're right we couldn't really change the behavior of |
Don't know if this issue is still a concern now. Just to share some ideas. Have you checked JLD2.jl? It's quite stable now and able to store Julia struct, while compatible for HDF5 format. (Also a basic visualization support is currently provided by the vscode H5web extension) If there's too large a work to migrate or maintain, just forget what I've said. :) |
We have considered JLD2, and in our own usage have found it works well. One nice thing about it, you may know, is that it doesn't require us to add explicit support for many, maybe most, of our types since it is able to figure out automatically how to write them to disk. So users are welcome and encouraged to try JLD2 for their data including data from ITensor. Meanwhile, we do still plan to also support HDF5 since it's usable across multiple languages, more standard, etc. |
@emstoudenmire probably you have investigated this but I was interested in the current state of
h5read
when looking over the docs you moved over here: #634.Unfortunately, the more compact notation for reading using
h5read
doesn't work for some (maybe all?) of our types:There are two issues going on here. In the first issue, I believe it is more of a limitation on the HDF5.jl side, where
Index
is technically an abstract typeIndex{T} where {T}
withtypeof(Index) === UnionAll
, whileh5read
only accepts a concrete type likeIndex{Int}
withtypeof(Index{Int}) === DataType
. In the second issue, the problem is more on our side, since we don't allow specifying a concrete type in this case, so we could expand the definition here to accept a more generalType{<: Index}
. However, this fix is still inconvenient, since we don't want people having to specify the particular concreteIndex{Int}
type.The version without the explicit type runs:
but of course doesn't output an
Index
, just some default data structure. It is difficult to find information about how to make this work for custom types, but my understanding from this comment is that you may need to define a custom file format. This makes a certain amount of sense, since then the file format can be determined and dispatched on, and without that there doesn't seem to be a way to tell HDF5.jl to do some special parsing of the files to search for ITensor-specific type information. @emstoudenmire, have you investigated this? That seems like the strategy the packages like JLD.jl take for saving and loading custom types.The text was updated successfully, but these errors were encountered: