Skip to content

Commit 7745c96

Browse files
authored
enable python 3.10 in build matrix (#167)
* enable python 3.10 in build matrix * nox only run doctests if torch available
1 parent a99fafb commit 7745c96

File tree

14 files changed

+53
-52
lines changed

14 files changed

+53
-52
lines changed

deeptime/basis/src/basis_bindings.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ np_array<std::int32_t> computePowerMatrix(std::size_t stateSpaceDim, std::size_t
9292
}
9393

9494
template<typename dtype>
95-
np_array<dtype> evaluateMonomials(ssize_t p, const np_array_nfc<dtype> &xArr,
95+
np_array<dtype> evaluateMonomials(py::ssize_t p, const np_array_nfc<dtype> &xArr,
9696
const np_array<std::int32_t> &powerMatrixArr) {
9797
auto x = xArr.template unchecked<2>();
9898
auto stateSpaceDim = x.shape(0);
@@ -106,10 +106,10 @@ np_array<dtype> evaluateMonomials(ssize_t p, const np_array_nfc<dtype> &xArr,
106106
std::fill(outArr.mutable_data(), outArr.mutable_data() + outArr.size(), static_cast<dtype>(1));
107107
auto out = outArr.template mutable_unchecked<2>();
108108

109-
for (ssize_t i = 0; i < nMonomials; ++i) {
110-
for (ssize_t j = 0; j < stateSpaceDim; ++j) {
109+
for (py::ssize_t i = 0; i < nMonomials; ++i) {
110+
for (py::ssize_t j = 0; j < stateSpaceDim; ++j) {
111111
auto power = powerMatrix(stateSpaceDim - 1 - j, i);
112-
for (ssize_t k = 0; k < nTestPoints; ++k) {
112+
for (py::ssize_t k = 0; k < nTestPoints; ++k) {
113113
out(i, k) *= std::pow(x(j, k), power);
114114
}
115115
}
@@ -131,9 +131,9 @@ PYBIND11_MODULE(_basis_bindings, m) {
131131
std::vector<std::string> out;
132132
out.reserve(nMonomials);
133133

134-
for (ssize_t i = 0; i < nMonomials; ++i) {
134+
for (py::ssize_t i = 0; i < nMonomials; ++i) {
135135
std::string monFeature {};
136-
for (ssize_t j = 0; j < stateSpaceDim; ++j) {
136+
for (py::ssize_t j = 0; j < stateSpaceDim; ++j) {
137137
auto power = powerMatrix.at(stateSpaceDim - 1 - j, i);
138138

139139
if (power != 0) {

deeptime/clustering/include/bits/kmeans_bits.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ inline std::tuple<np_array<T>, np_array<int>> cluster(const np_array_nfc<T> &np_
4343

4444
/* do the clustering */
4545
if (n_threads == 0) {
46-
for (pybind11::ssize_t i = 0; i < n_frames; ++i) {
46+
for (py::ssize_t i = 0; i < n_frames; ++i) {
4747
int argMinDist = 0;
4848
{
4949
T minDist = Metric::template compute(&chunk(i, 0), &centers(0, 0), dim);
@@ -59,7 +59,7 @@ inline std::tuple<np_array<T>, np_array<int>> cluster(const np_array_nfc<T> &np_
5959
{
6060
assignmentsPtr[i] = argMinDist;
6161
centers_counter.at(argMinDist)++;
62-
for (pybind11::ssize_t j = 0; j < dim; j++) {
62+
for (py::ssize_t j = 0; j < dim; j++) {
6363
newCentersRef(argMinDist, j) += chunk(i, j);
6464
}
6565
}
@@ -69,7 +69,7 @@ inline std::tuple<np_array<T>, np_array<int>> cluster(const np_array_nfc<T> &np_
6969
omp_set_num_threads(n_threads);
7070

7171
#pragma omp parallel for schedule(static, 1)
72-
for (pybind11::ssize_t i = 0; i < n_frames; ++i) {
72+
for (py::ssize_t i = 0; i < n_frames; ++i) {
7373
std::vector<T> dists(n_centers);
7474
for (std::size_t j = 0; j < n_centers; ++j) {
7575
dists[j] = Metric::template compute(&chunk(i, 0), &centers(j, 0), dim);
@@ -82,7 +82,7 @@ inline std::tuple<np_array<T>, np_array<int>> cluster(const np_array_nfc<T> &np_
8282
{
8383
assignmentsPtr[i] = argMinDist;
8484
centers_counter.at(static_cast<std::size_t>(argMinDist))++;
85-
for (pybind11::ssize_t j = 0; j < dim; j++) {
85+
for (py::ssize_t j = 0; j < dim; j++) {
8686
newCentersRef(argMinDist, j) += chunk(i, j);
8787
}
8888
}
@@ -115,7 +115,7 @@ inline std::tuple<np_array<T>, np_array<int>> cluster(const np_array_nfc<T> &np_
115115
std::unique_lock<std::mutex> lock(m);
116116
assignmentsPtr[i] = argMinDist;
117117
centers_counter.at(argMinDist)++;
118-
for (pybind11::ssize_t j = 0; j < dim; j++) {
118+
for (py::ssize_t j = 0; j < dim; j++) {
119119
newCentersRef(argMinDist, j) += chunk(i, j);
120120
}
121121
}
@@ -133,11 +133,11 @@ inline std::tuple<np_array<T>, np_array<int>> cluster(const np_array_nfc<T> &np_
133133
auto centers_counter_it = centers_counter.begin();
134134
for (std::size_t i = 0; i < n_centers; ++i, ++centers_counter_it) {
135135
if (*centers_counter_it == 0) {
136-
for (pybind11::ssize_t j = 0; j < dim; ++j) {
136+
for (py::ssize_t j = 0; j < dim; ++j) {
137137
newCentersRef(i, j) = centers(i, j);
138138
}
139139
} else {
140-
for (pybind11::ssize_t j = 0; j < dim; ++j) {
140+
for (py::ssize_t j = 0; j < dim; ++j) {
141141
newCentersRef(i, j) /= static_cast<T>(*centers_counter_it);
142142
}
143143
}
@@ -180,7 +180,7 @@ inline std::tuple<np_array_nfc<T>, int, int, np_array<T>> cluster_loop(
180180
it += 1;
181181
} while (it < max_iter && !converged);
182182
int res = converged ? 0 : 1;
183-
np_array<T> npInertias({static_cast<pybind11::ssize_t>(inertias.size())});
183+
np_array<T> npInertias({static_cast<py::ssize_t>(inertias.size())});
184184
std::copy(inertias.begin(), inertias.end(), npInertias.mutable_data());
185185
return std::make_tuple(currentCenters, res, it, npInertias);
186186
}

deeptime/markov/hmm/_bindings/include/OutputModelUtils.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ np_array<std::int64_t> generateObservationTrajectory(const np_array_nfc<State> &
5252
auto nThreads = std::thread::hardware_concurrency();
5353
std::vector<deeptime::thread::scoped_thread> threads;
5454
threads.reserve(nThreads);
55-
auto grainSize = std::max(static_cast<pybind11::ssize_t>(1), nTimesteps / nThreads);
55+
auto grainSize = std::max(static_cast<py::ssize_t>(1), nTimesteps / nThreads);
5656

5757
const auto* hiddenStateTrajectoryBuf = hiddenStateTrajectory.data();
5858
const auto* outputProbabilitiesBuf = outputProbabilities.data();
5959

60-
for(pybind11::ssize_t nextIndex = 0; nextIndex < nTimesteps; nextIndex += grainSize) {
60+
for(py::ssize_t nextIndex = 0; nextIndex < nTimesteps; nextIndex += grainSize) {
6161
auto beginIndex = nextIndex;
6262
auto endIndex = std::min(nextIndex+grainSize, nTimesteps);
6363
threads.emplace_back([hiddenStateTrajectoryBuf, outputProbabilitiesBuf,
6464
beginIndex, endIndex, outputPtr, nObs]{
6565
auto generator = deeptime::rnd::randomlySeededGenerator();
6666
std::discrete_distribution<> ddist;
67-
for(pybind11::ssize_t t = beginIndex; t < endIndex; ++t) {
67+
for(py::ssize_t t = beginIndex; t < endIndex; ++t) {
6868
auto state = hiddenStateTrajectoryBuf[t];
6969
auto begin = outputProbabilitiesBuf + state * nObs; // outputProbabilities.at(state, 0)
7070
auto end = outputProbabilitiesBuf + (state+1) * nObs; // outputProbabilities.at(state+1, 0)
@@ -94,7 +94,7 @@ np_array<dtype> toOutputProbabilityTrajectory(const np_array_nfc<State> &observa
9494
auto T = observations.shape(0);
9595

9696
#pragma omp parallel for collapse(2) default(none) firstprivate(P, obs, nHidden, nObs, T, outputPtr)
97-
for (ssize_t t = 0; t < T; ++t) {
97+
for (py::ssize_t t = 0; t < T; ++t) {
9898
for (std::size_t i = 0; i < nHidden; ++i) {
9999
outputPtr[t*nHidden + i] = P[obs[t] + i*nObs];
100100
}
@@ -107,7 +107,7 @@ template<typename dtype, typename State>
107107
void sample(const std::vector<np_array_nfc<State>> &observationsPerState, np_array_nfc<dtype> &outputProbabilities,
108108
const np_array_nfc<dtype> &prior) {
109109
auto nObs = outputProbabilities.shape(1);
110-
ssize_t currentState{0};
110+
py::ssize_t currentState{0};
111111

112112
auto& generator = deeptime::rnd::staticThreadLocalGenerator();
113113
deeptime::rnd::dirichlet_distribution<dtype> dirichlet;
@@ -126,7 +126,7 @@ void sample(const std::vector<np_array_nfc<State>> &observationsPerState, np_arr
126126
std::vector<dtype> histPrivate(nObs, 0);
127127

128128
#pragma omp for
129-
for(ssize_t i = 0; i < T; ++i) {
129+
for(py::ssize_t i = 0; i < T; ++i) {
130130
++histPrivate.at(observationsBuf[i]);
131131
}
132132

@@ -140,7 +140,7 @@ void sample(const std::vector<np_array_nfc<State>> &observationsPerState, np_arr
140140

141141
#else
142142

143-
for (ssize_t i = 0; i < observations.size(); ++i) {
143+
for (py::ssize_t i = 0; i < observations.size(); ++i) {
144144
++hist.at(observations.at(i));
145145
}
146146

@@ -228,7 +228,7 @@ np_array<dtype> pO(dtype o, const np_array_nfc<dtype> &mus, const np_array_nfc<d
228228
auto sigmasBuf = sigmas.data();
229229

230230
#pragma omp parallel for
231-
for (pybind11::ssize_t i = 0; i < N; ++i) {
231+
for (py::ssize_t i = 0; i < N; ++i) {
232232
pBuf[i] = sample(o, musBuf[i], sigmasBuf[i]);
233233
}
234234

@@ -306,7 +306,7 @@ std::tuple<np_array<dtype>, np_array<dtype>> fit(std::size_t nHiddenStates, cons
306306
for (decltype(nHiddenStates) i = 0; i < nHiddenStates; ++i) {
307307
dtype dot = 0;
308308
dtype wStateSum = 0;
309-
for (ssize_t t = 0; t < obs.shape(0); ++t) {
309+
for (py::ssize_t t = 0; t < obs.shape(0); ++t) {
310310
dot += w.at(t, i) * obsPtr[t];
311311
wStateSum += w.at(t, i);
312312
}
@@ -335,7 +335,7 @@ std::tuple<np_array<dtype>, np_array<dtype>> fit(std::size_t nHiddenStates, cons
335335
for (decltype(nHiddenStates) i = 0; i < nHiddenStates; ++i) {
336336
dtype wStateSum = 0;
337337
dtype sigmaUpdate = 0;
338-
for (ssize_t t = 0; t < obs.shape(0); ++t) {
338+
for (py::ssize_t t = 0; t < obs.shape(0); ++t) {
339339
auto sqrty = static_cast<dtype>(obsPtr[t]) - static_cast<dtype>(means.at(i));
340340
sigmaUpdate += w.at(t, i) * sqrty*sqrty;
341341
wStateSum += w.at(t, i);

deeptime/markov/tools/estimation/dense/_bindings/include/sampler.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class RevPiSampler {
3434
auto b = arrB.template unchecked<1>();
3535
auto X = arrX.template mutable_unchecked<2>();
3636

37-
for (ssize_t k = 0; k < M; ++k) {
38-
for (ssize_t l = 0; l < k; ++l) {
37+
for (py::ssize_t k = 0; k < M; ++k) {
38+
for (py::ssize_t l = 0; l < k; ++l) {
3939
if (C(k, l) + C(k, l) > 0) {
4040
auto xkl = X(k, l);
4141
auto xkl_new = sample_quad(X(k, l), X(k, k), X(l, l),

deeptime/markov/tools/estimation/sparse/mle/newton/objective_sparse_ops.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "common.h"
66

77
template<typename dtype>
8-
void convertImpl(ssize_t M, const np_array_nfc<dtype> &xArr, const np_array_nfc<dtype> &yArr,
8+
void convertImpl(py::ssize_t M, const np_array_nfc<dtype> &xArr, const np_array_nfc<dtype> &yArr,
99
const np_array_nfc<dtype> &dataArr, np_array_nfc<dtype> &nuArr,
1010
np_array_nfc<dtype> &dataPArr, np_array_nfc<dtype> &diagPArr,
1111
const np_array<std::int32_t> &indicesArr, const np_array<std::int32_t> &indptrArr) {
@@ -22,7 +22,7 @@ void convertImpl(ssize_t M, const np_array_nfc<dtype> &xArr, const np_array_nfc<
2222
auto nu = nuArr.template mutable_unchecked<1>();
2323

2424
// Loop over rows of Cs
25-
for (ssize_t k = 0; k < M; ++k) {
25+
for (py::ssize_t k = 0; k < M; ++k) {
2626
nu(k) = std::exp(y(k));
2727
// Loop over nonzero entries in row of Cs
2828
for (std::int32_t l = indptr(k); l < indptr(k + 1); ++l) {
@@ -46,7 +46,7 @@ void convertImpl(ssize_t M, const np_array_nfc<dtype> &xArr, const np_array_nfc<
4646
}
4747

4848
template<typename dtype>
49-
void FImpl(ssize_t M, const np_array_nfc<dtype> &xArr, const np_array_nfc<dtype> &yArr,
49+
void FImpl(py::ssize_t M, const np_array_nfc<dtype> &xArr, const np_array_nfc<dtype> &yArr,
5050
const np_array_nfc<dtype> &cArr, const np_array_nfc<dtype> &dataArr,
5151
np_array_nfc<dtype> &FvalArr,
5252
const np_array<std::int32_t> &indicesArr, const np_array<std::int32_t> &indptrArr) {
@@ -61,7 +61,7 @@ void FImpl(ssize_t M, const np_array_nfc<dtype> &xArr, const np_array_nfc<dtype>
6161
auto Fval = FvalArr.template mutable_unchecked<1>();
6262

6363
// Loop over rows of Cs
64-
for (ssize_t k = 0; k < M; ++k) {
64+
for (py::ssize_t k = 0; k < M; ++k) {
6565
Fval(k) += 1.0;
6666
Fval(k + M) -= c(k);
6767

@@ -83,7 +83,7 @@ void FImpl(ssize_t M, const np_array_nfc<dtype> &xArr, const np_array_nfc<dtype>
8383
}
8484

8585
template<typename dtype>
86-
void dfImpl(ssize_t M, const np_array_nfc<dtype> &xArr, const np_array_nfc<dtype> &yArr,
86+
void dfImpl(py::ssize_t M, const np_array_nfc<dtype> &xArr, const np_array_nfc<dtype> &yArr,
8787
const np_array_nfc<dtype> &dataArr,
8888
np_array_nfc<dtype> &dataHxxArr, np_array_nfc<dtype> &dataHyyArr, np_array_nfc<dtype> &dataHyxArr,
8989
np_array_nfc<dtype> &diagDxxArr, np_array_nfc<dtype> &diagDyyArr, np_array_nfc<dtype> &diagDyxArr,
@@ -104,7 +104,7 @@ void dfImpl(ssize_t M, const np_array_nfc<dtype> &xArr, const np_array_nfc<dtype
104104

105105

106106
// Loop over rows of Cs
107-
for (ssize_t k = 0; k < M; ++k) {
107+
for (py::ssize_t k = 0; k < M; ++k) {
108108
// Loop over nonzero entries in row of Cs
109109
for (std::int32_t l = indptr(k); l < indptr(k + 1); ++l) {
110110
// Column index of current element

deeptime/markov/tools/kahandot/kahandot_module.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ template<typename dtype>
88
auto ksum(const dtype* const begin, const dtype* const end) -> dtype {
99
auto n = std::distance(begin, end);
1010
dtype sum {0};
11-
ssize_t o {0};
11+
py::ssize_t o {0};
1212
dtype correction {0};
1313

1414
while (n--) {
@@ -44,11 +44,11 @@ auto kdot(const np_array_nfc<dtype> &arrA, const np_array_nfc<dtype> &arrB) -> n
4444

4545
auto C = Carr.template mutable_unchecked<2>();
4646

47-
for (ssize_t i = 0; i < n; ++i) {
48-
for (ssize_t j = 0; j < l; ++j) {
47+
for (py::ssize_t i = 0; i < n; ++i) {
48+
for (py::ssize_t j = 0; j < l; ++j) {
4949
dtype err{0};
5050
dtype sum{0};
51-
for (ssize_t k = 0; k < m; ++k) {
51+
for (py::ssize_t k = 0; k < m; ++k) {
5252
auto y = A(i, k) * B(k, j) - err;
5353
auto t = sum + y;
5454
err = (t - sum) - y;

devtools/azure-pipelines-linux.yml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
python.version: '3.8'
1313
Python39:
1414
python.version: '3.9'
15+
Python310:
16+
python.version: '3.10'
1517

1618
maxParallel: 10
1719

devtools/azure-pipelines-osx.yml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
python.version: '3.8'
1414
Python39:
1515
python.version: '3.9'
16+
Python310:
17+
python.version: '3.10'
1618

1719
maxParallel: 10
1820

devtools/azure-pipelines-win.yml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
python.version: '3.8'
1313
Python39:
1414
python.version: '3.9'
15+
Python310:
16+
python.version: '3.10'
1517

1618
maxParallel: 10
1719

devtools/conda-recipe/meta.yaml

-8
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,3 @@ requirements:
3636
test:
3737
imports:
3838
- deeptime
39-
source_files:
40-
- tests/*
41-
requires:
42-
- pytest
43-
- pytest-sugar
44-
- scikit-learn
45-
- pytorch
46-
- cpuonly

devtools/conda-recipe/run_test.py

-5
This file was deleted.

devtools/conda-setup+build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ steps:
1010
displayName: 'Update and install dependencies'
1111
continueOnError: false
1212
- bash: |
13-
conda build devtools --python 3.9 --numpy 1.21 -c pytorch
13+
conda build devtools --python 3.10 --numpy 1.21
1414
displayName: 'Build and test'
1515
continueOnError: false

noxfile.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ def tests(session: nox.Session) -> None:
2424
session.log("Running without coverage")
2525
cov_args = []
2626

27-
session.run("pytest", '-vv', '--doctest-modules', '--durations=20', *cov_args, '--pyargs', "tests/", 'deeptime')
27+
test_dirs = ["tests/"]
28+
try:
29+
import torch
30+
# only run doctests if torch is available
31+
test_dirs.append('deeptime')
32+
except ImportError:
33+
pass
34+
35+
session.run("pytest", '-vv', '--doctest-modules', '--durations=20', *cov_args, '--pyargs', *test_dirs)
2836

2937

3038
@nox.session(reuse_venv=True)

tests/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ scipy==1.7.2
66
pybind11==2.8.1
77
scikit-learn==1.0.1
88
threadpoolctl==3.0.0
9-
torch==1.10.0
9+
torch>=1.10.0; python_version<"3.10"
1010

1111
pytest==6.2.5
1212
pytest-cov

0 commit comments

Comments
 (0)