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

Many packages fail with UndefVarError now #57328

Open
KristofferC opened this issue Feb 10, 2025 · 15 comments
Open

Many packages fail with UndefVarError now #57328

KristofferC opened this issue Feb 10, 2025 · 15 comments
Milestone

Comments

@KristofferC
Copy link
Member

KristofferC commented Feb 10, 2025

https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_hash/7825364_vs_d63aded/report.html

With the new binding rules there are many patterns used in the wild that now causes UndefVarError. The amount of breakage is a bit too high in my opinion so it would be good to see if some mechanisms could be created that would soften this breakage. Some patterns:

~ 150 packages fail with some Zygote issue:

Failed to precompile Zygote [e88e6eb3-aa80-5325-afca-941959d7151f] to "/home/pkgeval/.julia/compiled/v1.12/Zygote/jl_xJEA0V".
WARNING: Detected access to binding `Forward._pushforward` in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
ERROR: LoadError: UndefVarError: `chain_rrule` not defined in `Base`
Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/Zygote/TWpme/src/compiler/interface2.jl:-1 [inlined]
  [2] _pullback(::Zygote.Context{false}, ::typeof(>), ::Int64, ::Int64)
    @ Zygote ~/.julia/packages/Zygote/TWpme/src/compiler/interface2.jl:91
  [3] _pullback(::Zygote.Context{false}, ::typeof(Zygote.pow), ::Int64, ::Int64)
    @ Zygote ~/.julia/packages/Zygote/TWpme/src/compiler/interface2.jl:91
  [4] pullback(::Function, ::Zygote.Context{false}, ::Int64, ::Vararg{Int64})
    @ Zygote ~/.julia/packages/Zygote/TWpme/src/compiler/interface.jl:90
The set of packages that fail with `UndefVarError`
PrecompileTools
Requires
EnzymeCore
RoundingEmulator
LoweredCodeUtils
CompTime
CryptoGroups
FlatBuffers
RecurrenceAnalysis
GeoParams
BlockTensorKit
CTBase
Tensorial
TemporalGPs
DimensionfulAngles
Tracy
ADOLC
IntervalLinearAlgebra
CSDP
PowerSystemCaseBuilder
GridMaps
AStarGridSearch
AdaptiveSparseGrids
XDiag
RustFFT
Presentation
XmlStructWriter
ToyPublicKeys
JuDGE
CircleFit
AbsSmoothFrankWolfe
PowerModelsAnnex
RadiationPatterns
SphericalScattering
SUNRepresentations
CategoryData
IESopt
HomalgProject
RHEOS
PowerPlots
ConstrainedDynamicsVis
Tasmanian
ForestMensuration
Supernovae
NuclearToolkit
CropRootBox
Packages that fail with Zygote undefvar error:
SymbolicIndexingInterface
Functors
Roots
SciMLJacobianOperators
Optimisers
MLUtils
SymbolicUtils
MarchingCubes
LinearOperators
CoordRefSystems
LogDensityProblemsAD
DataScienceTraits
TransmuteDims
GeoTables
DifferentiableFlatten
AbstractGPs
AbstractDifferentiation
NonconvexCore
GeoStatsBase
ReinforcementLearningCore
ParameterHandling
FourierTools
PrimitiveOneHot
VLBILikelihoods
JOLI
ReinforcementLearning
GeoStatsFunctions
ParameterSchedulers
EnergySamplers
GeoStatsModels
MLJFlux
ExponentialAction
ForwardDiffPullbacks
StandardizedRestrictedBoltzmannMachines
GPLikelihoods
BaytesMCMC
JUDI
UnderwaterAcoustics
GslibIO
FluxTraining
NonconvexIpopt
AutoDiffOperators
QuantumGradientGenerators
SliceMap
OptimizationNLopt
NonconvexMMA
CallableExpressions
GCMAES
ControllerFormats
ProximalAlgorithms
CenteredRBMs
Stheno
NonconvexSemidefinite
NonconvexPercival
JetPack
GeoIO
UnitfulChainRules
DiffImageRotation
RadonKA
TensorGames
BayesianLinearRegressors
DistributionMeasures
GraphSignals
CoordGridTransforms
ParametricMCPs
DifferentiableTrajectoryOptimization
ReinforcementLearningFarm
SurrogatesRandomForest
WaveOpticsPropagation
CountriesBorders
ReinforcementLearningZoo
RvSpectML
LoopFieldCalc
FactorLoadingMatrices
CannotWaitForTheseOptimisers
PositionalEmbeddings
AllocArrays
FinancialToolbox
MonotonicSplines
IsingModels
AdvRBMs
FlashAttentionWrapper
DifferentiableExpectations
PottsGumbelRBMLayers
LinearMixingModels
RandomFeatureMaps
BigO
DifferentiableFrankWolfe
SignalTemporalLogic
SNOW
ThermodynamicIntegration
NonconvexSearch
NonconvexNLopt
LowRankLayers
NonconvexMetaheuristics
FieldTracer
GraphNets
DiscoDiff
RecurrentLayers
LuxTestUtils
InvariantPointAttention
RobustNeuralNetworks
NonconvexNOMAD
ConjugateComputationVI
GaussianVariationalInference
MeshIntegrals
RelevancePropagation
MarginalLogDensities
TuringBenchmarking
OptimizationManopt
DiffFusion
DeconvOptim
JsonGrinder
DerivableFunctions
OptimizationFlux
MixtureDensityNetworks
DrillHoles
SuperfluidRotSpec
UlamMethod
SymbolicAnalysis
GlobalApproximationValueIteration
ParametrisedConvexApproximators
JointEnergyModels
RegressionDiscontinuity
GeoGrids
DeepQLearning
Gogeta
ObjectDetector
NonconvexJuniper
NonconvexPavito
CompressedBeliefMDPs
NonconvexBayesian
RvLineList
ColBERT
LocalAnisotropies
GeoStats
GeometricFlux
NeuralEstimators
ClapeyronHANNA
ElectrochemicalKinetics
ChainPlots
TaijaData
SimulatedNeuralMoments
Microstructure
PlantGeom
SwissVAMyKnife
TaijaPlotting
@Keno
Copy link
Member

Keno commented Feb 10, 2025

We could consider extending the backdating mechanism to more cases, but I'm not sure the two linked instances are good examples. The former does need to explicitly be updated because it deals with world ages. The latter example is just confused about the scope of those variables. The more backdating we do, the more problematic the semantics become.

@KristofferC
Copy link
Member Author

I just took two examples, maybe they were bad, there are 150 more to chose from.

@Keno
Copy link
Member

Keno commented Feb 10, 2025

Yeah, we'll have to go through them and see if there's some common themes that are useful to mitigate.

@KristofferC
Copy link
Member Author

Quite a few of these are actually due to

module_keys not defined in Base

which Is a completely separate JLD2 error.

@KristofferC
Copy link
Member Author

This is just unworkable I guess:

function createstruct(types::Vector{DataType}, A::Vector{T}) where {T}
	T1 = definestruct(types)
	eval(:(newt = $T1($(A...))))
	return newt
end

https://github.com/JuliaData/FlatBuffers.jl/blob/f8feaa977e34b073aa3653b43310a9f4049af7e3/src/FlatBuffers.jl#L420-L421

@KristofferC
Copy link
Member Author

https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_hash/7825364_vs_d63aded/RecurrenceAnalysis.primary.log

This package seems to export embed for no reason (https://github.com/JuliaDynamics/RecurrenceAnalysis.jl/blob/576b119e8d0d85077a976b53cdc80ca392582498/src/RecurrenceAnalysis.jl#L35), because it doesn't define it at all. Only when you load DelayEmbeddings (https://github.com/JuliaDynamics/RecurrenceAnalysis.jl/blob/576b119e8d0d85077a976b53cdc80ca392582498/test/skeletontest.jl#L2) do you get access to it. I guess the first dummy export now "pollutes" the namespace saying that embed has to refer to RecurrenceAnalysis.embed?

@lgoettgens
Copy link
Contributor

This is just unworkable I guess:

function createstruct(types::Vector{DataType}, A::Vector{T}) where {T}
	T1 = definestruct(types)
	eval(:(newt = $T1($(A...))))
	return newt
end

JuliaData/FlatBuffers.jl@f8feaa9/src/FlatBuffers.jl#L420-L421

I think that can just useinvokelatest(getproperty, .....).

I can transform (julia 1.11.3)

julia> module FooModule
           function foo()
               eval(:(bar = 3))
               return bar
           end
       end
Main.FooModule

julia> FooModule.foo()
3

to (julia nightly)

julia> module FooModule
           function foo()
               eval(:(bar = 3))
               return invokelatest(getproperty, FooModule, :bar)
           end
       end
Main.FooModule

julia> FooModule.foo()
3

@Keno
Copy link
Member

Keno commented Feb 10, 2025

I guess the first dummy export now "pollutes" the namespace saying that embed has to refer to RecurrenceAnalysis.embed?

Ambiguous bindings are no longer disambiguated by resolvedness, so it's possible to get more ambiguities (the UndefVarError should tell you that's it's ambiguous, though making the error message better is on my TODO list). That said, it's supposed to ignore bindings with undefined values in the lookup set. It's possible that's broken.

@Keno
Copy link
Member

Keno commented Feb 10, 2025

to (julia nightly)

Yes, and/or possibly the package author intended that variable to be const.

@giordano
Copy link
Contributor

which Is a completely separate JLD2 error.

Wasn't that fixed already in the package? Are these packages using an old version of JLD2?

@KristofferC
Copy link
Member Author

Are these packages using an old version of JLD2?

Yeah, it seems many were stuck on 0.4. We'll see if JuliaIO/JLD2.jl#631 helps at the next PkgEval run.

@KristofferC
Copy link
Member Author

KristofferC commented Feb 11, 2025

@KristofferC
Copy link
Member Author

KristofferC commented Feb 12, 2025

Here is a MWE of a failure in GeoParams (put this in a package) and do something like julia --project -e 'using GeoParams; @show GeoParams.A.B.C.S'. This works fine on 1.11 but errors on master with S not defined:

module GeoParams
    module A
        module B
            using GeoParams
            export S
            struct S end
            module C
                using GeoParams
                h() = S() # commenting this line: ok
                x -> nothing # changing this to a non-anon function: ok
            end
        end
    end

    using .A.B
    export S # moving this export up above module A: ok
end

The fact that the anonymous function is needed is quite wild.

@KristofferC
Copy link
Member Author

KristofferC commented Feb 12, 2025

Here is another MWE for (#57328 (comment)) here for https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_hash/7825364_vs_d63aded/BrillouinZoneMeshes.primary.log:

module M
    module A
        export S
    end
    using .A
    module B
        abstract type S end
        export S
    end
    using .B
    S
end

During package precompilation you don't really get a good error message but pasting into the REPL you see

ERROR: UndefVarError: `S` not defined in `Main.M`
Hint: It looks like two or more modules export different bindings with this name, resulting in ambiguity. Try explicitly importing it from a particular module, or qualifying the name with the module it should come from.

(And no, I don't know why people write their code like this...)

@KristofferC
Copy link
Member Author

KristofferC commented Feb 14, 2025

The Zygote error is basically (need to comment out the precompile.jl file in Zygote to get it to load):

julia> using Zygote

# 1.12
julia> code_warntype(Zygote._pullback, Tuple{Zygote.Context{false}, typeof(>), Int64, Int64})
MethodInstance for ZygoteRules._pullback(::Zygote.Context{false}, ::typeof(>), ::Int64, ::Int64)
  from _pullback(ctx::ZygoteRules.AContext, f, args...) @ Zygote ~/PkgEvalAnalysis/JuliaPkgs/Zygote.jl/src/compiler/interface2.jl:101
Arguments
  methodinstance::Core.Const(ZygoteRules._pullback)
  ctx::Zygote.Context{false}
  f::Core.Const(>)
  args::Tuple{Int64, Int64}
Body::Any
1%1 = Base.chain_rrule::Any # <----------------------------- Base module
...

# 1.11
julia> code_warntype(Zygote._pullback, Tuple{Zygote.Context{false}, typeof(>), Int64, Int64})
MethodInstance for ZygoteRules._pullback(::Zygote.Context{false}, ::typeof(>), ::Int64, ::Int64)
...
Body::Tuple{Bool, Zygote.ZBack{Returns{Tuple{ChainRulesCore.NoTangent, ChainRulesCore.NoTangent, ChainRulesCore.NoTangent}}}}
1%1 = Zygote.chain_rrule::Core.Const(Zygote.chain_rrule) # <---------------------------- Zygote module
...

where there is a disagreement over what module the chain_rrule function refers to (Base vs Zygote). The chain_rrule symbol gets inserted in an expression at

https://github.com/FluxML/Zygote.jl/blob/12cd77d82546674e4951b900e6c8076d94e397b4/src/compiler/interface2.jl#L15-L25

which is then used as input into the Core.GeneratedFunctionStub at:

https://github.com/FluxML/Zygote.jl/blob/12cd77d82546674e4951b900e6c8076d94e397b4/src/compiler/interface2.jl#L77-L89

I don't really know what determines what module this should be "expanded" into (probably something with the source input (which has a different type on 1.11 vs 1.12).

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

No branches or pull requests

4 participants