Skip to content

Avoid repeated status polling in smc #7351

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

Merged
merged 1 commit into from
Jun 17, 2024
Merged
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
14 changes: 10 additions & 4 deletions pymc/smc/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import warnings

from collections import defaultdict
from concurrent.futures import ProcessPoolExecutor
from concurrent.futures import ProcessPoolExecutor, wait
from typing import Any

import cloudpickle
Expand Down Expand Up @@ -404,13 +404,19 @@ def run_chains(chains, progressbar, params, random_seed, kernel_kwargs, cores):
)

# monitor the progress:
while sum([future.done() for future in futures]) < len(futures):
done = []
remaining = futures
while len(remaining) > 0:
finished, remaining = wait(remaining, timeout=0.1)
done.extend(finished)
for task_id, update_data in _progress.items():
stage = update_data["stage"]
beta = update_data["beta"]
# update the progress bar for this task:
progress.update(
status=f"Stage: {stage} Beta: {beta:.3f}", task_id=task_id, refresh=True
status=f"Stage: {stage} Beta: {beta:.3f}",
task_id=task_id,
refresh=True,
)

return tuple(cloudpickle.loads(r.result()) for r in futures)
return tuple(cloudpickle.loads(r.result()) for r in done)
Loading