Skip to content

Commit

Permalink
Workaround for scipy.stats seeding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleAalbers committed Sep 12, 2022
1 parent d126573 commit 2b3950d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions paltas/Sampling/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
set from the input distributions.
"""
import warnings
from scipy._lib._util import check_random_state

# Definte the components we need the sampler to consider.
# TODO: add point source & lens light
lensing_components = ['subhalo','los','main_deflector','source','lens_light',
Expand Down Expand Up @@ -56,6 +58,17 @@ def draw_from_dict(draw_dict):
for key in sorted(draw_dict):

value = draw_dict[key]

# Dirty workaround for https://github.com/scipy/scipy/issues/16998
# Explicitly ensure the distributions use the global random state
if hasattr(value, '__self__'):
# Scipy distribution
value.__self__.random_state = check_random_state(None)
elif hasattr(value, 'dist'):
# Duplicate or MultipleValues.
# Other custom paltas dists not yet supported..
value.dist.__self__.random_state = check_random_state(None)

if callable(value):
# Sampling function: call to draw
draw = value()
Expand Down

0 comments on commit 2b3950d

Please sign in to comment.