Skip to content

Commit

Permalink
ci: run TrainSessions with num_threads=1
Browse files Browse the repository at this point in the history
  • Loading branch information
tvandera committed Jul 3, 2024
1 parent c40f755 commit 7e49332
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 27 deletions.
8 changes: 4 additions & 4 deletions python/test/test_gfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ 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):
Y = scipy.sparse.rand(10, 20, 0.2)
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))


Expand Down
14 changes: 11 additions & 3 deletions python/test/test_macau.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_macau(self):
direct=True,
num_latent=4,
verbose=verbose,
num_threads=1,
burnin=200,
nsamples=200)

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -97,6 +103,7 @@ def test_macau_tensor(self):
direct=True,
num_latent = 4,
verbose=verbose,
num_threads=1,
burnin=200,
nsamples=200)

Expand Down Expand Up @@ -125,6 +132,7 @@ def test_macau_tensor_univariate(self):
univariate = True,
num_latent=4,
verbose=verbose,
num_threads=1,
burnin=200,
nsamples=2000)

Expand Down
2 changes: 1 addition & 1 deletion python/test/test_noisemodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion python/test/test_pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions python/test/test_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 ),
Expand Down
9 changes: 8 additions & 1 deletion python/test/test_pybind.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions python/test/test_scarce.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ 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)

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()
40 changes: 30 additions & 10 deletions python/test/test_smurff.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import itertools
import collections

verbose = 0
verbose = 1

class TestSmurff(unittest.TestCase):

Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down

0 comments on commit 7e49332

Please sign in to comment.