From 881d3f58a38960d4a5a88496417265349cd816ec Mon Sep 17 00:00:00 2001 From: Johannes Buchner Date: Thu, 12 Dec 2024 11:54:12 +0100 Subject: [PATCH] make flaky test deterministic; fix error if nsteps is passed --- tests/test_clustering.py | 12 +++++++----- ultranest/stepsampler.py | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/test_clustering.py b/tests/test_clustering.py index 790916c8..1f8c9a01 100644 --- a/tests/test_clustering.py +++ b/tests/test_clustering.py @@ -83,11 +83,13 @@ def test_clusteringcase_eggbox(): points = np.loadtxt(os.path.join(here, "eggboxregion.txt")) transformLayer = ScalingLayer() transformLayer.optimize(points, points) - region = MLFriends(points, transformLayer) - maxr = region.compute_maxradiussq(nbootstraps=30) - assert 1e-10 < maxr < 6e-10 - print('maxradius:', maxr) - nclusters, clusteridxs, overlapped_points = update_clusters(points, points, maxr) + for seed in range(10): + np.random.seed(seed) + region = MLFriends(points, transformLayer) + maxr = region.compute_maxradiussq(nbootstraps=30) + assert 1e-10 < maxr < 6e-10 + print('maxradius:', maxr) + nclusters, clusteridxs, overlapped_points = update_clusters(points, points, maxr) # plt.title('nclusters: %d' % nclusters) # for i in np.unique(clusteridxs): # x, y = points[clusteridxs == i].transpose() diff --git a/ultranest/stepsampler.py b/ultranest/stepsampler.py index dbaa538c..3b2c2b57 100644 --- a/ultranest/stepsampler.py +++ b/ultranest/stepsampler.py @@ -1505,9 +1505,10 @@ def SpeedVariableRegionSliceSampler(step_matrix, *args, **kwargs): Updates only some dimensions at a time, completely user-definable. """ generate_direction = kwargs.pop('generate_direction', generate_region_random_direction) + nsteps = kwargs.pop('nsteps', len(step_matrix)) return SliceSampler( *args, **kwargs, - nsteps=kwargs.pop('nsteps', len(step_matrix)), + nsteps=nsteps, generate_direction=SpeedVariableGenerator( step_matrix=step_matrix, generate_direction=generate_direction