markovmodel / PyEMMA

🚂 Python API for Emma's Markov Model Algorithms 🚂
http://pyemma.org
GNU Lesser General Public License v3.0
311 stars 118 forks source link

cktest of a bayesian msm breaks down for n_jobs=None #1328

Closed cwehmeyer closed 6 years ago

cwehmeyer commented 6 years ago

The cktest method of a Bayesian MSM raises a TypeError if I supply the parameter n_jobs=None because of a check whether n_jobs > 1; Bayesian HMMs show the exact same behaviour. I am using pyemma-2.5.3 on [OSX, conda, Python3.6].

While this parameter choice is not supported according to the docstring, it is accepted in other methods (e.g. pyemma.msm.its) and very useful.

Here is a minimal example...

import pyemma
from pyemma.datasets.double_well_discrete import DoubleWell_Discrete_Data

print(pyemma.__version__)

dtraj = DoubleWell_Discrete_Data().generate_traj(10000)
pyemma.msm.bayesian_markov_model(dtraj, lag=1).cktest(2, n_jobs=None)

... and the resulting traceback

Traceback ```Python-Traceback 2.5.3 estimating BayesianMSM 0% 0/9 [00:00 in () 5 6 dtraj = DoubleWell_Discrete_Data().generate_traj(10000) ----> 7 pyemma.msm.bayesian_markov_model(dtraj, lag=1).cktest(2, n_jobs=None) ~/Library/miniconda3/lib/python3.6/site-packages/pyemma/msm/estimators/maximum_likelihood_msm.py in cktest(self, nsets, memberships, mlags, conf, err_est, n_jobs, show_progress) 864 ck = ChapmanKolmogorovValidator(self, self, memberships, mlags=mlags, conf=conf, 865 n_jobs=n_jobs, err_est=err_est, show_progress=show_progress) --> 866 ck.estimate(self._dtrajs_full) 867 return ck 868 ~/Library/miniconda3/lib/python3.6/site-packages/pyemma/_base/estimator.py in estimate(self, X, **params) 410 if params: 411 self.set_params(**params) --> 412 self._model = self._estimate(X) 413 # ensure _estimate returned something 414 assert self._model is not None ~/Library/miniconda3/lib/python3.6/site-packages/pyemma/msm/estimators/lagged_model_validators.py in _estimate(self, data) 152 estimated_models, estimators = \ 153 estimate_param_scan(self.test_estimator, data, pargrid, return_estimators=True, failfast=False, --> 154 progress_reporter=progress_reporter, n_jobs=self.n_jobs) 155 if include0: 156 estimated_models = [None] + estimated_models ~/Library/miniconda3/lib/python3.6/site-packages/pyemma/_base/estimator.py in estimate_param_scan(estimator, X, param_sets, evaluate, evaluate_args, failfast, return_estimators, n_jobs, progress_reporter, show_progress, return_exceptions) 305 description="estimating %s" % str(estimator.__class__.__name__)) 306 --> 307 if n_jobs > 1 and os.name == 'posix': 308 if hasattr(estimators[0], 'logger'): 309 estimators[0].logger.debug('estimating %s with n_jobs=%s', estimator, n_jobs) TypeError: '>' not supported between instances of 'NoneType' and 'int' ```
marscher commented 6 years ago

thanks for providing the minimal example, that was really useful. I changed the code such, that if None is passed it will always react like the NJobsMixin, which obeys several rules (environmental settings etc.).