From ec43cda0945de4434090a152cdd68d6af132cc31 Mon Sep 17 00:00:00 2001 From: Tom Vander Aa Date: Wed, 3 Jul 2024 13:38:39 +0200 Subject: [PATCH] ci: run TrainSessions with num_threads=1 --- python/test/test_gfa.py | 8 +++---- python/test/test_macau.py | 14 +++++++++--- python/test/test_noisemodels.py | 2 +- python/test/test_pp.py | 2 +- python/test/test_predict.py | 8 +++---- python/test/test_pybind.py | 9 +++++++- python/test/test_scarce.py | 6 ++--- python/test/test_smurff.py | 40 ++++++++++++++++++++++++--------- 8 files changed, 62 insertions(+), 27 deletions(-) diff --git a/python/test/test_gfa.py b/python/test/test_gfa.py index 3e3b291fd..3deceb4bb 100644 --- a/python/test/test_gfa.py +++ b/python/test/test_gfa.py @@ -16,19 +16,19 @@ class TestGFA(unittest.TestCase): def test_gfa_1view(self): Y = scipy.sparse.rand(10, 20, 0.2) Y, Ytest = smurff.make_train_test(Y, 0.5) - predictions = smurff.gfa([Y], Ytest=Ytest, num_latent=4, verbose=verbose, burnin=5, nsamples=5) + predictions = smurff.gfa([Y], Ytest=Ytest, num_latent=4, verbose=verbose, num_threads=1, burnin=5, nsamples=5) self.assertEqual(Ytest.nnz, len(predictions)) def test_gfa_2view(self): Y = scipy.sparse.rand(10, 20, 0.2) Y, Ytest = smurff.make_train_test(Y, 0.5) - predictions = smurff.gfa([Y, Y], Ytest=Ytest, num_latent=4, verbose=verbose, burnin=5, nsamples=5) + predictions = smurff.gfa([Y, Y], Ytest=Ytest, num_latent=4, verbose=verbose, num_threads=1, burnin=5, nsamples=5) self.assertEqual(Ytest.nnz, len(predictions)) def test_gfa_3view(self): Y = scipy.sparse.rand(10, 20, 0.2) Y, Ytest = smurff.make_train_test(Y, 0.5) - predictions = smurff.gfa([Y, Y, Y], Ytest=Ytest, num_latent=4, verbose=verbose, burnin=5, nsamples=5) + predictions = smurff.gfa([Y, Y, Y], Ytest=Ytest, num_latent=4, verbose=verbose, num_threads=1, burnin=5, nsamples=5) self.assertEqual(Ytest.nnz, len(predictions)) def test_gfa_mixedview(self): @@ -36,7 +36,7 @@ def test_gfa_mixedview(self): Y, Ytest = smurff.make_train_test(Y, 0.5) D1 = np.random.randn(10, 2) D2 = scipy.sparse.rand(10, 5, 0.2) - predictions = smurff.gfa([Y, D1, D2], Ytest=Ytest, num_latent=4, verbose=verbose, burnin=5, nsamples=5) + predictions = smurff.gfa([Y, D1, D2], Ytest=Ytest, num_latent=4, verbose=verbose, num_threads=1, burnin=5, nsamples=5) self.assertEqual(Ytest.nnz, len(predictions)) diff --git a/python/test/test_macau.py b/python/test/test_macau.py index e6dae931e..bb99c8d67 100644 --- a/python/test/test_macau.py +++ b/python/test/test_macau.py @@ -29,6 +29,7 @@ def test_macau(self): direct=True, num_latent=4, verbose=verbose, + num_threads=1, burnin=200, nsamples=200) @@ -46,7 +47,9 @@ def test_macau_side_bin(self): num_latent=5, burnin=200, nsamples=200, - verbose=verbose) + verbose=verbose, + num_threads=1, + ) def test_macau_dense(self): Y = scipy.sparse.rand(15, 10, 0.2) @@ -59,7 +62,9 @@ def test_macau_dense(self): num_latent=5, burnin=200, nsamples=200, - verbose=verbose) + verbose=verbose, + num_threads=1 + ) def test_macau_univariate(self): Y = scipy.sparse.rand(10, 20, 0.2) @@ -73,13 +78,14 @@ def test_macau_univariate(self): univariate = True, num_latent=4, verbose=verbose, + num_threads=1, burnin=200, nsamples=200) self.assertEqual(Ytest.nnz, len(predictions)) def test_macau_tensor(self): shape = [30, 4, 2] - + A = np.random.randn(shape[0], 2) B = np.random.randn(shape[1], 2) C = np.random.randn(shape[2], 2) @@ -97,6 +103,7 @@ def test_macau_tensor(self): direct=True, num_latent = 4, verbose=verbose, + num_threads=1, burnin=200, nsamples=200) @@ -125,6 +132,7 @@ def test_macau_tensor_univariate(self): univariate = True, num_latent=4, verbose=verbose, + num_threads=1, burnin=200, nsamples=2000) diff --git a/python/test/test_noisemodels.py b/python/test/test_noisemodels.py index 6079add70..388abfdf3 100644 --- a/python/test/test_noisemodels.py +++ b/python/test/test_noisemodels.py @@ -59,7 +59,7 @@ def test_noise_model(density, nmodes, side_info, noise_model): if si is not None: priors[0] = 'macau' - trainSession = smurff.TrainSession(priors = priors, num_latent=8, burnin=20, nsamples=20, threshold=.0, seed=seed, verbose=verbose) + trainSession = smurff.TrainSession(priors = priors, num_latent=8, burnin=20, nsamples=20, threshold=.0, seed=seed, verbose=verbose, num_threads=1) trainSession.addTrainAndTest(Ytrain, Ytest, nm) if not si is None: diff --git a/python/test/test_pp.py b/python/test/test_pp.py index 77aa4c879..c9ca6a6e6 100644 --- a/python/test/test_pp.py +++ b/python/test/test_pp.py @@ -35,7 +35,7 @@ def test_bmf_pp(self): Y = scipy.sparse.rand(30, 20, 0.2) Y, Ytest = smurff.make_train_test(Y, 0.5, seed=seed) trainSession = smurff.BPMFSession(Y, is_scarce = True, Ytest=Ytest, - num_latent=4, verbose=verbose, burnin=20, nsamples=20, save_freq=1, + num_latent=4, verbose=verbose, num_threads = 1, burnin=20, nsamples=20, save_freq=1, seed = seed, save_name=smurff.helper.temp_savename()) trainSession.run() predict_session = trainSession.makePredictSession() diff --git a/python/test/test_predict.py b/python/test/test_predict.py index 6560a7162..4c94ba25e 100644 --- a/python/test/test_predict.py +++ b/python/test/test_predict.py @@ -16,13 +16,13 @@ class TestPredictSession(unittest.TestCase): __name__ = "TestPredictSession" def run_train_session(self, nmodes, density): - shape = range(5, nmodes+5) # 5, 6, 7, ... + shape = range(5, nmodes+5) # 5, 6, 7, ... Y, X = smurff.generate.gen_tensor(shape, 3, density) self.Ytrain, self.Ytest = smurff.make_train_test(Y, 0.1) priors = ['normal'] * nmodes trainSession = smurff.TrainSession(priors = priors, num_latent=4, - burnin=10, nsamples=nsamples, verbose=verbose, + burnin=10, nsamples=nsamples, verbose=verbose, num_threads=1, save_freq = 1, save_name = smurff.helper.temp_savename()) trainSession.addTrainAndTest(self.Ytrain, self.Ytest) @@ -47,7 +47,7 @@ def assert_almost_equal_sparse(self, A, B): c1,v1 = smurff.find(A) c2,v2 = smurff.find(B) assert np.array_equal(c1,c2) - assert np.allclose(v1,v2, atol=0.01) + assert np.allclose(v1,v2, atol=0.01) def run_predict_some_all_one(self, train_session, predict_session): coords, _ = smurff.find(self.Ytest) @@ -83,7 +83,7 @@ def run_predict_predict(self, predict_session, X): """ Test the PredictSession.predict function """ def run_n_samples(samples, expected_nsamples): - operand_and_sizes = [ + operand_and_sizes = [ [ ( Ellipsis , x.shape[0] ), ( slice(3) , 3 ), diff --git a/python/test/test_pybind.py b/python/test/test_pybind.py index 1fbdd85dd..52fc63981 100644 --- a/python/test/test_pybind.py +++ b/python/test/test_pybind.py @@ -4,7 +4,14 @@ import scipy.sparse as sp def test_pybind(): - trainSession = smurff.TrainSession(priors = ["normal", "normal"], verbose = 2 ) + trainSession = smurff.TrainSession( + priors = ["normal", "normal"], + burnin = 10, + nsamples = 10, + num_latent = 4, + verbose = 2, + num_threads = 1, + ) Y = np.array([[1.,2.],[3.,4.]]) trainSession.setTrain(Y) diff --git a/python/test/test_scarce.py b/python/test/test_scarce.py index 3cc4c0cff..0922e1b85 100644 --- a/python/test/test_scarce.py +++ b/python/test/test_scarce.py @@ -22,7 +22,7 @@ class TestScarce(unittest.TestCase): def test_simple(self): matrix = matrix_with_explicit_zeros() self.assertTrue(matrix.nnz == 6) - + matrix.eliminate_zeros() self.assertTrue(matrix.nnz == 3) @@ -30,8 +30,8 @@ def test_smurff(self): matrix = matrix_with_explicit_zeros() self.assertTrue(matrix.nnz == 6) - predictions = smurff.bpmf(matrix, Ytest=matrix, num_latent=4, burnin=5, nsamples=5) + predictions = smurff.bpmf(matrix, Ytest=matrix, num_latent=4, burnin=5, nsamples=5, num_threads=1) self.assertEqual(len(predictions), 6) - + if __name__ == '__main__': unittest.main() diff --git a/python/test/test_smurff.py b/python/test/test_smurff.py index 9272dc457..9d86db498 100644 --- a/python/test/test_smurff.py +++ b/python/test/test_smurff.py @@ -6,7 +6,7 @@ import itertools import collections -verbose = 0 +verbose = 1 class TestSmurff(unittest.TestCase): @@ -21,6 +21,7 @@ def test_bpmf(self): priors=['normal', 'normal'], num_latent=4, verbose=verbose, + num_threads=1, burnin=50, nsamples=50) self.assertEqual(Ytest.nnz, len(predictions)) @@ -35,7 +36,9 @@ def test_bpmf_numerictest(self): num_latent=10, burnin=10, nsamples=15, - verbose=verbose) + verbose=verbose, + num_threads=1, + ) def test_macau(self): Ydense = np.random.rand(10, 20) @@ -54,6 +57,7 @@ def test_macau(self): # side_info_noises=[[('fixed', 1.0, None, None, None)], [('adaptive', None, 0.5, 1.0, None)]], num_latent=4, verbose=verbose, + num_threads=1, burnin=50, nsamples=50) #self.assertEqual(Ytest.nnz, len(predictions)) @@ -71,7 +75,8 @@ def test_macau_side_bin(self): num_latent=5, burnin=10, nsamples=5, - verbose=verbose) + verbose=verbose, + num_threads=1) def test_macau_dense(self): Y = scipy.sparse.rand(15, 10, 0.2) @@ -85,7 +90,8 @@ def test_macau_dense(self): num_latent=5, burnin=10, nsamples=5, - verbose=verbose) + verbose=verbose, + num_threads = 1) def test_macau_dense_probit(self): A = np.random.randn(25, 2) @@ -97,13 +103,15 @@ def test_macau_dense_probit(self): Ytrain, Ytest = smurff.make_train_test(df, 0.2) threshold = 0.5 # since we sample from mu(0,1) - + trainSession = smurff.TrainSession(priors=['macau', 'normal'], num_latent=4, threshold=threshold, burnin=200, nsamples=200, - verbose=False) + verbose=0, + num_threads=1, + ) trainSession.addTrainAndTest(Ytrain, Ytest, smurff.ProbitNoise(threshold)) trainSession.addSideInfo(0, A, direct=True) @@ -127,6 +135,7 @@ def test_macau_univariate(self): direct=True, num_latent=4, verbose=verbose, + num_threads=1, burnin=50, nsamples=50) self.assertEqual(Ytest.nnz, len(predictions)) @@ -137,7 +146,9 @@ def test_too_many_sides(self): smurff.smurff(Y, priors=['normal', 'normal', 'normal'], side_info=[None, None, None], - verbose = False) + verbose = 0, + num_threads=1, + ) def test_bpmf_emptytest(self): X = scipy.sparse.rand(15, 10, 0.2) @@ -146,7 +157,9 @@ def test_bpmf_emptytest(self): num_latent=10, burnin=10, nsamples=15, - verbose=verbose) + verbose=verbose, + num_threads=1, + ) def test_bpmf_emptytest_probit(self): X = scipy.sparse.rand(15, 10, 0.2) @@ -156,7 +169,9 @@ def test_bpmf_emptytest_probit(self): num_latent=10, burnin=10, nsamples=15, - verbose=verbose) + verbose=verbose, + num_threads=1 + ) def test_make_train_test(self): X = scipy.sparse.rand(15, 10, 0.2) @@ -206,6 +221,7 @@ def test_bpmf_tensor(self): priors=['normal', 'normal', 'normal'], num_latent=4, verbose=verbose, + num_threads=1, burnin=50, nsamples=50) @@ -224,6 +240,7 @@ def test_bpmf_tensor2(self): priors=['normal', 'normal', 'normal'], num_latent=4, verbose=verbose, + num_threads=1, burnin=20, nsamples=20) @@ -247,6 +264,7 @@ def test_bpmf_tensor3(self): priors=['normal', 'normal', 'normal'], num_latent=4, verbose=verbose, + num_threads=1, burnin=20, nsamples=20) @@ -271,7 +289,9 @@ def test_macau_tensor_empty(self): num_latent=2, burnin=5, nsamples=5, - verbose=verbose) + verbose=verbose, + num_threads=1, + ) self.assertFalse(predictions)