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

Fixing unreasonable memory usage when creating an InferenceData object from an emcee sampler #2215

Merged
merged 4 commits into from
Feb 21, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### New features

### Maintenance and fixes
- Fix memory usage and improve efficiency in `from_emcee` ([2215](https://github.com/arviz-devs/arviz/pull/2215))

### Deprecation

Expand Down
11 changes: 6 additions & 5 deletions arviz/data/io_emcee.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ def __init__(
def posterior_to_xarray(self):
"""Convert the posterior to an xarray dataset."""
# Use emcee3 syntax, else use emcee2
if hasattr(self.sampler, "get_chain"):
samples_ary = self.sampler.get_chain().swapaxes(0, 1)
else:
samples_ary = self.sampler.chain

data = {
var_name: (
self.sampler.get_chain()[(..., idx)].swapaxes(0, 1)
if hasattr(self.sampler, "get_chain")
else self.sampler.chain[(..., idx)]
)
var_name: (samples_ary[(..., idx)])
for idx, var_name in zip(self.slices, self.var_names)
}
return dict_to_dataset(
Expand Down