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

Update random_seed behavior in config to be less confusing. #1309

Merged
merged 8 commits into from
Sep 11, 2024

Conversation

rmjarvis
Copy link
Member

@rmjarvis rmjarvis commented Aug 8, 2024

@kailicao discovered an error in the recent Roman image simulations where the random seed was not updating for each galaxy as expected. This only affected Poisson noise on the flux values (the "realized flux"), since most values were from SkyCatalog, not generated from an rng. But the statistics of the fluxes ended up messed up.

@matroxel and I tracked down the problem to the random_seed specification in the config file, which used a dict to evaluate a value based on the input file. This was intended to be the initial seed, to be converted into a sequence as usual. But the (documented) behavior in that case is to take the user's dict specification as is, and not convert it. This is confusing behavior, since most of the time evaluation like this is equivalent to setting a literal value.

Troxel also noticed that imsim's example config has the same problem, although the config files used by @jchiang87 for the recent simulation runs didn't use that. (It used a string eval value for the seed.) So imsim users may also be getting wrong random values currently.

So I changed the behavior to always convert the first random_seed in the list (or only one if not a list) into the sequence in the usual way. Any other items in the list are evaluated as the user specifies. This is technically an API change, since it's possible that some users have been relying on the old behavior to leave dict specifications as is and convert int or str values. However, (a) I think it's unlikely that anyone was using this feature other than to have the first item be normal and later items be dicts, and (b) we know of two accidental erroneous usages mentioned above, and it wouldn't surprise me if there were others. So this is more like a bug fix than a feature change. Anyway, I document it as an API change nonetheless to warn users who might be relying on the old behavior.

@rmjarvis rmjarvis added bug report Bug report config Related to the config-processing functionality. labels Aug 8, 2024
@rmjarvis rmjarvis added this to the v2.6 milestone Aug 8, 2024
Copy link
Member

@jmeyers314 jmeyers314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

to be some complex Eval operation, you should make it a dict with an explicit
``type: Eval``, rather than use the ``$`` shorthand notation.

* If ``random_seed`` is a list, then the first one will be converted as described above, but the later ones will not. Rather, it will respect your specification and evaluate the seed for each object as you specifiy. This will create multiple random number generators, according to the multiple seed specifications. This is normally used to have one random number behave normally for noise and such, and another one (or more) repeat with some other cadence (e.g. repeat for each image in an exposure to make sure you generate the same PSFs for multiple CCDs in an exposure). See `Demo 7` and `Demo 13` for examples of this. Whenever you want to use an rng other than the first one, add ``rng_num`` to the field and set it to the number of the rng you want to use in this list.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe specify that rng_num starts at 0.

galsim/config/util.py Outdated Show resolved Hide resolved
rmjarvis and others added 2 commits August 19, 2024 13:42
typo

Co-authored-by: Josh Meyers <jmeyers314@gmail.com>
@rmjarvis rmjarvis merged commit ed67f0a into main Sep 11, 2024
10 checks passed
@rmjarvis rmjarvis deleted the random_seed_dict branch September 11, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Bug report config Related to the config-processing functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants