# Saving inference data to netcdf when using nutpie

**URL:** <https://discourse.pymc.io/t/saving-inference-data-to-netcdf-when-using-nutpie/17718>\
**Category:** v5\
**Created:** [May 18, 2026, 3:01pm UTC](https://discourse.pymc.io/t/saving-inference-data-to-netcdf-when-using-nutpie/17718 "2026-05-18T15:01:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hyperthetical](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hyperthetical/32/9453_2.png) [@Hyperthetical](https://discourse.pymc.io/u/Hyperthetical)\
**Post date:** [May 18, 2026, 3:01pm UTC](https://discourse.pymc.io/t/saving-inference-data-to-netcdf-when-using-nutpie/17718/1 "2026-05-18T15:01:39Z")

</div>

I have a model that works fine and saves to a netcdf file fine when using the default nuts sampler. However, when using nutpie I cannot save a netcdf file. What I get is TypeError stemming from the sample\_stats attribute.

Invalid value for attr ‘sample\_stats’: {‘inference\_library’: …ect

I tried removing the attribute via delattr but the same error occurs again when try to\_netcdf afterwards. Help would be wonderful.

---

<div class="post-metadata">

**Author:** ![Hyperthetical](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hyperthetical/32/9453_2.png) [@Hyperthetical](https://discourse.pymc.io/u/Hyperthetical)\
**Post date:** [May 18, 2026, 5:19pm UTC](https://discourse.pymc.io/t/saving-inference-data-to-netcdf-when-using-nutpie/17718/2 "2026-05-18T17:19:03Z")

</div>

I have reproduced this on a second computer in a fresh conda env. A workaround is pymc 6.0, but it would be nice to fix on v5.

---

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [May 18, 2026, 5:25pm UTC](https://discourse.pymc.io/t/saving-inference-data-to-netcdf-when-using-nutpie/17718/3 "2026-05-18T17:25:07Z")

</div>

late v5 is a bit of a dependency tangle, what are your pymc arviz xarray and nutpie versions? Also @OriolAbril and @aloctavodia because this might be more of an arviz thing than pymc

---

<div class="post-metadata">

**Author:** ![Hyperthetical](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hyperthetical/32/9453_2.png) [@Hyperthetical](https://discourse.pymc.io/u/Hyperthetical)\
**Post date:** [May 18, 2026, 6:08pm UTC](https://discourse.pymc.io/t/saving-inference-data-to-netcdf-when-using-nutpie/17718/4 "2026-05-18T18:08:11Z")

</div>

pymc 5.28.4

arviz 0.23.4

nutpie 0.16.10

xarray 2026.4.0

---

<div class="post-metadata">

**Author:** ![aseyboldt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/aseyboldt/32/5795_2.png) [@aseyboldt](https://discourse.pymc.io/u/aseyboldt)\
**Post date:** [May 20, 2026, 12:42pm UTC](https://discourse.pymc.io/t/saving-inference-data-to-netcdf-when-using-nutpie/17718/5 "2026-05-20T12:42:34Z")

</div>

This looks like a problem I might have introduced in nutpie 0.16.10, when I added more sampler info int the attributes. But when I check locally everything seems to work as is should. Can you share the code you used, the full error message and `trace.sample_stats.attrs`?

---

<div class="post-metadata">

**Author:** ![bridgeland](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/bridgeland/32/2773_2.png) [@bridgeland](https://discourse.pymc.io/u/bridgeland)\
**Post date:** [June 10, 2026, 2:02pm UTC](https://discourse.pymc.io/t/saving-inference-data-to-netcdf-when-using-nutpie/17718/6 "2026-06-10T14:02:56Z")

</div>

I am also seeing this error, with almost the same combination of versions, just pymc 5.28.5 instead of 5.28.4. Error message:

```python
TypeError: Invalid value for attr 'sample_stats': {'inference_library': 'nutpie', 'inference_library_version': '0.16.10', 'inference_library_settings': '{"sampler": "nuts", "adaptation": "diag", "settings": {"num_tune": 1000, "num_draws": 600, "maxdepth": 10, "mindepth": 0, "store_gradient": false, "store_unconstrained": false, "store_transformed": false, "max_energy_error": 1000.0, "store_divergences": false, "adapt_options": {"step_size_settings": {"target_accept": 0.9, "initial_step": 0.1, "jitter": 0.1, "adapt_options": {"method": "DualAverage", "dual_average": {"k": 0.75, "t0": 10.0, "gamma": 0.05, "max_step_size": 3.141592653589793}, "adam": {"beta1": 0.9, "beta2": 0.999, "epsilon": 1e-08, "learning_rate": 0.05}}}, "mass_matrix_options": {"store_mass_matrix": false, "use_grad_based_estimate": true}, "early_window": 0.3, "step_size_window": 0.15, "mass_matrix_switch_freq": 80, "early_mass_matrix_switch_freq": 10, "mass_matrix_update_freq": 1, "mass_matrix_window_growth": 1.5}, "check_turning": true, "target_integration_time": null, "trajectory_kind": "Euclidean", "num_chains": 2, "seed": 18013295764713678085, "extra_doublings": 0}}'}. For serialization to netCDF files, its value must be of one of the following types: str, Number, ndarray, number, list, tuple, bytes

```

```python
synth.history_trace.sample_stats.attrs
{'created_at': '2026-06-10T12:58:36.165129+00:00', 'arviz_version': '0.23.4'}

```

I cannot replicate the error with a small example, so perhaps some combination of settings or model complexity.

Perhaps this is a reason to upgrade to pymc 6?

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [June 11, 2026, 1:54am UTC](https://discourse.pymc.io/t/saving-inference-data-to-netcdf-when-using-nutpie/17718/7 "2026-06-11T01:54:09Z")

</div>

> [@bridgeland](#):
>
> Perhaps this is a reason to upgrade to pymc 6?

There are many more reasons 😃
