Skip to content

Commit

Permalink
minor improvements (#268)
Browse files Browse the repository at this point in the history
* move azure cibuildwheel main yml to root

* print cmake status for version and whether tests are enabled

* increase verbosity for cibuildwheel on linux

* fix tests: compatibility to numpy 1.24, fixed some deprecation warnings regarding matplotlib and networkx

* make test_reversible_pi flaky
  • Loading branch information
clonker authored Dec 20, 2022
1 parent a833ab4 commit 66c10e4
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 88 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ endif()
project(deeptime LANGUAGES C CXX VERSION ${DEEPTIME_VERSION})
set(DEEPTIME_ROOT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}")

message(STATUS "Got deeptime version ${DEEPTIME_VERSION}")
message(STATUS "Got deeptime full version ${DEEPTIME_VERSION_INFO}")
message(STATUS "Building tests: ${DEEPTIME_BUILD_CPP_TESTS}")

include(GNUInstallDirs)

if(SKBUILD)
Expand Down
29 changes: 29 additions & 0 deletions azure-cibuildwheel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
jobs:
- job: linux
pool: { vmImage: 'Ubuntu-22.04' }
variables:
CIBW_BUILD: cp3{8,9,10,11}-manylinux_x86_64
CIBW_BUILD_VERBOSITY: 2
steps:
- template: devtools/cibuildwheel.yml

- job: macos
pool: { vmImage: 'macOS-12' }
variables:
CIBW_BUILD: cp3{8,9,10,11}-macosx_*
CIBW_ARCHS_MACOS: $(arch)
strategy:
matrix:
x86_64:
arch: 'x86_64'
arm64:
arch: 'arm64'
steps:
- template: devtools/cibuildwheel.yml

- job: windows
pool: { vmImage: 'windows-2019' }
variables:
CIBW_BUILD: cp3{8,9,10,11}-win_amd64
steps:
- template: devtools/cibuildwheel.yml
2 changes: 1 addition & 1 deletion deeptime/plots/chapman_kolmogorov.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def legend(self, conf=None):
handles.append(self._lpred_handles[ix])
labels.append(predlabel)
labels.append(estlabel)
self.figure.legend(handles, labels, 'upper center', ncol=2, frameon=False)
self.figure.legend(handles, labels, loc='upper center', ncol=2, frameon=False)

@property
def n_tests(self):
Expand Down
6 changes: 3 additions & 3 deletions deeptime/plots/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _draw_arrow(ax, pos_1, pos_2, label="", width=1.0, arrow_curvature=1.0, colo
@property
def edge_base_scale(self):
r""" Base scale for edges depending on the matplotlib default line width and the maximum off-diagonal
element in the adjacency matrix """
element in the adjacency matrix. Returns default line width if all off-diagonal elements are zero. """
if issparse(self.adjacency_matrix):
mat = self.adjacency_matrix.tocoo()
max_off_diag = 0
Expand All @@ -209,7 +209,7 @@ def edge_base_scale(self):
diag_mask = np.logical_not(np.eye(self.adjacency_matrix.shape[0], dtype=bool))
max_off_diag = np.max(np.abs(self.adjacency_matrix[diag_mask]))
default_lw = default_line_width()
return 2 * default_lw / max_off_diag
return 2 * default_lw / max_off_diag if max_off_diag > 0 else default_lw

@property
def edge_labels(self) -> Optional[np.ndarray]:
Expand Down Expand Up @@ -531,7 +531,7 @@ def plot_markov_model(msm: Union[MarkovStateModel, np.ndarray], pos=None, state_
P[flux < minflux] = 0.0
if pos is None:
import networkx as nx
graph = nx.from_scipy_sparse_matrix(P) if msm.sparse else nx.from_numpy_matrix(P)
graph = nx.from_scipy_sparse_array(P) if msm.sparse else nx.from_numpy_array(P)
pos = nx.spring_layout(graph)
network = Network(P, pos=pos, state_scale=state_scale, state_colors=state_colors, state_labels=state_labels,
state_sizes=state_sizes, edge_scale=edge_scale, edge_curvature=edge_curvature,
Expand Down
78 changes: 0 additions & 78 deletions devtools/azure-pipelines-cibuildwheel.yml

This file was deleted.

16 changes: 16 additions & 0 deletions devtools/cibuildwheel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
steps:
- template: checkout.yml
- task: UsePythonVersion@0
inputs:
versionSpec: '3.10'
architecture: 'x64'
displayName: Use Python 3.10
- bash: |
set -o errexit
python3 -m pip install --upgrade pip
pip3 install cibuildwheel
displayName: Install dependencies
- bash: cibuildwheel --output-dir wheelhouse .
displayName: Build wheels
- task: PublishBuildArtifacts@1
inputs: { pathtoPublish: 'wheelhouse' }
4 changes: 2 additions & 2 deletions tests/markov/msm/test_tram.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_tram_different_input_data_types(dtrajs, ttrajs, bias_matrix_as_ndarray,


def test_lagtime_too_long():
dtrajs = np.asarray([[0, 1, 0], [0, 1, 2, 1], [2, 3]])
dtrajs = np.asarray([[0, 1, 0], [0, 1, 2, 1], [2, 3]], dtype=object)
bias_matrices = [np.random.rand(len(traj), 3) for traj in dtrajs]
tram = TRAM(maxiter=100, lagtime=2)
with np.testing.assert_raises(ValueError):
Expand Down Expand Up @@ -150,7 +150,7 @@ def to_numpy_arrays(dtrajs, bias_matrices, ttrajs):
ttrajs = [np.asarray(traj) for traj in ttrajs]

if not isinstance(bias_matrices, np.ndarray):
bias_matrices = [np.asarray(M) for M in bias_matrices]
bias_matrices = [np.asarray(M, dtype=object) for M in bias_matrices]

return dtrajs, bias_matrices, ttrajs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.. moduleauthor:: B.Trendelkamp-Schroer <benjamin DOT trendelkamp-schroer AT fu-berlin DOT de>
"""

import flaky
import numpy as np
import pytest
from deeptime.markov.tools.estimation import transition_matrix as tmatrix
Expand Down Expand Up @@ -60,7 +60,8 @@ def test_reversible(dtype):


@pytest.mark.parametrize("dtype", (np.float32, np.float64, np.longdouble))
def test_reversible_pi(fixed_seed, dtype):
@flaky.flaky(3)
def test_reversible_pi(dtype):
C = np.array([[7048, 6, 0], [6, 2, 3], [0, 3, 2933]]).astype(dtype)
pi = np.array([0.70532947, 0.00109989, 0.29357064])
P_mle = tmatrix(C, reversible=True, mu=pi)
Expand Down
2 changes: 1 addition & 1 deletion tests/markov/tools/flux/test_reactive_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def test_coarse_grain(sparse_mode):
Csym = C + C.T
P = Csym / np.sum(Csym, axis=1)[:, np.newaxis]
if sparse_mode:
P = sparse.csr_matrix(P)
P = sparse.lil_matrix(P)
msm = MarkovStateModel(P)
tpt = msm.reactive_flux([0, 4], [11, 15])
coarse_sets = [[2, 3, 6, 7], [10, 11, 14, 15], [0, 1, 4, 5], [8, 9, 12, 13], ]
Expand Down
2 changes: 1 addition & 1 deletion tests/plots/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_network(labels, cmap):

flux = MarkovStateModel(Psparse).reactive_flux([2], [3])

positions = nx.planar_layout(nx.from_scipy_sparse_matrix(flux.gross_flux))
positions = nx.planar_layout(nx.from_scipy_sparse_array(flux.gross_flux))
pl = Network(flux.gross_flux, positions, edge_curvature=2., edge_labels=labels,
state_colors=np.linspace(0, 1, num=flux.n_states), cmap=cmap)
ax = pl.plot()
Expand Down

0 comments on commit 66c10e4

Please sign in to comment.