I have a code that takes a long time to run, longer than the max allowed walltime on the cluster. It relies on rand(), so in order to run the code in multiple sequences on the cluster, I am using
julia> r = copy(Random.GLOBAL_RNG)
to capture the state of the global random number generator at the end of a run. I need to save 'r' to a file, then read that variable from the file when I start up the next run on the cluster -- in essence to be able to "pick up where I left off". When I try (using the package DelimitedFiles):
julia> writedlm("rngState.bin",r)
however, I get the following error
ERROR: MethodError: no method matching iterate(::MersenneTwister)
Closest candidates are:
iterate(::Core.SimpleVector) at essentials.jl:568
iterate(::Core.SimpleVector, ::Any) at essentials.jl:568
iterate(::ExponentialBackOff) at error.jl:199
Which leads me to believe that the state of a Mersenne Twister rng is not something that can be written to a file. Is this correct? Does anyone know how I could save the state of the GLOBAL_RNG to a file so I can read it back in later to pick up where I left off?
Aucun commentaire:
Enregistrer un commentaire