From 8b2a530de9153791049f095cf29438d054841163 Mon Sep 17 00:00:00 2001 From: vherdeiro-at-036205687955 Date: Tue, 25 Jun 2019 17:07:29 +0100 Subject: [PATCH 1/2] replaced all imports of tqdm with tqdm.auto --- pymc3/parallel_sampling.py | 6 ++---- pymc3/sampling.py | 2 +- pymc3/stats.py | 3 +-- pymc3/tuning/starting.py | 2 +- pymc3/variational/inference.py | 8 ++++---- requirements.txt | 2 +- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pymc3/parallel_sampling.py b/pymc3/parallel_sampling.py index 0c3ee164e4..41851aa165 100644 --- a/pymc3/parallel_sampling.py +++ b/pymc3/parallel_sampling.py @@ -347,9 +347,7 @@ def __init__( progressbar=True, ): if progressbar: - import tqdm - - tqdm_ = tqdm.tqdm + from tqdm.auto import tqdm if any(len(arg) != chains for arg in [seeds, start_points]): raise ValueError("Number of seeds and start_points must be %s." % chains) @@ -371,7 +369,7 @@ def __init__( self._progress = None if progressbar: - self._progress = tqdm_( + self._progress = tqdm( total=chains * (draws + tune), unit="draws", desc="Sampling %s chains" % chains, diff --git a/pymc3/sampling.py b/pymc3/sampling.py index d6dedbc8d2..d9f4b1184b 100644 --- a/pymc3/sampling.py +++ b/pymc3/sampling.py @@ -24,7 +24,7 @@ from .exceptions import IncorrectArgumentsError from pymc3.step_methods.hmc import quadpotential import pymc3 as pm -from tqdm import tqdm +from tqdm.auto import tqdm import sys diff --git a/pymc3/stats.py b/pymc3/stats.py index 63488c4451..830f449d91 100644 --- a/pymc3/stats.py +++ b/pymc3/stats.py @@ -9,7 +9,7 @@ from scipy.stats import dirichlet from scipy.optimize import minimize from scipy.signal import fftconvolve -from tqdm import tqdm +from tqdm.auto import tqdm from .model import modelcontext from .util import get_default_varnames @@ -1110,4 +1110,3 @@ def r2_score(y_true, y_pred, round_to=2): r2_mean = np.around(np.mean(r2), round_to) r2_std = np.around(np.std(r2), round_to) return r2_r(r2_median, r2_mean, r2_std) - diff --git a/pymc3/tuning/starting.py b/pymc3/tuning/starting.py index 1df27609f1..005b97f1aa 100644 --- a/pymc3/tuning/starting.py +++ b/pymc3/tuning/starting.py @@ -6,7 +6,7 @@ from scipy.optimize import minimize import numpy as np from numpy import isfinite, nan_to_num -from tqdm import tqdm +from tqdm.auto import tqdm import pymc3 as pm from ..vartypes import discrete_types, typefilter from ..model import modelcontext, Point diff --git a/pymc3/variational/inference.py b/pymc3/variational/inference.py index 23185aec7d..84af1cdd0d 100644 --- a/pymc3/variational/inference.py +++ b/pymc3/variational/inference.py @@ -3,7 +3,7 @@ import collections import numpy as np -import tqdm +from tqdm.auto import tqdm import pymc3 as pm from pymc3.variational import test_functions @@ -73,7 +73,7 @@ def run_profiling(self, n=1000, score=None, **kwargs): score=score, fn_kwargs=fn_kwargs, **kwargs ) - progress = tqdm.trange(n) + progress = tqdm(range(n)) try: for _ in progress: step_func() @@ -129,7 +129,7 @@ def fit(self, n=10000, score=None, callbacks=None, progressbar=True, callbacks = [] score = self._maybe_score(score) step_func = self.objective.step_function(score=score, **kwargs) - with tqdm.trange(n, disable=not progressbar) as progress: + with tqdm(range(n), disable=not progressbar) as progress: if score: state = self._iterate_with_loss(0, n, step_func, progress, callbacks) else: @@ -259,7 +259,7 @@ def refine(self, n, progressbar=True): if self.state is None: raise TypeError('Need to call `.fit` first') i, step, callbacks, score = self.state - with tqdm.trange(n, disable=not progressbar) as progress: + with tqdm(range(n), disable=not progressbar) as progress: if score: state = self._iterate_with_loss(i, n, step, progress, callbacks) else: diff --git a/requirements.txt b/requirements.txt index 17c14b1268..62690d1ac3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,5 @@ numpy>=1.13.0 scipy>=0.18.1 pandas>=0.18.0 patsy>=0.4.0 -tqdm>=4.8.4 +tqdm>=4.28.1 h5py>=2.7.0 From c894f689f750fdae341f75d9c6aa693cdce46c1d Mon Sep 17 00:00:00 2001 From: vherdeiro-at-036205687955 Date: Wed, 26 Jun 2019 12:23:38 +0100 Subject: [PATCH 2/2] added release note line for new notebook progress bars look --- RELEASE-NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index c59e3b6873..d07c7a340d 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -6,6 +6,7 @@ - Distinguish between `Data` and `Deterministic` variables when graphing models with graphviz. PR [#3491](https://github.com/pymc-defs/pymc3/pulls/3491). - Sequential Monte Carlo - Approximate Bayesian Computation step method is now available. The implementation is in an experimental stage and will be further improved. +- Makes use of new `tqdm` auto import mode which adapts the progress bars to console or jupyter notebook environments. ### Maintenance - Moved math operations out of `Rice`, `TruncatedNormal`, `Triangular` and `ZeroInflatedNegativeBinomial` `random` methods. Math operations on values returned by `draw_values` might not broadcast well, and all the `size` aware broadcasting is left to `generate_samples`. Fixes [#3481](https://github.com/pymc-devs/pymc3/issues/3481) and [#3508](https://github.com/pymc-devs/pymc3/issues/3508)