Skip to content

Truncate retrieved arrays to chain length #39

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 2 commits into from
Jul 27, 2022
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
2 changes: 1 addition & 1 deletion mcbackend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
pass


__version__ = "0.1.1"
__version__ = "0.1.2"
10 changes: 7 additions & 3 deletions mcbackend/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ def to_inferencedata(self, **kwargs) -> InferenceData:
posterior = collections.defaultdict(list)
sample_stats = collections.defaultdict(list)
for c, chain in enumerate(chains):
# Every retrieved array is shortened to the previously determined chain length.
# This is needed for database backends which may get inserts inbetween.
clen = chain_lengths[chain.cid]

# Obtain a mask by which draws can be split into warmup/posterior
if "tune" in chain.sample_stats:
tune = chain.get_stats("tune").astype(bool)
tune = chain.get_stats("tune")[:clen].astype(bool)
else:
if c == 0:
_log.warning(
Expand All @@ -200,12 +204,12 @@ def to_inferencedata(self, **kwargs) -> InferenceData:

# Split all variables draws into warmup/posterior
for var in variables:
draws = chain.get_draws(var.name)
draws = chain.get_draws(var.name)[:clen]
warmup_posterior[var.name].append(draws[tune])
posterior[var.name].append(draws[~tune])
# Same for sample stats
for svar in self.meta.sample_stats:
stats = chain.get_stats(svar.name)
stats = chain.get_stats(svar.name)[:clen]
warmup_sample_stats[svar.name].append(stats[tune])
sample_stats[svar.name].append(stats[~tune])

Expand Down
4 changes: 3 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
arviz
clickhouse-driver
flake8
pymc>=4.0.1
pymc==4.1.4
pytest
pytest-cov
# Temporary pin to fix Aesara import
setuptools>=48.0.0
twine
wheel