JLD.jl icon indicating copy to clipboard operation
JLD.jl copied to clipboard

Conditional loading requires file to exist at "Compile time"

Open krcools opened this issue 8 years ago • 1 comments
trafficstars

I often use a pattern where my code can run in one of two modes:

  • Record, where benchmark results are created
  • Playback, where previously recorded results are used in regression testing or post-processing

This leads to code snippets like:

record = true
if record
    println("Recording mode...")
    a = 42
    @save "bench.jld" a
else
    println("Playback mode...")
    @load "bench.jld"
end

Running this leads to ErrorException("File bench.jld cannot be found") being thrown. Apparently the file is required to exist during macro expansion as opposed to at runtime.

Is this required in the current design of JLD or can this requirement be relaxed?

krcools avatar Oct 12 '17 09:10 krcools

Give it a shot! But if memory serves those macros are pretty horrifying. Easiest is to use the functional forms of load and save.

timholy avatar Oct 12 '17 16:10 timholy