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

Use Preferences for using custom hdf5 library #1061

Merged
merged 41 commits into from
Jun 2, 2023

Conversation

JoshuaLampert
Copy link
Contributor

@JoshuaLampert JoshuaLampert commented Apr 19, 2023

This switches to Preferences.jl for using a system-provided hdf5 library and replaces the additional build step. Additionally, I allowed additional names of the library binaries as in my case, e.g., the binaries are located in /usr/lib/x86_64-linux-gnu/libhdf5_openmpi.so and /usr/lib/x86_64-linux-gnu/libhdf5_openmpi_hl.so.

closes #1037

cc @ranocha, @sloede

@JoshuaLampert
Copy link
Contributor Author

Honestly, I don't understand why the tests complain about Package HDF5 does not have HDF5_JLL in its dependencies. Isn't HDF5_jll listed as a dependency here or am I missing something stupid?

Project.toml Outdated Show resolved Hide resolved
src/api/api.jl Outdated Show resolved Hide resolved
src/api/api.jl Outdated Show resolved Hide resolved
Project.toml Outdated Show resolved Hide resolved
docs/src/index.md Show resolved Hide resolved
docs/src/mpi.md Show resolved Hide resolved
src/api/api.jl Outdated Show resolved Hide resolved
@JoshuaLampert JoshuaLampert marked this pull request as ready for review April 19, 2023 15:33
@mkitti
Copy link
Member

mkitti commented Apr 19, 2023

Please run the formatter. See the contrib folder for a utility.

Also this is breaking so I think we will want to version bump to 0.17 unless we implement a fallback. I'm also wondering if we could include a migration utility.

@sloede
Copy link
Contributor

sloede commented Apr 20, 2023

Also this is breaking so I think we will want to version bump to 0.17 unless we implement a fallback. I'm also wondering if we could include a migration utility.

MPI.jl had performed a similar migration last year, from configuration via environment variables to using Preferences. Back then they solved this by adding a migration guide to the docs and included notes for HPC administrators on how to configure this on clusters with managed MPI/HDF5 installations. Maybe this can serve as a blueprint for this PR here as well?

@ranocha
Copy link
Contributor

ranocha commented Apr 20, 2023

Also this is breaking so I think we will want to version bump to 0.17 unless we implement a fallback. I'm also wondering if we could include a migration utility.

This should probably be mentioned in https://github.com/JuliaIO/HDF5.jl/blob/master/HISTORY.md, too, I guess?

@mkitti
Copy link
Member

mkitti commented Apr 20, 2023

Yes, please document this as much as possible. If we do provide migration instructions, that should also be tested.

@JoshuaLampert
Copy link
Contributor Author

I provided some migration instructions.

@sloede
Copy link
Contributor

sloede commented Apr 21, 2023

I provided some migration instructions.

This reads already very well! One suggestion from my side: Maybe you can give an example for admins of clusters what the Preferences file could look like and maybe explicitly mention that for backward compatibility it is recommended to both set the environment variables and use the Preferences file for the time being. But these are just suggestions, they are not critical IMHO. Other than that, this PR LGTM!

@JoshuaLampert
Copy link
Contributor Author

I've also added an example of how the LocalPreferences.toml could look like and added a recommendation to also set the environment variable for backward compatibility.

@sloede
Copy link
Contributor

sloede commented Apr 21, 2023

I've also added an example of how the LocalPreferences.toml could look like and added a recommendation to also set the environment variable for backward compatibility.

Great, thanks!

@JoshuaLampert
Copy link
Contributor Author

JoshuaLampert commented May 31, 2023

For me, it's also failing on master with the same error using a local libhdf5 v1.10.6 on

julia> versioninfo()
Julia Version 1.9.0
Commit 8e630552924 (2023-05-07 11:25 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
  Threads: 1 on 8 virtual cores
Environment:
  JULIA_HDF5_PATH = /usr/lib/x86_64-linux-gnu/hdf5/openmpi

I'm rather confused why it's not failing in the other CI tests from other PRs.

@simonbyrne
Copy link
Collaborator

I think the problem is that h5d_get_space is broken for virtual datasets for libhdf5 1.10. At the moment, we only test custom hdf5 build on Julia 1.3, and where we disable the virtual dataset tests.

We previously thought it was a buggy JLL, but it could just be all v1.10. I was able to replicate the error with a local build using libhdf5 1.10.7.

I suggest we just disable the virtual dataset tests if using libhdf5 <1.12.

@JoshuaLampert
Copy link
Contributor Author

That totally makes sense. Thanks, @simonbyrne! I disabled the virtual datasets tests for libhdf5 < 1.12.

@JoshuaLampert
Copy link
Contributor Author

Loading MPI.jl before HDF5.jl is not required anymore with Preferences.jl, right? I changed the docs accordingly.

@ranocha
Copy link
Contributor

ranocha commented Jun 1, 2023

Status of this PR is that HDF5.jl still uses Requires.jl to load the MPI code, doesn't it? If so, it's still necessary to first load MPI.jl as far as I know

Copy link
Contributor

@ranocha ranocha left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good to me. Let's keep fingers crossed that tests pass 🤞

@mkitti
Copy link
Member

mkitti commented Jun 1, 2023

Could we issue a warning if we detect that the environment variable JULIA_HDF5_PATH is set?

@mkitti mkitti requested a review from simonbyrne June 1, 2023 15:29
@JoshuaLampert
Copy link
Contributor Author

Could we issue a warning if we detect that the environment variable JULIA_HDF5_PATH is set?

Done in 8e98087.

Copy link
Member

@mkitti mkitti left a comment

Choose a reason for hiding this comment

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

The warning should be done during __init__ since the environment can change after precompilation occurs. Also, since we are encouraging people to set both the enviornment variable and Preferences.jl we should not warn if they are in fact using both.

I'm also wondering if we should just add a convenience method HDF5.API.set_libraries!.

const HDF5_JL_UUID = UUID("f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f")

function set_libraries!(libhdf5 = nothing, libhdf5_hl = nothing; force = true)
   if isnothing(libhdf5) && isnothing(libhdf5_hl)
      delete_preferences!(HDF5_JL_UUID, "libhdf5")
      delete_preferences!(HDF5_JL_UUID, "libhdf5_hl")
      delete_preferences!("HDF5_jll", "libhdf5", "libhdf5_hl")
      @info "The libraries from HDF5_jll will be used."
    elseif isnothing(libhdf5) && isnothing(libhdf5_hl)
        throw(ArgumentError("Specify either no positional arguments or both positional arguments."))
   else
       isfile(libhdf5) || throw(ArgumentError("$libhdf5 is not a file that exists.")
       isfile(libhdf5_hl) || throw(ArgumentError("$libhdf5_hl is not a file that exists.")
       set_preferences!(HDF5_JL_UUID, "libhdf5" => libhdf5; force)
       set_preferences!(HDF5_JL_UUID, "libhdf5_hl" => libhdf5_hl; force)
       # Also set the HDF5_jll override settings in case some other package tries to use HDF5_jll
       set_preferences!(
           "HDF5_jll",
           "libhdf5_path" => libhdf5,
           "libhdf5_jl_path" => libhdf5_jl
       )
   end
   @info "Please restart Julia and reload HDF5.jl for the library changes to take effect"
end

See https://github.com/jheinen/GR.jl/blob/master/src/preferences.jl for further inspiration. Perhaps that is for another pull request.

src/api/api.jl Outdated Show resolved Hide resolved
src/api/api.jl Show resolved Hide resolved
import UUIDs, Preferences
Preferences.set_preferences!(
UUIDs.UUID("f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"), # UUID of HDF5.jl
"libhdf5" => joinpath(JULIA_HDF5_PATH, "libhdf5.so");
Copy link
Member

Choose a reason for hiding this comment

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

Could libhdf5.so also be in a lib or lib64 subdirectory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not as it is now. Primarily, I created this file for CI, where we know, where the binaries are located. Now, that we suggest the user to have a look at this file, it would probably be nice to also allow the binaries to be in joinpath(JULIA_HDF5_PATH, "lib") or joinpath(JULIA_HDF5_PATH, "lib64").

test/configure_packages.jl Outdated Show resolved Hide resolved
test/configure_packages.jl Outdated Show resolved Hide resolved
test/configure_packages.jl Outdated Show resolved Hide resolved
docs/src/index.md Show resolved Hide resolved
@mkitti
Copy link
Member

mkitti commented Jun 1, 2023

I think we should also document configuring HDF5_jll as well in case some other package tries to load that.

See https://docs.binarybuilder.org/stable/jll/#Overriding-specific-products

docs/src/mpi.md Outdated Show resolved Hide resolved
@mkitti
Copy link
Member

mkitti commented Jun 2, 2023

If you would prefer, I would be fine merging this as is and implementing the above later.

@JoshuaLampert
Copy link
Contributor Author

I addressed most of the suggestions. The remaining parts can be done in a separate PR.

@mkitti mkitti merged commit 4d446fc into JuliaIO:master Jun 2, 2023
@sloede
Copy link
Contributor

sloede commented Jun 2, 2023

🥳

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.

Switch to Preferences for using system hdf5
5 participants