Skip to content

Commit

Permalink
Added uniform() call to remove the last hacky access from outside prng
Browse files Browse the repository at this point in the history
This should make it easier if we ever want to parallelize other random functions
  • Loading branch information
ceriottm committed Apr 29, 2024
1 parent fe94cd4 commit 776848d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ipi/engine/motion/scphonons.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def bind(self, ens, beads, nm, cell, bforce, prng, omaker):
if self.random_type == "file":
self.random_sequence = np.loadtxt("SOBOL-RNG")
elif self.random_type == "pseudo":
self.random_sequence = self.prng.rng[0].uniform(
self.random_sequence = self.prng.uniform(
size=(self.max_steps * self.max_iter, self.dof)
)
elif self.random_type == "sobol":
Expand All @@ -182,7 +182,7 @@ def bind(self, ens, beads, nm, cell, bforce, prng, omaker):
)

# Shuffles the
self.prng.rng[0].shuffle(self.random_shuffle)
self.prng.shuffle(self.random_shuffle)

def step(self, step=None):
if self.isc == self.max_iter:
Expand Down
12 changes: 12 additions & 0 deletions ipi/utils/prng.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ def poisson(self, lam=1.0, size=None):

return self.rng[0].poisson(lam, size)

def uniform(self, low=0.0, high=1.0, size=None):
"""Interface to the standard uniform() function.
Args:
Same as numpy.Generator.uniform
Returns:
Uniform random reals in the prescribed interval
"""

return self.rng[0].uniform(low, high, size)

def integers(self, low, high=None, size=None, dtype=np.int64, endpoint=False):
"""Interface to the standard integers() function.
Expand Down

0 comments on commit 776848d

Please sign in to comment.