Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace progressbar2 by tqdm #502

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
replace progressbar2 by tqdm
  • Loading branch information
chaozg committed Sep 2, 2024
commit 13ab258afabcbc9e583464ad97ab00ae12794a53
10 changes: 5 additions & 5 deletions cuqi/experimental/mcmc/_gibbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import warnings

try:
from progressbar import progressbar
from tqdm import tqdm
except ImportError:
def progressbar(iterable, **kwargs):
warnings.warn("Module mcmc: Progressbar not found. Install progressbar2 to get sampling progress.")
def tqdm(iterable, **kwargs):
warnings.warn("Module mcmc: tqdm not found. Install tqdm to get sampling progress.")
return iterable

# Not subclassed from Sampler as Gibbs handles multiple samplers and samples multiple parameters
Expand Down Expand Up @@ -152,13 +152,13 @@ def validate_targets(self):

def sample(self, Ns) -> 'HybridGibbs':
""" Sample from the joint distribution using Gibbs sampling """
for _ in progressbar(range(Ns)):
for _ in tqdm(range(Ns)):
self.step()
self._store_samples()

def warmup(self, Nb) -> 'HybridGibbs':
""" Warmup (tune) the Gibbs sampler """
for idx in progressbar(range(Nb)):
for idx in tqdm(range(Nb)):
self.step()
self.tune(idx)
self._store_samples()
Expand Down
10 changes: 5 additions & 5 deletions cuqi/experimental/mcmc/_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from cuqi.samples import Samples

try:
from progressbar import progressbar
from tqdm import tqdm
except ImportError:
def progressbar(iterable, **kwargs):
warnings.warn("Module mcmc: Progressbar not found. Install progressbar2 to get sampling progress.")
def tqdm(iterable, **kwargs):
warnings.warn("Module mcmc: tqdm not found. Install tqdm to get sampling progress.")
return iterable

class Sampler(ABC):
Expand Down Expand Up @@ -220,7 +220,7 @@ def sample(self, Ns, batch_size=0, sample_path='./CUQI_samples/') -> 'Sampler':
if hasattr(self, "_pre_sample"): self._pre_sample()

# Draw samples
for _ in progressbar( range(Ns) ):
for _ in tqdm( range(Ns) ):

# Perform one step of the sampler
acc = self.step()
Expand Down Expand Up @@ -260,7 +260,7 @@ def warmup(self, Nb, tune_freq=0.1) -> 'Sampler':
if hasattr(self, "_pre_warmup"): self._pre_warmup()

# Draw warmup samples with tuning
for idx in progressbar(range(Nb)):
for idx in tqdm(range(Nb)):

# Perform one step of the sampler
acc = self.step()
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ sphinx-panels
sphinx-copybutton
sphinx-gallery
versioneer==0.26
progressbar2 # For experimental mcmc module
tqdm # For experimental mcmc module
Loading