Skip to content

Commit

Permalink
Add a warning if the user has a Sequence for the first random_seed.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmjarvis committed Aug 9, 2024
1 parent 944d0d0 commit 79fbdb7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 12 additions & 1 deletion galsim/config/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from ..utilities import SimpleGenerator, single_threaded
from ..random import BaseDeviate
from ..errors import GalSimConfigError, GalSimConfigValueError, GalSimError
from ..errors import GalSimConfigError, GalSimConfigValueError, GalSimError, galsim_warn

max_queue_size = 32767 # This is where multiprocessing.Queue starts to have trouble.
# We make it a settable parameter here really for unit testing.
Expand Down Expand Up @@ -396,6 +396,17 @@ def ParseRandomSeed(config, param_name, base, seed_offset):
# are left as they are, so the user can do something more complicated if they want.
if param_name in ['random_seed', 0] and not (
isinstance(config[param_name], dict) and config[param_name].get('default', False)):
if (isinstance(config[param_name], dict)
and config[param_name].get('type',None) == 'Sequence'):
# Not really a deprecation, but similar.
# Warn users of the change in behavior.
galsim_warn('You have a custom Sequence as the (first) random_seed. '
'As of GalSim version 2.6, this will be parsed as an integer '
'and converted to a new sequence indexed by obj_num, '
'rather than whatever sequence you have specified. '
'You probably want to put your custom random_seed sequence '
'as the second item in the radom_seed list and use rng_num=1.')

first = ParseValue(config, param_name, base, int)[0]
seed_rng = BaseDeviate(first)
new_first = seed_rng.raw()
Expand Down
12 changes: 11 additions & 1 deletion tests/test_config_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,7 @@ def test_multirng():
np.testing.assert_array_equal(im.array, images2[n].array)
np.testing.assert_array_equal(im.array, images3[n].array)

# Finally, test invalid rng_num
# Test invalid rng_num
config4 = galsim.config.CopyConfig(config)
config4['image']['world_pos']['rng_num'] = -1
with assert_raises(galsim.GalSimConfigError):
Expand All @@ -2354,6 +2354,16 @@ def test_multirng():
with assert_raises(galsim.GalSimConfigError):
galsim.config.BuildImage(config7)

# Check that a warning is given if the user uses a Sequence for the first random seed.
config8 = galsim.config.CopyConfig(config)
config8['image']['random_seed'] = {
'type': 'Sequence',
'repeat': 3
}
with assert_warns(galsim.GalSimWarning):
galsim.config.BuildImage(config8)


@timer
def test_sequential_seeds():
"""Test using sequential seeds for successive images.
Expand Down

0 comments on commit 79fbdb7

Please sign in to comment.