This PR makes it possible to reproduce datasets, and individual images from training datasets (without generating all previous images). This should be useful e.g. to generate convergence maps, or the list of subhalo masses and positions, for specific images in datasets we are interested in.
Paltas already allows you to set the numpy random seed via the config. However, it also draws some random numbers from numba, which uses a separate random number generator. Thus, setting the seed in paltas' config does not yet result in predictable images. This also means some of the unit tests are not fully deterministic.
After this PR:
We re-seed the numpy random number generator before generating each image, and seed the separate numba random generator right after that.
The first generated image uses a base seed. The second uses a tuple (base_seed, 1) as a seed (or base_seed + (1,) if base_seed is already a tuple), then (base_seed, 2), etc. Numpy uses SeedSequence internally to turn these low-quality (not very random) seeds into high-quality seeds, see e.g. here.
If the user doesn't specify a base seed to use in the config, ConfigHandler will set the random number generator seed to a random int64. (We could use a larger seed, but this way seeds are still easy to copy-paste from metadata.)
We're not exactly following best practice with random number generators: current wisdom avoids np.seed and instead makes separate random generator instances and passes them around the code. That would be a much bigger change affecting the entire code though.
Two minor changes smuggled in:
When creating the folder with npy images files, allow the folder to already exist. The mkdir can be triggered if the folder already exists, when the catalog's main npy is missing (for some reason).
Do not create a tfrecord during the generate tests, so we can run all the non-analysis tests in environments without tensorflow. The tfrecord was not actually tested anyway (other than implicity requiring it exists by the os.remove cleanup statement). If you'd rather the file is made during testing we could e.g. check if tf imports, and only ask for the tfrecord in the tests if it does.
This PR makes it possible to reproduce datasets, and individual images from training datasets (without generating all previous images). This should be useful e.g. to generate convergence maps, or the list of subhalo masses and positions, for specific images in datasets we are interested in.
Paltas already allows you to set the numpy random seed via the config. However, it also draws some random numbers from numba, which uses a separate random number generator. Thus, setting the seed in paltas' config does not yet result in predictable images. This also means some of the unit tests are not fully deterministic.
After this PR:
ConfigHandler
will set the random number generator seed to a random int64. (We could use a larger seed, but this way seeds are still easy to copy-paste from metadata.)We're not exactly following best practice with random number generators: current wisdom avoids
np.seed
and instead makes separate random generator instances and passes them around the code. That would be a much bigger change affecting the entire code though.Two minor changes smuggled in: