"Error Importing Custom Julia Package: UndefVarError: Zygote not defined Despite Dependency Declaration"

I’m trying to import a developed package, but I get the following error:

julia> using RandomProjections
[ Info: Precompiling RandomProjections [acf8f2c6-418f-403f-a7f7-d35fd4a663f5]
ERROR: LoadError: UndefVarError: `Zygote` not defined
Stacktrace:
 [1] top-level scope
   @ :0
 [2] include
   @ ./Base.jl:457 [inlined]
 [3] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
   @ Base ./loading.jl:2010
 [4] top-level scope
   @ stdin:2
in expression starting at /Users/jmfrutos/.julia/dev/RandomProjections/src/RandomProjections.jl:117
in expression starting at /Users/jmfrutos/.julia/dev/RandomProjections/src/RandomProjections.jl:117
in expression starting at stdin:2
ERROR: Failed to precompile RandomProjections [acf8f2c6-418f-403f-a7f7-d35fd4a663f5] to "/Users/jmfrutos/.julia/compiled/v1.9/RandomProjections/jl_55w7Tu".

I’m not quite sure why, since Zygote is listed in my dependencies:

name = "RandomProjections"
uuid = "acf8f2c6-418f-403f-a7f7-d35fd4a663f5"
authors = ["José Manuel de Frutos"]
version = "1.0.0-DEV"

[deps]
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
KernelDensity = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Memoize = "c03570c3-d221-55d1-a50c-7939bbd78826"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

Not defined likely means you’re missing using Zygote somewhere in the code itself?

I have it

module RandomProjections

export RandomProjection, apply_defining_function, get_powers, homopoly, linear_projection, poly_projection, circular_projection, random_slice, get_slice, max_rand_proj, max_rand_proj_with_nn

using Flux
using Zygote
using Random
using LinearAlgebra
using ProgressMeter
using Memoize
1 Like

Hmm. What at line 117, where it is pointing?

Yes, sorry, first line is 117

Zygote.@nograd function get_powers(dim::Int, degree::Int)
    """
    Generates the powers of a homogeneous polynomial.

    Example:
    get_powers(2, 3) -> [(0, 3), (1, 2), (2, 1), (3, 0)]
    get_powers(3, 2) -> [(0, 0, 2), (0, 1, 1), (0, 2, 0), (1, 0, 1), (1, 1, 0), (2, 0, 0)]
    """
    if dim == 1
        return [(degree,)]
    else
        result = []
        for value in 0:degree
            for permutation in get_powers(dim - 1, degree - value)
                push!(result, tuple(value, permutation...))  # Concatenating the current value with the permutation
            end
        end
        return result
    end
end

I wonder if having the exports before the usings is doing something?

Other than that, I assume you’ve tried reloading the REPL?