Saving inference data to netcdf when using nutpie

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.

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.

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

pymc 5.28.4

arviz 0.23.4

nutpie 0.16.10

xarray 2026.4.0

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?

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:

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
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?

There are many more reasons :smiley: