Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
Remove msmtools (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
clonker authored Apr 26, 2022
1 parent 6d1f334 commit 192df9c
Show file tree
Hide file tree
Showing 57 changed files with 407 additions and 1,086 deletions.
1 change: 0 additions & 1 deletion devtools/conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ requirements:
- intel-openmp # [osx]
- matplotlib
- mdtraj >=1.8
- msmtools >=1.2
- {{ pin_compatible('numpy') }}
- pathos
- psutil >3.1
Expand Down
1 change: 1 addition & 0 deletions devtools/conda-setup+build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ steps:
displayName: 'Install dependencies'
continueOnError: false
- bash: |
export PYTHONUNBUFFERED=1
conda mambabuild devtools/conda-recipe
displayName: 'Build and test'
continueOnError: false
10 changes: 9 additions & 1 deletion pyemma/_base/serialization/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class SerializableMixIn(object):
which are preserved during serialization.
To aid the process of loading old models in a new version of the software, there
is the the static field '__serialize_interpolation_map', which is a mapping from
is the static field '__serialize_interpolation_map', which is a mapping from
old version number to a set of operations to transform the old class state to the
recent version of the class.
Expand Down Expand Up @@ -403,6 +403,10 @@ def __getstate__(self):
if isinstance(self, Model):
state.update(Model.__my_getstate__(self))

from deeptime.base import Model as DeeptimeModel
if isinstance(self, DeeptimeModel):
state.update(self.__dict__)

from pyemma import version
state['pyemma_version'] = version

Expand Down Expand Up @@ -444,6 +448,10 @@ def __setstate__(self, state):
if isinstance(self, Model):
Model.__my_setstate__(self, state)

from deeptime.base import Model as DeeptimeModel
if isinstance(self, DeeptimeModel):
self.__dict__.update(state)

for klass in to_inspect:
self._set_state_from_serializeable_fields_and_state(state, klass=klass)

Expand Down
14 changes: 8 additions & 6 deletions pyemma/coordinates/clustering/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@ def assign(self, X=None, stride=1):
# return
return mapped

def save_dtrajs(self, trajfiles=None, prefix='',
output_dir='.',
output_format='ascii',
extension='.dtraj'):
def save_dtrajs(self, trajfiles=None, prefix='', output_dir='.', output_format='ascii', extension='.dtraj'):
"""saves calculated discrete trajectories. Filenames are taken from
given reader. If data comes from memory dtrajs are written to a default
filename.
Expand All @@ -258,9 +255,14 @@ def save_dtrajs(self, trajfiles=None, prefix='',

# obtain filenames from input (if possible, reader is a featurereader)
if output_format == 'ascii':
from msmtools.dtraj import write_discrete_trajectory as write_dtraj
def write_dtraj(_filename, _dtraj):
_dtraj = np.asarray(_dtraj)
with open(_filename, 'w') as f:
_dtraj.tofile(f, sep='\n', format='%d')
else:
from msmtools.dtraj import save_discrete_trajectory as write_dtraj
def write_dtraj(_filename, _dtraj):
_dtraj = np.asarray(_dtraj)
np.save(_filename, _dtraj)
import os.path as path

output_files = []
Expand Down
17 changes: 7 additions & 10 deletions pyemma/coordinates/tests/test_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@
@author: marscher
'''

import unittest
import os
import pkg_resources
import unittest
from logging import getLogger

import numpy as np
import pkg_resources
from deeptime.markov.msm import MarkovStateModel

from pyemma.coordinates import pca, source
from logging import getLogger
import pyemma.util.types as types


from pyemma.coordinates import pca, source

logger = getLogger('pyemma.'+'TestPCA')

Expand All @@ -42,8 +41,6 @@ class TestPCAExtensive(unittest.TestCase):

@classmethod
def setUpClass(cls):
import msmtools.generation as msmgen

# set random state, remember old one and set it back in tearDownClass
cls.old_state = np.random.get_state()
np.random.seed(0)
Expand All @@ -57,7 +54,7 @@ def setUpClass(cls):
# continuous trajectory
cls.X = np.zeros((cls.T, 2))
# hidden trajectory
dtraj = msmgen.generate_traj(cls.P, cls.T)
dtraj = MarkovStateModel(cls.P).simulate(cls.T)
for t in range(cls.T):
s = dtraj[t]
cls.X[t,0] = widths[s][0] * np.random.randn() + means[s][0]
Expand Down Expand Up @@ -85,7 +82,7 @@ def test_cumvar(self):
def test_cov(self):
cov_ref = np.dot(self.X.T, self.X) / float(self.T)
assert(np.all(self.pca_obj.cov.shape == cov_ref.shape))
assert(np.max(self.pca_obj.cov - cov_ref) < 3e-2)
assert(np.max(self.pca_obj.cov - cov_ref) < 3e-1)

def test_data_producer(self):
assert self.pca_obj.data_producer is not None
Expand Down
16 changes: 6 additions & 10 deletions pyemma/coordinates/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.




import unittest
import os
import unittest

import numpy as np
import pkg_resources
from deeptime.markov.msm import MarkovStateModel

from pyemma.coordinates import api
from pyemma.coordinates.data import DataInMemory
from pyemma.coordinates.data import MDFeaturizer
from pyemma.coordinates import api
import msmtools.generation as msmgen
import tempfile

import pkg_resources
from pyemma.util.files import TemporaryDirectory
import pyemma.coordinates as coor


class TestPipeline(unittest.TestCase):
@classmethod
Expand All @@ -54,7 +50,7 @@ def setUpClass(cls):
# continuous trajectory
x = np.zeros((t, 2))
# hidden trajectory
dtraj = msmgen.generate_traj(p, t)
dtraj = MarkovStateModel(p).simulate(t)
for t in range(t):
s = dtraj[t]
x[t, 0] = widths[s][0] * np.random.randn() + means[s][0]
Expand Down
5 changes: 2 additions & 3 deletions pyemma/coordinates/tests/test_tica.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import pkg_resources
import numpy as np
import scipy.linalg as scl
from deeptime.markov.msm import MarkovStateModel

from pyemma.coordinates import api

Expand Down Expand Up @@ -198,8 +199,6 @@ class TestTICAExtensive(unittest.TestCase):
@classmethod
def setUpClass(cls):
with numpy_random_seed(123):
import msmtools.generation as msmgen

# generate HMM with two Gaussians
cls.P = np.array([[0.99, 0.01],
[0.01, 0.99]])
Expand All @@ -209,7 +208,7 @@ def setUpClass(cls):
# continuous trajectory
cls.X = np.zeros((cls.T, 2))
# hidden trajectory
dtraj = msmgen.generate_traj(cls.P, cls.T)
dtraj = MarkovStateModel(cls.P).simulate(cls.T)
for t in range(cls.T):
s = dtraj[t]
cls.X[t, 0] = widths[s][0] * np.random.randn() + means[s][0]
Expand Down
1 change: 0 additions & 1 deletion pyemma/coordinates/tests/test_traj_info_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
pdbfile = get_bpti_test_data()['top']


@pytest.mark.skip(reason="Sometimes causes CI to go spinning beach ball of death")
class TestTrajectoryInfoCache(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand Down
16 changes: 8 additions & 8 deletions pyemma/coordinates/tests/test_vamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

import unittest
import numpy as np
from deeptime.decomposition import cvsplit_trajs

from pyemma.coordinates import vamp as pyemma_api_vamp
from pyemma.msm import estimate_markov_model
from logging import getLogger

from pyemma.msm.estimators._dtraj_stats import cvsplit_dtrajs

logger = getLogger('pyemma.'+'TestVAMP')


Expand Down Expand Up @@ -230,7 +230,7 @@ def test_singular_functions_against_MSM(self):
assert_allclose_ignore_phase(V, phi, atol=1E-5)
references_sf = [U.T.dot(np.diag(self.p0)).dot(np.linalg.matrix_power(self.msm.P, k*self.lag)).dot(V).T for k in
range(10-1)]
cktest = self.vamp.cktest(n_observables=2, mlags=10)
cktest = self.vamp.cktest(n_observables=2, mlags=10, n_jobs=1)
pred_sf = cktest.predictions
esti_sf = cktest.estimates
for e, p, r in zip(esti_sf[1:], pred_sf[1:], references_sf[1:]):
Expand All @@ -250,7 +250,7 @@ def test_cumvar_variance_cutoff(self):

def test_CK_expectation_against_MSM(self):
obs = np.eye(3) # observe every state
cktest = self.vamp.cktest(observables=obs, statistics=None, mlags=4)
cktest = self.vamp.cktest(observables=obs, statistics=None, mlags=4, n_jobs=1)
pred = cktest.predictions[1:]
est = cktest.estimates[1:]

Expand All @@ -263,7 +263,7 @@ def test_CK_expectation_against_MSM(self):
np.testing.assert_allclose(est_, pred_, atol=0.006)

def test_CK_covariances_of_singular_functions(self):
cktest = self.vamp.cktest(n_observables=2, mlags=4) # auto
cktest = self.vamp.cktest(n_observables=2, mlags=4, n_jobs=1) # auto
pred = cktest.predictions[1:]
est = cktest.estimates[1:]
error = np.max(np.abs(np.array(pred) - np.array(est))) / max(np.max(pred), np.max(est))
Expand All @@ -272,7 +272,7 @@ def test_CK_covariances_of_singular_functions(self):
def test_CK_covariances_against_MSM(self):
obs = np.eye(3) # observe every state
sta = np.eye(3) # restrict p0 to every state
cktest = self.vamp.cktest(observables=obs, statistics=sta, mlags=4, show_progress=True)
cktest = self.vamp.cktest(observables=obs, statistics=sta, mlags=4, show_progress=True, n_jobs=1)
pred = cktest.predictions[1:]
est = cktest.estimates[1:]

Expand Down Expand Up @@ -302,9 +302,9 @@ def test_self_score_with_MSM(self):
def test_score_vs_MSM(self):
from pyemma.util.contexts import numpy_random_seed
with numpy_random_seed(32):
trajs_test, trajs_train = cvsplit_dtrajs(self.trajs)
trajs_test, trajs_train = cvsplit_trajs(self.trajs)
with numpy_random_seed(32):
dtrajs_test, dtrajs_train = cvsplit_dtrajs(self.dtrajs)
dtrajs_test, dtrajs_train = cvsplit_trajs(self.dtrajs)

methods = ('VAMP1', 'VAMP2', 'VAMPE')

Expand Down
15 changes: 8 additions & 7 deletions pyemma/datasets/double_well_discrete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# This file is part of PyEMMA.
#
# Copyright (c) 2015, 2014 Computational Molecular Biology Group, Freie Universitaet Berlin (GER)
Expand All @@ -20,8 +19,11 @@
__author__ = 'noe'

import numpy as np
from deeptime.markov.msm import MarkovStateModel

from pyemma.msm import markov_model


class DoubleWell_Discrete_Data(object):
""" MCMC process in a symmetric double well potential, spatially discretized to 100 bins
Expand All @@ -33,6 +35,7 @@ def __init__(self):
datafile = np.load(filename)
self._dtraj_T100K_dt10 = datafile['dtraj']
self._P = datafile['P']
self._msm_dt = MarkovStateModel(self._P)
self._msm = markov_model(self._P)

@property
Expand Down Expand Up @@ -63,8 +66,8 @@ def dtraj_T100K_dt10_n(self, divides):
""" 100K frames trajectory at timestep 10, arbitrary n-state discretization. """
disc = np.zeros(100, dtype=int)
divides = np.concatenate([divides, [100]])
for i in range(len(divides)-1):
disc[divides[i]:divides[i+1]] = i+1
for i in range(len(divides) - 1):
disc[divides[i]:divides[i + 1]] = i + 1
return disc[self.dtraj_T100K_dt10]

@property
Expand All @@ -79,10 +82,8 @@ def msm(self):

def generate_traj(self, N, start=None, stop=None, dt=1):
""" Generates a random trajectory of length N with time step dt """
from msmtools.generation import generate_traj
return generate_traj(self._P, N, start=start, stop=stop, dt=dt)
return self._msm_dt.simulate(N, start=start, stop=stop, dt=dt)

def generate_trajs(self, M, N, start=None, stop=None, dt=1):
""" Generates M random trajectories of length N each with time step dt """
from msmtools.generation import generate_trajs
return generate_trajs(self._P, M, N, start=start, stop=stop, dt=dt)
return [self.generate_traj(N, start=start, stop=stop, dt=dt) for _ in range(M)]
19 changes: 3 additions & 16 deletions pyemma/msm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,15 @@
ReactiveFlux
PCCA
MSM functions (low-level API)
=============================
Low-level functions for estimation and analysis of transition matrices and io have been moved to `MSMTools
<https://msmtools.readthedocs.io/>`_.
"""

######################################################
from msmtools.analysis.dense.pcca import PCCA

#####################################################
# Estimators and models
from .models import MSM, HMSM, SampledMSM, SampledHMSM, ReactiveFlux

from .estimators import MaximumLikelihoodMSM, BayesianMSM
from .estimators import MaximumLikelihoodHMSM, BayesianHMSM
from .estimators import AugmentedMarkovModel, OOMReweightedMSM
from .estimators import ImpliedTimescales
from .estimators import ChapmanKolmogorovValidator

from .estimators import ImpliedTimescales
from .estimators import MaximumLikelihoodHMSM, BayesianHMSM
from .estimators import MaximumLikelihoodMSM, BayesianMSM

# high-level api
from .api import *
Loading

0 comments on commit 192df9c

Please sign in to comment.