Skip to content

World Age Warning Due to Multiple sample Function Definitions #349

@nathanaelbosch

Description

@nathanaelbosch

Problem

JET.jl reports a world age warning during testing:

WARNING: Detected access to binding `ProbNumDiffEq.sample` 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.

Root Cause

We have two sample functions defined in different files:

  1. sample(process::AbstractGaussMarkovProcess, times, N=1) in src/priors/common.jl (line 247)
  2. sample(sol::ProbODESolution, n::Int=1) in src/solution_sampling.jl

During module loading, when the first sample method is defined, code paths that reference sample get compiled. When the second method is added later, this creates a world age boundary issue. The precompilation step in src/precompile.jl likely triggers this by executing code that might indirectly reference sample.

Proposed Solution

Rename one of these functions since they serve fundamentally different purposes:

  • sample(process::AbstractGaussMarkovProcess, ...)sample_process(...) or marginalize_and_sample(...)
  • sample(sol::ProbODESolution, ...)sample_solution(...) or keep as sample

Recommendation: Rename the prior's sample to sample_process since:

  1. It's the less commonly used function (internal to prior sampling)
  2. The solution sampling is the user-facing API and should keep the simpler name
  3. It makes the distinction clearer: sampling from a process vs. sampling solution trajectories

Additional Notes

This issue will become an error (not just a warning) in future Julia versions, so it needs to be fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions