JuliaGPU / AMGX.jl

MIT License
11 stars 4 forks source link

`using AMGX` errors on non-supported machines -- is there a good way to conditionally use AMGX? #22

Closed navidcy closed 1 year ago

navidcy commented 1 year ago

So on a machine that can't support AMGX calling using AMGX gives an error. But it only gives that error the first time it's called! (See code below.)

Because using AMGX only errors the first time, an approach like

const hasamgx =
    try
        using AMGX
        true
    catch
        false
    end

won't work.

It would be good if using AMGX would always work. Otherwise developers need to figure out ways to load AMGX conditionally based on the machine. Any suggestions on how to do that? Or what's the best way to conditionally load AMGX? Is there, for example, a way to check whether libamgxsh exists or can be installed on the machine?

cc @glwagner, @Elise-palethorpe

(base) navid:~/ (main) $ julia --project
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.2 (2022-09-29)
 _/ |\__'_|_|_|\__'_|  |
|__/                   |

julia> using AMGX
ERROR: InitError: UndefVarError: libamgxsh not defined
Stacktrace:
 [1] getproperty
   @ ./Base.jl:31 [inlined]
 [2] __init__()
   @ AMGX ~/.julia/packages/AMGX/GFHHN/src/AMGX.jl:30
 [3] _include_from_serialized(pkg::Base.PkgId, path::String, depmods::Vector{Any})
   @ Base ./loading.jl:831
 [4] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt64)
   @ Base ./loading.jl:1039
 [5] _require(pkg::Base.PkgId)
   @ Base ./loading.jl:1315
 [6] _require_prelocked(uuidkey::Base.PkgId)
   @ Base ./loading.jl:1200
 [7] macro expansion
   @ ./loading.jl:1180 [inlined]
 [8] macro expansion
   @ ./lock.jl:223 [inlined]
 [9] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1144
during initialization of module AMGX

julia> using AMGX

julia> a=1
1
KristofferC commented 1 year ago

We could only run the __init__ stuff if AMGX.AMGX_jll.is_available() returns true.

navidcy commented 1 year ago

You mean in the __init__ of the AMGX package?