22# dingo is part of GeomScale project
33
44# Copyright (c) 2022 Apostolos Chalkis
5- # Copyright (c) 2022 Vissarion Fisikopoulos
5+ # Copyright (c) 2022-2025 Vissarion Fisikopoulos
66# Copyright (c) 2022 Haris Zafeiropoulos
77# Copyright (c) 2024 Ke Shi
88
1111import unittest
1212import os
1313import sys
14+ import numpy as np
1415from dingo import MetabolicNetwork , PolytopeSampler
1516from dingo .pyoptinterface_based_impl import set_default_solver
1617
18+ def test_shape_and_non_zero (steady_states , shape0 , shape1 , testing_class ):
19+ testing_class .assertTrue ( steady_states .shape [0 ] == shape0 )
20+ testing_class .assertTrue ( steady_states .shape [1 ] == shape1 )
21+ testing_class .assertTrue ( np .any (np .abs (steady_states ) > 1e-12 ) )
22+
1723def sampling (model , testing_class ):
1824 sampler = PolytopeSampler (model )
1925
2026 #Gaussian hmc sampling
21- steady_states = sampler .generate_steady_states_no_multiphase (method = 'mmcs' , ess = 1000 )
22-
23- testing_class .assertTrue ( steady_states .shape [0 ] == 95 )
24- testing_class .assertTrue ( steady_states .shape [1 ] == 1000 )
25-
26- #Gaussian hmc sampling
27- steady_states = sampler .generate_steady_states_no_multiphase (method = 'gaussian_hmc_walk' , n = 500 )
28-
29- testing_class .assertTrue ( steady_states .shape [0 ] == 95 )
30- testing_class .assertTrue ( steady_states .shape [1 ] == 500 )
27+ steady_states = sampler .generate_steady_states_no_multiphase (method = 'gaussian_hmc_walk' , n = 1000 )
28+ test_shape_and_non_zero (steady_states , 95 , 1000 , testing_class )
3129
3230 #exponential hmc sampling
33- steady_states = sampler .generate_steady_states_no_multiphase (method = 'exponential_hmc_walk' , n = 500 , variance = 50 )
34-
35- testing_class .assertTrue ( steady_states .shape [0 ] == 95 )
36- testing_class .assertTrue ( steady_states .shape [1 ] == 500 )
37-
31+ steady_states = sampler .generate_steady_states_no_multiphase (method = 'exponential_hmc_walk' , n = 1000 , variance = 50 )
32+ test_shape_and_non_zero (steady_states , 95 , 1000 , testing_class )
33+
3834 #hmc sampling with Gaussian distribution
39- steady_states = sampler .generate_steady_states_no_multiphase (method = 'hmc_leapfrog_gaussian' , n = 500 )
40-
41- testing_class .assertTrue ( steady_states .shape [0 ] == 95 )
42- testing_class .assertTrue ( steady_states .shape [1 ] == 500 )
35+ steady_states = sampler .generate_steady_states_no_multiphase (method = 'hmc_leapfrog_gaussian' , n = 1000 )
36+ test_shape_and_non_zero (steady_states , 95 , 1000 , testing_class )
4337
4438 #hmc sampling with exponential distribution
45- steady_states = sampler .generate_steady_states_no_multiphase (method = 'hmc_leapfrog_exponential' , n = 500 , variance = 50 )
46-
47- testing_class .assertTrue ( steady_states .shape [0 ] == 95 )
48- testing_class .assertTrue ( steady_states .shape [1 ] == 500 )
39+ steady_states = sampler .generate_steady_states_no_multiphase (method = 'hmc_leapfrog_exponential' , n = 1000 , variance = 50 )
40+ test_shape_and_non_zero (steady_states , 95 , 1000 , testing_class )
4941
5042 #steady_states[12].mean() seems to have a lot of discrepancy between experiments, so we won't check the mean for now
5143 #self.assertTrue( abs( steady_states[12].mean() - 2.504 ) < 1e-03 )
@@ -70,8 +62,6 @@ def test_sample_sbml(self):
7062 model = MetabolicNetwork .from_sbml ( input_file_sbml )
7163 sampling (model , self )
7264
73-
74-
7565if __name__ == "__main__" :
7666 if len (sys .argv ) > 1 :
7767 set_default_solver (sys .argv [1 ])
0 commit comments