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

rng working with previous gaslim versions #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions galsim_hub/generative_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,20 @@ def sample(self, cat, noise=None, rng=None, x_interpolant=None, k_interpolant=N
# Populate feed dictionary with input data
feed_dict={self.inputs[k]: cat[k] for k in self.quantities}

# If not provided, create a RNG
# If not provided, create a RNG with random seed. If you want reproducible results, give a rng with controled seed in the sample args.
if rng is None:
rng = galsim.BaseDeviate(rng)
orig_rng = rng.duplicate()
rng = galsim.GaussianDeviate(seed=None, mean=0.0, sigma=1.0)

''' We never use that right ? '''
# orig_rng = rng.duplicate()

# Look for requested random_variables
if 'random_normal' in self.random_variables:
# Draw a random normal from the galsim RNG
noise_shape = self.module.get_input_info_dict()['random_normal'].get_shape()
noise_shape = [len(cat)] + [noise_shape[i+1].value for i in range(len(noise_shape)-1)]
noise_array = np.empty(np.prod(noise_shape), dtype=float)
gd = galsim.random.GaussianDeviate(rng, sigma=1)
gd.generate(noise_array)
rng.generate(noise_array)
feed_dict[self.inputs['random_normal']] = noise_array.reshape(noise_shape).astype('float32')

# Run the graph
Expand Down