@@ -186,6 +186,10 @@ def __init__(
186
186
We usually just do steps of adaptive sampling without. "robust" would be the backup.
187
187
Default: dict(method="adaptive", options=dict(min_sc_iter=0)),
188
188
189
+ rseed: int or None, optional, default=None
190
+ Seed to use when constructing a new RNGState. If rseed is None, will use the global
191
+ np.random RNG to generate a seed.
192
+
189
193
Notes
190
194
-----
191
195
The reduced potential energy ``u_kn[k,n] = u_k(x_{ln})``, where the reduced potential energy ``u_l(x)`` is
@@ -266,30 +270,34 @@ def __init__(
266
270
# verbosity level -- if True, will print extra debug information
267
271
self .verbose = verbose
268
272
273
+ if rseed is None :
274
+ rseed = np .random .randint (np .iinfo (np .int32 ).max )
275
+ self .rng = np .random .default_rng (rseed )
276
+
269
277
# perform consistency checks on the data.
270
278
271
279
self .samestates = []
280
+ # if, for any set of data, all reduced potential energies are the same,
281
+ # they are probably the same state.
282
+ #
283
+ # This can take quite a while, so we do it on just
284
+ # the first few data points.
285
+ #
286
+ # determine if there are less than 50 points to compare energies.
287
+ # If so, use that number instead of 50.
288
+ # (the number 50 is pretty arbitrary)
289
+
290
+ maxpoint = 50
291
+ if self .N < maxpoint :
292
+ maxpoint = self .N
293
+ # pick random indices
294
+ # indices = np.arange(maxpoint) # can uncomment this if need to remove random choices in testing.
295
+ # Done outside of the verbose if statement to ensure deterministic results of bootstrapping, independent of
296
+ # the Verbose flag
297
+ indices = self .rng .choice (np .arange (self .N ), maxpoint )
298
+ # this could possibly be made faster with np.unique(axis=0,return_indices=True)
299
+ # but not clear if needed.
272
300
if self .verbose :
273
- # if, for any set of data, all reduced potential energies are the same,
274
- # they are probably the same state.
275
- #
276
- # This can take quite a while, so we do it on just
277
- # the first few data points.
278
- #
279
- # determine if there are less than 50 points to compare energies.
280
- # If so, use that number instead of 50.
281
- # (the number 50 is pretty arbitrary)
282
-
283
- maxpoint = 50
284
- if self .N < maxpoint :
285
- maxpoint = self .N
286
-
287
- # this could possibly be made faster with np.unique(axis=0,return_indices=True)
288
- # but not clear if needed.
289
-
290
- # pick random indices
291
- # indices = np.arange(maxpoint) # can uncomment this if need to remove random choices in testing.
292
- indices = np .random .choice (np .arange (self .N ), maxpoint )
293
301
for k in range (K ):
294
302
for l in range (k ):
295
303
diffsum = 0
@@ -402,11 +410,6 @@ def __init__(
402
410
elif pname == "bootstrap_solver_protocol" :
403
411
bootstrap_solver_protocol = prot
404
412
405
- if rseed != None :
406
- self .rstate = np .random .get_state ()
407
- else :
408
- np .random .seed (rseed )
409
-
410
413
self .f_k = mbar_solvers .solve_mbar_for_all_states (
411
414
self .u_kn , self .N_k , self .f_k , self .states_with_samples , solver_protocol
412
415
)
@@ -426,7 +429,7 @@ def __init__(
426
429
# which of the indices are equal to K
427
430
k_indices = np .where (self .x_kindices == k )[0 ]
428
431
# pick new random ones, selected of these K.
429
- new_kindices = k_indices [np . random . randint (int (N_k [k ]), size = int (N_k [k ]))]
432
+ new_kindices = k_indices [self . rng . integers (int (N_k [k ]), size = int (N_k [k ]))]
430
433
rints [k_indices ] = new_kindices
431
434
# If we initialized with BAR, then BAR, starting from the provided initial_f_k as well.
432
435
if initialize == "BAR" :
0 commit comments